If you are working with a command prompt, you can type the following to compile a file:
javac MyJavaClass.java
Now, if you do just that, and there are no syntax errors, then a file called MyJavaClass.class will be created in the current directory.
IF your file has a package statement (first non-blank line), then you'll need to have a directory structure equal to the package naming structure where periods '.' are replaced with path separators: '/' or '\'.
So if you have the following simple Java file:
package foo.bar.baz;
public class MyJavaClass {
}
And you instead compile it as follows:
javac -d . MyJavaClass.java
Again, assuming everything compiles, the compiler will output MyJavaClass.class as before BUT it will also create the correct directory structure to hold the class.
The directory structure will be:
./foo/bar/baz/MyJavaClass.class
If you want to execute that class, you would have to do the following:
I suggest getting JCreator (http://www.jcreator.com/download.htm) its an alternate IDE than Net Beans, you just click compile to get a class file then run to run the class file.
Comments
when u compile ur java file a class file creates automatically
enjoy
If you are working with a command prompt, you can type the following to compile a file:
javac MyJavaClass.java
Now, if you do just that, and there are no syntax errors, then a file called MyJavaClass.class will be created in the current directory.
IF your file has a package statement (first non-blank line), then you'll need to have a directory structure equal to the package naming structure where periods '.' are replaced with path separators: '/' or '\'.
So if you have the following simple Java file:
package foo.bar.baz;
public class MyJavaClass {
}
And you instead compile it as follows:
javac -d . MyJavaClass.java
Again, assuming everything compiles, the compiler will output MyJavaClass.class as before BUT it will also create the correct directory structure to hold the class.
The directory structure will be:
./foo/bar/baz/MyJavaClass.class
If you want to execute that class, you would have to do the following:
java -cp . foo.bar.baz.MyJavaClass
in Netbeans, each time you compile the .java file it creates a class file to run it. It should be in the "classes" folder of your project.
A .class file is simply the result of compiling your .java file.
I suggest getting JCreator (http://www.jcreator.com/download.htm) its an alternate IDE than Net Beans, you just click compile to get a class file then run to run the class file.
Good Luck!
A .class file is created when you compile your program.