how to convert .java file to a .class file

.java file is the code file. A .class file is the compiled file.

It’s not exactly “conversion” – it’s compilation. Suppose your file was called “herb.java”, you would write (in the command prompt):

 javac herb.java

It will create a herb.class file in the current folder.

It is “executable” only if it contains a static void main(String[]) method inside it. If it does, you can execute it by running (again, command prompt:)

 java herb

Leave a Comment

error code: 523