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