Monday, September 11, 2023

Is Java a Pure Object Oriented Programming Language?

Hello guys, today, I am going to discuss one of the oldest questions related to Java, whether Java is a pure object-oriented language or not? The short answer is no. My answer is based on the fact that in a pure object-oriented language everything is an object and there are many things in Java that are not objects like primitive data types like boolean, char, short, int, long, float, double, different kinds of arithmetic, logical and bitwise operator like +, -. *, /, &&, || etc. There are only a few pure OO programming languages are Smalltalk and Eiffel, If there is more, I may not know but Smalltalk is often touted as the purest form of an object-oriented language.

Though Java is probably the most successful Object-oriented programming language, which also got some functional programming touch in Java 8, it has been never considered 100% or pure object-oriented programming language. If it were, all its primitives would be objects.

It actually moves halfway in this direction with String (and perhaps Array), but it doesn't quite go far enough. Actually, one could argue that as String and Array aren't inheritable, that makes those parts of Java at best object-based.

Though, if you have to choose an object-oriented programming language for Software development, I would argue to choose Java because of its immense popularity, features, and community support. If you want to learn Java, I also recommend you to check out The Complete Java Masterclass by Tim Buchalaka on Udemy, one of the most up-to-date courses on Java.





Is Java is Pure Object-Oriented language?

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

1. Encapsulation/Data Hiding

2. Inheritance

3. Polymorphism

4. Abstraction

5. All predefined types are objects

6. All operations are performed by sending messages to objects

7. All user-defined types are objects.

If you look at these seven qualities, Java does satisfy most of them. 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, all predefined types are not objects in Java, because you can define primitive types. This means it also violates #6. That's why Java is not a pure object-oriented language.

If you want to learn more about Object-Oriented Design in Java, you can further check out Java Fundamentals: Object-oriented Design course on Pluralsight, it's free for one month in April, make most of that time to go through this course.

Is Java a Pure Object Oriented Programming Language?




Why Java is not a Pure Object-Oriented language? 

Smalltalk is often considered one of the purest Object-oriented languages and comparing Java with Smalltalk will give you sufficient reasons, why Java is not 100% object-oriented language. The following point makes sense to me.

Is Java Pure Object Oriented Programming Language
1) Primitive data types are either stored directly in fields or on the stack rather than on the heap. This is the reason Java is not considered a pure OO programming language

2) If we have to classify in "pure OO" or "non-pure OO" we have a problem. It’s better to talk about "purity levels". Smalltalk has a higher purity level than Java. "Primitive types" in Smalltalk are actually "Primitive Classes" and in Smalltalk, all "procedures" or "functions" are really messages


On closing notes, You can make your program pure object-oriented by using Autoboxing, but the Java compiler supports primitive data types, so Java cannot be Pure object-oriented unless it makes everything in terms of objects.

In short, Java is not a pure object-oriented programming language because it supports primitive data types and everything is not an object in Java.

Let me know what is your thought about this, do you consider Java a pure object-oriented language? If not, can you think of reasons due to which Java is not a 100% object-oriented language?



Other Programming Articles You May Like to Explore

Thanks for reading this article so far. If you like this article, then please share it with your friends and colleagues. If you have any questions or feedback, then please drop a note.

P. S. - If you are new to Object-Oriented Programming and looking for some free courses to learn Object-Oriented Programming then you can also see this list of my favorite free courses to learn OOP online for beginners.

22 comments:

  1. The most important reason that java isn't OO, in practice, is the overwhelming use of DataObject/ActionObject bifurcation. It's just FORTRAN with lower case syntax.

    ReplyDelete
  2. Actually, the way to go for a programming language is to mix various programming paradigms. For example Java is now an object-oriented language with elements of functional programming.

    ReplyDelete
  3. Since primitive types are heavily used in the Application making them object degrades the performance of the application as Objects are heavy compared to primitive types .So It is a good decision from the java guys to not to make primitive types as objects.

    ReplyDelete
  4. "making them object degrades the performance of the application as Objects are heavy compared to primitive types"

    not necessarily true. It just pushes the burden of optimization to the programmer. Making them syntactically an object and then letting the compiler optimize them to primitives is a far more productive (and potentially less error prone) way to achieve this c.f. scala where all types are considered "objects" but where possible the compiler implements the code using primitives automatically.

    ReplyDelete
  5. Java support wraper class so how u say java is not purely object oriented? reply me aon bhaskarbhatt000@gmail.com

    ReplyDelete
    Replies
    1. because even though there are wrapper classes, the primitive types still are there.
      also, the use of static is not OO . you can call methods and use variables without having an object.

      Delete
  6. oh god, what the hell ??? is it very important whether java is a pure OO language? java is cross os platform and easy to learn , so we can implement an application rapidly, and we dont have to consider the cross os issue. i think this is the key point.

    ReplyDelete
  7. I think so Tom! and that's what really matter.

    ReplyDelete
  8. Hi @Tom and @Reynier silverio, this question is mainly for purist, but some interviewer do prefer to ask, why Java is not a pure object oriented language or which language is considered as purest object oriented language etc. It's a topic of discussion, but things happens.

    ReplyDelete
  9. But java supports Autoboxing which clearly box primitive to wrapper, then how could it stops java from being pure Object oriented. Somebody please make this concept clear to me.

    ReplyDelete
    Replies
    1. @Unknown, there are many things in Java which are not as per object oriented programming concept e.g. static variable. In Pure OOP, every thing should be object, nothing should belong to class.

      Delete
  10. Even if we have primitives, java will do Autoboxing by itself. So primitives will be converted to Objects. How it is violating OO concept.

    ReplyDelete
  11. right now java is a pure object oriented or not

    ReplyDelete
  12. Java is not a pure Object Oriented Language! It's because it supports primitive data types. Moreover, it does not support some features like operator overloading and multiple inheritance.

    ReplyDelete
  13. The Straight answer is Yes, Java is Object Oriented.
    Reason:
    Without creating classe(s) and/or Object(s) we cannot achieve any functionality in java.
    That's why the makers of java told EVERYTHING IN JAVA IS OBJECT.

    ReplyDelete
  14. Nice article! Even though we all are in familiar, we all are still having such kind of confusion with java!

    ReplyDelete
  15. Nice Aticle. Thanks for Sharing this information

    ReplyDelete
    Replies
    1. glad you liked it David, thx for your comment.

      Delete
  16. Replies
    1. glad you liked it Nethra, thx for your comment.

      Delete
  17. such a valuable article, Thanks for sharing

    ReplyDelete

Feel free to comment, ask questions if you have any doubt.