Chapter 2 Introduction to Java Applications Outline 2























































- Slides: 55

Chapter 2 - Introduction to Java Applications Outline 2. 1 2. 2 2. 3 2. 4 2. 5 2. 6 Introduction A Simple Program: Printing a Line of Text Another Java Application: Adding Integers Memory Concepts Arithmetic Decision Making: Equality and Relational Operators 2000 Prentice Hall, Inc. All rights reserved. 1

2 2. 1 Introduction • In this chapter – Introduce examples to illustrate features of Java – Two program styles - applications and applets 2000 Prentice Hall, Inc. All rights reserved.

2. 2 A Simple Program: Printing a Line of Text • Application – Program that executes using the java interpreter • Sample program – Show program, then analyze each line 2000 Prentice Hall, Inc. All rights reserved. 3

Outline 1 // Fig. 2. 1: Welcome 1. java 2 // A first program in Java program 3 4 public class Welcome 1 { 5 public static void main( String args[] ) 6 { 7 8 9 System. out. println( "Welcome to Java Programming!" ); } } Welcome to Java Programming! 2000 Prentice Hall, Inc. All rights reserved. Program Output 4

2. 2 A Simple Program: Printing a Line of Text 1 // Fig. 2. 1: Welcome 1. java – // remainder of line is comment • Comments ignored • Document and describe code – Multiple line comments: /*. . . */ /* This is a multiple line comment. It can be split over many lines */ 2 // A first program in Java – Another line of comments – Note: line numbers not part of program, added for reference 2000 Prentice Hall, Inc. All rights reserved. 5

2. 2 A Simple Program: Printing a Line of Text 3 – Blank line • Makes program more readable • Blank lines, spaces, and tabs are whitespace characters – Ignored by compiler 4 public class Welcome 1 { – Begins class definition for class Welcome 1 • Every Java program has at least one user-defined class • Keyword: words reserved for use by Java – class keyword followed by class name • Naming classes: capitalize every word – Sample. Class. Name 2000 Prentice Hall, Inc. All rights reserved. 6

2. 2 A Simple Program: Printing a Line of Text 4 public class Welcome 1 { – Name of class called identifier • Series of characters consisting of letters, digits, underscores ( _ ) and dollar signs ( $ ) • Does not begin with a digit, has no spaces • Examples: Welcome 1, $value, _value, button 7 – 7 button is invalid • Case sensitive (capitalization matters) – a 1 and A 1 are different – For chapters 2 to 7, use public keyword • Certain details not important now • Mimic certain features, discussions later 2000 Prentice Hall, Inc. All rights reserved. 7

2. 2 A Simple Program: Printing a Line of Text 4 public class Welcome 1 { – Saving files • File name is class name and. java extension • Welcome 1. java – Left brace { • Begins body of every class • Right brace ends definition (line 9) 5 public static void main( String args[] ) – Part of every Java application • Applications begin executing at main – Parenthesis indicate main is a method – Java applications contain one or more methods 2000 Prentice Hall, Inc. All rights reserved. 8

2. 2 5 A Simple Program: Printing a Line of Text public static void main( String args[] ) • Exactly one method must be called main – Methods can perform tasks and return information • void means main returns no information • For now, mimic main's first line 6 { – Left brace begins body of method definition • Ended by right brace 2000 Prentice Hall, Inc. All rights reserved. 9

2. 2 7 A Simple Program: Printing a Line of Text System. out. println( "Welcome to Java Programming!" ); – Instructs computer to perform an action • Prints string of characters – String - series characters inside double quotes • Whitespaces in strings are not ignored by compiler – System. out • Standard output object • Print to command window (i. e. , MS-DOS prompt) – Method System. out. println • Displays line of text • Argument inside parenthesis – This line known as a statement • Statements must end with semicolon ; 2000 Prentice Hall, Inc. All rights reserved. 10

2. 2 A Simple Program: Printing a Line of Text 8 } – Ends method definition 9 } – Ends class definition – Can add comments to keep track of ending braces – Lines 8 and 9 could be rewritten as: 8 9 } } // end of method main() // end of class Welcome 1 – Remember, compiler ignores comments 2000 Prentice Hall, Inc. All rights reserved. 11

