Java Reference
In-Depth Information
The complete class definition “template” now looks like this:
class CLASSNAME {
// FINAL CLASS VARIABLE DEFINITIONS
// CLASS VARIABLE DEFINITIONS
// FINAL INSTANCE VARIABLE DEFINITIONS
// INSTANCE VARIABLE DEFINITIONS
// CONSTRUCTOR METHOD DEFINITIONS
// INSTANCE METHOD DEFINITIONS
// CLASS METHOD DEFINITIONS
// MAIN METHOD DEFINITION (OPTIONAL)
}
The final section of this chapter guides you through Java's standard edition built‐in classes and high-
lights some particularly useful ones that will return in many of the following chapters.
java se Built‐in classes
Recall from the introduction to Java in Chapter 2 that there are multiple “editions” of Java. The most
widely used edition—the one used here as well—is aptly named Java SE, Standard Edition. This edi-
tion comes with class libraries containing a number of built‐in classes that meet most of your needs
you will encounter while programming. One of them—the HashSet —was already briefly discussed in
the last Try It Out, as a simple way to keep a set of objects. This class is part of the so‐called “collec-
tions” class library, which contains a number of other helpful “array alternatives” as well.
The following subsections provide a short tour through all of Java SE's frequently used built‐in
classes. I've organized them by their packages. I still need to discuss packages in-depth, but for now,
just think of them as a way to organize classes using a naming scheme that looks a bit like web
URLs. For example, both the Java HashSet and ArrayList classes are found in the package java.
util . Their full canonical names are java.util.HashSet and java.util.ArrayList , which is all
you need to know for now.
classes in the java.lang package
The java.lang package contains core classes related to the Java language, including:
java.lang.Object : Every class you define silently inherits all the behavior defined in this class.
This class contains methods such as equals (to perform object equality checks), clone (to make
a copy of an object), and toString (to retrieve a textual representation of an object), which can
be overridden and customized by programmers. Chapter 8 will tell you more about this.
java.lang.Exception and all its subclasses: Classes representing errors. Chapter 6 talks
more about exceptions, errors, debugging, and testing.
java.lang.String , as well as wrapper classes for all primitive types ( java.lang.Integer ,
java.lang.Double , and so on).
java.lang.StringBuilder : An alternative class for dealing with strings that's especially
helpful if you need to perform a lot of modifications to a String.
 
Search WWH ::




Custom Search