Java is purely Object-Oriented Language or not?

Pure Object-Oriented Language or Complete Object-Oriented Language is a completely object-oriented language that supports or has the characteristic of treating everything inside the program as an object. It does not support primitive data types (such as int, char, float, bool, etc.). A pure object-oriented programming language needs to satisfy seven qualities. they are:

  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 at the objects.

Why Java is not a Pure Object-Oriented Language? 

Java supports attributes 1, 2, 3, 4, and 6, but does not support attributes 5 and 7 given above. The Java language is not a pure object-oriented language because it contains the following properties:

  • Primitive Data Type ex. int, long, bool, float, char, etc as Objects: Smalltalk is a "pure" object-oriented programming language, which is different from Java and C++ because there is no difference between object values ??and basic type values. In Smalltalk, primitive values ??such as integers, booleans, and characters are also objects. In Java, we predefine the type as a non-object (primitive type).
int a = 5; 
System.out.print(a);
  • The static keyword: When we declare a class as static, it can be used without using Java objects. If we use a static function or static variable, then we cannot call the function or variable by using dot(.) or a class object, which violates the object-oriented characteristics.
  • Wrapper Class: The Wrapper class provides mechanisms for converting primitive types into objects and converting objects into primitive types. In Java, you can use Integer, Float, etc. instead of int, float, etc. We can communicate with objects without calling their methods. predecessor. Use arithmetic operators.
String s1 = "ABC" + "A" ;

The use of wrapper classes also doesn't make Java a pure OOP language, as operations like unboxing and autoboxing are used internally. So if you create an integer instead of an int and do some calculations, under the hood Java only uses the primitive type int.

public class BoxingExample
{
	public static void main(String[] args)
	{
			Integer i = new Integer(10);
			Integer j = new Integer(20);
			Integer k = new Integer(i.intValue() + j.intValue());
			System.out.println("Output: "+ k);
	}
}

In the above code, there are 2 problems where Java fails to work as pure OOP:

 

  1. While creating Integer class you are using primitive type “int” i.e. numbers 10, 20.
  2. While doing addition Java is using primitive type “int”.

Submit Your Programming Assignment Details