NCTU CIS: WWW and Java Programming (July 2005)

Course Information

Instructor

Wuu Yang, <wuuyang@cis.nctu.edu.tw>, EC332B, 03-5712121 ext. 56614.

Lectures

This lecture meets every Tuesday night 6:30-9:30 pm, from July 12 2005, for 9 times. This course will last for 9 weeks.

Lab time:

2nd lab: traffic.pdf

Answer to 3rd lab: CopyDirFile.java.

 

Try Example018.Thread

Try work022

Course URL

http://www.cis.nctu.edu.tw/~wuuyang/Lecture/lecture.java.html

Course Description

With the rapid deployment of the internet, the World-Wide-Web quickly becomes one of the most useful tools in our daily work and entertainment. The Java language is closely combined with the Web. Java has become a very practical programming language due to its true cross-platform nature, which is well worth your investment to learn. In this course, we will discuss applications of WWW and Java programming for the Web. We plan to cover the following material:

Textbook

The textbook for the class is: Mary Campione and Kathy Walrath, The Java Tutorial, Addison-Wesley, 1996. List price NT$980, 831 pages. An on-line copy of the book is here. This textbook is on Java version 1.0. The current version of Java is 1.4. If you want to buy books about Java, buy the newer books.

(reference only)D. Flanagan, Java in a Nutshell, 3rd ed., 1999. This is a good reference on the new version (versions 1.2 and 1.3) of Java.

(reference only)G. McGraw and E.W. Felten, Java Security, Wiley, 1997. This book discusses security issues in Java and in networking.


A notes on using java on CIS workstations:

1. log in one of cissol1, cissol2, cissol3, or cissol4.
2. Add /usr/local/java/jdk1.1.5/bin to your $PATH.
3. Java compiler is javac. Java interpreter is java.
4. To see the manual page, use "man javac" and "man java".


Homework

It is said Java provides hiding, overriding, and overloading. Please explain the three terms: hiding, overriding, and overloading.


Project 0.

In this project, you need to install JDK 1.3 (downloaded from this page) on your personal computers. After that, you need to edit, compile, and run the first two examples on the classnotes, one for an application, and the other for an applet.


Project. Practice program

Write a program to sort the following integers. Hint: use arrays and basic Java statements. 11 23 9 48 6 15 63 2


Project. Practice program

Sort the above numbers with quicksort.


Project. Practice program

Implement the Eratoshenes Sieve for prime numbers.


Project. Practice program

Copy a file.


Project. Practice program

Copy all the files and subdirectories in a directory.


Project 1. Differential Directory-Based Backup

Backup is a practical, but difficult piece of work. When we work on the computers, our files are saved on the hard disks. Though hard disks are quite reliable nowadays, to avoid the serious trouble of losing data, it is absolutely necessary to save copies of the files on a separate medium. The separate medium used to be a tape drive. It could also be another hard disk.

In our project, we consider backup with anther hard disk. Our strategy is to make an identical copy of the working hard disk on the backup hard disk at the midnight of every day. This method is called \f5periodical disk mirroring\f6.

A straightforward way of backup is to copy all the files on the working hard disk to a second disk every day. When the size of the working files is too voluminous, complete backup may take too much time. We note that, though the size of all the working files could be voluminous, only a small fraction of all the working files are modified each day. It saves a lot of time if only modified files are copied to the backup hard disk.

The situation at the midnight of every day is as follows: we have a backup disk, containing all the files at the beginning of the day and a working disk, containing all the files at the end of the day. We want to copy necessary files from the working disk to the backup disk so that the backup disk will become identical to the working disk.

To determine whether an old file and a new file differ, we simply check the modification times of the files. If the modification times are different, we assume that the file is modified and needs to be copied to the backup disk.

