The JVM and the Starting Class 
 By Lon Hosford
 
The JVM (Java Virtual Machine) requires the name of the starting class as you have seen if you use the command line: java HelloWorld where HelloWorld is the starting class.
 
Java programs are made of one or more classes. For the most part of the course you work with one class. For applications with more than one class, usually there is one class that defines the starting point. Then the other classes are used much in the same way you are using classes from the Java API (Application Programming Interface).
 
Rules for starting class members
Remember class members are fields and methods.
 
    1. All fields are declared as static.
    2. All methods are declared as static.
    3. The main method is declared as public.
 
Here is a starting class that contains fields, the main method and one programmer defined method. The minimal required keywords are included.
 
class HelloWorld
{
    // Fields
       static int total = 10;
       static float price = 1.0;
    public static void main(String[] args)
   {
       // This is where the program starts.
          System.out.println( getCost());
 
   }
   static float getCost()
    {
        return total * price;
    }
 
}
 
Why the static keyword?
In OOP (Object Oriented Modeling) the idea of classes that represent only one object in the world is how the JVM looks at your starting class.
 
Not to say you cannot have two different starting classes with different names. Its to say that each starting class is treated as there can only be one each time the JVM is invoked with that class.
 
It is also not to say you cannot invoke the JVM more than once with the same starting class if the operating system allows multi-tasking and most do.
 
The point of knowing that the JVM is expecting with each invocation your starting class  represent only one object in your application is in the mechanics of the members of the starting class.
 
The JVM is expecting all members of your starting class to carry the keyword static in their declarations. So fields and methods must be static. The keyword static merely means there is only one.
 
Why the public keyword for the main method?
Public simply means the method is accessible by all other parts of code running inside the JVM. 
 
Details of the keywords, public, private, protected, and their omission are introduced as you learn more about Java. They indicate the access level of other classes and their objects.
 
Notice that the starting class name does not need to be declared public nor does the programmer defined method getCost.