Why Java is not a Purely Object-Oriented Language?Java is an interpreted language that has strong relation with OOP, known as Object-Oriented Programming. The language is not classified as a purely object oriented programming language. However, to understand this premise, it is imperative to investigate the essential nature of object-oriented languages and their features, and then elucidate how or why Java differs in this or that particular regard. In this section we will discuss the reasons why Java is not pure object-oriented language. Java's Object-Oriented FeaturesJava is built with special consideration from the object-oriented paradigms. Encapsulation is supported through classes and objects, while inheritance means reuse of code, which helps enable polymorphism, meaning there can be objects of different classes but treated in the same way. Java follows the class-based structure and objects of the OOP design and the language adheres to these principles of OOP well, making Java an excellent object-oriented language. Concepts of Pure Object-Oriented ProgrammingPurely object-oriented languages do not deviate from the cardinal principles of OOP, namely, encapsulation, inheritance, and polymorphism. In such languages, everything is considered as an object so all operations are carried out on objects. It means that primitive operations and basic control flow constructs have to be represented as objects. Pure or Complete Object-Oriented Language are Fully Object-Oriented Language that supports features that behave everything inside the program as objects. It does not support primitive datatype (like int, char, float, bool, etc.). Any programming language that satisfies the following seven qualities is called pure object-oriented language.
Java supports the qualities 1 to 5 (as above specified) but not satisfies qualities 6 and 7. Java language is not a Pure Object Oriented Language as it contains these properties: Deviations from Pure OOPDespite its robust object-oriented design, Java deviates from being purely object-oriented due to several reasons: Despite its object-oriented solid design, Java deviates from being purely object-oriented due to several reasons: Primitive Data TypesJava has eight primitive data types that are int, char, Boolean, byte, short, long float, and double. These types are not objects and are used directly in Java code for the improvement of application performance. Some of the basic types of data used in Java include Integers, floating-point numbers, characters, Boolean, and more are less complex than objects and play an essential role in driving Java performance and memory. A purely object-oriented language would address all the data, including the basic types, as objects only. Similarly, Java provides wrapper classes, such as Integer, Character, etc., to box the primitives whenever required, but the existence of two types of data proves that Java has not purely followed the OOP paradigm. Static Methods and VariablesIn Java, static keywords can be used for methods and variables. Class members are of two types: static members and non-static or instance members. These types of members belong to the class and are not bound by any instance of the class. It means you are able to use the static methods and variables directly by simply calling their names without having to create an instance of the class. For instance, comparison operators such as 'greater than' and 'less than' are provided in the Java Math class, among others like Math. sqrt(), which is a JavaScript function that you do not have to construct an instance of the Math object before using. If it is purely object-oriented, then it will not support static methods and variables, as all operations have to belong to an object. Control Flow ConstructsJava has the conventional control flow structures as the if, for, while, and switch statements. These are considered implicit, and no objects are created out of them, although the language contains such constructs. Actual COO (Complete Object-Oriented) languages enclose control mechanisms within objects; that is, all operations are implemented by a call to an object's methods. Exception HandlingThe mechanism of throwing exceptions in Java is handled by using the concept of try, catch, finally, and throw. Exceptions in Java are objects from the Throwable class. But the mechanism of exception handling relies upon these control constructs, which are not objects. Based on a traditional object-oriented programming language, all exception handling mechanisms would be controlled unambiguously through other object-oriented constructs. Native MethodsJava has the ability to use native methods with the help of Java Native Interface (JNI). The new techniques are also written in other languages like C and C and can be used for system-related operations or to connect with other libraries. The feature describes how Java is somewhat helpful in its interactions with lower-level system functions, which is not a complete object-oriented paradigm in which everything would be encapsulated as an object. Wrapper ClassThe wrapper classes provide the concept to convert primitive type into object and vice-versa. In Java, you can use Integer, Float, etc. as wrapper class. instead of int, float etc. Using the wrapper classes do not make Java a pure OOP language, as internally it will use the concept like Unboxing and Autoboxing. So, if you create Integer instead of int and perform any mathematical operation (like +) on it, Java is going to use primitive type (int) only. File Name: BoxingConcept.java Output: Result: 12.9 Consider the above program, there are the following two problems that fails to make Java as pure OOP:
Note: The above Java program runs on JDK 17.0.1 or older version. If you are using JDK latest version i.e. 21.0.0, it shows warning, as Float class has deprecated in latest JDK.ConclusionJava is another used and very flexible language that has implemented many of the fundamental concepts of object orientation. Its design also encourages adhering to 'good' OOP principles like the use of classes/encapsulation, inheritance, and polymorphism. Nonetheless, it does not qualify to be a pure object-oriented language because it supports primitive data types, static methods and variables, traditional control flow statements, and native methods. These features account for down-to-earth thinking when it comes to defining new programming languages, concentrating on the advantages of object-oriented approaches, calculation capacities, and real-life programming requirements. Java is capable of being both fast and versatile, which is able to meet numerous programming situations and ideas while keeping the fundamental idea of the object-oriented programming paradigm. |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India