You will study the most up-to-date programming technologies including
object-oriented programming, visual programming, and programming for the
Internet. Topics include object-based programming, object-oriented programming,
strings and characters, graphics, basic graphical user interface (GUI)
components, multithreading, bit manipulation and introductory data structures.
Instructor Symon Chang has taught many Java classes in US, and published many Java articles on computer magazines in Taiwan.
If you install JDK 1.2 on Windows, read this page first. The size of JDK 1.2 is 20 MB. It will take 2+ hours to download under slow dial-up link.
If you are using your home machine, follow the instructions for that compiler/interpreter. You will need to create a text file called Test.java and put these contents in it:
class Test {
public static void main (String []args) {
System.out.println("Testing the Emergency Broadcast " +
"Program ");
}
}
Open a DOS window, and make sure you set the path:
SET PATH=c:\jdk1.1.7\bin;%path%Where the c:\jdk1.1.7 is the directory that you install your JDK under.
Then you should use the Java compiler (which is called javac) to compile it. Try this:
javac Test.javaIf everything is ok, you'll just get the prompt back. If there are errors in your code look at the error messages, fix the bugs, and try again. The result of a successful compilation is a .class file, so you should have Test.class in your directory now.
To run the program, you need to invoke the Java interpreter on the resulting class (which is called Test). So use:
java TestThis should cause the program to run and print the message on the terminal. Note that you do not put the name of the file that has the compiled class in it, you put the name of the class.
Note: If you want to know more in how to get start with Java, check here...
Note: If you have problem with classpath, check here...

To set-up your DOS windows for the Java class, you need to copy MS-DOS windows Icon from your desktop, and rename it to Java MS-DOS Window. Then, you need to change the properties of the Java Window. This will look like this....
The setjdk.bat file will look like this:
doskey SET PATH=c:\jdk1.1.7\bin;%path% SET CLASSPATH=.;c:\jdk1.1.7
Please visit the following web pages:
We will have the first mid-term on 04/06/99. The mid-term will cover the following topics:
Sample Employee.txt can be downloaded from here.
AWT Programs
We will start to do same simple AWT Applets like this:
See EmployeeField.java for how to do it.
*********** OUTPUT *************
C:\My Documents\java1\CIS102>java ClientVector
Write vector to file Client.Vector.data
Error on writing vector to Client.Vector.data
java.io.NotSerializableException: Client
at java.io.ObjectOutputStream.outputObject(Compiled Code)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:248)
at java.io.ObjectOutputStream.outputArray(Compiled Code)
at java.io.ObjectOutputStream.checkSubstitutableSpecialClasses(ObjectOutputStream.java:340)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:244)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:369)
at java.io.ObjectOutputStream.outputObject(Compiled Code)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:248)
at ClientVector.writeAndClose(ClientVector.java:52)
at ClientVector.main(ClientVector.java:200)
A: You need to implements java.io.Serializable on your Client class.
Example:
String fName = "missing.txt";
try {
/* Open FIle */
fileInput = new FileInputStream(fName);
} catch (Exception e) {
System.err.println("Unable to open " + fName);
return;
}
EmployeeApp Program
The EmployeeApp now is using Layout Manger. The class will like this:
See EmployeeApp.java for how to do it.
public void paint(Graphics g) {
g.setFont(new Font("TimesRoman", Font.BOLD, 26));
g.drawString(sTitle, 0, 40);
g.setFont(new Font("TimesRoman", Font.PLAIN, 14));
g.drawString("Symon Chang", 64, 60);
g.drawString("e-mail: symonchang@earthlink.net", 21, 80);
g.setFont(new Font("TimesRoman", Font.BOLD, 12));
g.drawString("Press 'About' again to cancel", 39, 106);
}
Hit this button to see the output.
See TestAbout.java for how to do it.
*********** OUTPUT *************
D:\cis102\Homework\Project8_hw5\project>java ProjectApp
Reading objects from Project.Vector.data ...
Exception occurred during event dispatching:
java.lang.NullPointerException
at ProjectApp.action(ProjectApp.java:108)
at java.awt.Component.handleEvent(Compiled Code)
at java.awt.Component.postEvent(Compiled Code)
at java.awt.Component.postEvent(Compiled Code)
at java.awt.Component.postEvent(Compiled Code)
at java.awt.Component.postEvent(Compiled Code)
at java.awt.Component.dispatchEventImpl(Compiled Code)
at java.awt.EventDispatchThread.run(Compiled Code)
*********** PROGRAM *************
public boolean action(Event evt, Object obj) {
int id = 0;
String n;
String desp;
String c;
if (evt.target == btnAdd) {
n = txtProjName.getText().trim();
if (n.length() < 1) {
showStatus("Error: Invalid Project Name");
return true;
}
a = v.getProjectByName(n);
if ( null != a) {
showStatus("Error: " + n + " already exist");
return true;
}
desp = txtProjDesp.getText().trim();
if (desp.length() < 1) {
showStatus("Error: Invalid Description");
return true;
}
c = txtClientName.getText().trim();
if (c.length() < 1) {
showStatus("Error: Invalid Clinet Name");
return true;
}
c_exist = vc.getClientByName(c); // This is line 108
if (null == c_exist) {
showStatus("Error: Client " + c + " does not exist");
return true;
}
showStatus("Adding new Project Object");
id = v.getTotalProject() + 1;
a = new Project(c_exist, id, n, desp);
v.add(a);
can.repaint();
}
if (evt.target == btnSave) {
v.writeAndClose();
}
return true;
}
A: Your need to create the ClientVector object, before you use it. In your init() method,
just add one more line:
vc = new ClientVector();
TipApplet Program
TipApplet will show the Frame of Tips Menu, which is using Menu and MenuItem in AWT.
Hit this to see the Tips Main Menu.
EmployeeLocator.java will show how to get next Employee object.
See Employee Locator Information for more information.
EmployeeManager.java will show how to update and delete the Employee object.
See EmployeeManager.java for how to do it.
EmployeeID.java will show how to get the Employee object by EmployeeID.
See EmployeeID.java for how to do it.
DateTest.java will show how to get the Date object from GUI. It gets mm/dd/yy from GUI, and display the Date object.
See DateTest.java for how to do it.
See Tips for some tips.
Last modified: 05-11-99