The name 7button is not a valid identifier because it begins with a digit, and the name input field is not a valid identifier because it contains a space. Some valid identifiers are Welcome1, $value, _value, m_inputField1 and button7.
A class name is an identifier-a series of characters consisting of letters, digits, underscores ( _) and dollar signs ( $) that does not begin with a digit and does not contain spaces. Class Names and Identifiersīy convention, class names begin with a capital letter and capitalize the first letter of each word they include (e.g., SampleClassName). The complete list of keywords is shown in Appendix C. Keywords (sometimes called reserved words) are reserved for use by Java and are always spelled with all lowercase letters. The class keyword introduces a class declaration and is immediately followed by the class name ( Welcome1). Every Java program consists of at least one class that you (the programmer) define. Declaring a Classīegins a class declaration for class Welcome1. Use blank lines and spaces to enhance program readability. We demonstrate Javadoc comments and the javadoc utility in Appendix M, Creating Documentation with javadoc. The javadoc utility program (part of the Java SE Development Kit) reads Javadoc comments and uses them to prepare your program's documentation in HTML format. Such comments are the preferred Java documenting format in industry. Javadoc comments enable you to embed program documentation directly in your programs.
The compiler ignores all text between the delimiters. Java provides comments of a third type, Javadoc comments. Java incorporated traditional comments and end-of-line comments from the C and C++ programming languages, respectively. These begin and end with delimiters, /* and */. Java also has traditional comments, which can be spread over several lines as in /* This is a traditional comment. Is a comment that describes the purpose of the program. An end-of-line comment need not begin a line it also can begin in the middle of a line and continue until the end (as in lines 10 and 11).
2.1: Welcome1.javaīegins with //, indicating that it is an end-of-line comment-it terminates at the end of the line on which the // appears. The Java compiler ignores comments, so they do not cause the computer to perform any action when the program is run.īy convention, we begin every program with a comment indicating the figure number and file name. We insert comments to document programs and improve their readability. 3 4 public class Welcome1Ħ // main method begins execution of Java application 7 public static void main( String args )ĩ ( "Welcome to Java Programming!" ) ġ0 } // end method main 11 } // end class Welcome1 2.1: Welcome1.java 2 // Text-printing program. We'll see that line 9 does the real work-displaying the phrase Welcome to Java Programming! on the screen. This example illustrates several important Java features. We've added these for instructional purposes-they're not part of a Java program. Figure 2.16 shows the program followed by a box that displays its output. First we consider a simple application that displays a line of text.
Later in this section we'll discuss how to compile and run a Java application. Learn More Buy 2.2 Your First Program in Java: Printing a Line of TextĪ Java application is a computer program that executes when you use the java command to launch the Java Virtual Machine (JVM). Java How to Program (early objects), 9th Edition