2. 2 A Simple Program: Printing a Line of Text • Compiling a program – Open a command window, go to directory where program is stored – Type javac Welcome 1. java – If no errors, Welcome 1. class created • Has bytecodes that represent application • Bytecodes passed to Java interpreter • Executing a program – Type java Welcome 1 • Interpreter loads. class file for class Welcome 1 • . class extension omitted from command – Interpreter calls method main 2000 Prentice Hall, Inc. All rights reserved. 12

Outline 1 // Fig. 2. 1: Welcome 1. java 2 // A first program in Java program 3 4 public class Welcome 1 { 5 public static void main( String args[] ) 6 { 7 8 9 System. out. println( "Welcome to Java Programming!" ); } } Program Output 2000 Prentice Hall, Inc. All rights reserved. 13

2. 2 A Simple Program: Printing a Line of Text • Other methods – System. out. println • Prints argument, puts cursor on new line – System. out. print • Prints argument, keeps cursor on same line 2000 Prentice Hall, Inc. All rights reserved. 14

1 // Fig. 2. 3: Welcome 2. java 2 // Printing a line with multiple statements 1. Comments 3 4 Outline 15 public class Welcome 2 { 5 public static void main( String args[] ) 6 { 7 System. out. print( "Welcome to " ); 8 System. out. println( "Java Programming!" ); 9 2. Blank line 3. Begin class Welcome 2 3. 1 Method main } 10 } 4. Method System. out. print keeps the cursor on the same line, so System. out. println continues on the same line. 4. 1 Method System. out. println 5. end main, Welcome 2 Welcome to Java Programming! 2000 Prentice Hall, Inc. All rights reserved. Program Output

2. 2 A Simple Program: Printing a Line of Text • Escape characters – Backslash ( ) – Indicates special characters be output • Backslash combined with character makes escape sequence • n - newline r - carriage return " - double quote • t - tab \ - backslash • Usage – Can use in System. out. println or System. out. print to create new lines • System. out. println( "Welcomenton. Javan. Programming!" ); 2000 Prentice Hall, Inc. All rights reserved. 16

1 // Fig. 2. 4: Welcome 3. java 2 // Printing multiple lines with a single statement 3 4 Class Welcome 1 public class Welcome 3 { 5 public static void main( String args[] ) 6 { 7 System. out. println( "Welcomenton. Javan. Programming!" ); 8 9 Outline 17 } 1. main 2. System. out. println (uses n for newline) } Welcome to Java Programming! Program Output Notice how a new line is output for each n escape sequence. 2000 Prentice Hall, Inc. All rights reserved.

2. 2 A Simple Program: Printing a Line of Text • Display – Most Java applications use windows or a dialog box • We have used command window – Class JOption. Pane allows us to use dialog boxes • Packages – Set of predefined classes for us to use – Groups of related classes called packages • Group of all packages known as Java class library or Java applications programming interface (Java API) – JOption. Pane is in the javax. swing package • Package has classes for using Graphical User Interfaces (GUIs) 2000 Prentice Hall, Inc. All rights reserved. 18

2. 2 A Simple Program: Printing a Line of Text • Sample GUI 2000 Prentice Hall, Inc. All rights reserved. 19

2. 2 A Simple Program: Printing a Line of Text • Upcoming program – Application that uses dialog boxes – Explanation will come afterwards 2000 Prentice Hall, Inc. All rights reserved. 20

Outline 1 // Fig. 2. 6: Welcome 4. java 2 // Printing multiple lines in a dialog box 3 import javax. swing. JOption. Pane; // import class JOption. Pane Java program using dialog box 4 5 public class Welcome 4 { 6 public static void main( String args[] ) 7 { 8 JOption. Pane. show. Message. Dialog( 9 null, "Welcomenton. Javan. Programming!" ); 10 11 12 System. exit( 0 ); // terminate the program } 13 } Program Output 2000 Prentice Hall, Inc. All rights reserved. 21

2. 2 A Simple Program: Printing a Line of Text – Lines 1 -2: comments as before 3 import javax. swing. JOption. Pane; // import class JOption. Pane – import statements • Locate the classes we use • Tells compiler to load JOption. Pane from javax. swing package 4 5 public class Welcome 4 { 6 public static void main( String args[] ) 7 { – Lines 4 -7: Blank line, begin class Welcome 4 and main 2000 Prentice Hall, Inc. All rights reserved. 22

