How does a java program run without defining the main method?
I'm looking at some java source code and notice that the main methods are not defined
How does Java compile source code without knowing where to start?
Solution
The main method is only used when the Java virtual machine is executing code Code cannot be executed without the main method, but it can still be compiled
When compiling code, you usually specify a set of files on the command line
javac MyClass1.java MyClass2.java
The java compiler (javac) checks each class you pass to it and compiles it into Class file
One reason java source code may lack primary methods is because it is designed to be used as a library rather than executed
You may find something interesting: Although the source code compiled by the java compiler does not need a main method, the source code for the java compiler itself does have a main method