Object Orientation

Java is an Object Orientated programming language. Part of the philosophy behind Object Orientation is that programmers should be able to use off-the shelf components in the same way that engineers do in the real world. Thus when an electronics designer decides to create a new graphics card, or washing machine controller they don't create every integrated circuit from scratch. They generally use off the shelf components with some custom configuration.

In the world of software design there has been a long and rather unfortunate history of constantly "re-inventing" the wheel. It seems that there are a million ways of performing common programming tasks such as searching, and sorting. If programmers could re-use off-the shelf components they could get on with the real creative part of software creation rather than getting bogged in the low level details.

Classes

Object Orientation in Java (and most language) is performed using the concept of classes, self contained bundles of code and data that have their own "behaviour". A class is a template for creating an "instance" or Object based on that template. You can think of classes as a way of creating your own data types. In older languages such as C or Pascal you had pre-defined types such as int or float. In Java you can define your own types that wrap up both data and code, and you can use classes that come with the Java language or those provided by other programmers. For example when you are creating a graphical interface and you needed to create a button you you could create an instance of the JButton class and take advantage of the data and functionality that comes with it.

Methods

The "behaviour" of an object is set up in its methods which are callable chunks of code in a similar way to subroutines in structured programming languages such as C or Pascal. The difference between a method in Java and a function in C is that in Java the method belongs to the instance of a class, whereas in C a function belongs to the currently running program. If you are new to Object Orientation the terminology can be a little confusing at first but it soon becomes second nature. In java every object is a descendent of a great grandparent class called Object.

Objects as defined by sun http://java.sun.com/docs/books/tutorial/java/concepts/object.html

Last modified: Thursday, 24 July 2014, 2:54 PM