First Java Program - Hello.java

This section provides a tutorial example on how to write, compile, and execute the first Java program, Hello.java, with OpenJDK.

With OpenJDK's JRE and JDK packages installed, we can use "javac" and "java" commands to compile and run Java programs.

Let's try these commands with a very simple Java program. Use a text editor to enter the following Java program into a file called Hello.java:

class Hello {
  public static void main(String[] a) {
    System.out.println("Hello world!");
  }
}

Then compile this program with the "javac" command:

herong$ javac Hello.java

To execute the program, use the "java" command:

herong$ java Hello

Hello world!

Congratulations, you have successfully entered, compiled and executed your first Java program.

Table of Contents

 About This Book

 Introduction to Linux Systems

 Process Management

 Files and Directories

 Running Apache HTTP Server (httpd) on Linux Systems

 Running Apache Tomcat on Linux Systems

 Running PHP Scripts on Linux Systems

 Running MySQL Database Server on Linux Systems

 Running Python Scripts on Linux Systems

 Conda - Environment and Package Manager

 GCC - C/C++ Compiler

OpenJDK - Open-Source JDK

 Install and Manage OpenJDK on CentOS

 Upgrade OpenJDK on CentOS

First Java Program - Hello.java

 Graphics Environments on Linux

 SquirrelMail - Webmail in PHP

 Tools and Utilities

 References

 Full Version in PDF/EPUB