2. 2 A Simple Program: Printing a Line of Text 8 JOption. Pane. show. Message. Dialog( 9 null, "Welcomenton. Javan. Programming!" ); – Call method show. Message. Dialog of class JOption. Pane • • Requires two arguments Multiple arguments separated by commas (, ) For now, first argument always null Second argument is string to display – show. Message. Dialog is a static method of class JOption. Pane • static methods called using class name, dot (. ) then method name – All statements end with ; • A single statement can span multiple lines • Cannot split statement in middle of identifier or string 2000 Prentice Hall, Inc. All rights reserved. 23

2. 2 8 9 A Simple Program: Printing a Line of Text JOption. Pane. show. Message. Dialog( null, "Welcomenton. Javan. Programming!" ); – Executing lines 8 and 9 displays the dialog box • Automatically includes an OK button – Hides or dismisses dialog box • Title bar has string Message 2000 Prentice Hall, Inc. All rights reserved. 24

2. 2 11 A Simple Program: Printing a Line of Text System. exit( 0 ); // terminate the program – Calls static method exit of class System • Terminates application – Use with any application displaying a GUI • Because method is static, needs class name and dot (. ) • Identifiers starting with capital letters usually class names – Argument of 0 means application ended successfully • Non-zero usually means an error occurred – Class System part of package java. lang • No import statement needed • java. lang automatically imported in every Java program – Lines 12 -13: Braces to end Welcome 4 and main 2000 Prentice Hall, Inc. All rights reserved. 25

Outline 1 // Fig. 2. 6: Welcome 4. java 2 // Printing multiple lines in a dialog box 3 import javax. swing. JOption. Pane; // import class JOption. Pane 1. import statement 4 5 public class Welcome 4 { 6 public static void main( String args[] ) 7 { 8 JOption. Pane. show. Message. Dialog( 9 null, "Welcomenton. Javan. Programming!" ); 10 11 12 System. exit( 0 ); 2. Class Welcome 4 2. 1 main 2. 2 show. Message. Dialog // terminate the program } 2. 3 System. exit 13 } Program Output 2000 Prentice Hall, Inc. All rights reserved. 26

2. 3 Another Java Application: Adding Integers • Upcoming program – Use input dialogs to input two values from user – Use message dialog to display sum of the two values 2000 Prentice Hall, Inc. All rights reserved. 27

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Outline // Fig. 2. 8: Addition. java // An addition program import javax. swing. JOption. Pane; public class Addition { public static void main( { String first. Number, second. Number; int number 1, number 2, sum; // import class JOption. Pane String args[] ) // // // first string entered by user second string entered by user first number to add second number to add sum of number 1 and number 2 // read in first number from user as a string first. Number = JOption. Pane. show. Input. Dialog( "Enter first integer" ); // read in second number from user as a string second. Number = JOption. Pane. show. Input. Dialog( "Enter second integer" ); // convert numbers from type String to type int number 1 = Integer. parse. Int( first. Number ); number 2 = Integer. parse. Int( second. Number ); // add the numbers sum = number 1 + number 2; // display the results 2000 Prentice Hall, Inc. All rights reserved. Java Program using input dialogs 28

31 32 33 34 35 36 JOption. Pane. show. Message. Dialog( null, "The sum is " + sum, "Results", JOption. Pane. PLAIN_MESSAGE ); System. exit( 0 ); Outline // terminate the program } 37 } Program Output 2000 Prentice Hall, Inc. All rights reserved. 29

2. 3 Another Java Application: Adding Integers 4 import javax. swing. JOption. Pane; // import class JOption. Pane – Location of JOption. Pane for use in the program 6 public class Addition { – Begins public class Addition • Recall that file name must be Addition. java – Lines 7 -8: main 9 10 String first. Number, second. Number; // first string entered by user // second string entered by user – Declaration • first. Number and second. Number are variables 2000 Prentice Hall, Inc. All rights reserved. 30

