Java logo

HANDOUTS - CODE

FALL 2001/SPRING 2002



Hello!

Sources for HelloWorld.java and HelloWorldApplet.java

PIO


pio.java: A package for simple input.
testpio.java: A sample test program for pio.

FACTORIAL


Source for Factorial.java which will help with homework 2.

COMMAND LINE ARGUMENTS


Source for CommandLine.java which will help with homework 3.

TIMED FIBONACCI NUMBERS


Source for TimedFibonacci.java which will help with homework 4.

Arrays


Source for Array.java which gives an example of an Array with methods and constructors.
Source for ArrayTest.java which gives a test of the Array class.

Queues


Source for Queue.java which gives an example of a Queue with methods and constructors.

Vectors


Source for Vectors: which gives an example of vectors.

APPLETS

See: http://www.bruceeckel.com for a good book with examples!
You can download the source code from that book at: ftp://www.mindview.net/pub/eckel/TIJ2/
The sources for Chapter 13 from Eckel's book as a JAR file is here.


Source for Applets: which gives a very general example of a template for applets.
Source for pArc.java which gives a very complete example of an applet with graphics.
From Teach Yourself Java in 21 Days, 2nd Ed. you may look at the source from Chapter 9 and from Chapter 10. These should help you with homework. Also, here is the Buttons stuff I showed in class from Deitel & Deitel in JAR form.
Also from Teach Yourself Java in 21 Days, 2nd Ed. there are files ButtonActionsTest.java and HandleButton which show how to change colors of the background using buttons.

Excellent Reference!


You may download the source code from the web site for this text or get it directly as a ZIP file TYJ21PRE.ZIP

ZIP


Here is wiz401xN.exe which is Info-ZIP's graphical archiver, version 4.01, Windows 32-bit exes & docs in self-extracting format. This is a "evaluation" version. If you like it, buy it! Check out
http://www.cdrom.com/pub/inforzip/

Here is winzip70.exe which is the "standard" graphical archiver, version 7.0. Windows 32-bit exes & docs in self-extracting format. This is the "evaluation" version. If you like it, buy it! Check out
http://www.winzip.com


If you want to see how to place a frame in the window, download CenterFrame.java and see how it is done.
If you want to see how to be able to have the same code work both as an Applet and as an Application, download MessagePanel.java and then also download the real program DisplayMessageApp.java and try it. Note, I have put the HTML stuff necessary within the Java code so you can just call
appletviewer DisplayMessageApp.java
or
java DisplayMessageApp x y M
where x and y are the coordinates and M the message.
I have been showing examples from Liang's book. You can download them from the publisher or here: liang.jar This "jar" (Java archive) file is like a "zip" file and you can find out about it with
jar -h

The Dining Philosopher's Problem code by Dr. Page is available for download. Just click Diners.java.
Some material helpful for Chapter 16 (Multimedia) may be downloaded here: multimedia.jar
The jar file UserEmail.jar described in class may be downloaded here: UserEmail.jar
The TextPad program I have been demonstrating in class can be downloaded here: TextPadSetup.exe I like it and suggest you pay for it if you also want to use it.
StringTokenizers should be used as follows:
	StringTokenizer tokenizer = new StringTokenizer( string );
	----------------------------------------------------------
	while (tokenizer.hasMoreTokens())
	{	String token = tokenizer.nextToken();
		/* process token */
	}
	----------------------------------------------------------
	int tokenCount = tokenizer.countTokens();
	for (int i = 0; i < tokenCount; i++)
	{	String token = tokenizer.nextToken();
		/* process token */
	}
	==========================================================
	/* Constructor  [in java.util.*]

		StringTokenizer ( string , delims )

	   will allow one to choose the delimiters;
	   e.g., 

		StringTokenizer ( string, " \t\n\r,.:;'\"")

	   would use space, tab, newline, return, and also comma, 
	   period, semi-colon, colon, apostrophy, and quote as 
	   nonreturned delimiters. 

The ChatServer adapted from Bishop's book can be found here