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). Sections 2.2.12.2.2 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.

Fig. 2.1

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

Text-printing program.

We use line ...

Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.