ITEC 1011 A,B
Week 6 Lab Instructions
Oct 19, 20 2000

The Joy Of Java!!!

The subject line for your email will be oct22: lastname studentnumber Remember the space after the colon and after yourlastname .



I assume that everyone did, and understood last week's lab. Java runs in the DOS environment, so it is important that you know how DOS works.
  1. Download the files. This depends on where you are working. Click where you are: Gauss Lab or Home. Home is either your actual home computer or some other location where you are able to compile and run java programs and applets.
  2. Now that the files are installed on your F: directory at York or on some other directory at home you won't have to do this again.

  3. Preparing to work with Java

    Gauss Lab:

    1. In the Gauss lab: Open up a DOS window. (you should know how to do this!)
    2. Go to the F:\java directory.
    3. Type init at the prompt. (This runs a batch file that sets the CLASS and CLASSPATH environment variables.) You need to do this each time you launch DOS.) If you get an error message,

      Out of environment

      just run init a second time. This time there should be no error messages.

    4. You're ready to go. Proceed to the next step.

    From Home:

    1. Open a DOS window. (You should know how to do this.)
    2. Go to the directory where you will write your Java Programs.
    3. Proceed to the next step.
  4. Compile a program

    There are several programs in Chapter One, we will compile and run them all.
    1. The compile command in Java is javac []. The file name is case sensitive, so watch the CaPiTaL LeTTeRs.
    2. Type javac It will appear that nothing happens except a pause. Java is actually converting the text file '' into a Java executable file, 'Hello.class'
    3. Type dir Hello* to confirm that the .class file was made.
    4. That is how you compile a Java program. Pretty easy, Eh?

  5. Run a compiled program

    1. The Run command is java [FileName]. Note that no .class or .java extension is used.
    2. First,we will try and run a program that isn't compiled.
      Type java Hello2 What happened? This is what is known as an error message. Get used to them, they happen often.
    3. Type java Hello This file is already compiled so it should work.
    4. Congratulations, you have run your first Java program. Exciting isn't it?

  6. Practice:

    Compile and run the following programs:
    The last one is kind of fun. Take a few minutes and draw a house or something.
    This program demonstrates the power of Java's graphics capabilities. You can quit DemoGuiDraw by clicking on the X in the top right of the window that opens up.

  7. Using the applet viewer

    Applets are Java programs designed to run off of a web browser, like Netscape. The developers of Java have provided us with the applet viewer so that we can test our applets without opening up a web browser.
    1. The applet viewer command is appletviewer [FileName.html]. Note that you use an HTML file as the parameter. More on this later.
    2. Compile the program
    3. Type appletviewer DemoApplet.html
    4. Close the applet window by clicking on the X.
    5. Compile and run the applets:

      Note that the DemoSound won't be very interesting on the Lab computers. They don't have sound cards.
    6. You can also use Netscape to view an applet. Just open up the webpage that refers to the applet (i.e. file:\\\F:\DemoApplet.html)

  8. Write a Java program

    OK, here's your task for this lab: Write a java program to print your name and YU-number, with a border above and below. The name of the program should be, using your YU-number and with "YU" in uppercase. The output should contain four lines, something like this:
    // Name: Joe Student            *
    // Student number: 9999999      *
    Make sure each line of output begins with two forward slashes, just like the example above.

    If you think you know how to do this, just proceed on your own. When finished, skip ahead to Step 9.

    If you need some help, follow the steps below. Ask the lab instructor for further assistance, if necessary.

    1. To save on typing, begin by making a copy of the file. Name the new file If you paid attention during last week's lab, you should know how to do this. Use your own YU-numuber, and put "YU" in uppercase.
    2. Edit the source program as follows. Do this from a DOS window using EDIT.
      1. Delete the comment block at the top of the file. (You can include a few comments of your own choosing if you like. It's your call.)
      2. Change the name of the class from "Hello" to "YU123456". (Use your YU-number.) If you are not sure about this step, review the section "Simple Java Programs" in Chapter 1 of the Java Primer.
      3. Copy the line "System.out.println("Hello, world");" and paste it 3x immediately below.
      4. Edit the four print statements so that they generate the output requested above. Make sure each line begins with two forward slashes.
      5. Save the changes and exit the editor.
    3. Do a dir YU*
    4. Compile the program. Fix any compile errors before proceeding.
    5. Execute the program. Does it generate the required output? Fix any run-time error or output errors before proceeding.

  9. Submission

    Congratulations, you have just written your first Java program. To submit your work and receive a mark for this week's lab, proceed as follows.
    1. First, make a backup copy of your source program and name it YU123456.bak. This is just a precaution. Hopefully, you won't need this.
    2. Execute your program one more time using the following command line:

      F:\java\java YU123456 >>

      If you paid attention during last week's lab, you should know exactly what this statement is doing. The output is appended to the source file rather than appearing on the console.
    3. Send an e-mail message to the TA ( or Copy the entire contents of your source program file into the body of the email message. Make the to use subject line oct22: lastname studentnumber.

Disclaimer: Students are responsible for the content of their WWW pages.