Java is often referred to as an object-oriented programming language. However, it is not a purely object-oriented language. It is because of its primitive data types such as int, byte, long, etc.
Before going into the details, we’ll first understand what criteria a language should satisfy to be a pure object-oriented language.
A language must have the following qualities to be purely object-oriented:
Java is not a pure object-oriented programming language because it does not satisfy the following two properties:
All predefined types should be objects.
All the operations performed on objects must be through methods defined for them.
In pure object-orientated programming languages, everything is an object. However, Java has primitive data types like integer, boolean, float, char, etc. These data types are not part of the object hierarchy. Hence, Java does not satisfy this criterion of being a purely object-orientated language.
int num = 5;char letter = 'A';boolean flag = true;
Smalltalk is a purely object-oriented language. In this language, everything is an object, including primitive data types. For instance, the integer data type in Smalltalk is an object created from the class integer.
Java provides wrapper classes that allow the conversion of primitive data types into objects and vice versa. Although we can convert primitive data types to objects, it does not make Java a pure object-oriented language, as these objects are not originally associated with Java.
Integer intWrapper = new Integer(42);Character charWrapper = new Character('A');
Java supports static methods and variables within classes. By adding keyword static
with variables and methods, they can be accessed without using an object. Also, static members are not associated with object instances and can be accessed without object instantiation.
public class MyClass{// Static variablestatic int staticVar = 0;//Static methodstatic staticFun(){ return 'I am a static function'; }}
A purely object-oriented language, for instance, Smalltalk, does not have the concept of static methods and variables. It uses class methods, similar to static methods in Java, but tied to the class itself rather than to class instances. Similarly, instead of static variables, Smalltalk has class variables that are shared among instances of the class and its subclasses
Java, while being a primarily object-oriented language, is not considered purely object-oriented for two major reasons. First is that Java supports primitive data types that are not objects, and second is that the concept of static methods and variables exists in Java, making it a non-pure object-oriented language.
Free Resources