Back to 111 Main Page

Mobius strip

Assignment 0b

Task

Get ready to program by writing a "Hello, World!" program on the same computer you plan to use to do your assignments.

Textbook: 1.4 - 1.5
New concepts: Compiling; printing to the screen.

Steps:

JDK

If you are planning to use your home machine, you will need to download and install the JDK.

"Java SE Development Kit (JDK) 6 Update 11" is the latest version, but version 5 will also work for this course. (Make sure you get the JDK, not the JRE. You do not need NetBeans--which is a large IDE program used when writing code--but you can get that version if you want to.)

Hello, World!

Using Notepad or Wordpad, write a simple program, such as:

/**
 * My first program.  It prints a greeting to the screen.
 *
 * @author Zach Tomaszewski
 * @version 15 Jan 2008
 */
public class Hello {

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

}

Compile this program at the command line: javac Hello.java

And then run it: java Hello

Of course, to submit this program, you will need to change its name to UsernameA00b.java, where Username is your UH username. Remember that the class name must match the file name and that Java is case-sensitive.

What to Submit

Upload your UsernameA00b.java file to Tamarin.

Grading [2 points]

0.5 - Upload
You successfully upload a file to Tamarin.
0.5 - Compiles
The program compiles successfully.
1 - Output
The program prints something--a line or two of text--to the screen.

FAQs

When I try to compile, I get the following error: 'javac' is not recognized as an internal or external command, operable program or batch file.
This means that Windows cannot find the javac program. Sometimes when you download and install the JDK, it sets the path variable correctly; more often, it doesn't. Here's how to fix the problem.
  1. Find out where the javac.exe file was installed. It will probably be somewhere like C:\Program Files\Java\jdk1.6.0_11\bin\ (You might also try a file search for javac.exe if you can't find it by browsing.)
  2. Once you find javac.exe, type the full path on the command line, something like this:
      "C:\Program Files\Java\jdk1.5.0_16\bin\javac" Hello.java
    
    You may need the quotes around the file path if it contains any spaces.
  3. If this works (Windows can now find javac), then Java is installed correctly. Now you can update your path so you don't have to type the whole path name every time. These are the steps to do this in WindowsXP (some translation may be required for Vista):
    1. Go to Start -> Control Panel -> System. (It's easiest to find System when you change Control Panel to Classic View.)
    2. Go to the Advanced tab
    3. Click the Environment Variables button
    4. Scroll down through the System variables until you find Path.
    5. Edit this variable, adding the path up to but not include javac (so probably C:\Program Files\Java\jdk1.6.0_11\bin\) to the end of the list. Make sure there is a ; (semi-colon) between this path and the one before it.
    6. Click OK for all of that, saving it all.
    7. Now open a new command prompt and see if just javac -version or javac Hello.java works, without the whole path.
If you ran into problems, let me know how far into this process you made it and what went wrong.
javac works, but when I compile I get this error:
  error: cannot read: Hello.java
  1 error
This means javac can't find the .java file you are trying to compile (in this case, Hello.java). Check that you are in the same directory as the file. Type dir on the command line and you should see your .java file in the list of files displayed. (If you need to switch directories to find where you saved Hello.java, remember that cd .. moves up a level, and cd dirName will move down one level into the sub-directory named dirName.)


~ztomasze Index : TA Details: ICS111: Assignment 0b
http://www2.hawaii.edu/~ztomasze
Last Edited: 13 Jan 2009
©2008 by Z. Tomaszewski.