Please note that I do not give permission to post the free PDF version of this book on other people’s web sites: I consider this to be commercial exploitation in violation
of the Creative Commons License that I have chosen for this book. Having my free web books only available on my web site brings viewers to my site and helps attract
customers for my consulting business. I do encourage you to copy the PDF for this book onto your own computer for local reading and it is fine to email copies of the
free PDF to friends.
If you enjoy reading the no-cost PDF version of this book I would also appreciate it if you would purchase a print copy using the purchase link:
http:www.lulu.comcontent4502573 I thank you for your support.
1.3 Book Software
You can download a large ZIP file containing all code and test data used in this book from the URL:
http:markwatson.comopencontentjavaai_3rd_code.zip All the example code that I have written is covered by the licenses discussed in the
Preface. The code examples usually consist of reusable non GUI libraries and throwaway
text-based test programs to solve a specific application problem; in some cases, the test code will contain a test or demonstration GUI.
1.4 Use of Java Generics and Native Types
In general I usually use Java generics and the new collection classes for almost all of my Java programming. That is also the case for the examples in this book
except when using native types and arrays provides a real performance advantage for example, in the search examples.
Since arrays must contain reifiable types they play poorly with generics so I prefer not to mix coding styles in the same code base. There are some obvious cases where
not using primitive types leads to excessive object creation and boxingunboxing. That said, I expect Java compilers, Hotspot, and the JVM in general to keep getting
better and this may be a non-issue in the future.
2
Book
Many of the example programs do not strictly follow common Java programming idioms – this is usually done for brevity. For example, when a short example is all
in one Java package I will save lines of code and programing listing space by not declaring class data private with public getters and setters; instead, I will sometimes
simply use package visibility as in this example:
public static class Problem { constants for appliance types:
enum Appliance {REFRIGERATOR, MICROWAVE, TV, DVD}; constants for problem types:
enum ProblemType {NOT_RUNNING, SMOKING, ON_FIRE,
MAKES_NOISE}; constants for environmental data:
enum EnvironmentalDescription {CIRCUIT_BREAKER_OFF, LIGHTS_OFF_IN_ROOM};
Appliance applianceType; ListProblemType problemTypes =
new ArrayListProblemType; ListEnvironmentalDescription environmentalData =
new ArrayListEnvironmentalDescription; etc.
} Please understand that I do not advocate this style of programming in large projects
but one challenge in writing about software development is the requirement to make the examples short and easily read and understood. Many of the examples started as
large code bases for my own projects that I “whittled down” to a small size to show one or two specific techniques. Forgoing the use of “getters and setters” in many of
the examples is just another way to shorten the examples.
Authors of programming books are faced with a problem in formatting program snippets: limited page width. You will frequently see what would be a single line in
a Java source file split over two or three lines to accommodate limited page width as seen in this example:
private static void createTestFactsWorkingMemory workingMemory
throws Exception { ...
}
3