• List of Programming Assignments
  • General Information about Programming

  • PROGRAMMING ASSIGNMENTS

    The table below gives the assignments, and associated dates. All future dates are tentative until such assignments are made available.

    Program Topic Date
    prog01 WebHistory 8pm Monday, 9 September 2002
    prog02 Merging (Singly) Linked Lists 8pm Monday, 16 September 2002
    prog03 Memory Management
    (Linked Vectors)
    8pm Monday, 23 September 2002
    prog04 Maintaining a List of Cards 8pm Monday, 7 October 2002
    prog05 Arithmetic Expression Trees 8pm Monday, 21 October 2002
    prog06 Bin Packing 8pm Monday, 11 November 2002
    prog07 Radix-sort vs. Quick-sort 8pm Monday, 25 November 2002
    prog08 (2,4) Trees 8pm Wednesday, 4 December 2002


    GENERAL INFORMATION ABOUT PROGRAMMING

  • Introduction
  • Programming Assignments
  • What to submit
  • Source Code
  • "readme" File
  • Test Input
  • Electronic Submission Procedure
  • Receiving Grade Reprots
  • Java: Software, Documentation, Technicalities
  • Which version of Java?
  • Which development platform?
  • Which I/O package?
  • Documentation for Java?
  • Technical Subtleties in Java
  • Modular Arithmetic
  • Equivalence of Object's
  • Coverting Primitive Types to Object's (e.g., int vs. Integer)
  • Platform Specific Tasks
  • Command Line Arguments
  • Running an Applet
  • The Java Console for applets
  • Computing at Loyola

  • Introduction

    Our general philosophy for this course will be to make our programming assignments as flexible as possible for allowing students to develop programs on any Java platform. That is, although we certainly expect that many students will be working in our department labs, you will notice that assignments can be developed on just about any machine or environment which supports Java.

    Programming Assignments

    What to submit
    The beauty of Java is its portability, so you should be able to develop your programs on any computing platform you wish. At the same time, it is important that some standard procedures are followed so that we can properly compile, run and grade your work.
  • Source Code
    For each assignment, you must submit all source code files which you have created or modified. For portability, you should only be submitting files which end with the {\tt .java} suffix, as these are the true source code files. All other types of files are either machine dependent, or dependent on your development environment. Keep in mind that we will not be able to successfully compile your program unless we have all of the source code files which you are using.

    For many assignments, we will have provided you with a number of files containing source code which need not be modified. In such cases, there is no need for you to re-submit these files - we have them already.

  • "readme" File
    You are required to submit a text file titled "readme" with every program you submit. This file must be a plain, unformatted text file (for instance one created with "Notepad" on a Windows system). Do not submit any formatted files such as those produced by Microsoft Word or other word processors. It will be read at the time your program is graded, so it allows you to give helpful information.

    The content of the file should generally include

  • Your name and login
  • A clear citation of any help you received on this program from other (approved!) sources, as detailed in the policy on Academic Honesty.
  • A brief (i.e. one or two paragraph) overview of your program and any interesting design decisions which you made.
  • Additionally, many of our program assignments will require that you include other specific information in this file. Please read the individual program assignments carefully.
  • Finally, you may include any other discussion which you feel will be helpful when grading your assignment. For example, if there are known bugs or problems with your program, you might briefly discuss them here.
  • Test Input
    For some of the programming assignments, you will be asked to submit an additional file "inputfile" which provides test input for the program. In these cases, we will run all of the students' programs on all of the students' test inputs. Your goal will be to have your test input fool as many students as possible while having your program work correctly on as many of the other test inputs as possible.

    In such cases, please make sure that your input files conform strictly to the expected format standards when the program driver is run using your file as input. Again, such input files must be submitted as a plain unformatted text file (for instance one created with "Notepad" on a Windows system). Do not submit any formatted files such as those produced by Microsoft Word or other word processors.

  • Electronic Submission Procedure
    All programming assignments must be submitted electronically. For each assignment, there will be an aptly named folder in your online submit directory.

    Receiving Grade Reports
    Grade reports for each program, as well as an overview of all grades received in the course will be kept for each student in a special directory named 'grades' within the online submit directory.

    Java: Software, Documentation, Technicalities

    Which version of Java?
    If developing programs elsewhere, you are encouraged to use a version of Java consistent with the "Java 2" platform (i.e. Java release 1.2 or greater). However, most of the code which we provide will also be compatible with Java version 1.1 for your convience in portability (unless otherwise noted).

    Which development platform?
    Sun distributes the basic Java Development Kit (JDK) which can be used in developing and running all programs for this course, on Windows, Unix, or Linux machines. For those wishing to use JDK directly from a DOS window on our lab machines, Dr. Harrington has some advice.

    Manyintegrated development environments (IDEs) have been created which sit on top of JDK, providing graphical interfaces and more functionality (though usually at the expense of slower running times and the possibility of additional bugs in their software). The software in our department labs currently includes Symantec's Visual Cafe 4.1, the BlueJ 1.1.3 interactive Java Environment from www.bluej.org, Borland's JBuilder 5.0 and Sun's Forte 3.0 IDE. So long as you submit the pure source code files with the .java suffix, you may feel free to use any such development environment with which you are comfortable.

    Which I/O package?
    Another issue with Java is whether to use the base I/O classes defined in the language, or to use other I/O packaged which have been built on top of the basic classes.

    Our goal for this course will be to minimize all issues involving I/O as much as reasonably possible. We will not sponsor any specific I/O package in this class. In fact, for the most part when our programs rely on text files as input, we will use a very "simple" file format, and generally we will provide you with drivers so that you do not have to write much code involving fetching input.

    Any code which we provide will use only routines which are standard in Java, so you should be able to use our drivers on any Java environment. In writing your own code, however, you are welcome to use any I/O package with which you are familiar. If you choose, several packages which have been used recently at Loyola can be found on the department machines within the folder e:\java\classes\.

    Documentation for Java?
    Chapter 1 of our textbook provides a review of programming in Java You should be familiar with most of this material as a prerequisite for this course, however you may choose to read this chapter as a review, or use it throughout the course as a convenient source of documentation on Java.

    Chapter 2 of our textbook includes more advanced details of programming in Java, which many are probably not familiar with. We will cover much of this material in the class as it arises, and some of the highlights are given in the remainder of this handout.

    Finally, there are enormously many other tutorials or references for the Java language available, only a few of which are listed in the suggested reading from the course informaton handout. Documentation is also available online, for example through Sun at java.sun.com/docs/.

    Technical Subtleties in Java
    At various times in this course, the code from the text and our programming assignments will rely on various subtleties in the language. Perhaps students are familiar with some of these topics from past programming experiences, but it also may be the case that some of these issues are new to students.
  • Modular Arithmetic
    If you use the "%" operator for doing modular arithmetic, please keep in mind that it has equivalent precedence as multiplication and division. That is, the expression a + b % c + d is implicitly evaluated as a + (b % c) + d, which is not the same as (a + b) % (c + d). Furthermore, the behavior of the "%" operator in Java is peculiar, when one or both of the operands are negative numbers. You will probably want to avoid allowing negative numbers to enter into such calculations.

  • Equivalence of Object's
    A key subtlety arises due to the difference between a reference to an object and the object itself. When defining equivalence in the context of variables which reference objects, there are two possible definitions. One is to say that two variables are equivalent if they reference the same object; the other is to say that two variables are equivalent if they reference equivalent objects. Though at first glance, these definitions may seem, well, equivalent, they are in fact quite different. There may be two distinct objects, in two different places in memory, which happen to look identical in terms of data.

    Let's look at an example involving objects of type String. Consider the following code:

      String a = new String("Hello");
      String b = new String("Hello");
    
    The question may arise whether a and b are equivalent. In the strictest sense, we could write:
      if (a==b) {
        ...
      }
    
    For this example, such a test will fail. The expression literally tests whether or not the two variables are referencing the same object in memory. Though the words may appear to be the same, there are indeed two independent String objects sitting in memory.

    The more general notion of equivalence is accomplished with the test,

      if (a.equals(b)) {
        ...
      }
    
    This test uses the method equals() which must be defined for all subclasses of Object. In this way, each particular class can define its own notion of equivalent objects. For the class String, the notion is what we would expect, that equivalent strings are comprised of the same sequence of characters. Thus on this example, such a test will succeed.

  • Converting Primitive Types to Object's (e.g., int vs. Integer)
    Java has several primitive types, such as int, double and boolean. Everything else is an Object. When a primitive type is passed as a parameter or stored in a variable, the actual value is used. Conversely, when an Object is passed as a parameter or stored in a variable, it is actually the reference to the object which is used.

    Because of this differentiation, you will notice that you cannot assign a primitive value to a variable or parameter which expects a reference to an Object. For example, if you have a class Stack with method push(Object obj) defined, you cannot invoke the method with parameter Stack.push(23).

    Of course, we often would like to be able to use an integer value in situation where an Object is expected. For this reason, Java defined "wrapper classes" for all primitive types. For example, to correspond with the primitive type int there is a class Integer, which essentially is a simple class which contains a single int as an instance variable. The class supports two useful functions (among others) which let you convert from the primitive type to the object, and back:

  • If you have a variable, int value, and you want to create a new Integer with that value, you may type something such as:
      Integer I = new Integer(value);

  • If you have a variable, Integer i, and you want to know what value it represents, you can type something such as:
      int value = I.intValue();
  • Casting
    I hope to add more comments about this one day. For now, please refer to Ch. 2.5 of the text.
  • Platform Specific Tasks
    There are some standard tasks you will need to be able to perform in this course, the extact details of which depend on your development platform. We will try to give highlights of these for the standards most often used at Loyola. If you are using some other development platform, please check the documentation.
  • Command Line Arguments
    Input parameters for a program often comes from the keyboard. However, there is an alternate approach which is often quite convenient and will be used by drivers throughout this course.

    Arguments can be specified to a program at runtime, and are often called runtime arguments or command-line arguments. Specifying arguments is something that is done differently depending on the Java development environment you are using, however all such environments should allow you a way to specify arguments.

  • JDK (Sun's Java Development Kit)
    If you are running your program directly in JDK using the command java, you specify arguments by including them on the command line, such as:
    java MyProgram 40000 2

  • VisualCafe
    You can specify an argument from the Project --> Options dialogue box. Then selecting the "Project" tab, you should see a text box near the bottom half labeled "Program Arguments". You would type the arguments in that box, separated by a space, such as:
    40000 2

  • BlueJ
    When you click on the main class you may select to run the method void main(String[ ]). In this case, a dialogue box for the method call allows you to specify the arguments. These arguments must be expressed as an array of strings, using a precise syntax such as:
    {"40000", "2"};

  • Borland's JBuilder
    You can specify an argument from Project --> Project Properties -> Run. For JBuilder6 or earlier, you will see a field "application parameters" in which you can type the arguments. For JBuilder7, you must hit "Edit" to launch the parameter frame. In both cases, argments are entered delimited by a space, such as:
    40000 2

  • Sun's Forte
    From the Properties window, choose the Execution tab Arguments can be specified by selecting the Execution tab from the Properties window. (The explorer window and the properties window are usually displayed in addition to the source code window, when a project is open. If they are not on, they can be launched from View -> Property.)

    From the Execution tab, fill in the arguments field, delimited by a space, such as:
    40000 2

  • Running an Applet
    An Applet is very much like other Java programs you have seen and written, however it is designed to be embedded into an html document (and thus can be made easily available through the web if you so choose). Although we will not every have you write an Applet from scratch in this class, Applets are often useful because they allow for the convenient use of graphics both in displaying output and in designing a graphical user interface. For these reasons, there will be times in this class where we ask you to use, view or modify a prepared Applet.

    To run an applet you generally need to specify the class which implements the Applet, as well as parameters such as the initial height or width of the applet window. Often these values are stored in an .html file which can be used to start an applet.

    WARNING: When developing your own applets from source code, a potential pitfall exists if you end up in a situation where a Web Browser is being used to run the applet. Many web browsers try to save time by "caching" much of the information it downloads so that the next time it needs it, there will be no need to reload it over the Internet. Unfortunately, some browsers do this with the .class files which define an Applet. This means that you may end up in a situation where you make a change to your sourcecode, recompile the new code, and rerun the Applet while unbeknownst to you, the browser is still running the old/cached version of your code. This can cause great frustration. I might recommend that try to rely on appletviewer when developing code. If you must rely on the browser, you may need to restart the browser between runs, or worse yet force it to clear its cache and then restart.

  • Using a Web Browser
    Most modern web browsers allow you to view an Applet directly. To do so, you must make sure that the .html file and all compiled .class files are in the same directory. Then you should be able to view your applet by sending your browser to the URL such as:
    file:///C:/ThisIsAnExample.html

  • JDK (Sun's Java Development Kit)
    Sun provides an executable called appletviewer which can be used to view an applet. In fact, most other development packages use appletviewer as the underlying way of displaying the applet. To start an applet, you simply specify an HTML file on the command line (such as in a DOS window):
    appletviewer SamplePage.html

  • VisualCafe
    To create a project as an Applet, go to the "Project" menu and select "Options". You will want to consider changing three relevant fields:
  • Project Type: set this to "Applet - A program that runs inside a Web Page"
  • Start with Web page: set this to the desired html file, by clicking on the button labeled "..." to the right of the dialogue box. This will allow you to browse and select the html file.
  • Execute Applet in Default Web Browser: If this option is set to true, the Applet will be run in your default browser. If you leave this option set to false, the Applet will be run using appletviewer.
  • BlueJ
    Click the right mouse on the source code for the Applet, and choose option "Run Applet". This brings up a dialogue box which asks you to give parameters to the applet, such as the height and width. (Sorry, it seems that the current version of BlueJ does not have a way for you to use a prewritten HTML page to specify these values). Once you have set the parameters, you may choose to run the Applet through either the program appletviewer or through your default web browser.

  • Borland's JBuilder
    You can specify an argument from Project --> Project Properties -> Run. (for JBuilder7, you need to also hit "Edit" to launch the runtime parameter frame). From this point, select applet-> and set the html file path by hitting "...". JBuilder uses the default web browser to display the applet.

  • Sun's Forte
    Forte uses the appletviewer by default. But you can choose the external browser by filling in the executor field from the Execution tab of the Properties window. (The explorer window and the properties window are usually displayed in addition to the source code window, when a project is open. If they are not on, they can be launched from View -> Property.)

    You could also set the executor info thru Project -> settings -> execution type -> applet execution. But once you change any property here, your change affects all classes that use that executor.

  • The Java Console for Applets
    When you are running a normal application in Java, all generated output and error messages are displayed in a window (this depends someone on your IDE).

    When you are running an Applet, however, standard output (e.g., that of System.out.println) is not displayed in the main Applet window. Furthermore, if your program crashes, the error information will not be displayed in the Applet window either. Instead, when an Applet is running all standard text output goes to a special window called the Java console. However, you may not see this console unless you look for it. In particular, if you are using Internet Explorer to run Applets, the top-level "View" menu of the browser should contain an entry labeled "Java Console" which you can select to display the console. Similar, using Netscape Navigator/Communicator, you will have to explicit ask to see the Java Console. Which menu to use depends on the version of Netscape. You will likely find it under the "Communicator" menu or the "Communicator->Tools" menus.


  • Last modified: 15 November 2002