Naming a java file same as the public class is due to the running phase of the java file or a java class
----The steps to run a java file is
1.first the java compiler is used to compile the java file to provide an output .class file.{COMPILER phase}
2.this output .class file is interpreted by JVM{Interpreter phase}
For example to run file which has class with main method:
[javadoc]public class ABC{
public static void main(String[] args){
System.out.println("hello");
}
}
//other supporting classes
class A{
}[/javadoc]
Example 1: File aABC.java has a public class ABC Now during compilation of ABC.java will produce a byte code .class file ABC.class
We need to run this ABC.class file to run our program.
Example 2: File XYZ.java has a public class ABC Now during compilation of XYZ.java will produce a byte code .class file ABC.class
We need to run this ABC.class file to run our program
---------------------------------------------------------------------------------
This process leads to confusion in case of some large application.
Some times even these small programs also confuse due various process to run the file.
To reduce the confusion to the user Sun decided to directly make a standard that the public class needs to be the file name so that we can refer to the required class easily.
Post by:autobot
She still doesn't approve of my superhero lifestyle. Or this shameless plug:
a bit of art, as a gift, that will fit in a stocking