THOUSANDS OF FREE BLOGGER TEMPLATES

Monday, April 19, 2010

Working w/ the Java

Object-oriented programming (OOP) is a programming paradigm
that uses "objects" – data structures
consisting of datafields and methods together
with their interactions – to design applications
and computer programs. Programming techniques may
include features such as data abstraction, encapsulation,
modularity, polymorphism, and inheritance. It was not
commonly used in mainstream software application
development until the early 1990s.

Encapsulation is the technique of making the fields in a
class private and providing access to the fields
via public methods. If a field is declared private,
it cannot be accessed by anyone outside the class,
thereby hiding the fields within the class. For this
reason, encapsulation is also referred to as data
hiding.Encapsulation can be described as a protective
barrier that prevents the code and data being randomly
accessed by other code defined outside the class. Access
to the data and code is tightly controlled by an interface.
The main benefit of encapsulation is the ability to modify
our implemented code without breaking the code of others who
use our code.

Object - Objects have states and behaviors.
Example: A dog has states-color, name, breed as
well as behaviors -wagging, barking, eating. An object
is an instance of a class.

Class - A class can be defined as a template/ blue print
that describe the behaviors/states that object of
its type support.

Class Variables
When a number of objects are created from the same
class blueprint, they each have their own distinct
copies of instance variables. In the case of the
Bicycle class, the instance variables are cadence,
gear, and speed. Each Bicycle object has its own
values for these variables, stored in different memory
locations.
Sometimes, you want to have variables that are common
to all objects. This is accomplished with the static
modifier. Fields that have the static modifier in their
declaration are called static fields or class variables.
They are associated with the class, rather than with any
object. Every instance of the class shares a class variable,
which is in one fixed location in memory. Any object can change
the value of a class variable, but class variables can also be
manipulated without creating an instance of the class.

Class Instantiation
In programming, instantiation is the creation of a real
instance or particular realization of an abstraction or
template such as a class of objects or a computer process.
To instantiate is to create such an instance by, for example,
defining one particular variation of object within a class,
giving it a name, and locating it in some physical place

The Method Declaration
A method's declaration provides a lot of information about
the method to the compiler, the runtime system and to other
classes and objects. Besides the name of the method, the method
declaration carries information such as the return type of the
method, the number and type of the arguments required by the
method, and what other classes and objects can call the method.
While this may sound like writing a novel rather than simply
declaring a method for a class, most method attributes can be
declared implicitly. The only two required elements of a method
declaration are the method name and the data type returned by
the method. For example, the following declares a method named
isEmpty() in the Stack class that returns a boolean value
(true or false):
class Stack
{
. . .
boolean isEmpty() {
. . .
}
}



STATIC VARIABLES
A static variable is associated with the class as a whole
rather than with specific instances of a class. Each object
will share a common copy of the static variables i.e. there
is only one copy per class, no matter how many objects are
created from it. Class variables or static variables are
declared with the static keyword in a class. These are declared
outside a class and stored in static memory. Class variables are
mostly used for constants. Static variables are always called by
the class name. This variable is created when the program starts
and gets destroyed when the programs stops. The scope of the class
variable is same an instance variable. Its initial value is same as
instance variable and gets a default value when its not initialized
corresponding to the data type. Similarly, a static method is a method
that belongs to the class rather than any object of the class and
doesn’t apply to an object or even require that any objects of the
class have been instantiated.
Static methods are implicitly final, because overriding is done based
on the type of the object, and static methods are attached to a class,
not an object. A static method in a superclass can be shadowed by another
static method in a subclass, as long as the original method was not
declared final. However, you can’t override a static method with
a non-static method. In other words, you can’t change a static method
into an instance method in a subclass.

0 comments: