Monday, 15 April 2013

My First Java Program

Once I had installed the Java Software Development Kit (SDK), I typed the code below into a text file:

UBUNTU > cat Andrew_Was_Here.java
/*
 * My First Program
*/
public class Andrew_Was_Here
  {
  public static void main(String args[])
    {
    System.out.println("Andrew was here!");
    }
  }
UBUNTU >


The file was in a directory by itself:

UBUNTU > ls
Andrew_Was_Here.java
UBUNTU >

I compiled it as follows:

UBUNTU > javac Andrew_Was_Here.java
UBUNTU >

A new file called Andrew_Was_Here.class appeared in the directory:

UBUNTU > ls
Andrew_Was_Here.class  Andrew_Was_Here.java
UBUNTU >

This contains the compiled Java code. I ran it like this: 

UBUNTU > java Andrew_Was_Here
Andrew was here!
UBUNTU >