While compiling a Java class from command line with javac
, .java
is used, however .class
is not used while trying to run the main
method in a class with the java
command.
For example, for compiling a class named HelloWorld we use javac HelloWorld.java
, however to run that same class (supposing it has the main method), we write java HelloWorld
and not java HelloWorld.class
. Why is this so? The generated .class
file has the bytecode for the same class, but still only the name is passed.