Writing My First Java Program

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

When JDK is installed on your machine, it provides two commands for you to compile and run Java programs.

Let's try these commands with a very simple Java program. Use NotePad 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 in a command window 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

JDK - Java Development Kit

 Downloading and Installing JDK on Mac

 Downloading and Installing JDK on Windows

 Adding JDK "bin" Directory to Path Setting

 Downloading and Installing JDK on Linux

Writing My First Java Program

 JDK Documentation Installation

 Execution Process, Entry Point, Input and Output

 Primitive Data Types and Literals

 Control Flow Statements

 Bits, Bytes, Bitwise and Shift Operations

 Managing Bit Strings in Byte Arrays

 Reference Data Types and Variables

 Enum Types and Enum Constants

 StringBuffer - The String Buffer Class

 System Properties and Runtime Object Methods

 Generic Classes and Parameterized Types

 Generic Methods and Type Inference

 Lambda Expressions and Method References

 Java Modules - Java Package Aggregation

 Execution Threads and Multi-Threading Java Programs

 ThreadGroup Class and "system" ThreadGroup Tree

 Synchronization Technique and Synchronized Code Blocks

 Deadlock Condition Example Programs

 Garbage Collection and the gc() Method

 Assert Statements and -ea" Option

 Annotation Statements and Declarations

 Java Related Terminologies

 Archived Tutorials

 References

 Full Version in PDF/EPUB