javac command for Compiler
Commands for compiling Java files
The java main is the entry point. for the Java execution.
If you write java MyClass,
then the class with the
main method is MyClass.
Note that it would be erroneous
to write java MyClass.class,
since MyClass.class is not
the name of the class.
When you compile with
javac MyClass.java
you need to tell the
java compiler
the extension,
because it is a file and it needs to find it.
javac MyClass.java // CORRECT FOR FILESCommand to compile a java file: javac <java_file_name>.java [.java extension is compulsory]
Command to execute a java class: java <class_file_name> [.class extension should not be used]Digimon Evolution
Using the javac command is like making a digimon produce an evolution (compiled code) and then with the java command we can call the name for the attack and run the program.
Let us consider
an example for.
creating a Sample
Java program with name `Sample.java.
public class Sample {
public static void main(String args[]) {
System.out.println("Hi welcome to Tutorialspoint");
}
}If you compile this program
using javac command
as shown below:
C:\Examples >javac Sample.javaThis command compiles
the given java file and
generates a .class file (byte code).
And if you execute the
generated byte code (.class)
file using the java command
as shown below -
C:\Sample> java SampleIt takes byte code as input and
runs it and produces the output.