Saturday, April 12, 2014
One of the frequent question related to Java is whether Java a pure object oriented language or not is often asked in an interview. The answer is NO. There are many things in Java which are not objects e.g. primitive data types like boolean, int, float etc., different kinds of arithmetic, logical and bitwise operator e.g. +, -. *, /, &&, || etc. Few pure OO languages are Smalltalk and Eiffel. Though Java is one of the most successful Object oriented programming language, which also got some functional programming touch in Java 8 is never considered 100% or pure object-oriented programming language. If it were, all its primitives would be objects. It actually moves half-way in this direction with String and Array, but it doesn't quite go far enough.

There are seven qualities to be satisfied for a programming language to be pure Object Oriented.

  • Encapsulation/Data Hiding
  • Inheritance
  • Polymorphism
  • Abstraction
  • All predefined types are objects
  • All operations are performed by sending messages to objects
  • All user defined types are objects.
Java supports Encapsulation at class and package level, It supports Abstraction, Inheritance and Polymorphism, and all user defined types are also objects. What it doesn't support is #5 and #6.

Why Java is not Pure Object Oriented language? 
Smalltalk is often considered one of the purest Object oriented language and comparing Java with Smalltak will give sufficient reasons, why Java is not pure OO language.
  • Primitive data types are either stored directly in fields or on the stack rather than on the heap.
  • "Primitive types" in Smalltalk are actually "Primitive Classes" and in Smalltalk all "procedures" or "functions" are really messages
Though you can make your program pure object oriented by using Autoboxing, but Java compiler supports primitive data types, so Java cannot be Pure OO unless it makes everything objects.

0 comments:

Post a Comment

Total Pageviews

Followers


Labels

Popular Posts

free counters