The main objective of this small article is to provide an introduction about operators in Java, the possibility of overloading operators and method overloading.
Operators in programming languages are used to assign, and calculate a math expression, for instance. The usual Java operators are: + – * / for addition, subtraction, multiplication, and division. The Java language also offers also shortcuts like +=, for instance.
Actually Java does not support overloading with operators with objects. That means, you can’t use the following expression:
Figure 1 Operator overloading in Java
The most close to an operator overloading is the possibility of using the + operator to concatenate Strings.
Figure 2 String concatenation in Java
Method overloading is the possibility of two of more methods to have the same names in a class. In Java, you may specify the same name for methods, however using a different argument list, in terms of quantity of parameters or the type of the argument.
The method signature can be defined as “The name of a method and the list of parameter types in the heading of the method definition is called the method signature.The signature of a method consists of the method name and the list of types for parameters that are listed in the heading of the method name”. (Savitch, 2013).The code below shows the overloading of the method setDate:
Figure 3 Illustration of method overloading written using the Java Programming Language
I personally believe the possibility of String concatenation using the Java language is something trivial for a programming language and it is implemented as expected, however in Java, I don’t think the operand of concatenating objects would be a good resource in terms of the search for being semantically clean. The overriding method possibility is such a good resource in terms of producing APIs and the extensibility is such a good resource to be pointed.
Savitch, W, 2013. Absolute Java. 5th ed. USA: Pearson.
Horstmann & Cornell, 2008. Core Java – Volume 1 fundamentals. 8th ed. California, USA: Sun Microsystems Press.