CS 455/555 - Intro to Networks and Communications
Fall 2009: Tues/Thurs 3-4:15pm, Spong 0108

Print - Admin



  • Dr. Michele Weigle
  • mweigle at cs.odu.edu
  • E&CS 3214
  • Office Hours: MW 2:30-4pm
  • Grader: Hui Shi
  • hshi at cs.odu.edu


Syllabus (pdf)

Useful Links

Program 1: Java Refresher

Assigned: Tues, Sep 1, 2009
Due: Tues, Sep 8, 2009 before class

Motivation Description Rules Testing Submission Java Intro


We will be using Java for programming assignments throughout the semester. It is assumed that you already know Java or feel comfortable enough in your programming skills to be able to learn enough Java to complete the assignments. The reason we are using Java is that the socket programming constructs used to develop network applications are much simpler in Java than in C or C++.

If you cannot complete this assignment in just a few (2-4) hours, please come talk to me.


Task 1: Read in the command-line arguments.

The program should take 3 command-line arguments:

  1. a URL beginning with http://
  2. an integer
  3. a top-level domain (TLD) beginning with . (ex: .com, .edu, .uk)
  • If there are not 3 command-line arguments, exit after printing the usage statement
Usage: java Prog1 URL integer .TLD
  • If the URL does not start with http://, exit after printing the error message
ERR - URL format
  • If the second argument is not an integer, exit after printing the error message
ERR - arg 2
  • If the TLD does not start with ., exit after printing the error message
ERR - TLD format

Task 2: Output the number of characters in the URL after http://

  • Output only the number of characters on a single line.

Task 3: Output the product of the number calculated in Task 2 and the integer command-line argument

  • Output only the resulting number on a single line.

Task 4: Determine if the hostname in the URL ends in the TLD

  • If the hostname does not contain a ., exit after printing the error message
ERR - hostname format
  • If the hostname ends in the TLD, print the message
  • If the hostname does not end in the TLD, print the message

For this assignment, valid URLs will be written in the form http://hostname[/path] , where hostname is the web server's hostname, and path is the path from the web server's main directory to the requested file and is optional. Only lowercase letters will be used.


  • As with all projects, you are not permitted to work with anyone else (even students not in the class) - all of the coding and documentation must be your own.
  • Your program must compile and run on the CS Unix machines. If you do not have an account, see me today!
  • You must write neat code and document it well. You will lose points for sloppy programs that contain little or no comments.


A large part of your program's grade will be determined by how well it handles a set of inputs. You should test your program rigorously before submitting. Because your programs will be run and tested using a script, you must format your output exactly as I have described or you will lose points.

Example 1

java Prog1 
Usage: java Prog1 URL integer .TLD

Example 2

java Prog1 http://amazon.com 3 .com

Example 3

java Prog1 http://amazon.edu.com 5 .edu

Example 4

java Prog1 http://www.amazon.com/myaccount.html 5 .com

Example 5

java Prog1 ftp://amazon.com 4 .edu
ERR - URL format

Example 6

java Prog1 http://amazon/banana.html 5 .com
ERR - hostname format


You must name your source file Prog1.java (capitalize only the first letter). Make sure that you submit all files necessary to compile your program. But, do not submit compiled files (.class files).

Directions for submitting your assignment through Blackboard

Getting Started with Java

If you've never programmed with Java before, here are a couple of helpful hints:

  • Java syntax is very, very similar to C++.
  • Only one class is allowed per file, and the name of the class must match (exactly!) the name of the file. For Program 1, you are to name your source file Prog1.java, so you must name your class Prog1.
  • The "import" statement is used give access to built-in libraries, much like the "#include" statement in C/C++.
  • To print output (instead of printf), use System.out.print() or System.out.println(). println() adds a newline character to the end of the String given.
  • The main method should be declared as "public static void main (String argv[])". The String array, argv, gives you access to the command-line arguments. The first element of the array (argv[0]) is the first argument (and not the program name as in C/C++).
  • To compile your program, use "javac". Ex: javac Prog1.java
  • To run your program, use "java". Ex: java Prog1 http://www.amazon.com 3 .com
  • The Java String class reference will be useful in completing this assignment.

Here is the skeleton for Program 1 (to be saved as Prog1.java):

// Insert Your Name 
// Insert Your Class (CS 455 or CS 555), Fall 2009
// Program 1 - Java Refresher

import java.io.*; 

class Prog1 { 

   public static void main (String argv[]) 

       // insert your code here