CIS 111 Getting Java running

Objectives

  • Get a Java compiler installed and running

Getting Java running

Follow the instructions at: https://www3.ntu.edu.sg/home/ehchua/programming/howto/JDK_Howto.html

Sample program

Type the following code in a text editor such as notepad. Save it as Hello.java (and remember where you saved it). Start a console window (Start | Run... | cmd). Change to the directory where you saved the file ('cd' command). Type the following to compile the program: javac Hello.java. If it compiles, then type the following to run it: java Hello.

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

If you have problems, you may need to check your PATH and CLASSPATH environment variable settings. Please try this soon so the instructor can help you get up and running as soon as possible.

How Java applications are created

  • you write the source code with a text editor
  • save the source code file with a .java extension (e.g. Hello.java)
  • compile the source code using javac (e.g. javac Hello.java)
  • the previous step should have created a class file if the compile worked (Hello.class)
  • run the class file on the JVM (e.g. java Hello)
  • basic Java program (see Hello.java)
  • slightly less basic Java program (see Hello2.java)

Resources