Nick Vc wrote:So in essence this means that javac is there to remind us of errors en java runs the program ?
javac converts your code into a format (byte code) that can be executed by the JVM. In the process it reports the errors and if there are any errors then the class file (which is executed by the jvm) is not created.
Have a look at this page from Oracle's Java Tutorials.
It works as follows:
1. You create a Java source file, which is just a text file with the extension ".java", which contains the source code of your program.
2. You use the Java compiler, javac, to convert it to a ".class" file.
3. You use the java command to run the code in the .class file.
Nick Dillan wrote:Now its getting really confusing
But in fact it's really very simple
Four simple steps:
1 write your java program and save it in the your_filename.java (with .java extension)
2 call javac your_filename.java to compile this programm (javac requires the .java extension)
3. If compilation in step 2 failed, go to step 1 and correct errors in your program
4. call java your_filename (without .java extension) to run this programm
The javac command (the compiler) expects the filename of the source file as an argument. The filename has a ".java" extension, so that's what you have to type when you invoke the compiler. For example: javac MyProgram.java
The java command (that runs the compiled program) expects the class name (not a filename!) of the class to run. If your class is named "MyProgram", the command to use is: java MyProgram (without ".class", because that's not part of the name of the class). Ofcourse it will try to load a file named "MyProgram.class" when you call it - but the point to understand is that you're not specifying the filename directly, but the name of the class.