318 Building Java Applications for the iSeries Server with VisualAge for Java 3.5
7.1.6 Instance variables
Instance variables are specific to an object and are not shared among other objects. They
may be visible to other objects (in which case, they are said to be
public) or hidden from other
objects (
private most instance variables are private). They can be public, private, protected,
or default.
7.1.7 Instance methods
Instance methods are only usable when an object has been created. They provide the code
that implements the programming logic for the class. Instance methods may be public,
private, protected, or default.
7.1.8 Thread
Thread is a Java way to make a single Java virtual machine look like many machines and all
running at the same time. Java provides a number of tools for creating and managing threads.
This facility helps us to create the objects which can be running concurrently.
7.1.9 Object destruction
Objects are not explicitly destroyed in Java. They are automatically removed by the garbage
collector when there are no further references to the object. This work is usually done in the
background by a low priority thread. The idea of a garbage collector has existed for a long
time and has been implemented in languages such as Smalltalk and Lisp. The JVM knows
which objects it has allocated. It can also determine which variables reference which objects.
It has algorithms that can determine when an object is no longer needed.
There is an important consequence of the nature of automatic garbage collection. The
objects cannot be collected if we allow accessible references to those unnecessary objects in
our program. Therefore, it may be a good idea to explicitly assign null value into a variable
when it is no longer needed:
myThing = null;
7.1.10 Subclasses and inheritance
Inheritance is one of the more powerful features of an OO language. It allows code to be
reused by creating a subclass of an existing class. The new class gets all of the code in the
parent class (super class) and can extend the parent class by providing its own routines to do
things that the parent class was not designed to do.
7.1.11 Overloading and overriding methods
There are some circumstances when we want to re-use a method of its super class. There
are two ways that we can do this with Java. Reusing the same method name with different
arguments and perhaps a different return type is known as
overloading. Using the same
method name with identical arguments and return type is known as
overriding.
This allows a class to change the behavior of a method that is provided by its super class. For
example, a class hierarchy that represents various geometric shapes can have an Ellipse
class that inherits from a Circle class. Both classes may need a means of returning the size of
their area. However, calculating the area of an ellipse is different from calculating the area of a
circle so the Ellipse class can override the Circle area() method.

Get Building Java Applications for the iSeries Server with VisualAge for Java 3.5 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.