This page contains links to source code files from different
sources, and in particular from the current and previous textbooks
used for this course. If you have come to this page, we assume it is either
to browse, or because you are looking for a particular file
and know the name of the file and/or its author and location. Clicking on
an author's name in the table below will take you to the
starting point for access to files by that author.
This starting point may be a list of files in order
by chapter (Eckel) or simply a directory containing
futher subdirectories which in turn contain the
files for each chapter (Horstmann, Deitel, Jia). Some Horstmann
and Deitel examples will
require Java 5.0, while the others should all run under Java 1.4
and some may even run under ealier versions.
In each subcategory of the Misc category, a given program
is intended to illustrate some particular aspect of that
subcategory's topic, but all such programs will naturally,
if inadvertently, be illustrating other things as well.
From Eckel, Bruce: Thinking in Java (2nd Edition) (Prentice Hall)
The following programs are all taken from the
second edition of the text by Bruce Eckel.
Each of the programs has a brief annotation to
suggest the sort of thing you might expect to
find illustrated in it. Within each Chapter
section, the programs are listed in the order
that they appear in the text.
(Note: The 3rd edition is now available
in bookstores, and on-line at www.bruceeckel.com.
The programs in the 3rd edition have been modified
to incorporate testing for checking whether expected
output is in fact the same as actual output.)
Chapter 2 (Everything is an Object)
-
HelloDate.java
Eckel's version of everyone's first program.
Chapter 3 (Controlling Program Flow)
-
Assignment.java
(Also produces Number.class)
Although assignment of primitive values works as expected in
Java, this program shows that assigning objects can lead to
aliasing and needs to be treated carefully.
-
PassObject.java
(Also produces Letter.class)
Shows that aliasing will also occur when you pass an object
to a method.
-
MathOps.java
Mainly designed to illustrate the usual arithmetic and
"assignment with operation" operators, but also shows
a random number generator, and several short utility
functions used for displaying values of various primitive
data types. This program may or may not run to completion.
For example, since values are being generated randomly,
if you happen to get a value of 0 for k on a given run,
this will generate a "divide by zero" ArithmeticException
and the program will terminate at that point.
-
AutoInc.java
Illustrates the autoincrement and autodecrement operators (++ and --).
-
Equivalence.java
Be sure you understand what this program shows: that == and !=
only test for equality of object references (are they actually
the same object), not for equality of the objects themselves
(are they different objects, but with exactly the same attributes).
(But note, in passing, that == and != work as you would expect
for primitive types.)
-
EqualsMethod.java
Illustrates the use of the special method equals() for testing
equality of objects.
-
EqualsMethod2.java
(Also produces Value.class)
Shows that even the special method equals() does not always work
for testing equality of objects. In fact it never works
properly unless it is defined to work properly, since
its default behavior is just to test references. So, this
"special method", which is inherited from the Mother of All
Classes (Object), must be overridden in each class where
the "equality" of different objects is to be tested.
-
Bool.java
Illustrates the use of the relational and boolean operators.
-
ShortCircuit.java
Illustrates the use of "short-circuiting" in the evaluation
of boolean expressions.
-
URShift.java
Illustrates the use of the "unsigned right shift operator"
(>>>), an operator that has no counterpart in C or C++.
-
BitManipulation.java
Illustrates the use of all Java operators for manipulating
data at the bit level.
-
Literals.java
This source code file, like the next one, is not a "program",
just a class that will compile without error, but will not
run because it lacks a main function. The idea is just to
show you various forms that literal values of the char and
numerical primitive types can have.
-
AllOps.java
This source code file, like the previous one, is not a "program",
just a class that will compile without error, but will not
run because it lacks a main function. The idea is just to
show you a (very) large number of expressions,
some of which will compile and some that won't (and hence
are commented out). Examination of this code should give you
an excellent idea of what is, and what isn't, a valid Java
expression.
-
Overflow.java
Illustrates that arithmetic overflow can happen in Java,
and is something we should be on guard against.
-
IfElse.java
Illustrates the if..else construct (in fact, a nested
if construct in this case).
-
IfElse2.java
A variation on the previous program.
-
WhileTest.java
Illustrates a while loop by generating and printing
random numbers until the generated value exceeds a
given value.
-
ListCharacters.java
Illustrates use of a for-loop to display all of the standard
ASCII characters, except the one with ASCII code 26, which may
or may not cause your screen to clear (depending on how
your screen is set up to receive such "control characters").
There are probably other characters at the beginning of
the sequence (among the first 32 characters) that should
not be sent to a typical "terminal screen" either.
-
CommaOperator.java
Illustrates the use of the comma operator (not to be confused
with the "comma separator") in the control expression of a
for-loop.
-
BreakAndContinue.java
Illustrates the use of the "break" and "continue" statements
in loops.
-
LabeledFor.java
Illustrates how the break and continue statements can be
used to "jump" out of the loop body where they occur to
a labeled statement. Just because you can do
this doesn't mean that you should. In fact, doing so
would nearly always be a step back in time to the bad
ol' "goto days", a place you should avoid if at all possible.
-
LabeledWhile.java
See the comments above on the LabeledFor.java program, and
say "ditto" here.
-
VowelsAndConsonants.java
See the comments above on the LabeledFor.java program, and
say "ditto" here.
-
CastingNumbers.java
Illustrates casting a numerical value to a character value.
-
RandomBounds.java
Experiments with random number generator output. But you
read what the text says about this particular program.
Back to Top
Chapter 4 (Initialization and Cleanup)
-
SimpleConstructor.java
(Also produces Rock.class)
Illustrates a simple default constructor (no parameters).
-
SimpleConstructor2.java
(Also produces Rock2.class)
Illustrates a simple constructor with a parameter.
-
Overloading.java
(Also produces Tree.class)
Illustrates overloading in Java, with both overloaded
constructors and overloaded ordinary methods.
-
OverloadingOrder.java
Illustrates that even argument order is sufficient
to distinguish overloaded methods, though this is
not a recommended way to distinguish methods.
-
PrimitiveOverloading.java
Illustrates the potential confusion when a primitive
value is passed to an overloaded method (and gets
"promoted" in the process).
-
Demotion.java
A variation on the previous program that illustrates
the (required) use of casting if a supplied argument
is "bigger" than the corresponding formal parameter
and hence needs an explicit "narrowing conversion"
to be used.
-
DefaultConstructor.java
(Also produces Bird.class)
This program doesn't actually produce any output when run,
so it's really just there as a shell to be used as a starting
point for experimentation as suggested in the text (to illustrate
the fact that Java will supply its own default constructor, unless
the programmer supplies at least one).
-
Leaf.java
Illustrates simple use of the "this" keyword.
-
Flower.java
Illustrates use of "this" to call one constructor
from another.
-
Garbage.java
Demonstrates the JVM "garbage collector" and "finalization".
-
DeathCondition.java
(Also produces Book.class)
Illustrates the use of "finalize" to verify the
"death condition" and thus help to avoid bugs that
might otherwise be difficult to find.
-
InitialValues.java
(Also produces Measurement.class)
Shows the default initial values of the Java primitive data types.
-
OrderOfInitialization.java
(Also produces Tag.class and Card.class)
Shows that order of variable initialization is determined
by the order of definition, and also that all variables are
initialized before any methods can be called.
-
StaticInitialization.java
(Also produces Bowl.class, Cupboard.class and Table.class)
Shows when static storage gets initialized.
-
ExplicitStatic.java
(Also produces Cup.class and Cups.class)
Illustrates a "static construction clause" (or "static block",
or "static initialization block").
-
Mugs.java
(Also produces Mug.class)
Illustrates the syntax (which is similar to that used for
the static initialization block in the previous example) for
initializing non-static variables for each object. (Note:
This syntax is necessary to support the initialization of
anonymous inner classes.)
-
Arrays.java
Illustrates arrays of primitive values, array assignment
and the "length member" of an array object.
-
ArrayNew.java
Illustrates the use of "new" to create an array of
a given size.
-
ArrayClassObj.java
Illustrates the difference between an array of
class objects and an array of primitives.
-
ArrayInit.java
Illustrates the use of a list enclosed in braces
(curly brackets) to initialize an array.
-
VarArgs.java
Illustrates a syntax similar to C's "variable argument
lists" (or "varargs") to initialize an array.
-
MultiDimArray.java
Illustrates multidimensional arrays.
Back to Top
Chapter 5 (Hiding the Implementation)
-
LibTest.java
(imports com.bruceeckel.simple.*)
A simple driver for testing whether the classpath
is set up properly, so that the package to be used
can be found.
-
ToolTest.java
(imports com.bruceeckel.tools.*)
Another driver for testing access to another package.
-
TestAssert.java
(imports com.bruceeckel.tools.debug.*)
A driver for showing how using different imports can
be used to change behavior (in going from beta code
to production code, for example).
-
Dinner.java
(imports c05.dessert.*)
Illustrates access to a public class in a package.
-
Cake.java and
Pie.java
Illustrates what happens and what is possible when
two files are in the same directory and have no
explicit package name.
-
IceCream.java
(Also produces Sundae.class)
Illustrates use of the "private" keyword.
-
ChocolateChip.java
(imports c05.dessert.*)
Illustrates access restrictions in the context of
inheritance and packages.
-
Lunch.java
(Also produces Sandwich.class and Soup.class)
Illustrates the use of private constructors to
restrict access to a class.
Back to Top
Chapter 6 (Reusing Classes)
-
SprinklerSystem.java
(Also produces WaterSource.class)
Illustrates composition syntax by placing both
primitives and references to non-primitive objects
inside a new class definition.
-
Bath.java
(Also produces Soap.class)
Illustrates three ways of initializing a reference to an
object: at the point of definition, in a constructor for
the class, or right before you need to use the object
(lazy initialization).
-
Detergent.java
(Also produces Cleanser.class)
Illustrates inheritance syntax.
-
Cartoon.java
(Also produces Art.class and Drawing.class)
Illustrates base-class initialization with three
levels of inheritance and default (parameterless)
constructors.
-
Chess.java
(Also produces Game.class and BoardGame.class)
Illustrates how you call a base-class constructor
which has one or more arguments by using the
super
keyword and supplying an
appropriate arument list.
-
PlaceSetting.java
(Also produces Plate.class, DinnerPlate.class, Utensil.class,
Spoon.class, Fork.class, Knife.class and Custom.class)
Illustrates the combination of composition and inheritance,
along with the necessary constructor initialization.
-
CADSystem.java
(Also produces Shape.class, Circle.class and Line.class)
Illustrates some steps that may have to be taken to
guarantee proper cleanup, despite Java's automatic
garbage collection: explicitly writing a cleanup method
and placing it in a
finally
clause.
-
Hide.java
(Also produces Home.class, Milhouse.class and Bart.class)
Illustrates that redefining a method in a derived class
does not hide any base class versions. (C++ programmers
take note!)
-
Car.java
(Also produces Engine.class, Wheel.class,
Window.class and Door.class)
Illustrates a situation in which it makes sense
to have the class user directly access the
composition of a new class (i.e., a situation
in which the member objects can be made public).
-
Orc.java
(Also produces Villain.class)
Illustrates use of the
protected
keyword.
-
Wind.java
(Also produces Instrument.class)
Illustrates the concept of "upcasting".
-
FinalData.java
(Also produces Value.class)
Illustrates
final
fields in a class.
-
BlankFinal.java
(Also produces Poppet.class)
Illustrates the concept of "blank" final fields in a class:
fields that are declared
final
but are not
give a value and so must be initialized before use, thus
providing fields that can be differenent for each object
but still retain their immutable quality.
-
FinalArguments.java
(Also produces Gizmo.class)
Illustrated the concept of a
final
argument
in a parameter list.
-
FinalOverridingIllusion.java
(Also produces WithFinals.class, OverridingPrivate.class,
and OverridingPrivate2.class)
Illustrates some potential confusion between
final
and private
.
-
Jurassic.java
(Also produces SmallBrain.class, Dinosaur.class)
Illustrates the concept of a
final
class.
-
Beetle.java
(Also produces Insect.class)
Another example illustrating the whole initialization
process, including inheritance.
Back to Top
Chapter 7 (Polymorphism)
-
music/Music.java
(Also produces Instrument.class, Note.class and Wind.class)
Another "upcasting" example, that also illustrates a
potential problem.
-
music2/Music2.java
(Also produces Instrument.class, Note.class, Wind.class,
Brass.class and Stringed.class)
Illustrates why polymorphism is such a useful idea (and the
problems you would probably have if you couldn't make use of it).
-
Shapes.java
(Also produces Shape.class, Circle.class, Square.class
and Triangle.class)
Illustrates the use of polymorphism.
-
music3/Music3.java
(Also produces Instrument.class, Wind.class, Brass.class,
Stringed.class, Percussion.class and Woodwind.class)
Illustrates the power of polymorphism in that it allows
code to be "unaware" of code changes being made all around
it and yet still continue to work properly with the new code.
-
WindError.java
(Also produces NoteX.class, InstrumentX.class, WindX.class)
Illustrates why you have to be careful to distinguish
between overriding and overloading.
-
music4/Music4.java
(Also produces Instrument.class, Wind.class, Brass.class,
Stringed.class, Percussion.class and Woodwind.class)
Illustrates the use of
abstract
classes and methods.
-
Sandwich.java
(Also produces Meal.class, Bread.class, Cheese.class,
Lettuce.class, Lunch.class, PortableLunch.class)
Illustrates the effects of composition, inheritance and
polymorphism on the order of constructor calls.
-
Frog.java
(Also produces DoBaseFinalization.class, Characteristic.class,
LivingCreature.class, Animal.class, Amphibian.class)
Illustrates the importance of calling the base-class
finalize() when you override finalize() in an inherited
class.
-
PolyConstructors.java
(Also produces Glyph.class, RoundGlyph.class)
Illustrates a problem that may be caused by Java's
dynamic binding mechanism during a constructor call.
See the text for some adive on how to avoid this problem.
-
Transmogrify.java
(Also produces Actor.class, HappyActor.class, SadActor.class,
Stage.class)
Illustrates that it's possible to dynamically choose a
type (and hence behavior) when using composition, whereas
inheritance requires an exact type to be known at compile-time.
The lesson here may be that it's better to choose composition
over inheritance when it's not obvious which should be used.
-
RTTI.java
(Also produces Useful.class, MoreUseful.class)
Illustrates the behavior of RTTI (Run Time Type Identification).
Back to Top
Chapter 8 (Interfaces & Inner Classes)
-
Music5.java
(Also produces Instrument.class, Wind.class, Brass.class,
Stringed.class, Percussion.class and Woodwind.class)
-
Adventure.java
(Also produces CanFight.class, CanSwim.class, CanFly.class,
ActionCharacter.class, Hero.class)
-
InterfaceCollision.java
(Also produces
C.class,
C2.class,
C3.class,
C4.class,
I1.class,
I2.class, and
I3.class)
-
HorrorShow.java
(Also produces
Monster.class,
DangerousMonster.class,
Lethal.class,
DragonZilla.class,
Vampire.class)
-
Months.java
-
Month2.java
-
RandVals.java
-
TestRandVals.java
(Also produces RandVals.class)
-
NestingInterfaces.java
(Also produces
A.class,
A$B.class,
A$BImp.class,
A$BImp2.class,
A$C.class,
A$CImp.class,
A$CImp2.class,
A$D.class,
A$DImp.class,
A$DImp2.class,
E.class,
E$G.class,
E$H.class,
NestingInterfaces$BImp.class,
NestingInterfaces$CImp.class,
NestingInterfaces$EImp.class,
NestingInterfaces$EGImp.class,
NestingInterfaces$EImp2.class, and
NestingInterfaces$EImp2$EG.class
)
-
Parcel1.java
(Also produces
Parcel1$Contents.class and Parcel1$Destination.class)
-
Parcel2.java
(Also produces
Parcel2$Contents.class and Parcel2$Destination.class)
-
Destination.java
-
Contents.java
-
Parcel3.java
(Also produces
Contents.class,
Destination.class,
Parcel3$1.class,
Parcel3$PContents.class,
Parcel3$PDestination.class, and
Test.class)
-
Wrapping.java
-
Parcel4.java
(Also produces
Destination.class, and
Parcel4$1$PDestination.class)
-
Parcel5.java
(Also produces Parcel5$1$TrackingSlip.class)
-
Parcel6.java
(Also produces Contents.class and Parcel6$1.class)
-
Parcel7.java
(Also produces Wrapping.class and Parcel7$1.class)
-
Parcel8.java
(Also produces Destination.class and Parcel8$1.class)
-
Parcel9.java
(Also produces Destination.class and Parcel9$1.class)
-
Sequence.java
(Also produces
Selector.class,
Sequence$1.class, and
Sequence$1$SSelector.class)
-
Parcel10.java
(Also produces
Contents.class,
Destination.class,
Parcel10$1.class,
Parcel10$PContents.class,
Parcel10$PDestination.class, and
Parcel10$PDestination$AnotherLevel.class)
-
IInterface.java
(Also produces IInterface$Inner.class)
-
TestBed.java
(Also produces TestBed$Tester.class)
-
Parcel11.java
(Also produces
Parcel1!$Contents.class and
Parcel11$Destination.class)
-
MultiNestingAccess.java
(Also produces
MNA.class,
MNA$A.class and
MNA$A$B.class)
-
InheritInner.java
(Also produces WithInner.class and WithInner$Inner.class)
-
BigEgg.java
(Also produces
Egg.class,
Egg$Yolk.class and
BigEgg$Yolk.class)
-
BigEgg2.java
(Also produces
Egg2.class,
Egg2$Yolk.class and
BigEgg2$Yolk.class)
-
MultiInterfaces.java
(Also produces
A.class,
B.class,
X.class,
Y.class, and
Y$1.class)
-
MultiImplementation.java
(Also produces
C.class,
D.class,
Z.class, and
Z$1.class)
-
Callbacks.java
(Also produces
Caller.class,
Callee1.class,
Callee2.class,
Callee2$1.class,
Callee2$Closure.class,
Incrementable.class, and
MyIncrement.class)
-
controller/Event.java
-
controller/Controller.java
(Also produces EventSet.class)
-
GreenhouseControls.java
(Also produces
GreenhouseControls$Bell.class,
GreenhouseControls$LightOff.class,
GreenhouseControls$LightOn.class,
GreenhouseControls$Restart.class,
GreenhouseControls$ThermostatDay.class,
GreenhouseControls$ThermostatNight.class,
GreenhouseControls$WaterOff.class, and
GreenhouseControls$WaterOn.class)
Back to Top
Chapter 9 (Holding Your Objects)
-
ArraySize.java
(Also produces Weeble.class)
-
IceCream.java
-
TestArrays2.java
-
FillingArrays.java
-
CopyingArrays.java
-
ComparingArrays.java
-
CompType.java
-
Reverse.java
-
ComparatorTest.java
-
StringSorting.java
-
AlphabeticSorting.java
-
ArraySearching.java
-
AlphabeticSearch.java
-
PrintingContainers.java
-
FillingLists.java
-
FillTest.java
-
Cat.java
-
Dog.java
-
CatsAndDogs.java
-
Mouse.java
-
WorksAnyway.java
-
MouseList.java
-
MouseListTest.java
-
CatsAndDogs2.java
-
HamsterMaze.java
-
InfiniteRecursion.java
-
SimpleCollection.java
-
Collection1.java
-
List1.java
-
StackL.java
-
Queue.java
-
Set1.java
-
Set2.java
-
Map1.java
-
Statistics.java
-
SpringDetector.java
-
SpringDetector2.java
-
Mpair.java
-
SlowMap.java
-
SimpleHashMap.java
-
StringHashCode.java
-
CountedString.java
-
References.java
-
CanonicalMapping.java
-
Iterators2.java
-
ListPerformance.java
-
SetPerformance.java
-
MapPerformance.java
-
ListSortSearch.java
-
ReadOnly.java
-
Synchronization.java
-
FailFast.java
-
Unsupported.java
-
Enumerations.java
-
Stacks.java
-
Bits.java
Back to Top
Chapter 10 (Error Handling with Exceptions)
-
SimpleExceptionDemo.java
-
FullConstructors.java
-
ExtraFeatures.java
-
ExceptionMethods.java
-
Rethrowing.java
-
ThrowOut.java
-
RethrowNew.java
-
NeverCaught.java
-
FinallyWorks.java
-
OnOffSwitch.java
-
WithFinally.java
-
AlwaysFinally.java
-
LostMessage.java
-
StormyInning.java
-
Cleanup.java
-
Human.java
Back to Top
Chapter 11 (The Java I/O System)
-
Dirlist.java
-
DirList2.java
-
DirList3.java
-
MakeDirectories.java
-
IOStreamDemo.java
-
TestEOF.java
-
IOProblem.java
-
Echo.java
-
Redirecting.java
-
GZIPcompress.java
-
ZipCompress.java
-
Worm.java
-
Alien.java
-
FreezeAlien.java
-
xfiles/ThawAlien.java
-
Blips.java
-
Blip3.java
-
Logon.java
-
SerialCtl.java
-
MyWorld.java
-
CADState.java
-
WordCount.java
-
AnalyzeSentence.java
-
ClassScanner.java
Back to Top
Chapter 12 (Run time Type Identification)
-
Shapes.java
-
SweetShop.java
-
PetCount.java
-
PetCount2.java
-
PetCount3.java
-
FamilyVsExactType.java
-
ToyTest.java
-
ShowMethods.java
-
ShowMethodsClean.java
Back to Top
Chapter 13 (Creating Windows and Applets)
-
Applet1.java
-
Applet1b.java
-
Applet1c.java
-
Applet1d.java
-
Button.java
-
Button2.java
-
TextArea.java
-
BorderLayout1.java
-
FlowLayout1.java
-
GridLayout1.java
-
GridBagLayout.java
-
BoxLayout1.java
-
Box1.java
-
Box2.java
-
Box3.java
-
ShowAddListeners.java
-
TrackEvent.java
-
Buttons.java
-
ButtonGroups.java
-
Faces.java
-
TextFields.java
-
Borders.java
-
JScrollPanes.java
-
TextPane.java
-
CheckBoxes.java
-
RadioButtons.java
-
ComboBoxes.java
-
List.java
-
TabbedPane1.java
-
MessageBoxes.java
-
SimpleMenus.java
-
Menus.java
-
Popup.java
-
SineWave.java
-
Dialogs.java
-
TicTacToe.java
-
FileChooserTest.java
-
HTMLButton.java
-
Program.java
-
Trees.java
-
Table.java
-
LookAndFeel.java
-
CutAndPaste.java
-
DynamicEvents.java
-
Separation.java
-
Frrog.java
-
BeanDamper.java
-
BangBean.java
-
BangBeanTest.java
Back to Top
Chapter 14 (Multiple Threads)
-
Counter1.java
-
SimpleThread.java
-
Counter2.java
-
Counter3.java
-
Counter4.java
-
Daemons.java
-
Sharing1.java
-
Sharing2.java
-
BangBean2.java
-
Blocking.java
-
Interrupt.java
-
Suspend.java
-
Counter5.java
-
TestAccess.java
-
ThreadGroup1.java
-
ColorBoxes.java
-
ColorBoxes2.java
Back to Top
Chapter 15 (Distributed Computing)
-
WhoAmI.java
-
JabberServer.java
-
JabberClient.java
-
MultiJabberServer.java
-
MultiJabberClient.java
-
ShowHTML.java
-
Fetcher.java
-
jdbc/Lookup.java
-
jdbc/VLookup.java
-
jdbc/CIDConnect.java
-
jdbc/CIDSQL.java
-
jdbc/CIDCreateTables.java
-
servlets/ServletsRule.java
-
servlets/EchoForm.java
-
servlets/ThreadServelet.java
-
servlets/SessionPeek.java
-
jsp/ShowSeconds.jsp
-
jsp/Hello.jsp
-
jsp/DisplayFormData.jsp
-
jsp/PageContext.jsp
-
jsp/SessionObject.jsp
-
jsp/SessionObject2.jsp
-
jsp/SessionObject3.jsp
-
jsp/Cookies.jsp
-
rmi/PerfectTimeI.java
-
rmi/PerfectTime.java
-
rmi/DisplayPerfectTime.java
-
corba/ExactTime.idl
-
corba/RemoteTimeServer.java
-
corba/RemoteTimeClient.java
-
ejb/PerfectTime.java
-
ejb/PerfectTimeHome.java
-
ejb/ejb-jar.xml
-
ejb/PerfectTimeClient.java
Back to Top
Appendix A (Passing & Returning Objects)
-
PassReferences.java
-
Alias1.java
-
Alias2.java
-
Cloning.java
-
LocalCopy.java
-
Snake.java
-
DeepCopy.java
-
AddingClone.java
-
Compete.java
-
HorrorFlick.java
-
CheckCloneable.java
-
CopyConstructor.java
-
ImmutableInteger.java
-
MutableInteger.java
-
Immutable1.java
-
Immutable2.java
-
Stringer.java
-
ImmutableStrings.java
Back to Top
Appendix B (The Java Native Interface (JNI))
-
ShowMessage.java
-
MsgImpl.cpp
-
UseObjects.java
-
UseObjImpl.cpp
Back to Top
Packages
-
com.bruceeckel.simple
-
com.bruceeckel.swing
-
com.bruceeckel.tools
-
com.bruceeckel.util
-
c05.dessert
Back to Top
Beans
-
Frog Bean
-
Bang Bean
Back to Top
Miscellaneous Programs from Various Sources
The following programs may be original creations
or may be taken (in possibly modified form) form
many different sources. Where appropiate, each
source is identified. Each program or group of
programs deals principally with a particular
"theme" of some kind, but, as always, the themes
will frequently, and inevitably, overlap.
Ant: Another Neat Tool
-
build.xml [Right-click and download only.]
This is a sample "buildfile" that you can use
with the ant utility for the Mastermind
project.
Back to Top
Classes: Some Programs Illustrating Java Classes
-
Line.java
Demonstrates a Point class which is an "inner class"
within a Line class.
-
TestLine.java
A test driver for the Line class.
Back to Top
Collections: A directory
containing some files illustrating the Vector class and
its associated iterator.
Back to Top
Design Patterns: Some directories
containing some files illustrating the design patterns
Back to Top
Environment: A directory
containing some files illustrating the interaction of
a java program with its environment.
Back to Top
Exceptions: Some Programs Illustrating Java Exceptions
-
ComputeQuotient.java
Demonstrates creating an (arithmetic) exception and
allowing the Java interpreter to handle it.
-
ComputeQuotientWithException1.java
Demonstrates creating an arithmetic exception and "catching" it.
-
ComputeQuotientWithException2.java
Demonstrates creating an arithmetic exception
or a number format exception, and "catching" it.
-
ComputeQuotientWithException3.java
Demonstrates creating an arithmetic exception
or a number format exception, and "catching" it.
Uses an alternate formulation from the previous version.
Also illustrates the "instanceof" operator.
-
TestMyException.java
Demonstrates use of programmer-defined exceptions and a stack trace.
-
TestRethrowing.java
Demonstrates re-throwing and exception, and the use of a stack trace.
-
TestFinally.java
Demonstrates the "finally" clause.
Back to Top
GUI: Some Programs Illustrating GUI Concepts
-
CalculatorGUIAppAWT.java
A very simple calculator with an AWT GUI.
-
CalculatorGUIAppSwing.java
A very simple calculator, like the previous example,
but with a Swing GUI.
-
ColorChangeGUIApp.java
A program illustrating a very simple way of
changing the colors of circular areas.
-
RoundButton.java
A program illustrating a RoundButton class
that you may find useful if you do not wish
to use the primitive way illustrated in
ColorChangeGUIApp.java for changing the colors
of circular regions. Unfortunately there is
apparently no "default round button" available.
-
FileDisplayGUIAppAWT.java
A program illustrating the loading in and displaying
in a TextArea window the contents of a textfile,
in a way that might be used for on-line help, for
example.
-
FileDisplayGUIAppSwing.java
A program illustrating the loading in and displaying
in a JTextArea window the contents of a textfile,
in a way that might be used for on-line help, for
example.
-
test1.txt,
test2.txt, and
test3.txt
Sample text files to use as input for
the previous program.
-
TestGUISwing1.java,
TestGUISwing2.java,
TestGUISwing3.java,
TestGUISwing4.java,
TestGUISwing5.java,
TestGUISwing6.java,
TestGUISwing7.java,
TestGUISwing8.java,
TestGUISwing9.java,
A sequence of programs illustrating a few basics
about the building of a GUI interface with Swing
and the kinds of things that can throw you off
if you're not careful.
-
TestJPanelGUIApp.java
A short program illustrating how you can specify
the size and position of a JPanel if you really
want to do this. Note that the "layering" takes
place in the opposite order to what you might
have guessed. And note what happens when you
comment out the second statement in the body
of the main function.
-
HeadlinesGUIApp.java
Illustrates scrolling headlines.
-
DigitalClockGUIApp.java
Illustrates a digital clock that updates each second.
-
See also the DigitalClock example under Chapter04 of Jia.
-
TopLevelDemoGUIApp.java
Illustrates a menu bar.
-
MenuDemoGUIApp1.java
Illustrates some menus.
-
GridBagLayoutDemo.java
Illustrates the GridBagLayout class.
Back to Top
Hello: Some Variations on "Hello, World!"
-
HelloConApp.java
A simple console program displaying "Hello, world!".
-
HelloApplet1.java
A simple applet which displays "Hello, world!" in a window
within a browser (or an appletviewer) via an HTML file.
The java source code file can also be used directly
by the appletviewer to display the applet.
-
HelloApplet1.html
An HTML file corresponding to, and for displaying,
the applet in HelloApplet1.java.
-
HelloApplet2.java
A slightly more interesting applet, which also displays
"Hello, world!", this time with some color.
-
HelloApplet3.java
Yet another applet which displays
"Hello, world!", this time with changing
text colors, and meant to illustrate what
happens when an applet is "covered" up and
then "uncovered".
-
HelloGUIApp1.java
A simple standalone application which displays
"Hello, world!" within a GUI.
-
HelloGUIApp2.java
A slightly more interesting standalone application
which displays "Hello, world!" within a GUI, in color.
-
HelloGUIApp3.java
The main addition to this example is to have the
application close when its window's close box is
clicked, or when the quit button of the application
itself is clicked.
-
HelloGUIApp4.java
This example shows how, when the window is resized
by a user, the button and label change positions,
while the position of the other text remains fixed.
-
HelloGUIApp5.java
This example shows how to use an instance of
an "anonymous inner class" to handle the shutting
down of the application when the window is closed.
-
HelloGUIApp6.java
This example shows how to place buttons in absolute
positions and determine which of the buttons has
been pressed, and also illustrates a call to the
"repaint()" method.
Back to Top
I/O: Some Programs Illustrating Java Input and Output
-
TestFileIO.java
Demo of file input and output.
-
TestFileIOWithException.java
Demo of file input and output, with
a "file not found" exception handler.
-
TestFileIO_in.txt
Sample input file for TestFileIO.java and
TestFileIOWithException.java.
-
ReadDataFileFromJar.java
Shows how to get a program to read an input
data file from the same jar file containing
the class that reads the file.
-
readdatafilefromjar.jar
A jar file corresponding to the previous
sample program, also containing an input
data file which that program reads from
the jar file.
Back to Top
Javadoc: Some directories
containing files to illustrate the use of the Javadoc
utility.
Back to Top
Junit: Some directories
containing files to illustrate the use of JUnit
for unit testing of Java programs.
Back to Top
Mastermind: Some Programs Relevant to the Mastermind Project
-
BannerPage.java
A class for displaying a "banner page" that might
be used as the opening screen for any console program.
-
TestBannerPage.java
A test driver for the BannerPage class.
-
Menu.class
The class file for the Menu class.
-
Menu_shell.java
A shell file to use when you start coding
your implementation of the Menu class.
-
TestMenu.java
A fairly comprehensive test driver for the
Menu class, which may be extended for further
testing of that class if desired.
-
mmconapp.jar
An executable jar file for Phase 1 of
the Mastermind console application.
It displays a banner page, and then
a Menu from which choices can be made,
but the program does not actually do
anything.
-
TextItems.class,
TextItems$ItemNode.class, and
TextItems$LineNode.class
The three files you need to use the TextItems class.
-
mm_textitems.txt
The (starup) file of textitems for the
Mastermind program. You may wish to add
additional textitems of your own to your
copy of this file as the project progresses.
-
TextItems_shell.java
A shell file to use when you start coding
your implementation of the TextItems class.
-
mmconapp2.jar
An executable jar file for Phase 2 of
the Mastermind console application.
It displays a banner page, and then
a Menu from which choices can be made.
Option 2 of the Main Menu now allows
the user to get information, but option
3 still does not do anything.
-
mmconapp3.jar
An executable jar file for Phase 3 of
the Mastermind console application.
This version retains the banner
page, menu, and on-line help features,
and now also allows the user to play
as Cobebreaker.
-
mmconapp4.jar
An executable jar file for Phase 4 of
the Mastermind console application.
This version retains the banner
page, menu, and on-line help features,
and now also allows the user to play
as both Cobebreaker and Codemaker.
Back to Top
Networks: A directory
containing some files illustrating simple "networking"
concepts
Back to Top
Multimedia: Some directories
containing some files illustrating simple "multimedia"
concepts, as well as some auxiliary image and sound files
Back to Top
OOP: Some Programs Illustrating Aspects of Object-Oriented Programming
-
ThreePillars.java,
Worker.java, and
Executive.java
This group illustrates encapsulation, inheritance,
and polymorphism.
-
TestRoundShapes.java,
RoundShape.java,
Circle.java, and
Sphere.java
This group illustrates an abstract class
that also uses an inner class.
-
TestInterface.java,
WorkerWithIFace.java,
ExecutiveWithIFace.java, and
NameAndPayInterface.java
This group illustrates the implementation of
an interface.
Back to Top
Other: Some Other Useful Programs
-
javaToHTML.zip
Windows version of a C++ program for converting
Java source code to HTML form and showing which
lines are longer that 74 characters. (Author: Andrew
Doane)
-
javaToHTML.tar.gz
Linux version of a C++ program for converting
Java source code to HTML form and showing which
lines are longer that 74 characters. (Author: Andrew
Doane)
Back to Top
Packages: Some Programs Illustrating Packages in Java
-
TestFriendly.java
A driver for class Friendly.
-
Friendly.java
A class with a static method to print out a greeting.
-
TestGreetings.java
A driver for the English, French and German classes.
-
English.java,
French.java, and
German.java
Classes that have static methods that just
display greetings in English, French and
German.
Back to Top
Security: A directory
containing some files illustrating Java security.
Back to Top
Serializtion: A directory
containing some files which illustrate the Java serialization
process.
Back to Top
Threads and Concurrency: Some directories
illustrating some simple "multithreading" concepts.
Back to Top
Tokenizing: A directory
containing some "tokenizing" examples.
Back to Top
Visio: Diagrams Prepared with Microsoft Visio
-
ChampionzoneUML.vsd
A "canonical" example that comes with
Microsoft Visio itself, showing all
UML diagrams (prior to UML 2) for
developing a software product that
deals with a Referee Certification System.
Back to Top