The real-world objects(any living or non- living thing) share two characteristics:
they do have state and behaviour. For example, dogs have a state ( like name, color, etc)
and behaviour ( like barking, fetching etc). Also consider for example a
Bicycles have a state such as current gear, current wheels, number of gears etc and
and behaviour such as braking, accelerating etc.
After the real-world objects Software objects have been modelled in that, they too,have
states and behaviours.
A software object maintains states in the variables and implements behaviour by methods.
The Benefit of Encapsulation
Modular programming-- The source code for any of the object can be written and maintained
independently from those of the source code written for other objects. Also, an object can be
easily used passing around in the system. For example you can give your bicycle to someone else
and it will still work for them too.
Information hiding-- An object has a public interface by which other objects can
communicate with it. But on the other hand objects can maintain private information and methods
that cannot be communicated to others.
The Benefit of Messages
Since everything that an object can do is expressed through its methods, message
passing supports all possible interactions between objects.
To send and receive messages back and forth objects don't need to be in the same
process or even on the same machine.
The Benefit of Classes
Objects provide the benefit of modularity and information hiding. Classes provide the
benefit of reusability. Bicycle manufacturers reuse the same blueprint over and over
again to build lots of bicycles. Software programmers use the same class over and
over to again create many objects.
The Benefit of Inheritance
Subclasses provide specialized behaviours from the basis of common elements provided by
the superclass. Through the use of inheritance, programmers can reuse the code in the
superclass many times.
Programmers can implement superclasses that define "generic" behaviours (called abstract
classes). The essence of the superclass is defined and may be partially implemented but much of
the class is left undefined and unimplemented. Other programmers fill in the details with
These are some of the rules on constructors:
private constructors()- keyword used "private", no one can instantiate the class as object.
But can still expose public static methods, and these methods can construct object
and return it, but no one else can do this.
package constructors() - None of them outside your package can construct an instance of your
class. This is useful when you want to have classes in your package which can do new
yourClass() and don't want to let anyone else to do this.
protected constructors() - keyword used "protected" only the subclasses of your class
can make use of this package.
public constructors() - keyword used "public" the generic constructor
will use these.
Setting Program Attributes
A program typically needs this information about the system and application environment
to make decisions about how to do something, or what to do. Also, a program may wish to
modify certain attributes itself, or allow a user to change them. Thus a program needs
to be able to read and write various system attributes and program-specific attributes.
Java programs can manage these attributes through three mechanisms: properties,
application command line arguments, and applet parameters.
Use properties to define environmental attributes on a persistent basis. That is, use
properties when they need to be in effect for each invocation of a program.
Application Command Line Arguments
Use command line arguments to define or modify environmental attributes on a
non-persistent basis. That is, use command line arguments to change one or more
attributes for just one invocation of a program.
Use applet parameters to define or modify environmental attributes on a non-persistent
basis for applets. That is, use parameters to set one or more attributes for a single
invocation of an applet.
What is Thread?
Programmers are familiar with writing sequential programs. The program that displays
"Hello World!", or program which sorts a list of names, or computes the list of
prime numbers, are sequential all programs: each has beginning, end, sequence,
and at any given time during runtime of program there is single point of execution.
A thread is similar to a sequential program, a single thread do also has
beginning, end, sequence, and at any given time during runtime of thread
there will be a single point of execution. But the thread itself is not a
program it cannot run by itself but runs within the program.
An applet can communicate with the other programs in three different ways:
By invoking the public methods of other applets on the same page
By using an API defined in the java.applet package, which allows it to communicate
in limited way with a browser or applet viewer that contains it.
By using the API defined in the java.net package to communicate over network with
the other programs. Other programs must be running on a host which the applet
How to Choose a Layout Manager
AWT-provided layout managers have different strengths and weakness. This section
discusses some of the common layout scenarios and which AWT layout managers may work
for each scenario. If none of the AWT layout managers is right for our situation, we
should use layout managers contributed to the net.
Scenario: We need to display a component in as much space as it can.
Consider using the BorderLayout or GridBagLayout. If you use the BorderLayout, we
will need to put the space-hungry component at the center. With GridBagLayout, we will
need to set constraints for the component so that the fill=GridBagConstraints.BOTH. Or,
if we do not mind every other component in the same container being as large as our
space-hungry component, we can use a GridLayout.
Scenario: We need to display a few components in the compact row at their natural size.
Consider using Panel to hold the components and using a Panel's default FlowLayout
Scenario: We need to display few same-sized components in rows and/or the columns.
GridLayout is perfect for this purpose. Use the Panel if it isnecessary to contain the
Drawing simple Shapes
Graphics class defines methods for drawing the following types of shapes:
Lines ( drawLine() )
Rectangles ( drawRect() & fillRect() )
Raised or lowered rectangles ( draw3DRect() and fill3DRect() )
Round-edged rectangles ( drawRoundRect() and fillRoundRect() )
Ovals ( drawOval() and fillOval())
Arcs ( drawArc() and fillArc() )
Polygons ( drawPolygon() and fillPolygon() )
Except for polygons and lines, all shapes are specified using their bounding rectangle.
Once you understand rectangles, drawing other shapes is relatively easy. For this
reason, this page will concentrate on rectangle drawing.