Week 8 Notes and Questions

Keywords revision and summary

Here is a table of some of the more Java-specific language keywords (as opposed to things like "if .. else") that you might come across. You can find a complete list in the Java Language Specification section 3.9.

abstract catch class
const extends final
finally implements import
instanceof interface native
new package private
protected public static
super synchronized this
throw throws transient
try volatile


Questions

Here are some questions that will require you to use classes from the standard class library:

  1. Write a program using a "Stack" object that allows a user to type in numbers until the value -1 is seen, after which the numbers are displayed back in reverse order, e.g.
      % java Reverse
      Number ? 9
      Number ? 1
      Number ? 2
      Number ? 7
      Number ? -1
      In reverse order, the numbers are:  7 2 1 9
    
  2. Write a program that will convert values from Hex to Decimal and vice versa. For example:
      % java Convert 1234
      1234 == 0x4d2
    
      % java Convert 0x63ffd
      0x63ffd == 409597
    
    
  3. Write a program that will multiply two arbitrarily large integers, e.g.
      % java Multiply 2 3
      2 * 3 = 6
    
      % java Multiply 52652653652635 27384728734872634
      % 52652653652635 * 27384728734872634 = 1441878637448610235081603490590
    
    
  4. Write a program that will tell you what day of the week your birthday is, e.g.
      % java MyBirthday 7 12
      This year your birthday is on a Sunday
    
  5. Write a program that lists the files in a zipfile. E.g.
      % java ListZipContents nick.zip
      nick.dat
      fred.dat
      files/
      files/another.txt
    
  6. Write a program that will extract the host name and path from a www address. E.g.
      % java WWW http://funky.reo.cpqcorp.net/nick/tutorial/week8-questions.html
      The host is funky.reo.cpqcorp.net
      The path is /nick/tutorial/week8-questions.html
    
  7. You have a webserver running on your machine and can see from the logs that clients from addresses "16.37.9.14" and "16.37.9.124" are continually trying to access it. For some reason, the only tool you have at your disposal is a JDK.
    Write a Java program that accepts an IP address on the command line and translates that address into a proper nodename. For example:
      % java NodeInfo 16.37.9.226
      16.37.9.226 is "alffa.reo.cpqcorp.net"
    
    Use this program to find out who "16.37.9.14" and "16.37.9.124" are.

Back to index page