【正文】
to Java! public class Wele { public static void main(String[] args) { (Wele to Java!)。 } } Listing Methods P22 ,167。 Liang, Introduction to Java Programming, Sixth Edition, (c) 2021 Pearson Education, Inc. All rights reserved. 0132221586 26 Creating and Editing Using NotePad Caution(P19,para1): The file name must end with the extension .java and must have exact same name as the public class. Liang, Introduction to Java Programming, Sixth Edition, (c) 2021 Pearson Education, Inc. All rights reserved. 0132221586 27 Compile source code (P19,para2) ?A java piler translates a java source file into a Java bytecode file . ?Java piler : ?Command : javac ?If there are no syntax error, the piler generate a bytecode file with a .class extension. Liang, Introduction to Java Programming, Sixth Edition, (c) 2021 Pearson Education, Inc. All rights reserved. 0132221586 28 Run the bytecode (P19,para3) ?To execute a java program is to run the bytecode. ?Interpreter : ?You can execute the bytecode on any platform with a JVM (Java virtual machine) ?Command : java Wele Liang, Introduction to Java Programming, Sixth Edition, (c) 2021 Pearson Education, Inc. All rights reserved. 0132221586 29 Java IDE Tools ? Borland JBuilder ? NetBeans Open Source by Sun ? Sun ONE Studio by Sun MicroSystems ? Eclipse Open Source by IBM Liang, Introduction to Java Programming, Sixth Edition, (c) 2021 Pearson Education, Inc. All rights reserved. 0132221586 30 Displaying Text in a Message Dialog Box you can use the showMessageDialog method in the JOptionPane class. JOptionPane is one of the many predefined classes in the Java system, which can be reused rather than “reinventing the wheel.” Run Source IMPORTANT NOTE: To run the program from the Run button, (1) set c:\\bin for path, and (2) install slides from the Instructor Resource Website to a directory (., c:\LiangIR) . Liang, Introduction to Java Programming, Sixth Edition, (c) 2021 Pearson Education, Inc. All rights reserved. 0132221586 31 The showMessageDialog Method (null, Wele to Java!, “Display Message, ))。 Liang, Introduction to Java Programming, Sixth Edition, (c) 2021 Pearson Education, Inc. All rights reserved. 0132221586 32 Two Ways to Invoke the Method There are several ways to use the showMessageDialog method. For the time being, all you need to know are two ways to invoke it. One is to use a statement as shown in the example: (null, x, y, ))。 where x is a string for the text to be displayed, and y is a string for the title of the message dialog box. The other is to use a statement like this: (null, x)。 where x is a string for the text to be displayed. Liang, Introduction to Java Programming, Sixth Edition, (c) 2021 Pearson Education, Inc. All rights reserved. 0132221586 33 The exit Method Prior to JDK , you have to invoke () to terminate the program if the program uses JOptionPane dialog boxes. Since JDK , it is not necessary.