Wednesday, December 14, 2005

Session2-Classes and Objects

Classes:
Class in Java has data and functions that operate on those data.
In writing a Class we only describe it.

Classes use the concept of abstraction and are defined as a list of abstract attributes.
By using access modifiers Data can be made inaccessible to the outside world and only those functions which are stored in

the class could be made to access them.

Objects:
They are instances of a class.
Class is the blueprint while Object is the live model built from the blueprint.
We don't create classes in memory but when we instantiate a Class then it is called an Object and it is part of memory.

Example:

A class will have a data part and a functional part

Class Person
{
//Data part
organs eyes;
organs ears;

//functional part

see()
{
//implement seeing with your eyes.
}

hear()
{
//implement hearing with your ears.
}

}

Until now this is just a blue print. When you want to make a real person you would create a real model from this blue print which is called an Object.

Person person1 = new Person();

In the above example we have combined the data part and functional part in a single

entity[Class] which is a blue print of what we want. This is encapsulation.

We can have another Class which can inherit the properties of this Person.
That is inheritance.

In next session we will look at Access Modifiers, variables and data types.

Wednesday, December 07, 2005

Session 1 - Object Oriented Concepts

Object Oriented Concepts help programmers to translate real life situations[logical] in to computer applications.
The main concepts are given below.

Data abstraction
Abstraction refers to the act of representing essential features without including the background details or explanations.
Nutshell:
Expose on a need to know basis.
Example:
In a mobile phone to make a call all we do is to enter the number and press call/ok.
we don't need to know the technology of how it works.

Information Hiding
This is a design consideration. All data and internal implementations to be hidden from client view.
Nutshell:
Secrecy needed for data protection from data accessors [clients].
Example:
That is to fortify your defences against any client intrusions on your castle.
Subtle difference between abstraction and hiding.

Encapsulation
Storing data and functions in a single unit is encapsulation.
The idea is to combine the data part and the functional part of a single unit.
This is essentially a language facility. Java offers this facility.
Nutshell:
All related items in One place
Example:
It is like storing all your food items in the kitchen so that it helps you with easy access while cooking rather than having a separate store room.

Inheritance
Inheritance is the process by which objects can acquire the properties of objects of other class. In OOP, inheritance provides reusability, like, adding additional features to an existing class without modifying it. This is achieved by deriving a new class from the existing one. The new class will have combined features of both the classes.
Nutshell:
Like Father Like Son
Example:
Best example is people inheriting their genes from their predecessors.

Polymorphism
Polymorphism means the ability to take more than one form. An operation may exhibit different behaviours in different instances. The behaviour depends on the data types used in the operation. Polymorphism is extensively used in implementing Inheritance.
Nutshell:
One God Several Faces
Example:
A person exhibiting different characteristics while being in different moods.
But still he is the same person.

Advantages of OOP
Object-Oriented Programming has the following advantages over conventional approaches:

OOP provides a clear modular structure for programs which makes it good for defining abstract data types where implementation details are hidden and the unit has a clearly defined interface.

OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones.

OOP provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces.

NOTE:
Information hiding is not only confused with encapsulation, it is also often confused with abstraction.
Abstraction is a technique that helps us identify which specific information should be visible, and which information should be hidden. Encapsulation is then the technique for packaging the information in such a way as to hide what should be hidden, and make visible what is intended to be visible.

Next Session:
Classes and Objects.

Tuesday, December 06, 2005

Learn Java for free

Friends,

I'm a J2EE developer with a reputed company.I work in UK. I have been programming with Java and J2EE for the last 6 years.
When I started learning Java I was recommended with many books.I had a problem doing it that way.Most of the books were just talking about Foo and Foo.I didn't have an iota of idea about what was Foo an why they were talking about Foo.I couldn't read more than 2 pages a day.Sometimes it is very hard to push past even 1 page.So I thought may be I can make it easy.
All I'm going to do is to teach Java in a very simple manner.Most of the examples will be easy enough to understand relating them to real situations.I want to make this a fun session.We will have one session a week.I hope you will like this effort of mine.
Please feel free to add your comments.

Thanks in Advance for your support.
Pazham