What Is Java?
This appendix presents an overview of Java. An experienced Java programmer can safely skip
this section. For readers who are inexperienced with Java, reading this section should help to
understand the Java concepts and code snippets used throughout this book, as well as to make
Java is an object-oriented programming language, introduced in 1995. Its main strength when
compared with other object-oriented languages of its time (C++ being the most important) was its
portability: Java was designed to be architecture-neutral so that Java programs written on a Mac,
for example, would look and behave exactly in the same way as on Windows, Linux, and any
other platform that supports the Java specication. This design, coupled with modern object-ori-
ented programming features, built-in security measures, and easily accessible GUI and I/O, sig-
nicantly reduced development work and made Java a favorite among programmers worldwide.
All Java programs are object-oriented: whereas MATLAB functions can be created as stand-
alone functions or scripts, Java code must be enclosed in a containing class. The Java class
determines which properties belong to the class and which functions (methods) are available to
act on these properties.
Classes are often grouped into packages and sub-packages based on semantic and functional
relationships. For example, MATLAB has a com.mathworks.mwswing package that con-
tains the MJButton, MJLabel, and MJPanel classes. A class’s Fully Qualied Class Name
(FQCN) includes the package name along with all its parent packages (e.g., com.mathworks.
mwswing.MJButton). Sibling classes of the same package, or classes that explicitly import
denition of another package, do not need to use FQCN, and can use just the short classname
(e.g., MJButton). Classes whose package is not explicitly dened are still packaged, in a global
default package. It is customary, although not mandatory, for package names to be lower-cased
and for class names to be camel-cased (e.g., ClassName).
Java classes, properties, methods, and so on, all have accessibility attributes that control
whether these elements are accessible to external (non-class) code. A public attribute means
that the element is usable by any external class (including our MATLAB code); protected and
private attributes (and the default package visibility) reduce the element visibility/accessibility
to Java subclasses, the same class and the same package, respectively. Only public elements are
visible from our MATLAB code.
K13163_Book.indb 621 11/8/2011 8:10:42 PM