Thursday, January 10, 2008

Is Java an Object Oriented Programming Language?

In this era of computer science, where computers are presumed to provide solution to every real world problems, it is highly essential to adopt Object Oriented Programming Model. To achieve this, it is quite mandatory that the underlying programming language provides inbuilt support for this programming paradigm.

Java, being considered as one of the most successful and versatile computer programming language, also fits in the above requirement. Now the question comes in every programmer’s mind: Is java an Object Oriented Programming (OOP) Language?

In this article I tried to answer this critical question taking help from theoretical concepts.

As per the definition of Object Oriented Programming, a language can be categorized as PURE OOP based on following criteria:
  1. The language must have inbuilt support for encapsulation and abstraction.
  2. The language must have inbuilt support for Inheritance.
  3. The language must have inbuilt support for Polymorphism.
  4. All system defined types must be objects.
  5. All user defined types must be object.
  6. The only way of communication between objects is through the methods exposed on the same.

Criteria 1 to 3 are self explanatory and don’t require further clarification. So I am escaping those. Now consider criteria 4.

Criteria 4 states that all predefined types in the systems must be objects only. This means there can’t be anything other than objects defined by system. This is the first requirement where Java fails to fulfill the criteria to be categorized as pure Object Oriented Programming. Java has primitive types, which are not objects and thus violates this rule.

Criteria 5 suggests that all user defined types must also be objects only. This means users can’t define or create anything other than objects. This restriction is not applicable in using system defined types. Java successfully follows this rule where user can’t create or define anything other than objects.

Criteria 6 suggest that whenever objects communicate with each other, they communicate using the methods exposed on other objects. And this should be the only way of communication. Java violets this rule by using various operators. Consider the ‘+’ operator on String literals which can be used to add 2 or more string objects. By using this operator java violets the rule of object communication using methods. This holds true for other operators on primitive types as well.

Summing up the above points, java fulfils the criteria 1,2,3,5 but fails in 4 and 6. Failing of these 2 criteria deprived java from being categorized as PURE Object Oriented Programming Language. But still the programming community categorizes Java as OOP (although not Pure). In theory such languages are called ‘Hybrid OOP’ languages.

No comments: