What is a Java program? A Java program is an intentional interaction between a set of objects. One of the objects in a Java program must be capable of starting the interactions between the other objects. Three special Java object types can kick-start object interactions: 1) application objects (applications), 2) applet objects (applets), and 3) serv-let objects (servlets). (Servlets are part of the Java 2 Enterprise Edition (J2EE) and are therefore beyond the scope of this book, however, servlet concepts are easy to master when you understand how to write applications and applets.)
A Java application object is like an ordinary Java object with one important additional feature — it contains a special method named main(). The main() method is the starting point for program execution. When you attempt to execute an application with the java command-line tool it expects to find a main() method in the class file you are trying to execute. If you attempt to execute a class file that omits the main() method you will receive the following error:
Exception in thread "main" java.lang.NoSuchMethodError: main
The loading and execution of an application class file may result in the loading of additional class files and the creation of additional objects within the virtual machine environment. Thus, a Java program is an interaction between a set of objects.
When you talk about Java applications in your programming class or with your programmer colleagues, you will use the term “application” to refer to two things: 1) to the Java class you define in a source file that contains the main() method, and 2) to the collection of source files and class definitions that implement the solution to the problem you are trying to solve.
Another type of Java object that can start the object interaction process is an applet object. Java applet objects are created by subclassing the Applet class or the JApplet class. Appet objects are structured differently from application objects. Applets are formally discussed in chapter 21.