This site is currently under construction. It will eventually
serve as a resource for Java internet programming. As such it will support a
number of simple servers that illustrate web techniques in Java, including Java
access to data base services and other net services such as Gopher.
Also included will be a number of links to interesting sites. We are
especially interested in providing services to other computer science educators.
The Java Home Page is.
java.sun.com
There are lots of Java resources at
www.gamelan.com
You can also use altavista
to search for "java". Be sure to use all lower case letters in your search. If
you search the Web you get java resources. If you search Usenet, you get all
discussions of Java in all newsgroups. See bottom of this page for the altavista search engine. You can also subscribe to
comp.lang.java
Java is available over the internet from
ftp.javasoft.com.
It will run on Suns, Windows/95, and on the Macintosh under System 7.5.
Here are two sites at javasoft.sun.com.
Java Developer Connection - Home Page
Java: Programming for the Internet
More on Java
Digital Espresso = Usenet Summaries.
The Java Generic Library (JGL) . From Object Space. This library
is roughly equivalent to the Standard Template Library of C++, but is tailored for Java. It is
very good and complete. It is being bundled with many Java compilers (Codewarrior, Borland...). You
can download it from here.
A Java Zine. Check it out.
A Java Newsletter that you can read on the web or subscribe to.
Additional materials, including sample Java code.
Java files (text format).
Some sample Applets:
-
Three Applets On One Page . These are a visual sort demo, a simple game, and a simple spreadsheet program written in Java.
- A Nuclear Stability Calculator Built with Visual Café. This applet lets you determine if a certain balance of nuclear forces leads to a stable or unstable strategic situation.
- Echo Server. This is adapted from Core Java (2ed). It
echos what you send to it. Whatever you type will be echo'd. The source code
is in the book--except that a loop has been added so that it doesn't quit
after handling the first client.
- To use this server: Telnet to sol.pace.edu port 8189. It only handles
one client at a time, however. Note also that it runs intermitently so
it is not always available.
- To run this server you must first compile it with javac, of course.
Then run it in the background (on the server) with the command
java EchoServer &
It will then listen for requests at its port until you kill the process.
Remember the process number that is returned when you first run the server
so that you can later kill the process when you don't want the server
to run anymore.
- EXERCISE: Write a FortuneCookieServer. Each time
it is accessed it returns a randomly chosen or (harder) randomly generated
bit of text in the form of a fortune cookie like: "Your future will be
filled with happiness." Implement this a a threaded server with a fixed
maximum number of simultaneous clients (to prevent a hostile client from
generating so many requests that the server slows down).
- Echo Server (CGI). This is a very simple CGI (Common
Gateway Interface) program written in perl that simply echos its first command
line parameter. Here is an
applet that can test the server. This server runs on demand and does
not need to be started first. When you ask the server for service at the address
of this script, the server executes it using perl.
- The perl code for this server is trivial: echosvr.pl
#!/usr/bin/perl
($inp) = @ARGV;
print "Content-type: text/html\n\n";
print $inp;
print "\n";
- Note that this server doesn't run until there is a service request,
and a separaate process is created for each request. The first type of
server (above), which runs continuously and listens on a port can handle
several requests with only one process, but that process must run continuously.
- A CGI program can't be interactive. It takes a request and returns
a result and then quits.
- CGI programs can be written in java or c as well as perl, but they
require help from the server to execute them. They are normally used to
process Web forms, like the AltaVista form. On this server I need a little
shell script to actually run the java server.
- The Java code equivalent to the above Perl script is also trivial:
echosvr.java
public class echosvr
{
public static void main(String args[])
{ System.out.print("Content-type: text/html\n\n");
if(args.length>0)
System.out.print( args[0] );
}
}
This code is driven by the following simple shell script: echosvr.sh
#!/bin/sh
/external/jdk/jdk1.1.1/bin/java echosvr $1
- Dog Server. In 1993 a cartoon by P. Steiner appeared
in the New Yorker magazine. A dog was typing at a computer and talking to
another dog over its shoulder: "On the internet, nobody knows you're a dog."
This server was taken from the book Just Java, by Peter van der Linden,
published by Prentice-Hall. It attempts to determine if a client is a dog
by asking it a question. The client answers the question and the server
determines if the client is a dog or not. The question is: "If I met you
would you shake my hand, or sniff it?"
When it is running this server listens on port 4444 of sol.pace.edu. When
queried, it sends out its question and then examines the answer for the
word "sniff" to decide how to reply further.
A client applet or application must open a socket to port 4444 on sol
and then reply to the question. It can then process the answer to see if
the server has determined the "dog nature" of the client. The code may be
obtained from the book mentioned above or from Professor Bergin.
When the server is running you may exercise it with the
Dog Tester Applet .
- Proxy Server and the New York City Weather. A Java applet
can only connect to the machine that it was loaded from. This means that lots
of interesting things can't be done without some help from that host machine.
A proxy server runs on the applet host and takes requests from applets to
fetch documents from other places. Interestingly, a proxy server can fetch
pages from the web, but it can also know about other protocols, such as the
gopher protocol. Sol runs a proxy cgi written in Java that can do this. Here
is an applet that fetches the New York City weather (updated approximately
hourly) from a gopher server at the University of Michigan.
New York Weather Appplet NOTE:
The UM weather gopher has shut down so this won't work anymore. Here is a
link to Cay
Horstman's latest weather applet. It depends on a site maintained by NOAA,
so it should be more stable.
For this to work, the applet, downloaded from the server (like sol), makes
a request of the proxy server on the same server to fetch a gopher or other
document. The server fetches the document and then gives it to the applet.
The applet itself only connects to its host and uses no facilities of the
machine it is running on, or any other machine on the web.
- Chat Server Sol runs a simple (and flakey) chat server
on port 4440. Messages sent to it are broadcast to others connected at that
time. It only handles four users at this time and sometimes crashes. Both
the server and the applet that talks to it are multi-threaded. The server
must also manage shared memory to talk to the four threads representing the
users. Incoming messages from the users are queued for broadcast, but the
queue only holds one message.
Chat Applet
Using Inner Classes and Interfaces Together
"Java in a Nutshell, 2ed," David Flanagan, O'Reilly & Associates, 1997. This combines a good explanation and solid reference materials.
"Java Network Programming," Elliotte Rusty Harold, O'Reilly & Associates, 1997
"Core Java 2ed," Gary Cornell & Cay Horstmann, Prentice Hall, 1997 . Excellent examples and a guide to actually using Java.
"The Java Programming Language," Ken Arnold & James Gosling, Addison Wesley, 1996 . A good description of the language itself, by its creators.
"Concurrent Programmin in Java," Doug Lea, Addison Wesley, 1997 . Explains how to use the concurrency primitives to do interesting things. It is a course in concurrency, not in Java.
"The Java Virtual Machine Specification," Tim Lindholm and Frank Yellin, Addison Wesley, 1997 . The details of the inner workings of Java.
"The Java Class Libraries," Patric Chan and Rosanna Lee, Addison Wesley, 1997 . This is a reference work.
"Computing Concepts with Java Essentials," Cay Horstman, Wiley, 1998. This is an elementary programming book that uses Java. It is intended for beginners.
Alta Vista
The following will search the Alta Vista worldwide database for any information you would like.
Thanks to Digital Equipment Corporation for providing this service.
You may also link directly to the Alta Vista homepage:
http://altavista.digital.com . Go here for
Alta Vista help.
This site is maintained by Professor Joseph Bergin, berginf@pace.ed
http://csis.pace.edu/~bergin
Computer Science Department
Pace University
One Pace Plaza
New York, NY 10038 USA
Comments, suggestions, and bug reports are very welcome.
Last Updated: December 9, 2000