This section presents a simple Java class and a class for testing it.
The Java Development Kit (JDK) is a suite of tools for documenting,
compiling, and running Java programs.
Java program documentation is accomplished through the javadoc
utility, which is part of the JDK.
In this section we present the similarities between Java's core
language and C++.
Java and C++ are similar in the way they create new object references.
However, unlike C++, Java does not distinguish between objects and
references to them, so there is no need for a derefencing operator (*).
Like C++, Java passes
copies of parameters to methods.
Unlike C++, Java has no
reference parameters.
Since Java is an interpreted language, there are no static arrays as
in C++.
However, Java arrays are similar to C++ dynamic arrays.
Java classes are grouped into packages for organization and to
avoid clashing of class names.
In Java, exceptions are class objects arranged in a hierarchy.
The Java compiler enforces exception handling by distinguishing
between
checked and
unchecked exceptions.
Java has an enormous class library that is being added to all the time.
In this section we briefly describe a few essential classes from
the
java.lang and
java.util packages.
While C++ regards strings as arrays of characters, Java strings are (immutable)
class objects.
To facilitate internationalization, Java encodes strings as sequences
of 16-bit
Unicode characters.
The
String class is part of the
java.lang package.
Lists are one of the several elementary data structures provided by
Java's
Collection framework in the
java.util package.
Lists are implemented through either an underlying array, or through
linked nodes.
Generic class:
ArrayList<E>
collects objects of
type
E
E
cannot be a primitive type
Iterators are a natural and efficient way of accessing the elements of
collections such as lists.
A "static" class member (either a field or a method), as the term
suggests, is not dynamic.
That is, it is not invoked on an object, as in "
object.field" or
"
object.method(...)".
Programming with static class members is like programming in a
nonobject-oriented way (in C, for example).
This section presents a few guidelines on Java programming style and conventions.