Why is Java not a Purely Object-Oriented Language?

Introduction

In this article, we will take a look into why Java is not a 100% purely or fully OOP (Object-Oriented Programming) language. Java is widely recognized as an object-oriented programming (OOP) language, offering powerful features such as inheritance, polymorphism, encapsulation, and abstraction. However, it is often debated whether Java is purely object-oriented.

Seven Qualities of a Purely Object-Oriented Language

There are seven qualities to be satisfied for a programming language to be purely Object Oriented:

  1. Encapsulation/Data Hiding
  2. Inheritance
  3. Polymorphism
  4. Abstraction
  5. All predefined types are objects
  6. All user-defined types are objects
  7. All operations performed on objects must be only through methods exposed to the objects.

Java supports qualities 1, 2, 3, 4, and 6 but fails to support qualities 5 and 7 as shown in the diagram below:

Java not purely object-oriented

Why Java is not a Pure or Fully Object-Oriented Programming Language?

Java is not a pure OOP language due to two main reasons:

Primitive Data Types

The first reason is that the Object-oriented programming language should only have objects, whereas Java contains 8 primitive data types like char, boolean, byte, short, int, long, float, and double which are not objects. These primitive data types can be used without the use of any object.

Example:

public class IsJavaFullyOOPS {
    public static void main(String[] args) {
        int i = 10;
        byte b = 20;
        short s = 30;
        long l = 100L;
        double d = 100.10;
        float f = 200f;
        boolean flag = true;
        char c = 'R';
        System.out.println(i);
        System.out.println(b);
        System.out.println(s);
        System.out.println(l);
        System.out.println(d);
        System.out.println(f);
        System.out.println(flag);
        System.out.println(c);
    }
}

Output:

10
20
30
100
100.1
200.0
true
R

Even using Wrapper classes does not make Java a pure OOP language, as internally, it will use operations like Unboxing and Autoboxing. So, if you create use Integer instead of int and do any mathematical operation on it, under the hood, Java is going to use primitive type int only.

Static Keyword

The second reason is related to the static keyword. In a pure object-oriented language, we should access everything through objects. However, Java contains static variables and methods that can be accessed directly without using objects.

Example:

public class IsJavaFullyOOPS {
    private static String message = "hello";

    public static void main(String[] args) {

        // calling message instance variable without object
        System.out.println(message);

        // calling demo static method without object
        demo();
    }

    private static String demo(){
        return "hello from method";
    }
}

Conclusion

Java is a powerful and versatile object-oriented programming language, but it is not purely object-oriented. The inclusion of primitive data types and static methods and variables breaks some of the core principles of a purely object-oriented language. These features are designed to provide performance benefits and practical functionality but deviate from the strict principles of a purely object-oriented language.

Despite these deviations, Java remains a robust and widely used language that effectively supports object-oriented programming principles. This makes it a favorite among developers for building a wide range of applications.

Further Reading:

YouTube Video

Watch the YouTube video below to understand more about why Java is not a Pure or Fully Object-Oriented Programming Language:


Comments