|
Every .class file has a definition of one Java class. Usually you use another Java class by instantiating it and calling its methods from your class. You can do in your Java code as long as you can access its .class file. However, you cannot instantiate a Java class from the command line or from outside the JVM. Then how will you start the execution of any Java code? As a starting point, you need the ability to call the Java code from the command line. Java provides you with a special method called as the main method. This method can be called directly from the command line. The JVM calls this method whenever you try to execute a Java .class file from command-line. For instance, you can execute a Java class file Test.class as:
$ java Test
The java in the above command is a call to the Java interpreter; it first searches for Test.class file. Then it searches the main method in that class file and if present, executes it.
In this method, you can either create instances of other Java classes and call their methods or do whatever your application needs to do. Thus, it essentially provides you with an entry point from where you can start executing your Java application. That is the reason why if this particular method is present in your .class file, it becomes the Java Application instead of a mere Java class file.
|
|
An application is any standalone program capable of executing from the command line. |