Required Methods

There are three kinds of Java programs: applications, Applets, and Servlets. Servlets are outside the scope of this book. Applets will be considered in Chapter 9, "GUI Programming II: Applets." Here, I will focus only on applications. Every Java application—but not class—must have a method that looks like the one in listing 3.3.

Code Listing 3.3. Source File with the main Method Defined
public class LibraryCard
    {
       String borrowerName;
        float fines;
         public static void main(String[] args)
               {
                 System.exit(0);  // The proper (but optional) method
                                  // to exit a Java application
                }
         }

The only required method is main. It has several important parts to its signature:

  • public—This part of its signature grants access to this method from anywhere. ...

Get PURE Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.