Home  Listings  By Name  By Subject  Email  www.tomswan.com  Help 

Java 2 Just Click! Solutions

Chapter 4 Listings

© 2001 by Tom Swan. All rights reserved. Updated: 6/4/01 12:20:54 PM

Return to Listings page
Switch to Solutions by name page
Switch to Solutions by subject page


Listing 4-1 Welcome/Welcome.java Page 38

Return to top
001: class Welcome {
002:  public static void main(String args[]) {
003:   System.out.println("Welcome to Java 2 programming!");
004:  }
005: }
Return to top

Listing 4-2 NoComment/NoComment.java Page 44

Return to top
001: /* This paragraph shows that C-style comments
002:    may extend for
003:    several lines. */
004: 
005: /** The NoComment class demonstrates comment styles */
006: /** This and the last line are "Java Documentation Comments" */
007: class NoComment {
008:  public static void main(String args[]) {
009:   // This comment is not displayed
010:   System.out.println("This string is displayed");
011:   System.out.println( /* Embedded comment is not displayed */
012:    "This string is also displayed");
013:   /* This single-line C-style comment is not displayed */
014:  }
015: }
Return to top

Listing 4-3 VarDemo/VarDemo.java Page 49

Return to top
001: class VarDemo {
002:  public static void main(String args[]) {
003:   int count;   // Declare a variable
004:   count = 10;  // Assign value to variable
005:   System.out.println("Count = " + count);
006:  }
007: }
Return to top

Listing 4-4 IntDemo/IntDemo.java Page 52

Return to top
001: class IntDemo {
002:  public static void main(String args[]) {
003: 
004:   // Values in decimal, hex, and octal
005:   int decimalCount = 123; // decimal 123
006:   int hexCount = 0xF89C;  // decimal 63644
007:   int octalCount = 037;   // decimal 31
008: 
009:   // Display preceding variables
010:   System.out.println("decimalCount = " + decimalCount);
011:   System.out.println("hexCount     = " + hexCount);
012:   System.out.println("octalCount   = " + octalCount);
013: 
014:   // Variables of each integer data type
015:   byte byteCount = 0x0F;
016:   short shortCount = 32767;
017:   int intCount = 99999;
018:   long bigNumber = 0x7FFFFFFFFFFFFFFFL;  // Note final L
019: 
020:   // Display preceding variables
021:   System.out.println("byteCount    = " + byteCount);
022:   System.out.println("shortCount   = " + shortCount);
023:   System.out.println("intCount     = " + intCount);
024:   System.out.println("bigNumber    = " + bigNumber);
025:   }
026: }
Return to top