Manuals and instructions for everything

why operator overloading is not supported in java

This article was originally posted by. Unlike C++ java doesn t provide freedom to programmer to overload the standard arithmetic operators e. g. +, -, * and /, Java has left lot of feature supported in C++ e. g. Java doesn t support multiple inheritance, no pointers in Java and no pass by reference in java. Rarely this question asked in interview to check how programmer thinks about certain features which java doesn t have. Though I don t know the real reason behind it I think following observation make sense on
why Operator overloading is not supported in Java. 1) Simplicity and Cleanliness Simple and clear design is one of the goals of java designer they just don t want to replicate the language but wanted to have a clear, truly object oriented language. Adding Operator overloading will definitely make design more complex than without it and it also slows the JVM because it needs to do extra work to identify the actual meaning of operators and reduce the opportunity to optimize the language by guarantee behavior of operators in Java. 2) Avoid programming errors Java doesn t allow user defined operator overloading because if you allow programmer to do operator overloading they will come up with multiple meanings for same operator which will make the learning curve of any developer hard and things more confusing and messing.

Its been observed that there is increase in programming errors when language supports operator overloading which in turn increase the development and delivery time and since Java and JVM has taken most of developers responsibility in memory management by proving garbage collector it doesn t really make sense to left this feature to pollute the code and a loop hole for programming errors. 3) JVM complexity Form JVM perspective supporting operator overloading is more difficult and if the same thing can be achieved by using method overloading in more intuitive and clean way it does make sense to not support operator overloading in java. a complex JVM will result in slower JVM than a relatively simpler JVM and reduce the opportunity of optimization by taking out guaranteed behavior of operators in java. 4) Easy development of tools This you can think of an additional benefit of not supporting operator overloading in Java. omission of operator overloading has kept the language easier to handle and process which in turn makes to developed the tools that process the language e. g.

IDE or re-factoring tool. Re-factoring tools are far better than C++. In conclusion many things which can be achieved via operator overloading can be achieved using method overloading using more intuitive and easy way and that might be the reason java designer thought that supporting operator overloading will not be a big benefit for language, but in fact only java designer can answer real motivation of why Java doesn t support operator overloading, like some other questions as or. * The views expressed in this article are those of the author and do not necessarily represent the views of, and should not be attributed to, Jelastic or its technology and distribution partners. Java does not support operator overloading: Java is relatively a very simple language to use compared C/C++ with the non-support of complex and confusing features like pointers, multiple inheritance and operator overloading. These features are rarely used in practice and at the same time poorly understood by the language beginners. Every operator has a good meaning with its arithmetic operation it performs.

Operator overloading allows you to do something extra than what for it is expected for. You see + (plus) in some arithmetic operation doing (minus) operation. With the avoidance of operator overloading, + operator anywhere works for addition only, thus programmer need not think of (minus) or some other operation. This non-support gives programmer the avoidance programming errors and also a simple, cleaner and neat code. There is one more real advantage of Java does not support operator overloading. It becomes easy for the tool developers to develop a processing tool like JVM or an IDE tool to process the language. A simpler JVM increases the performance also. It is a wise decision and contribution of Designers not to support overloading to lead to a greater simplification of code. Designers did not provide any handles to overload the operator if thought by the programmer. It is a good design move, the Java designers adapted. Java also proved that a language can exist happily without the support of operator overloading. Pass your comments and suggestions on this tutorial Java does not support operator overloading. You may be interested in the following.

  • Views: 29

why does java take so long to install
why do we use annotations in java
why do we need to study java programming language
why do we need constructor in java
why we use method overloading in java
why do we use abstract class in java
why men are not allowed to take messages