Java 425
instead of Processing , specifying all libraries would always be required. Processing , however, assumes a
base set of libraries from Java (e.g., java.applet.*) and from Processing (e.g., processing.core.* ) which is
why we do not see these in every sketch.
• public —In Java, variables, functions, and classes can be “ public ” or “ private. ” This designation
indicates what level of access should be granted to a particular piece of code. It is not something
we have to worry much about in the simpler Processing environment, but it becomes an important
consideration when moving on to larger Java programs. As an individual programmer, you are
most often granting or denying access to yourself, as a means for protecting against errors. We
encountered some examples of this in Chapter 22’s discussion about encapsulation.
• class JavaExample —Sound somewhat familiar? Java, it turns out, is a true object-oriented language.
There is nothing written in Java that is not part of a class! We are used to the idea of the Zoog class,
Car class, PImage class, and so on, but it is important to note that the sketch as a whole is a class,
too! Processing fills this stuff in for us so we do not have to worry about classes when we are first
learning to program.
• extends PApplet —Well, after reading Chapter 22, we should be quite comfortable with what this
means. This is just another example of inheritance. Here, the class JavaExample is a child of the class
PApplet (or, equivalently, PApplet is the parent of JavaExample). PApplet is a class developed by
the creators of Processing and by extending it, our sketch has access to all of the Processing goodies—
setup( ), draw( ) , mouseX , mouseY , and so on. This little bit of code is the secret behind how almost
everything works in a Processing sketch.
Processing has served us so well because it eliminates the need to worry about the above four elements, all
the while providing access to the benefi ts of the Java programming language. e rest of this chapter will
show how we can begin to make use of access to the full Java API. (We briefl y began this journey when
we worked with String parsing in Chapters 17 and 18.)
23.3 Exploring the Java API
e Processing reference quickly became our best friend forever while learning to program. e Java API
will start off more as an acquaintance we bump into from time to time. at acquaintance might turn into
a really excellent friend someday, but for now, small doses will be just fi ne.
We can explore the full Java documentation by visiting:
http://java.sun.com/
ere, we can click over to API specifi cations:
http://java.sun.com/reference/api/index.html
and fi nd a selection of versions of Java. On a Mac, Processing will run with the selected version of Java
(run Java Preferences, found, e.g., in: /Applications/Utilities/Java/J2SE 5.0/). On a PC, the Processing
“ standard ” download comes with Java version 1.4.2 (the Windows expert version allows you to install
your own version of Java). Versions of Java will change in the future with updated info at processing.org.
In any case, while there are diff erences between the version of Java, for what we are doing, they will not
be terribly relevant, and we can look at the API for J2SE 1.4.2 for pretty much whatever we want to do.
See Figure 23.1 .