In this project, you need to implement a backup utility in Java to mirror disks. Specifically, you need to implement the following features:

  1. Create a dialog window, asking for the directory of the source.
  2. Create a dialog window, asking for the directory of the destination.
  3. Create a dialog window, asking for options for disk mirroring. Possible options include
    • t: for testing only. This options simply prints a list of files that should be copied but does not actually copy the files.
    • c: for copying. This option actually copies all the necessary files.
    • p: for purging. This option removed the files that are on the backup disk but are not on the working disk (because they are removed from the working disk by the user.
  4. Create a file, containing all the files that are actually copied during backup. The name of the output file should be taken from an environment variable with a suffix of the date of the backup date. An example file name could be "backup.19980401", "backup.19980402", etc.

You probably need to consult the java.io.File class for this project.


Project 2. FTP Server and Client

You are asked to write an FTP server similar to Servu and an FTP client similar to cutFtp. Each must come with a friendly user interface.

You probably need to consult the java.io.File class for this project.


Project 3. Multi-Threaded Servers

Rewrite the client/server example in chapter 11 so that the server creates a new thread when a client tries to connect to the server. The original server then is free to accept new connection requests from other clients. Your server should be able to serve at most five clients simultaneously. When a sixth client attempts to connect to the server, the server should tell the sixth client to try the connection a few minutes later. The original source code is available here.


Project 4. A Very-Simple File Manager

This question is concerned with the creation of a very simple file manager that comes with a graphical user interface. Suppose that we have a hierarchical file system, similar to the one in the Unix system. A file is addressed as /export/home/funnyguy/personal/letter.doc. You need to create a window that contain a menu bar and four panels as follows:

 --------------------------------------------------------------
 | file |                                                     |
 --------------------------------------------------------------
 |     directory name /export/home/funnyguy                   |
 --------------------------------------------------------------
 |                                                            | 
 |    panel 2                                                 | 
 |                                                            | 
 --------------------------------------------------------------
 |     directory name /export/home/funnyguy/letter            |
 --------------------------------------------------------------
 |                                                            | 
 |  panel 4                                                   | 
 |                                                            | 
 --------------------------------------------------------------

In the menu bar, there is a single file menu. It contains a single action exit. When the exit button is clicked, the file manager should close its window and stops.

In panel 2 and panel 4 above, there is one icon for each file or subdirectory in the current directory. There is a also an icon that represents the parent directory. Place the parent directory at the upper-left corner of the panel.

A user may do three things in this file manager window: First, she/he may travel to the parent directory or a subdirectory by double-clicking appropriate icons. Second, she/he may type the name of a directory in the first or third panel. When the enter key is hit, the system will display the content of the directory in panel 2 (or panel 4). If what the user types is not a directory name, the file manager should display a warning message. You should implement this action with Java exceptions.

The third thing a user can do is to drag an icon (representing a file, not a directory) from panel 2 to panel 4 (or from panel 4 to panel 2). The file manager will attempt to copy the file to the destination directory. If there is already a file with the same name in the destination directory, the file manager should ask the user whether she/he wants to overwrite the existing file. You may implement this part with the dialog component.

To make the question easier, we will assume that

  1. Only files may be copied.
  2. The window has a fixed size.
  3. Both panel 2 and panel 4 are large enough to display the full contents of a directory. No scroll bar is needed.
  4. All file names and directory names contain exactly 6 characters.
  5. There are no links, special files, etc.
  6. The user is permitted to visit all directories and copy any files to any directory. There is no access control.

You probably need to consult the java.io.File class for this project.


Project 5. Simple Fractal


Project 6. Draw lines

Give a sequence of line segments, you need to draw these line segments on a canvas. The input file has the form:

[pair (coord (0.0,0.0),coord (0.0,3.0)),pair (coord (0.0,3.0),coord ( ~2.598076144366072,4.500000116025305)),pair (coord (~2.598076144366072, 4.500000116025305),coord (0.0,6.0)),pair (coord (0.0,6.0),coord (0.0,9.0))]

Here [ ... ] denotes a sequence of line segments. Each segment is denoted by pair( ... ). The notation coord(0.0, 3.0) represents the coordinates of a point in a plane.


Local On-Line Information Concerning Java

Information on the Net


Wuu Yang, <wuuyang@cis.nctu.edu.tw>, EC332B, 03-5712121 ext. 56614.