Java Reference
In-Depth Information
Appendix A
Introduction to Java
One of the fundamental ways in which complexity can be handled is abstraction, which is applied
in almost every discipline. For instance, abstract art is art that does not represent or imitate external
reality or the objects of nature. As another example, some words are abstract, existing only in the
mind, like truth or justice . In Java, abstraction allows developers to layer complex systems into
manageable pieces by using class hierarchies that highlight the essential properties and behaviors of
an object, differentiating it from other objects.
Classes and Objects
A class is the fundamental building block of object-oriented (OO) programs. Each class generally
represents a real-world object. The class is a template for denoting and creating a category of
objects, thus modeling an abstraction by defining the properties and behavior of the objects
representing that abstraction. A property of an object is defined by a field, which is a variable that
can store the value representing that property. The behavior of an object is defined by a method.
The fields and methods of a class are known as its members . A class definition in Java consists of
member declarations (variable declarations and method declarations) and begins with the class
keyword, as illustrated in Listing A-1.
Listing A-1. A Java Class
class ClassA {
// members declarations
}
An object is an instance of a class. The object is constructed using the class as a blueprint and is a
concrete instance of the abstraction that the class represents. An object must be created before it
can be used in a program. The process of creating objects from a class is called instantiation . When
a class is instantiated, a reference value is returned that denotes the created object. A reference
value denotes a particular object. An object reference (or, simply, reference ) is a variable that can
store a reference value and provide a handle to an object. The code in Listing A-2 creates an object
of ClassA . The reference value of this object is stored in the variable var1 .
383
 
Search WWH ::




Custom Search