Why Java is not a pure OOP language?

Overview

In this blog, we will see why JAVA is not a purely Object-oriented programming language.

Properties of an OOP language

There are mainly 6-7 Properties for a language to be an OOP language. If any programming language is following all these properties then we can say it is a pure object-oriented language.

  1. Encapsulation : means should provide data hiding

  2. Inheritance : means should support IS-A relationship

  3. Polymorphism : means "many forms"

  4. Abstraction : means hiding the implementation details

  5. All predefined types must be objects.

  6. All user-defined types must be objects

  7. Operations can be performed only via objects of classes.

As we all know and for those who do not know, Java is following point number 1,2,3,4,6 only and it does not follow points number 5 & 7. This makes the JAVA a partial object-oriented language. Now let's see where java does not follow points number 5 & 7.

All predefined types are not objects in JAVA

In java we have 8 primitive dataTypes values these are byte, short, int, long, float, double, boolean, and char. Since these dataTypes are not objects, they do not have the qualities like encapsulation, polymorphism, Inheritance, etc. Java has also provided the wrapper classes like Integer, Character, Boolean, Byte, etc. Even these wrapper classes use the operations like Unboxing and Autoboxing. So internally Java is going to use a primitive type for performing the operations.

Operations can be performed without objects

Another reason is that we can declare the static variables and methods in java which can be invoked directly using the class name which again is violating property number 7.

public class Test {
    public static void main(String[] args) {
        Student s = new Student();
        System.out.println(Student.studentName); // Output : Harsh ,  as studentName is the static memeber of class we can directly get it from className hence This follows the property number 7 
        System.out.println(Student.rollNumber);// Compile Time Error ,  because this is not the static member of class
        System.out.println(s.rollNumber);// Output : 10 , This follows the property number 7 
    }
}
class Student {
    public static String studentName = "Harsh";
    public  int rollNumber = 10;
}

Other Arguable Reasons:

Reason 1. When it comes to inheritance property, Java does not support the multiple class inheritance (diamond problem) because different classes can have different method implementations with the same method name so the compiler will be confused about which method it should point to and gives a compile-time error if we try to extends multiple classes.

and there can be many more...

Bonus - Why Java is not removing primitive datatype?

Objects(such as wrapper class objects) are much more heavyweight as compared to primitive types, so primitive types are much more efficient than instances of wrapper classes.

Conclusion

In this blog,

  • We learned what are the mandatory properties for a programming language to be an object-oriented programming language.

  • We learned that due to the violation of some OOP language properties java is not a pure object-oriented programming language.