2. 3 9 Another Java Application: Adding Integers String first. Number, 10 second. Number; // first string entered by user // second string entered by user – Variables • Location in memory that stores a value – Declare with name and data type before use • first. Number and second. Number are of data type String (package java. lang) – Hold strings • Variable name: any valid identifier • Declarations end with semicolons ; – Can declare multiple variables of the same type at a time – Use comma separated list – Can add comments to describe purpose of variables 2000 Prentice Hall, Inc. All rights reserved. 31

2. 3 Another Java Application: Adding Integers 11 int number 1, // first number to add 12 number 2, // second number to add 13 sum; // sum of number 1 and number 2 – Declares variables number 1, number 2, and sum of type int • int holds integer values (whole numbers): i. e. , 0, -4, 97 • Data types float and double can hold decimal numbers • Data type char can hold a single character • Primitive data types - more Chapter 4 2000 Prentice Hall, Inc. All rights reserved. 32

2. 3 15 16 17 Another Java Application: Adding Integers // read in first number from user as a string first. Number = JOption. Pane. show. Input. Dialog( "Enter first integer" ); – Reads String from the user, representing the first number to be added • Method JOption. Pane. show. Input. Dialog displays the following: • Message called a prompt - directs user to perform an action • Argument appears as prompt text • If wrong type of data entered (non-integer), error occurs 2000 Prentice Hall, Inc. All rights reserved. 33

2. 3 15 16 17 Another Java Application: Adding Integers // read in first number from user as a string first. Number = JOption. Pane. show. Input. Dialog( "Enter first integer" ); – Result of call to show. Input. Dialog given to first. Number using assignment operator = • Assignment statement • = binary operator - takes two operands – Expression on right evaluated and assigned to variable on left • Read as: first. Number gets value of JOption. Pane. show. Input. Dialog( "Enter first integer" ) 2000 Prentice Hall, Inc. All rights reserved. 34

2. 3 19 20 21 Another Java Application: Adding Integers // read in second number from user as a string second. Number = JOption. Pane. show. Input. Dialog( "Enter second integer" ); – Similar to previous statement • Assigns variable second. Number to second integer input 23 24 25 // convert numbers from type String to type int number 1 = Integer. parse. Int( first. Number ); number 2 = Integer. parse. Int( second. Number ); – Method Integer. parse. Int • Converts String argument into an integer (type int) – Class Integer in java. lang • Integer returned by Integer. parse. Int is assigned to variable number 1 (line 24) – Remember that number 1 was declared as type int • Line 25 similar 2000 Prentice Hall, Inc. All rights reserved. 35

2. 3 27 28 Another Java Application: Adding Integers // add the numbers sum = number 1 + number 2; – Assignment statement • Calculates sum of number 1 and number 2 (right hand side) • Uses assignment operator = to assign result to variable sum • Read as: sum gets the value of number 1 + number 2 2000 Prentice Hall, Inc. All rights reserved. 36

2. 3 31 Another Java Application: Adding Integers JOption. Pane. show. Message. Dialog( 32 null, "The sum is " + sum, "Results", 33 JOption. Pane. PLAIN_MESSAGE ); – Use show. Message. Dialog to display results – "The sum is " + sum • Uses the operator + to "add" the string literal "The sum is" and sum • Concatenation of a String and another data type – Results in a new string • If sum contains 117, then "The sum is " + sum results in the new string "The sum is 117" • Note the space in "The sum is " • More on strings in Chapter 10 2000 Prentice Hall, Inc. All rights reserved. 37

2. 3 31 Another Java Application: Adding Integers JOption. Pane. show. Message. Dialog( 32 null, "The sum is " + sum, "Results", 33 JOption. Pane. PLAIN_MESSAGE ); – Different version of show. Message. Dialog • • • Requires four arguments (instead of two as before) First argument: null for now Second: string to display Third: string in title bar Fourth: type of message dialog – JOption. Pane. PLAIN_MESSAGE - no icon – JOption. Pane. ERROR_MESSAGE – JOption. Pane. INFORMATION_MESSAGE – JOption. Pane. WARNING_MESSAGE – JOption. Pane. QUESTION_MESSAGE 2000 Prentice Hall, Inc. All rights reserved. 38

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Outline // Fig. 2. 8: Addition. java // An addition program import javax. swing. JOption. Pane; public class Addition { public static void main( { String first. Number, second. Number; int number 1, number 2, sum; // import class JOption. Pane 1. import Declare variables: name and data type. String args[] ) 2. class Addition // first string entered by user // second string entered by user // first number to add // second number to add Input a String, // sumfirst of integer number 1 asand number 2 assign 2. 1 Declare variables (name and data type) to first. Number. 3. show. Input. Dialog // read in first number from user as a string first. Number = JOption. Pane. show. Input. Dialog( "Enter first integer" ); // read in second number from user as a string second. Number = Convert strings JOption. Pane. show. Input. Dialog( "Enter second integer" ); // convert numbers from type String to type int number 1 = Integer. parse. Int( first. Number ); Add, place number 2 = Integer. parse. Int( second. Number ); result // add the numbers sum = number 1 + number 2; // display the results 2000 Prentice Hall, Inc. All rights reserved. in sum. 4. parse. Int 5. Add numbers, put to integers. result in sum 39

