LAB1
CMP 12L
Winter 2015

Due: Friday, 6:00pm, Jan 9, 2015

Objectives:

To become familiar with computing environment, compiling, and submission procedures for CMPS 12A/L homeworks. Also be able to comment, modify, compile, run, submit an existing Java program.

Assignment:

  • Login to your account on unix.ic.ucsc.edu
  • Bold text below indicate commands that you enter at the unix command prompt.
  • Copy the following Java program and save it to a file named: Hello.java .
    import java.util.*;
    
    class Hello{
        public static void main( String[] args)
        {
    	String  name;
    
    	Scanner scan = new Scanner( System.in );
    	System.out.print( "What's your name? ");
    	name = scan.next();
    	
    	System.out.format( "Hi %s!\n", name );
        }
    }
    
  • The easiest way to do this is to use the cat command: cat > Hello.java, press enter, paste your text,
    then press <ctrl> d. This will create the file Hello.java and put your pasted text into it.
  • Alternatively, you can fire up your favorite text editor and paste the code there. Then, save the file as Hello.java.
  • To see the contents of your new file, use the more command: more Hello.java
  • Next, compile the java program using the following command:

    javac Hello.java

    javac runs the java compiler. Type java -h to see more options.

    The compiler will read and compile the code in Hello.java and produce an executable byte code and store it in a file called Hello.class If you copied and pasted the file properly, the compiler should not produce any errors.

  • Now if we type ls we should see two files: Hello.java and Hello.class. The class file is what the Java Virtual Machine looks at in order to run your code.

  • With Hello.class, we can actually run the program. We do this by giving the Java Virtual Machine the name of the class containing our main method (which is starting point of every program).

    Here's a sample run using the command:

    java Hello

    What's your name? alex
    Hi alex!
    

  • Before you submit your program, you need to make two changes to this program:
    1. Add comment block at the beginning of your program, similar to the following:

      //===============================================//
      //  Author:      your name here                  //
      //  Date:        date last edited here           //
      //  Program:     Lab 1 assignment                //
      //  Description: brief description of the        //
      //               assignment here.                //
      //===============================================//
      
    2. Next, modify the program so that it prints an extra line containing the URL of the class website.
      For example, "The CMPS12A webpage is: _______."

      1. This can be done by adding a line similar to:
        System.out.println("The CMPS12A webpage is: <replace_this_with_the site_url> ");
      2. Recompile and run your revised program to make sure that it produces the desired output.

  • Now we need to submit the program. At the terminal prompt:

    submit cmps012a-ap.w15 lab1 Hello.java

    This command copies Hello.java to a location which the Professor and TAs will have access to. Generally speaking, lab1 is the name of the assignment you are submitting and Hello.java is the name of the file that you want to submit.

  • Submitting files remotely from home. The basic steps for submitting files from home or dorm are:

    1. Use SSH (or FileZilla) to move the files to unix.ic.ucsc.edu. (see FAQ)

    2. Log onto unix.ic.ucsc.edu with SSH.

      Verify that your code compiles and runs on unix.ic.ucsc.edu.

      Help using SSH.

    3. Submit the Hello.java file as described above.

    Also, if you are working on a Windows machine you should know that Windows and Unix use different newline characters. (see FAQ)

    Grading Guidelines:

    
    General notes
    -------------
    100   Perfect score
     75   No comment block or no URL
     50   No comment block and no URL, or compiles but does not run
     25   Does not compile e.g. empty file, wrong file name, etc.
      0   No submit
    
    The grading for this lab assignment is based on these 5 scores.
    You should still follow  good programming practices.
    
    Who Will Grade What:
    --------------------
    Ryan   : aalkahel - dlopez8
    Kara   : dlskilli - jssorens
    Derek  : jtorre34 - romarks
    Eitan  : rpickett - zwang58