Writing My First Java Program

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

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)

 What Is JDK

 Downloading and Installing JDK 20

Writing My First Java Program

 Adding JDK "bin" Directory to Path Setting

 JDK Documentation Installation

 Introduction of Java Swing Package

 Graphics Environment of the Local System

 JFrame - Main Frame Class

 JLabel - Swing Label Class

 JButton - Swing Button Class

 JCheckBox - Swing Check Box Class

 JRadioButton - Swing Radio Button Class

 JTextField - Swing Text Field Class

 JComboBox - Swing Combo Box Class

 Menu Bar, Menus, Menu Items and Listeners

 Creating Internal Frames inside the Main Frame

 Layout of Components in a Container

 LookAndFeel and UIManager

 Option Dialog Boxes

 JEditorPane - The Editor Pane Class

 SwingWorker - The Background Task Worker

 AWT (Abstract Windows Toolkit)

 Integration with Desktop System

 Archived Tutorials

 References

 Full Version in PDF/EPUB