Why Java is not 100% Object-oriented?
Answers
-
Java is an object-oriented programming language, but it is not 100% object-oriented. This is because Java supports primitive data types, which are not objects. Primitive data types are the basic building blocks of data in Java, and they include things like integers, floats, and booleans. These data types are not objects because they do not have methods or properties.
There are two main reasons why Java supports primitive data types. First, primitive data types are more efficient than objects as objects require more memory and processing power. Second, primitive data types are easier to understand and use than objects.
Even though Java supports primitive data types, it is still considered to be an object-oriented programming language. This is because Java supports the four pillars of object-oriented programming:
Encapsulation: Encapsulation is the hiding of data and methods from the outside world. In Java, encapsulation is achieved through the use of classes and access modifiers.
Inheritance: Inheritance is the ability of one class to inherit the properties and methods of another class. In Java, inheritance is achieved through the use of the extends keyword.
Polymorphism: Polymorphism is the ability of an object to take on different forms. In Java, polymorphism is achieved through the use of methods and variables with the same name but different implementations.
Abstraction: Abstraction is the hiding of implementation details from the user. In Java, abstraction is achieved through the use of interfaces and abstract classes. -
Java is considered mostly object-oriented, but it falls short of being 100% due to the inclusion of primitive data types (int, char, etc.) that are not objects. Unlike purely object-oriented languages like Smalltalk, Java allows the use of these non-object primitive types for performance reasons. While Java promotes object-oriented programming principles, the coexistence of primitives allows for a balance between efficiency and object-oriented design, acknowledging the practical considerations of performance in real-world applications.
-
Java is considered object-oriented because it uses encapsulation, inheritance, and polymorphism, which are the main concepts of object-oriented programming. However, it's not entirely object-oriented due to certain features:
Primitive Data Types: Java has simple data types like int and double that are not objects and don't have a shared class they come from.
Static Members: The word "static" makes variables and methods belong to the whole class, not just individual objects. Which is different from pure object-oriented programming.
Procedural Programming: Java lets you use procedural programming features such as static methods and block statements. Which don't need objects, going against the focus on objects in OOP.
Java encourages object-oriented design, but some features it has don't strictly follow the object-oriented way.