Software Development Homework 1

Fall 2005 CSU 670

(you can download the text version here by right clicking)

Whenever you have questions about course material, please send e-mail to: This will reach both Karl Lieberherr and the Teaching Assistant.

Sign up for the mailinglist and use it for communication with the class. Check the archive of this mailing list to get many of your questions about Eclipse and other course topics answered ( CSU 670 Mailinglist Subscription ).

Due date:

THEME: Reverse Engineering of Java programs
Learn basics of XML by studying Demeter example: You learn about data type definitions (DTDs) and schemas, documents and Java code generation from XML DTDs or schemas. You learn the basics of Eclipse.

Eclipse is award-winning open-source technology that has strong backing by many companies, including IBM. Use the Eclipse IDE to browse through the files to understand what the program is doing, maybe using different perspectives . The reason is that later in the course you will add a plug-in to Eclipse and it will be very helpful to know how Eclipse works before you add your own plug-in. Check Eclipse Information to learn about Eclipse installations.

On CCS Northeastern machines,

On the WWW,
SD =
DemJ =
DJ =
D =

The directory containing administrative information and homeworks is: $SD

Use the following header for your homework submissions and put it at the top:

Course number: CSU 670
Account name:
Name: (unless you work individually)
Account name:
Assignment number:

Do NOT include your student id number in any work you submit because some of your work may be put on the web and you don't want your social security number visible.

Read chapters 1, 3 and 4 of the AP book.
Read: chapter 1: A Quick Tour of Java in the Java book by Arnold/Gosling or
the approximately equivalent information in your favorite Java book.

Skim read the following:

About UML class diagrams at
About XML:
(XML = eXtensible Markup Language is a W3C Recommendation,i.e., it is a standard.)

Read about the Law of Demeter: Read section 26: "Decoupling and the Law of Demeter" in the text book The Pragmatic Programmer (TPP). Consider the Challenges question on page 142 and compare with your D*J experiences you make in this course.

