Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 2. Introduction to Java Applicat... > Your First Program in Java: Printing...

2.2. Your First Program in Java: Printing a Line of Text

A Java application is a computer program that executes when you use the java command to launch the Java Virtual Machine (JVM). Later in this section we’ll discuss how to compile and run a Java application. First we consider a simple application that displays a line of text. Figure 2.1 shows the program followed by a box that displays its output. The program includes line numbers. We’ve added these for instructional purposes—they’re not part of a Java program. This example illustrates several important Java features. We’ll see that line 9 does the real work—displaying the phrase Welcome to Java Programming! on the screen.

Fig. 2.1. Text-printing program.

 1   // Fig. 2.1: Welcome1.java
 2   // Text-printing program.
 3
 4   public class Welcome1
 5   {
 6      // main method begins execution of Java application
 7      public static void main( String[] args )
 8      {
 9         System.out.println( "Welcome to Java Programming!" );
10      } // end method main
11   } // end class Welcome1

Welcome to Java Programming!



  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint