Why Java is not a purely Object-Oriented Language?
We are clear that Java is an Object-oriented Programming language. But there is a slight difference for a language to be Object-oriented and purely object-oriented. Java falls in the first category. In other words, Java is not a purely Object-oriented language. This article will give you the reasons supporting this statement.
What is a purely object-oriented language?
When a language is completely object-oriented, it treats everything in its program as objects. Such purely Object-oriented language is also called Complete Object-Oriented Language. These languages do not support primitive data type (int, float, char, etc.). Below listed are the qualities required for a language to be purely object-oriented:
1. Encapsulation/ Data Hiding
2. Inheritance
3. Abstraction
4. All predefined types are objects
5. All user-defined types are objects
6. All operations are performed through objects
Why does Java not come under this category?
As seen earlier, to denote a language as purely object-oriented, it must abide by the seven qualities listed above. Java supports the qualities at 1, 2, 3, 4, and 6. However, it does not abide by the property 5 and 7. Therefore, Java is not a pure object-oriented language. A good example of a language that supports all these characteristics is Smalltalk.
Why Java is not a purely Object-Oriented Language?
Primitive Data Type:
Java includes some generally known primitive data types: int, float, char, long, bool, double, short, and byte that are not objects. These data types can be used without involving an object.
Sample program to denote the presence of data types in Java:
public class FirstCode{ public static void main(String args[]) int a = 23; System.out.println(a); //here, the declared variable is used without any object } }
Output:
The presence of the static keyword:
In Java, the implementation of static variables and methods is possible. Therefore, the need for an object is not necessary. In addition, the static variable or method cannot be called using a dot(.). This makes it less than a purely object-oriented language.
Wrapper class:
The wrapper class consists of the mechanism to convert a primitive into an object and vice versa. This allows you to use Integer, Float, and so on in the place of int, float in Java. Furthermore, we can communicate with the objects using the wrapper class without calling their methods. This is possible using the arithmetic operators.
Sample program using arithmetic operator:
public class FirstCode{ public static void main(String args[]) { String s = "ABC" + "A"; System.out.println(s); } }
Output:
In addition to these, Java also contains various other options like Unboxing and Autoboxing that hinder it from being a pure object-oriented programming language. Therefore, you can even create an Integer instead of int in Java to attain the desired result.
Sample program depicting the failure of OOPS properties:
public static FirstCode{ public static void main(String args[]) { Integer a = new Integer(10); Integer b = new Integer(20); Integer c = new Integer(a.intValue() + b.intValue()); System.out.println(c); } }
Output:
Explanation:
In this sample program, the areas where the OOPS concept failed are:
- The primitive type “int” is used to create an Integer class. Here, the numbers used are 10 and 20.
- The primitive type “int” is used to add in Java.
Conclusion
From this article, you would’ve understood the reasons why Java is not a Purely object-oriented language. It consists of primitive data types that are not objects. There are also possibilities of accessing the static class members without creating an object. You can compare it with the characteristics of the language Small Talk which is purely object-oriented.