Index Copyright © 1997, 1998 by Axel T. Schreiner. All Rights Reserved.

Programming with Java -- Examples

applets/ applets on web pages
apps/ applications with graphical user interfaces
include/ auxiliary files to adapt make for various platforms
programs/ programs without graphical user interfaces
Introduction
programs/hello a first program
apps/hello a first application
applets/hello a first applet
The Programming Language Java
programs/int/ integer values
Ranges.java ranges, bit operations
Try.java dividing by zero, ArithmeticException
Cvt.java conversions, raising an Exception
programs/float/ floating point values
Ranges.java ranges, special values
Qgl.java solves a quadratic equation; conversions, arithmetic
programs/boolean/ conditions
Cvt.java conversions
programs/wc/ counting characters, package documentation
Wc0.java base class: processing the command line, designing the methods
Wc1.java base class: implementing the auxiliary methods
Bc.java counts bytes
Uc.java counts characters, UTF8 encoding
Wc.java counts lines, words, characters, and bytes with selectable encoding; demonstrates command option processing and specialized input streams
programs/char/ characters and strings
Prop.java properties, emulates printenv
Hi.java examples of inner classes
Expression.java evaluates arithmetic expressions; nested and anonymous classes
Expr.java command line as a Reader, emulates expr
programs/main/ command line processing
programs/cmd/ command line processing examples
Cmd.java trivial example for flags and options
Cat.java lists files or standard input; demonstrates working with file names
Wc.java counts lines, words, characters, and bytes with selectable encoding; demonstrates adapting the Wc classes to CommandLine
Ls.java lists information about files; demonstrates path operations
programs/sort/ sorting
ShellSort.java sorts arguments or lines, trivial implementation
Print.java lists arguments, trivial example for Print and Elements
A.java sorts arguments, simple example for Sorted, Comparable and Comparer
B.java sorts lines in ascending or descending order, simple example for Lines
C.java sorts system properties in ascending or descending order
D.java sorts system properties in ascending or descending order with a Comparable class
E.java sorts Float values from input lines in ascending or descending order with a Comparer class AsFloat
applets/thread/ thread status
Ts.java lists thread status in an applet or an application as diagnostic output
ATs.java shows thread status in an applet in a text field of the applet demonstration for suitable browsers
programs/thread/ threads
Many.java many threads list the command line arguments
Randy.java many threads list the command line arguments but only the last one should write a line feed; demonstrates synchronisation problem
Morse.java many synchronized threads list the command line arguments and only the last one writes a line feed
Any.java reader-writer problem: main thread produces command line arguments, several synchronized threads compete to write the output
Consumer.java reader-writer problem: main thread produces command line arguments, several synchronized threads compete to write the output; demonstrates Semaphore
Philosopher.java five dining philosphers share five forks for five courses; demonstrates conditional access to semaphores (forks)
Grep.java scans for command line argument on input lines
GrepAll.java scans for all command line arguments on one input line; uses instances of Grep as parallel threads connected by pipes
The Abstract Window Toolkit
apps/gui/ simple examples for all visible objects and their events; invoked with awt.main (require JDK >= 1.1)
applets/gui/ the same examples on web pages with awt.LoaderApplet and event display in awt.Listener (require appletviewer or hotjava)
A.java Button and arranging with a Panel [applet]
B.java Canvas with mouse events; quit by leaving the drawing area [applet]
C.java Checkbox connected with CheckboxGroup arranged with Panel; quit by selecting Really and then Quit [applet]
D.java Choice; quit by selecting Quit [applet]
E.java Dialog, regular and modal versions [applet]
F.java FileDialog to load and store files [applet]
G.java asynchronous display of an image in a Canvas loaded from a local file or from the net; quit by double clicking the image; uses ImageView [applet]
H.java Label with colors; quit by double clicking Quit [applet]
I.java List; quit by selecting Really and then double clicking Quit [applet]
J.java MenuBar and related classes, creates menus from a symbolic description; `_' is replaced by blank, entries with capitals receive shortcuts [applet]
K.java PopupMenu to color a Label [applet]
L.java Scrollbar connected to a TextField [applet]
M.java ScrollPane to show an image with an ImageView; quit by double clicking the image [applet]
N.java TextArea with changeable attributes [applet]
apps/awt/ package to analyze event handling
(requires JDK >= 1.1)
main.java accepts a class name as argument, loads a Panel or a Frame as an application and .properties files to filter event display
LoaderApplet.java accepts a class name as class parameter and optionally an applet name as listener parameter, loads a Panel or a Frame as an applet and connects it to the Listener applet
(requires appletviewer or hotjava)
Listener.java class with lots of inner classes to display events; can be used as an applet and accepts parameters to initialize event display
PrintArea.java TextArea with a thread to emulate a PrintWriter
Event Management
apps/calc/ various calculators as examples for event handling strategies (require JDK >= 1.1)
applets/calc/ the same examples on web pages with awt.LoaderApplet (require appletviewer or hotjava)
Fsa.java trivial calculator chip as finite state machine
Keyboard.java configurable keyboard as a new Component
A.java calculator application with Fsa [applet]
Cpu.jj calculator chip with javacc
Cpu1.java Cpu with listing
B.java calculator application with Cpu, uses standard output
C.java calculator application with Cpu [applet]
D.java calculator application with Cpu and Gate connections for listing [applet]
apps/edit/application framework for multi-document applications (requires JDK >= 1.1)
apps/edit/edit/ multi-document editor (requires JDK >= 1.1.6)
Layout Management
apps/layout/ examples for CardLayout and GridBagLayout (require JDK >= 1.1)
applets/layout/ the same examples on web pages (require JDK >= 1.1)
Cards.java general Panel with CardLayout [applet]
ConstraintsInspector.java panel to inspect a GridBagConstraints object [applet]
Grid.java experiments with GridBagLayout [applet]
Client/Server Programming
programs/tcp/ TCP sockets
Talk.java line oriented client
Echod.java echo server
Snoop.java proxy server for spying
Client.java multi-threaded client
programs/udp/ UDP sockets
Talk.java line oriented client, optionally with timeouts
Echod.java echo server, with super server, timeouts and random errors
programs/web/ simulation of a database connected to the web
applets/web/ query page
Db.java ``database'' with standard i/o and TCP interface
Web.java simple web server with standard i/o and TCP interface
Query.java query applet [applet]
programs/rmi/ Remote Method Invocation (requires JDK >= 1.1.4)
timed/ client and server for current time
logd/ client and server for error reports
logd2/ extension; demonstrates object migration
Database Access
programs/jdbc/ examples for Java Database Connectivity
Sql.java interactive SQL
jdbctest practice and test application from InterSolv
The Parser Generator JavaCC
programs/javacc/ examples from compiler construction
Calc0.jj recognition, javacc
Calc1.jj error handling
Calc2.jj evaluation
Calc3.jjt abstract syntax tree, jjtree
Calc4/Calc4.jjt operator tree
Calc5/Calc5.jjt infix and interpretation
Calc6/ semantic analysis and interpretation, class hierarchy for Java expressions
index 08/Mar/1998