From CS 455 Spring 2013

CS455-S13: Program 1: Java/Python Refresher

Assigned: Tuesday, January 14, 2013
Due: Tuesday, January 22, 2013

Contents (hide)


You may use either Java or Python for programming assignments throughout the semester. It is assumed that you already know one of these languages or feel comfortable enough in your programming skills to be able to learn enough to complete the assignments. The reason we are using Java/Python is that the socket programming constructs used to develop network applications are much simpler than in C or C++.

Note that the 6th edition of the textbook has socket programming examples in Python, while earlier editions use Java. When we get to Chapter 2, I will show examples in class using both languages.

The programming assignments during the semester will involve reading user input from the command line, parsing strings returned in network messages, and parsing URLs. This assignment is designed to refresh your memory on (or help you learn about) these particular parts of Java or Python.

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


Task 1: Read in the command-line arguments.

The program should take 2 command-line arguments:

  1. a URL beginning with http://
  2. an integer
Usage: java Prog1 URL integer
Usage: python URL integer
ERR - URL format
ERR - arg 2

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

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

Task 4: Output the hostname in the URL

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.



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.

In these examples, if you use Python, replace java Prog1 with python

Example 1

java Prog1 
Usage: java Prog1 URL integer

Example 2

java Prog1 3

Example 3

java Prog1 5

Example 4

java Prog1 5

Example 5

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

Example 6

java Prog1 4
ERR - URL format

Example 7

java Prog1 '' 10

Example 8

java Prog1 http://amazon/myaccount.html 1.5
ERR - arg 2


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

Directions for submitting your assignment through Blackboard

Getting Started


If you've never programmed with Java before, here are some helpful tips:

Here is the skeleton for Program 1 (to be saved as

// Insert Your Name 
// Insert Your Class (CS 455 or CS 555), Spring 2013
// Program 1 - Java/Python Refresher


class Prog1 { 

   public static void main (String argv[]) 

       // insert your code here 



If you've never programmed with Python before, here are some helpful tips:

Here is the skeleton for Program 1 (to be saved as

# Insert Your Name 
# Insert Your Class (CS 455 or CS 555), Spring 2013
# Program 1 - Java/Python Refresher

import sys

# insert your code here 


If you've never used Unix before, here are some helpful tips:

Retrieved from
Page last modified on January 20, 2013, at 08:45 PM