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.

Horstmann
( 2nd Ed )
HTML Slides
Chapter: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
Deitel
( 6th Ed )
Powerpoints
Chapter: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15
16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29
Appendix F | Appendix H | Appendix I | Appendix J | Appendix N
Jia
( 2nd Ed )
Chapter: 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12
Eckel
( 2nd Ed )
Chapter: 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15
Appendix A | Appendix B | packages | beans
Misc Ant | Classes | Collections | Design Patterns | Environment | Exceptions | GUI | Hello | I/O | Javadoc | JUnit | Mastermind | Multimedia | Networks | OOP | Other | Packages | Security | Serialization | Threads | Tokenizing | Visio |

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)

  1. HelloDate.java Eckel's version of everyone's first program.

  2. Chapter 3 (Controlling Program Flow)

  3. 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.
  4. PassObject.java (Also produces Letter.class) Shows that aliasing will also occur when you pass an object to a method.
  5. 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.
  6. AutoInc.java Illustrates the autoincrement and autodecrement operators (++ and --).
  7. 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.)
  8. EqualsMethod.java Illustrates the use of the special method equals() for testing equality of objects.
  9. 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.
  10. Bool.java Illustrates the use of the relational and boolean operators.
  11. ShortCircuit.java Illustrates the use of "short-circuiting" in the evaluation of boolean expressions.
  12. URShift.java Illustrates the use of the "unsigned right shift operator" (>>>), an operator that has no counterpart in C or C++.
  13. BitManipulation.java Illustrates the use of all Java operators for manipulating data at the bit level.
  14. 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.
  15. 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.
  16. Overflow.java Illustrates that arithmetic overflow can happen in Java, and is something we should be on guard against.
  17. IfElse.java Illustrates the if..else construct (in fact, a nested if construct in this case).
  18. IfElse2.java A variation on the previous program.
  19. WhileTest.java Illustrates a while loop by generating and printing random numbers until the generated value exceeds a given value.
  20. 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.
  21. 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.
  22. BreakAndContinue.java Illustrates the use of the "break" and "continue" statements in loops.
  23. 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.
  24. LabeledWhile.java See the comments above on the LabeledFor.java program, and say "ditto" here.
  25. VowelsAndConsonants.java See the comments above on the LabeledFor.java program, and say "ditto" here.
  26. CastingNumbers.java Illustrates casting a numerical value to a character value.
  27. RandomBounds.java Experiments with random number generator output. But you read what the text says about this particular program.

  28. Back to Top


    Chapter 4 (Initialization and Cleanup)

  29. SimpleConstructor.java (Also produces Rock.class) Illustrates a simple default constructor (no parameters).
  30. SimpleConstructor2.java (Also produces Rock2.class) Illustrates a simple constructor with a parameter.
  31. Overloading.java (Also produces Tree.class) Illustrates overloading in Java, with both overloaded constructors and overloaded ordinary methods.
  32. OverloadingOrder.java Illustrates that even argument order is sufficient to distinguish overloaded methods, though this is not a recommended way to distinguish methods.
  33. PrimitiveOverloading.java Illustrates the potential confusion when a primitive value is passed to an overloaded method (and gets "promoted" in the process).
  34. 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.
  35. 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).
  36. Leaf.java Illustrates simple use of the "this" keyword.
  37. Flower.java Illustrates use of "this" to call one constructor from another.
  38. Garbage.java Demonstrates the JVM "garbage collector" and "finalization".
  39. 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.
  40. InitialValues.java (Also produces Measurement.class) Shows the default initial values of the Java primitive data types.
  41. 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.
  42. StaticInitialization.java (Also produces Bowl.class, Cupboard.class and Table.class) Shows when static storage gets initialized.
  43. ExplicitStatic.java (Also produces Cup.class and Cups.class) Illustrates a "static construction clause" (or "static block", or "static initialization block").
  44. 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.)
  45. Arrays.java Illustrates arrays of primitive values, array assignment and the "length member" of an array object.
  46. ArrayNew.java Illustrates the use of "new" to create an array of a given size.
  47. ArrayClassObj.java Illustrates the difference between an array of class objects and an array of primitives.
  48. ArrayInit.java Illustrates the use of a list enclosed in braces (curly brackets) to initialize an array.
  49. VarArgs.java Illustrates a syntax similar to C's "variable argument lists" (or "varargs") to initialize an array.
  50. MultiDimArray.java Illustrates multidimensional arrays.

  51. Back to Top


    Chapter 5 (Hiding the Implementation)

  52. 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.
  53. ToolTest.java (imports com.bruceeckel.tools.*) Another driver for testing access to another package.
  54. 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).
  55. Dinner.java (imports c05.dessert.*) Illustrates access to a public class in a package.
  56. 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.
  57. IceCream.java (Also produces Sundae.class) Illustrates use of the "private" keyword.
  58. ChocolateChip.java (imports c05.dessert.*) Illustrates access restrictions in the context of inheritance and packages.
  59. Lunch.java (Also produces Sandwich.class and Soup.class) Illustrates the use of private constructors to restrict access to a class.

  60. Back to Top


    Chapter 6 (Reusing Classes)

  61. SprinklerSystem.java (Also produces WaterSource.class) Illustrates composition syntax by placing both primitives and references to non-primitive objects inside a new class definition.
  62. 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).
  63. Detergent.java (Also produces Cleanser.class) Illustrates inheritance syntax.
  64. Cartoon.java (Also produces Art.class and Drawing.class) Illustrates base-class initialization with three levels of inheritance and default (parameterless) constructors.
  65. 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.
  66. 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.
  67. 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.
  68. 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!)
  69. 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).
  70. Orc.java (Also produces Villain.class) Illustrates use of the protected keyword.
  71. Wind.java (Also produces Instrument.class) Illustrates the concept of "upcasting".
  72. FinalData.java (Also produces Value.class) Illustrates final fields in a class.
  73. 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.
  74. FinalArguments.java (Also produces Gizmo.class) Illustrated the concept of a final argument in a parameter list.
  75. FinalOverridingIllusion.java (Also produces WithFinals.class, OverridingPrivate.class, and OverridingPrivate2.class) Illustrates some potential confusion between final and private.
  76. Jurassic.java (Also produces SmallBrain.class, Dinosaur.class) Illustrates the concept of a final class.
  77. Beetle.java (Also produces Insect.class) Another example illustrating the whole initialization process, including inheritance.

  78. Back to Top


    Chapter 7 (Polymorphism)

  79. music/Music.java (Also produces Instrument.class, Note.class and Wind.class) Another "upcasting" example, that also illustrates a potential problem.
  80. 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).
  81. Shapes.java (Also produces Shape.class, Circle.class, Square.class and Triangle.class) Illustrates the use of polymorphism.
  82. 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.
  83. WindError.java (Also produces NoteX.class, InstrumentX.class, WindX.class) Illustrates why you have to be careful to distinguish between overriding and overloading.
  84. 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.
  85. 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.
  86. 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.
  87. 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.
  88. 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.
  89. RTTI.java (Also produces Useful.class, MoreUseful.class) Illustrates the behavior of RTTI (Run Time Type Identification).

  90. Back to Top


    Chapter 8 (Interfaces & Inner Classes)

  91. Music5.java (Also produces Instrument.class, Wind.class, Brass.class, Stringed.class, Percussion.class and Woodwind.class)
  92. Adventure.java (Also produces CanFight.class, CanSwim.class, CanFly.class, ActionCharacter.class, Hero.class)
  93. InterfaceCollision.java (Also produces C.class, C2.class, C3.class, C4.class, I1.class, I2.class, and I3.class)
  94. HorrorShow.java (Also produces Monster.class, DangerousMonster.class, Lethal.class, DragonZilla.class, Vampire.class)
  95. Months.java
  96. Month2.java
  97. RandVals.java
  98. TestRandVals.java (Also produces RandVals.class)
  99. 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 )
  100. Parcel1.java (Also produces Parcel1$Contents.class and Parcel1$Destination.class)
  101. Parcel2.java (Also produces Parcel2$Contents.class and Parcel2$Destination.class)
  102. Destination.java
  103. Contents.java
  104. Parcel3.java (Also produces Contents.class, Destination.class, Parcel3$1.class, Parcel3$PContents.class, Parcel3$PDestination.class, and Test.class)
  105. Wrapping.java
  106. Parcel4.java (Also produces Destination.class, and Parcel4$1$PDestination.class)
  107. Parcel5.java (Also produces Parcel5$1$TrackingSlip.class)
  108. Parcel6.java (Also produces Contents.class and Parcel6$1.class)
  109. Parcel7.java (Also produces Wrapping.class and Parcel7$1.class)
  110. Parcel8.java (Also produces Destination.class and Parcel8$1.class)
  111. Parcel9.java (Also produces Destination.class and Parcel9$1.class)
  112. Sequence.java (Also produces Selector.class, Sequence$1.class, and Sequence$1$SSelector.class)
  113. Parcel10.java (Also produces Contents.class, Destination.class, Parcel10$1.class, Parcel10$PContents.class, Parcel10$PDestination.class, and Parcel10$PDestination$AnotherLevel.class)
  114. IInterface.java (Also produces IInterface$Inner.class)
  115. TestBed.java (Also produces TestBed$Tester.class)
  116. Parcel11.java (Also produces Parcel1!$Contents.class and Parcel11$Destination.class)
  117. MultiNestingAccess.java (Also produces MNA.class, MNA$A.class and MNA$A$B.class)
  118. InheritInner.java (Also produces WithInner.class and WithInner$Inner.class)
  119. BigEgg.java (Also produces Egg.class, Egg$Yolk.class and BigEgg$Yolk.class)
  120. BigEgg2.java (Also produces Egg2.class, Egg2$Yolk.class and BigEgg2$Yolk.class)
  121. MultiInterfaces.java (Also produces A.class, B.class, X.class, Y.class, and Y$1.class)
  122. MultiImplementation.java (Also produces C.class, D.class, Z.class, and Z$1.class)
  123. Callbacks.java (Also produces Caller.class, Callee1.class, Callee2.class, Callee2$1.class, Callee2$Closure.class, Incrementable.class, and MyIncrement.class)
  124. controller/Event.java
  125. controller/Controller.java (Also produces EventSet.class)
  126. 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)

  127. Back to Top


    Chapter 9 (Holding Your Objects)

  128. ArraySize.java (Also produces Weeble.class)
  129. IceCream.java
  130. TestArrays2.java
  131. FillingArrays.java
  132. CopyingArrays.java
  133. ComparingArrays.java
  134. CompType.java
  135. Reverse.java
  136. ComparatorTest.java
  137. StringSorting.java
  138. AlphabeticSorting.java
  139. ArraySearching.java
  140. AlphabeticSearch.java
  141. PrintingContainers.java
  142. FillingLists.java
  143. FillTest.java
  144. Cat.java
  145. Dog.java
  146. CatsAndDogs.java
  147. Mouse.java
  148. WorksAnyway.java
  149. MouseList.java
  150. MouseListTest.java
  151. CatsAndDogs2.java
  152. HamsterMaze.java
  153. InfiniteRecursion.java
  154. SimpleCollection.java
  155. Collection1.java
  156. List1.java
  157. StackL.java
  158. Queue.java
  159. Set1.java
  160. Set2.java
  161. Map1.java
  162. Statistics.java
  163. SpringDetector.java
  164. SpringDetector2.java
  165. Mpair.java
  166. SlowMap.java
  167. SimpleHashMap.java
  168. StringHashCode.java
  169. CountedString.java
  170. References.java
  171. CanonicalMapping.java
  172. Iterators2.java
  173. ListPerformance.java
  174. SetPerformance.java
  175. MapPerformance.java
  176. ListSortSearch.java
  177. ReadOnly.java
  178. Synchronization.java
  179. FailFast.java
  180. Unsupported.java
  181. Enumerations.java
  182. Stacks.java
  183. Bits.java

  184. Back to Top


    Chapter 10 (Error Handling with Exceptions)

  185. SimpleExceptionDemo.java
  186. FullConstructors.java
  187. ExtraFeatures.java
  188. ExceptionMethods.java
  189. Rethrowing.java
  190. ThrowOut.java
  191. RethrowNew.java
  192. NeverCaught.java
  193. FinallyWorks.java
  194. OnOffSwitch.java
  195. WithFinally.java
  196. AlwaysFinally.java
  197. LostMessage.java
  198. StormyInning.java
  199. Cleanup.java
  200. Human.java

  201. Back to Top


    Chapter 11 (The Java I/O System)

  202. Dirlist.java
  203. DirList2.java
  204. DirList3.java
  205. MakeDirectories.java
  206. IOStreamDemo.java
  207. TestEOF.java
  208. IOProblem.java
  209. Echo.java
  210. Redirecting.java
  211. GZIPcompress.java
  212. ZipCompress.java
  213. Worm.java
  214. Alien.java
  215. FreezeAlien.java
  216. xfiles/ThawAlien.java
  217. Blips.java
  218. Blip3.java
  219. Logon.java
  220. SerialCtl.java
  221. MyWorld.java
  222. CADState.java
  223. WordCount.java
  224. AnalyzeSentence.java
  225. ClassScanner.java

  226. Back to Top


    Chapter 12 (Run time Type Identification)

  227. Shapes.java
  228. SweetShop.java
  229. PetCount.java
  230. PetCount2.java
  231. PetCount3.java
  232. FamilyVsExactType.java
  233. ToyTest.java
  234. ShowMethods.java
  235. ShowMethodsClean.java

  236. Back to Top


    Chapter 13 (Creating Windows and Applets)

  237. Applet1.java
  238. Applet1b.java
  239. Applet1c.java
  240. Applet1d.java
  241. Button.java
  242. Button2.java
  243. TextArea.java
  244. BorderLayout1.java
  245. FlowLayout1.java
  246. GridLayout1.java
  247. GridBagLayout.java
  248. BoxLayout1.java
  249. Box1.java
  250. Box2.java
  251. Box3.java
  252. ShowAddListeners.java
  253. TrackEvent.java
  254. Buttons.java
  255. ButtonGroups.java
  256. Faces.java
  257. TextFields.java
  258. Borders.java
  259. JScrollPanes.java
  260. TextPane.java
  261. CheckBoxes.java
  262. RadioButtons.java
  263. ComboBoxes.java
  264. List.java
  265. TabbedPane1.java
  266. MessageBoxes.java
  267. SimpleMenus.java
  268. Menus.java
  269. Popup.java
  270. SineWave.java
  271. Dialogs.java
  272. TicTacToe.java
  273. FileChooserTest.java
  274. HTMLButton.java
  275. Program.java
  276. Trees.java
  277. Table.java
  278. LookAndFeel.java
  279. CutAndPaste.java
  280. DynamicEvents.java
  281. Separation.java
  282. Frrog.java
  283. BeanDamper.java
  284. BangBean.java
  285. BangBeanTest.java

  286. Back to Top


    Chapter 14 (Multiple Threads)

  287. Counter1.java
  288. SimpleThread.java
  289. Counter2.java
  290. Counter3.java
  291. Counter4.java
  292. Daemons.java
  293. Sharing1.java
  294. Sharing2.java
  295. BangBean2.java
  296. Blocking.java
  297. Interrupt.java
  298. Suspend.java
  299. Counter5.java
  300. TestAccess.java
  301. ThreadGroup1.java
  302. ColorBoxes.java
  303. ColorBoxes2.java

  304. Back to Top


    Chapter 15 (Distributed Computing)

  305. WhoAmI.java
  306. JabberServer.java
  307. JabberClient.java
  308. MultiJabberServer.java
  309. MultiJabberClient.java
  310. ShowHTML.java
  311. Fetcher.java
  312. jdbc/Lookup.java
  313. jdbc/VLookup.java
  314. jdbc/CIDConnect.java
  315. jdbc/CIDSQL.java
  316. jdbc/CIDCreateTables.java
  317. servlets/ServletsRule.java
  318. servlets/EchoForm.java
  319. servlets/ThreadServelet.java
  320. servlets/SessionPeek.java
  321. jsp/ShowSeconds.jsp
  322. jsp/Hello.jsp
  323. jsp/DisplayFormData.jsp
  324. jsp/PageContext.jsp
  325. jsp/SessionObject.jsp
  326. jsp/SessionObject2.jsp
  327. jsp/SessionObject3.jsp
  328. jsp/Cookies.jsp
  329. rmi/PerfectTimeI.java
  330. rmi/PerfectTime.java
  331. rmi/DisplayPerfectTime.java
  332. corba/ExactTime.idl
  333. corba/RemoteTimeServer.java
  334. corba/RemoteTimeClient.java
  335. ejb/PerfectTime.java
  336. ejb/PerfectTimeHome.java
  337. ejb/ejb-jar.xml
  338. ejb/PerfectTimeClient.java

  339. Back to Top


    Appendix A (Passing & Returning Objects)

  340. PassReferences.java
  341. Alias1.java
  342. Alias2.java
  343. Cloning.java
  344. LocalCopy.java
  345. Snake.java
  346. DeepCopy.java
  347. AddingClone.java
  348. Compete.java
  349. HorrorFlick.java
  350. CheckCloneable.java
  351. CopyConstructor.java
  352. ImmutableInteger.java
  353. MutableInteger.java
  354. Immutable1.java
  355. Immutable2.java
  356. Stringer.java
  357. ImmutableStrings.java

  358. Back to Top


    Appendix B (The Java Native Interface (JNI))

  359. ShowMessage.java
  360. MsgImpl.cpp
  361. UseObjects.java
  362. UseObjImpl.cpp

  363. Back to Top


    Packages

  364. com.bruceeckel.simple
  365. com.bruceeckel.swing
  366. com.bruceeckel.tools
  367. com.bruceeckel.util
  368. c05.dessert

  369. Back to Top


    Beans

  370. Frog Bean
  371. Bang Bean

  372. 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

  1. build.xml [Right-click and download only.] This is a sample "buildfile" that you can use with the ant utility for the Mastermind project.

  2. Back to Top


    Classes: Some Programs Illustrating Java Classes

  1. Line.java Demonstrates a Point class which is an "inner class" within a Line class.
  2. TestLine.java A test driver for the Line class.

  3. 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

  1. ComputeQuotient.java Demonstrates creating an (arithmetic) exception and allowing the Java interpreter to handle it.
  2. ComputeQuotientWithException1.java Demonstrates creating an arithmetic exception and "catching" it.
  3. ComputeQuotientWithException2.java Demonstrates creating an arithmetic exception or a number format exception, and "catching" it.
  4. 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.
  5. TestMyException.java Demonstrates use of programmer-defined exceptions and a stack trace.
  6. TestRethrowing.java Demonstrates re-throwing and exception, and the use of a stack trace.
  7. TestFinally.java Demonstrates the "finally" clause.

  8. Back to Top


    GUI: Some Programs Illustrating GUI Concepts

  1. CalculatorGUIAppAWT.java A very simple calculator with an AWT GUI.
  2. CalculatorGUIAppSwing.java A very simple calculator, like the previous example, but with a Swing GUI.
  3. ColorChangeGUIApp.java A program illustrating a very simple way of changing the colors of circular areas.
  4. 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.
  5. 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.
  6. 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.
  7. test1.txt, test2.txt, and test3.txt Sample text files to use as input for the previous program.
  8. 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.
  9. 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.
  10. HeadlinesGUIApp.java Illustrates scrolling headlines.
  11. DigitalClockGUIApp.java Illustrates a digital clock that updates each second.
  12. See also the DigitalClock example under Chapter04 of Jia.
  13. TopLevelDemoGUIApp.java Illustrates a menu bar.
  14. MenuDemoGUIApp1.java Illustrates some menus.
  15. GridBagLayoutDemo.java Illustrates the GridBagLayout class.

  16. Back to Top


    Hello: Some Variations on "Hello, World!"

  1. HelloConApp.java A simple console program displaying "Hello, world!".
  2. 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.
  3. HelloApplet1.html An HTML file corresponding to, and for displaying, the applet in HelloApplet1.java.
  4. HelloApplet2.java A slightly more interesting applet, which also displays "Hello, world!", this time with some color.
  5. 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".
  6. HelloGUIApp1.java A simple standalone application which displays "Hello, world!" within a GUI.
  7. HelloGUIApp2.java A slightly more interesting standalone application which displays "Hello, world!" within a GUI, in color.
  8. 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.
  9. 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.
  10. 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.
  11. 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.

  12. Back to Top


    I/O: Some Programs Illustrating Java Input and Output

  1. TestFileIO.java Demo of file input and output.
  2. TestFileIOWithException.java Demo of file input and output, with a "file not found" exception handler.
  3. TestFileIO_in.txt Sample input file for TestFileIO.java and TestFileIOWithException.java.
  4. 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.
  5. 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.

  6. 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

  1. BannerPage.java A class for displaying a "banner page" that might be used as the opening screen for any console program.
  2. TestBannerPage.java A test driver for the BannerPage class.
  3. Menu.class The class file for the Menu class.
  4. Menu_shell.java A shell file to use when you start coding your implementation of the Menu class.
  5. TestMenu.java A fairly comprehensive test driver for the Menu class, which may be extended for further testing of that class if desired.
  6. 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.
  7. TextItems.class, TextItems$ItemNode.class, and TextItems$LineNode.class The three files you need to use the TextItems class.
  8. 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.
  9. TextItems_shell.java A shell file to use when you start coding your implementation of the TextItems class.
  10. 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.
  11. 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.
  12. 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.

  13. 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

  1. ThreePillars.java, Worker.java, and Executive.java This group illustrates encapsulation, inheritance, and polymorphism.
  2. TestRoundShapes.java, RoundShape.java, Circle.java, and Sphere.java This group illustrates an abstract class that also uses an inner class.
  3. TestInterface.java, WorkerWithIFace.java, ExecutiveWithIFace.java, and NameAndPayInterface.java This group illustrates the implementation of an interface.

  4. Back to Top


    Other: Some Other Useful Programs

  1. 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)
  2. 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)

  3. Back to Top


    Packages: Some Programs Illustrating Packages in Java

  1. TestFriendly.java A driver for class Friendly.
  2. Friendly.java A class with a static method to print out a greeting.
  3. TestGreetings.java A driver for the English, French and German classes.
  4. English.java, French.java, and German.java Classes that have static methods that just display greetings in English, French and German.

  5. 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

  1. 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.

  2. Back to Top