JAVATM- The Beginnings

The HelloWorld Program

When learning a new programming language, the first task is normally to write a program which simply prints the words “Hello World” to your computer’s display. Once we have written, compiled, and executed the program, and verified that “Hello World” appears on the display, we have successfully run the HelloWorld program.

Section 1 - Creating and Running the HelloWorld Program

In your favorite text editor, or in your programming Integrated Development Environment (IDE), create a file named HelloWorld.java which contains the following:

Listing 1 - HelloWorld.java

1        public class HelloWorld

2        {

3                public static void main(String[] args)

4                {

5                        System.out.println("Hello World");

6                }

7        }

To compile and run HelloWorld.java from the command line, type the following:

javac HelloWorld.java

java HelloWorld

The Javac command runs the Java compiler which converts Java source file HelloWorld.java into bytecode file HelloWorld.class. Java source files are text files containing the syntax, or  programming rules, of the Java programming language. All Java source files end with the extension .java .

The Java command runs the HelloWorld.class executable in the Java Virtual Machine (JVM). The following output is now visible on your computer display:

Hello World

Congratulations, you’ve just run your first Java program!

Copyright ©2017 by Ralph Lecessi Incorporated. All rights reserved.



Back to ralphlecessi.com