Week 1 Answers


  1. get hold of the Java Developer's Kit and install it on a PC (or VMS or UNIX)

    Hopefully you found this; the Sun website for downloads is http://java.sun.com/j2se/1.4.1/download.html. For VMS/UNIX, try http://h18012.www1.hp.com/java/download/index.html

  2. write a program that you can then build which when run displays "hello, world"

    Here's a program to do this:

    public class firstprog {
      public static void main(String[] args) {
        System.out.println("hello, world");
      }
    }
    
  3. write a program that takes an arbitrary number of parameters from the command line and displays them in ascending order

    There are loads of ways to do this, but chances are there will be a sort function already in the library somewhere. Here's an example of one way to accomplish the task:

    public class sorter {
        public static void main(String[] args) 
        {
            java.util.Arrays.sort(args);
            for (int i=0; i<args.length; i++) {
                System.out.println(args[i]);
            }
        }
    }
    
  4. put your program in a JAR file that runs when you use the "java -jar" command

    Once you have your "sorter.class", you also need a "manifest.mf" file that contains something like this:

    Manifest-Version: 1.0
    Main-Class: sorter
    
    Then create the JAR file using:
    % jar cfm sorter.jar manifest.mf sorter.class
    

Back to index page