The following is from the wiki page shown below:
You can play with yourself.
You can play with your own toys (but you can't take them apart),
You can play with toys that were given to you.
And you can play with toys you've made yourself.
For more information:


This homework is about reverse engineering of Java programs into an object-oriented design. Reverse engineering means to figure out the design from the program text. In this particular situation, the documentation for the program has been "lost" intentionally. You will learn how difficult it is to understand an undocumented program, even if it is small.

Consider the Java program in directory
The files in directory dir with suffix *.java make up the program. The last 4 lines in file prepare show how to compile and run.

To compile and run, please put the rt.jar file into your class path. See:

If you use the CCS .software file, use: CLASSPATH=.:/proj/demsys/demjava/rt.jar

Run "resoft" after the change.

Turn in the output produced by running the program you compiled.

Note: The files in dir have been generated by DemeterJ from short higher level files that comprise the "documentation" that you have to find. While you study the Java programs, you also learn how DemeterJ generates code. The code generation process is similar to the code generation process described in JSR 31, now implemented in JAXB by SUN. This Demeter-like code generation capability is now a part of the latest Java Web Services Developer Pack.
The file program.input that will be used later to create a Java object is an XML document following a simplified form of the offical Chemical Markup Language (CML): In CML, molecules are represented as graphs: the nodes are atoms and the edges are bonds between the atoms.

So we have the following correspondences:

XML Document type definition or schema :: (class dictionary. NOT GIVEN; YOU DRAW IT (by hand or using Eclipse with the OMONDO plug-in))
XML document :: program.input (sentence)

The following file gives you information on the code generation process:

Start your reverse engineering effort with file

Answer the following questions:

1. Draw a UML class diagram for the Java source files in $SD/hw/1/demeterj/dir. (For information on UML, see

Turn in a picture of the UML class diagram. Use your favorite drawing tool to create it and turn in the file that your drawing tool (maybe a pen) produces.

Your UML class diagram will contain directed associations. A directed association looks like:

--------                   --------
|  A   |                1  |  B   |
|      | ----------------->|      |
--------                x  --------

A is the source class, B the target class and x is the name of the role.
In the Java implementation, A and B are classes and A has an instance variable x of class B.

Association is a synonym for relation. The directed association above presents a binary relation. You think of it as a set of pairs, namely (A-object,B-object) pairs. A natural way to implement such a relation is to store the B-object which is
associated with a given A-object in the instance variable x of the A-object.

The name "association" comes from the OMT method. It has found its way into the UML vocabulary.

Do not put methods and their signatures into your UML class diagram unless you use a tool to automatically produce the diagram.

2. Describe the behavior of the program in English.
Try to summarize the program as much as possible. Do not just translate each line in the program into English. Try to describe the overall behavior of the methods. Explain the main() method that calls the print() method.

Here is a start: When
cd dir
cd classes
java Main < ../program.input

runs, the Java virtual machine executes the byte code in file Main.class. This code will execute function Main.main which creates a Molecule-object from file program.input using a parser whose functioning will not be explained here; the parser is automatically generated by a parser generator called ...
In the following we explain the behavior of print() ...

Do points 1-2 (class graph and program explanation) as in part A, but now reverse-engineer the program in


In the this directory the DAJ tool ( DAJ || DAJ on Source Forge ) is used as code generator. DAJ is a simpler compiler than DemeterJ. An important reason is that AspectJ ( is used as target language and not Java.

An added complication of this homework is that you need to learn a little about AspectJ. You need the basics of intertype declarations and the basics of pointcuts and before advice. Intertype declarations are easy: A.f() {} introduces a new method f into type A. Pointcuts select a set of events during the execution of the Java program and before advice is additional code to execute before those events happen.

It is not required to compile and run the program. If you want to compile you need to follow the instructions at:


You need to study the generated Java code (in the dir directory) although it might be confusing. Also keep in mind that there are several ways to generate the code and you see here only two ways. For example in the JAXB approach by SUN mentioned earlier there is a separate file that allows you to control the details of code generation. DemeterJ and DAJ each use a fixed method.

You are asked to wade through a tremendous amount of Java code.

When you study the Java code keep in mind that it must be very regular since it is produced from a small amount of information. Also keep in mind that not all generated code is actually used by the simple application programs. You have to focus only on the code which is used.

Take a look at:

and get a basic understanding of the package.

Find the unknowns in the following Java program: The program prints the city where an employee lives. You should find the UNKNOWNs by using knowledge from your Java book and by what is in the DJ package documentation. Only after you have found all the UNKNOWNs you may want to run the Java program.

class Main {
  static public void main(String args[]) throws Exception {

    // Build object
    Employee e = new Employee(
      new UNKNOWN1(
        new UNKNOWN2(
          new UNKNOWN3(
            new String("Boston")))),
      new UNKNOWN4(),
      new Date());

    ClassGraph cg = buildClassGraph();
    System.out.println("City where Employee lives");
    System.out.println("City where Employee lives: UNKNOWN5 ");


  public static ClassGraph UNKNOWN9() {
   ClassGraph cg=new  ClassGraph(true,false);
   // true: include all fields 
   // false: do NOT include all non-void no-argument methods
  System.out.println("The UNKNOWN10 version is: " + cg.getVersion());
  System.out.println("UNKNOWN11" + "=============================");
  System.out.println("end class graph " + "=============================");
  return cg;


class UNKNOWN12 {
  UNKNOWN13(PersonalInfo personalInfo_, Date d, Date a) {
    personalInfo = UNKNOWN14;
    departure = UNKNOWN15;
    arrival = UNKNOWN16;
  PersonalInfo personalInfo;
  Date arrival;
  Date departure;
  String get_city(ClassGraph cg) {
    return (String) cg.UNKNOWN17(this,
    "from Employee through City to java.lang.String");

class PersonalInfo {
  Address address; 
  PersonalInfo(Address address_) {
    address = address_;

class Address {
  Address(City city_) {
    city = city_;
  City city;

class City {
  City(String name_) {
    name = name_;
  String name;

class Date {

The DJ version is: DJ version 0.8.2
The class graph is=============================
Address = <city> City extends java.lang.Object.
City = <name> java.lang.String extends java.lang.Object.
java.lang.Object : City | Address | java.lang.String | Date | PersonalInfo | Employee | Main common .
java.lang.String = extends java.lang.Object implements, java.lang.Comparable. : java.lang.String common .
java.lang.Comparable : java.lang.String common .
Date = extends java.lang.Object.
Employee = <personalInfo> PersonalInfo <arrival> Date <departure> Date extends java.lang.Object.
PersonalInfo = <address> Address extends java.lang.Object.
Main = extends java.lang.Object.
java.util.Collection = <elements> java.lang.Object. = <elements> java.lang.Object.
end class graph =============================
City where Employee lives
City where Employee lives: bad way

To provide the answers,
use the file $SD/hw/1/UNKNOWNs

An UNKNOWN may be multiple words.

Do exercise 25 and 27 in TPP (section 26: Law of Demeter). Turn in the statement: we have done the "Law of Demeter" part of D.

From the course prerequisites you are expected to know what a grammar is. Write a grammar for atoms: here are three examples of atoms:
<atom id="a1" elementType="O" hydrogenCount="1"> </atom>
<atom id="a2" elementType="N" hydrogenCount="1"> </atom>
<atom id="a3" elementType="C" hydrogenCount="3"> </atom>

using the grammar notation you learned in your Theory of Computation course. (See $SD/hw/1/demeterj/dir/program.input how this representation is used to parse object descriptions = sentences.) This is the offical Chemical Markup Language (CML): Turn in your grammar.

Please follow the following rules:

Bring your hw solutions to class or put them into the mail box of the teaching assistant.

Please submit only once when you are done or on the due date. Submit a partial solution if you did not complete. If it is due on day x, it means at the beginning of class on that day.

For late homework we will deduct 20% per day late, unless you present a very good reason to the teaching assistant.

The Java programs used in this homework have been generated by DemeterJ and DAJ.

1. What kind of preparation do I need for this course?
Experience with object-oriented design and programming and theory of computation are the prerequisites. If you have not taken the equivalent of (COM 1204 or CSU370) AND (COM 1350 or CSU390) see the instructor immediately.

You also need to be prepared to practice pair programming
Pair programming requires the patience to collaborate with a fellow student towards a common goal: to both understand how to solve a specific software development problem. Pair-programming does not mean that one does the work and the other one watches. Pair-programming is an active collaboration where you frequently switch roles (who types and who supervises; who looks something up; etc.).

You are encouraged to do all homeworks and the project practicing pair programming. Pair programming teams turn in only one solution with both names on it. Keep the same partner throughout the course.

Please keep time logs by creating a file in your home directory ~/courses/csu670/timelog.txt where you keep a record for each homework and project. Indicate how much time you spent in each role and what you worked on and what you delivered. You select the roles.

2. What am I going to do if I join the class late?
All messages which I send to the class are archived. If you join the class late, join the csu670 mailing list and read that archive to get up-to-date.

3. How to download DJ and DemeterJ

The instructions for downloading DJ and DemeterJ are at:

4. Where can I find the instructions for DemeterJ?
DemeterJ is not needed for this homework, but if you are curious, the instructions are at URL:

5. How can I do my homework on my own computer? If you want to do your homework on your own computer, you need a Java development environment on your PC or workstation and Internet access. In each class usually several students use Windows or Linux to do their homework on their own machine. But you are responsible for installing the necessary software on your own machine.