Free php web host - 70 Introduction to Java Applications Chapter 2 37
70 Introduction to Java Applications Chapter 2 37 38 System.exit( 0 ); // terminate application 39 40 } // end method main 41 42 } // end class Addition Fig. 2.9An addition program in action (part 2 of 2). Fig. 2. Lines 1 and 2, // Fig. 2.9: Addition.java // An addition program. are single-line comments stating the figure number, file name and purpose of the program. Line 4, // Java extension packages is a single-line comment specifying that the next line imports a class from the Java extension packages. Line 5, import javax.swing.JOptionPane; // import class JOptionPane indicates that the compiler should load class JOptionPanefor use in this application. As stated earlier, every Java program consists of at least one class definition. Line 7, public class Addition { begins the definition of class Addition. The file name for this public class must be Addition.java. Remember that all class definitions start with an opening left brace (at the end of line 7), {, and end with a closing right brace, }(in line 42). As stated earlier, every application begins execution with method main(lines 10 40). The left brace (line 11) marks the beginning of main s body and the corresponding right brace (line 36) marks the end of main s body. Lines 12 13, String firstNumber; // first string entered by user String secondNumber; // second string entered by user Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/2/01