31 32 33 34 35 36 JOption. Pane. show. Message. Dialog( null, "The sum is " + sum, "Results", JOption. Pane. PLAIN_MESSAGE ); System. exit( 0 ); // terminate the program } Outline 6. show. Message. Dialog 37 } 7. System. exit Program Output 2000 Prentice Hall, Inc. All rights reserved. 40

41 2. 4 Memory Concepts • Variables – Every variable has a name, a type, a size and a value • Name corresponds to location in memory – When new value is placed into a variable, replaces (and destroys) previous value – Reading variables from memory does not change them • Visual representation number 1 2000 Prentice Hall, Inc. All rights reserved. 45

42 2. 5 Arithmetic • Arithmetic calculations used in most programs – Usage • * for multiplication • / for division • +, • No operator for exponentiation (more in Chapter 5) – Integer division truncates remainder 7 / 5 evaluates to 1 – Modulus operator % returns the remainder 7 % 5 evaluates to 2 2000 Prentice Hall, Inc. All rights reserved.

43 2. 5 Arithmetic • Operator precedence – Some arithmetic operators act before others (i. e. , multiplication before addition) • Use parenthesis when needed – Example: Find the average of three variables a, b and c • Do not use: a + b + c / 3 • Use: (a + b + c ) / 3 2000 Prentice Hall, Inc. All rights reserved.

44 2. 5 2000 Prentice Hall, Inc. All rights reserved. Arithmetic

2. 6 Decision Making: Equality and Relational Operators • if control structure – Simple version in this section, more detail later – If a condition is true, then the body of the if statement executed • 0 interpreted as false, non-zero is true – Control always resumes after the if structure – Conditions for if structures can be formed using equality or relational operators (next slide) if ( condition ) statement executed if condition true • No semicolon needed after condition 2000 Prentice Hall, Inc. All rights reserved. 45

2. 6 Decision Making: Equality and Relational Operators _ > _ < = • Upcoming program uses if structures – Discussion afterwards 2000 Prentice Hall, Inc. All rights reserved. 46

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ); 23 24 25 26 27 28 29 30 // Fig. 2. 17: Comparison. java // Using if statements, relational operators // and equality operators import javax. swing. JOption. Pane; public class Comparison { public static void main( { String first. Number, second. Number, result; int number 1, number 2; String args[] ) // // // first string entered by user second string entered by user a string containing the output first number to compare second number to compare // read first number from user as a string first. Number = JOption. Pane. show. Input. Dialog( "Enter first integer: " ); // read second number from user as a string second. Number = JOption. Pane. show. Input. Dialog( "Enter second integer: " // convert numbers from type String to type int number 1 = Integer. parse. Int( first. Number ); number 2 = Integer. parse. Int( second. Number ); // initialize result to the empty string result = ""; 2000 Prentice Hall, Inc. All rights reserved. Outline 47

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 } if ( number 1 == number 2 ) result = result + number 1 + " == " + number 2; if ( number 1 != number 2 ) result = result + number 1 + " != " + number 2; if ( number 1 < number 2 ) result = result + "n" + number 1 + " < " + number 2; if ( number 1 > number 2 ) result = result + "n" + number 1 + " > " + number 2; if ( number 1 <= number 2 ) result = result + "n" + number 1 + " <= " + number 2; if ( number 1 >= number 2 ) result = result + "n" + number 1 + " >= " + number 2; // Display results JOption. Pane. show. Message. Dialog( null, result, "Comparison Results", JOption. Pane. INFORMATION_MESSAGE ); System. exit( 0 ); } 2000 Prentice Hall, Inc. All rights reserved. Outline 48

