Hello World Tutorial -- Getting started with JAVA

1. Invoke your text editor.  Notepad is acceptable for starters, but better editors will be required for future work.  I use EditPlus.
2. Type the following code, EXACTLY AS GIVEN. Do not be concerned with what it all means at this time. This is only an exercise to familiarize yourself with the process.

---------------------- TYPE EVERYTHING FROM HERE ----------------

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

------------------------------- TO HERE ---------------------------

3. Save this file under the name "Hello.java".   Make sure that you do not have hidden extensions, or you may end up with "Hello.java.txt".  If you are in the ITEC labs, you should save your file to your personal (F) drive (the system drives may erase your files when you log out).

4a. Open a DOS prompt (click on the "Start" button, select the "Programs" menuitem, and then select the "MS-DOS" icon -OR- click on the "Start" button, select the "Run..." menuitem, and type in "command") and switch to your working directory.  Or better yet, find the file "command.com", copy it, and paste a copy into your working directory.  Double-clicking this icon will now open an MS-DOS command window already at your working directory.  Enter "dir" at the prompt, and you should see Hello.java listed as one of your files.

5a. At the prompt, enter "javac Hello.java". Depending on how fast your machine is, it may take very little time to several seconds for the prompt to re-appear.  If you get an error that says something like "javac is not a recognized command or filename", it means that your "PATH" variable is not set correctly -- see below for additional installation instructions.

4b-5b. If using Edit-Plus in the ITEC labs, select from the "Tools" menu "JAVA compile".

6. If the prompt returns without any error message, type "dir" again. You should see a new file named "Hello.class". This is the Java Bytecode executable file.

7a. Enter "java Hello".

7b. If using Edit-Plus in the ITEC labs, select from the "Tools" menu "JAVA".

8. If you see "Hello, World!" printed to the screen, then JAVA has been properly installed on your machine.  If you see an error that says something like "Hello -- class not found", it means that your "CLASSPATH" variable does not include "." (the current directory) -- see below for additional installation instructions.  Note: you may be able to avoid having to set your classpath variable if you are willing to specify it in the command line -- enter "java -classpath . Hello" instead.

---------------------- TYPE EVERYTHING FROM HERE ----------------

import java.util.Scanner;

public class Hello
{
    public static void main(String[] args)
    {
        System.out.println("Enter a number");
        Scanner scan = new Scanner(System.in);
        int input = scan.nextInt();
        System.out.println("You input " + input);
    }
}

------------------------------- TO HERE ---------------------------
 

9. Modify your program to the above.
10. Recompile using the command "javac Hello.java".
11. Rerun using the command "java -classpath . Hello".
12. Type a number and press the "Enter" key.

For more help on installing JAVA, please see the Sun site.  Pay special attention to 4 (which should be done by the install CD) and 5

In XP, open Control Panel.
Open System icon to get to System Properties.
Click on Advanced tab and then Environment Variables button at bottom.
Create new or edit Variable Name --> CLASSPATH
with Variable Value --> .

What do these mean?
JAVA looks for classes in all directories listed in the CLASSPATH. The "." means the current directory -- if you don't put the ".", then JAVA won't look in the directory that you are working in.  All directories to look in are separated by semi-colons.