1. Computing

Creating Your First Java Program

By

2 of 9

Write the Java Source Code
Program Code in Notepad

Microsoft product screen shot(s) reprinted with permission from Microsoft Corporation.

The first thing you need is a place to write your Java code. All Java programs are written using plain text files, therefore you can write them without any fancy software. For your first program, open up the simplest text editor you have on your computer. I’ll be using Notepad.

The program code looks like this:

 // The classic Hello World program!
 class HelloWorld {
 
    public static void main(String[] args) {
 
       //Write Hello World to the terminal window
       System.out.println("Hello World!");
 
    }
 } 

You could cut and paste the above code into your text editor, but it’s better to get into the habit of typing it in. It will help you learn Java quicker because you will get a feel for how programs are written, and you will make mistakes! It may sound odd, but any mistakes you make will help you become a better programmer in the long run. Just remember that your program code must match the example code, and you’ll be fine.

For this first program, I’m not going to explain how it works or what all the code means; that will come in later tutorials. At the moment, it’s more important for you to experience the steps you should follow to create and run a program.

  1. About.com
  2. Computing
  3. Java
  4. Getting Started
  5. Write the Java Source Code

©2014 About.com. All rights reserved.