Outline Program Output 2000 Prentice Hall, Inc. All rights reserved. 49

2. 6 Decision Making: Equality and Relational Operators – Lines 1 -9: Comments, import JOption. Pane, begin class Comparison and main 10 11 12 13 14 String first. Number, second. Number, result; int number 1, number 2; // // // first string entered by user second string entered by user a string containing the output first number to compare second number to compare – Declare variables 17 18 21 22 first. Number = JOption. Pane. show. Input. Dialog( "Enter first integer: " ); second. Number = JOption. Pane. show. Input. Dialog( "Enter second integer: " ); – Input data from user and assign to variables 2000 Prentice Hall, Inc. All rights reserved. 50

2. 6 25 26 Decision Making: Equality and Relational Operators number 1 = Integer. parse. Int( first. Number ); number 2 = Integer. parse. Int( second. Number ); – Convert Strings to ints and assign to variables 29 result = ""; – Initialize result with empty string 31 32 if ( number 1 == number 2 ) result = result + number 1 + " == " + number 2; – if structure to test for equality using (==) • If variables equal (condition true) – result concatenated using + operator – result = result + other strings – Right side evaluated first, new string assigned to result • If variables not equal, statement skipped 2000 Prentice Hall, Inc. All rights reserved. 51

2. 6 Decision Making: Equality and Relational Operators • Other if structures 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 if ( number 1 != number 2 ) result = result + number 1 + " != " + number 2; if ( number 1 < number 2 ) result = result + "n" + number 1 + " < " + number 2; if ( number 1 > number 2 ) result = result + "n" + number 1 + " > " + number 2; if ( number 1 <= number 2 ) result = result + "n" + number 1 + " <= " + number 2; if ( number 1 >= number 2 ) result = result + "n" + number 1 + " >= " + number 2; – Lines 50 -52: result displayed in a dialog box using show. Message. Dialog 2000 Prentice Hall, Inc. All rights reserved. 52

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ); 23 24 25 26 27 28 29 30 // Fig. 2. 17: Comparison. java // Using if statements, relational operators // and equality operators 1. import javax. swing. JOption. Pane; public class Comparison { public static void main( { String first. Number, second. Number, result; int number 1, number 2; String args[] ) // // // Outline first string entered by user second string entered by user a string containing the output first number to compare second number to compare 2. Class Comparison 2. 1 main 2. 2 Declarations // read first number from user as a string first. Number = JOption. Pane. show. Input. Dialog( "Enter first integer: " ); 2. 3 Input data (show. Input. Dialog) // read second number from user as a string second. Number = JOption. Pane. show. Input. Dialog( "Enter second integer: " 2. 4 parse. Int // convert numbers from type String to type int number 1 = Integer. parse. Int( first. Number ); number 2 = Integer. parse. Int( second. Number ); // initialize result to the empty string result = ""; 2000 Prentice Hall, Inc. All rights reserved. 2. 5 Initialize result 53

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 } if ( number 1 == number 2 ) result = result + number 1 + " == " + number 2; Outline Test for equality, greater than, less if ( number 1 != number 2 ) result = result + number 1 + " != " + number 2; than, etc. Create new string, assign 3. if statements to result. if ( number 1 < number 2 ) result = result + "n" + number 1 + " < " + number 2; if ( number 1 > number 2 ) result = result + "n" + number 1 + " > " + number 2; 4. show. Message. Dialog if ( number 1 <= number 2 ) result = result + "n" + number 1 + " <= " + number 2; if ( number 1 >= number 2 ) result = result + "n" + number 1 + " >= " + number 2; // Display results JOption. Pane. show. Message. Dialog( null, result, "Comparison Results", JOption. Pane. INFORMATION_MESSAGE ); System. exit( 0 ); } Notice use of JOption. Pane. INFORMATION_MESSAGE 2000 Prentice Hall, Inc. All rights reserved. 54

Outline Program Output 2000 Prentice Hall, Inc. All rights reserved. 55