Why java is not 100% object-oriented?
Java is often described as a “pure” object-oriented programming (OOP) language because it supports all the major features of OOP, including encapsulation, inheritance, and polymorphism. However, it is also true that Java is not considered 100% object-oriented due to a few reasons:
1. Primitive Data Types:
In Java, primitive data types such as
char, etc., are not objects. They do not inherit from a common class or have methods. For example, you can write code like this in Java:
int is a primitive data type, not an object. In a purely object-oriented language, all types, including primitive types, would be objects.
2. Static Members:
Java allows the creation of static methods and variables in classes. Static methods and variables are associated with the class itself, not with any specific object instance. In a pure object-oriented language, everything would be an instance of a class, including methods and variables.
3. Procedural Programming:
Java allows procedural programming constructs. You can write code that follows a procedural programming paradigm, focusing on procedures or routines instead of objects and their interactions. While Java encourages OOP, it doesn’t enforce it strictly.
4. Global Functions:
Java does not support global functions (functions not associated with any class). In purely object-oriented languages, all functions would be methods of some class.
5. Pragmatic Considerations:
Java was designed with practicality in mind. Including primitives and allowing static methods makes the language more efficient and versatile for various applications. While it may not adhere strictly to the theoretical concept of pure object-oriented programming, these features provide practical benefits in terms of performance and simplicity.
In summary, while Java is highly object-oriented and encourages the use of object-oriented principles, it includes features from other programming paradigms for practical reasons. This pragmatic approach allows developers to write efficient and flexible code while still leveraging the power of object-oriented programming.