Overloading Operations

INTRODUCTION

The main objective of this small article is to provide an introduction about operators in Java, the possibility of overloading operators and method overloading.

OVERLOADING OPERATORS

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:

ademir1

Figure 1 Operator overloading in Java

The most close to an operator overloading is the possibility of using the + operator to concatenate Strings.

ademir2

Figure 2 String concatenation in Java

METHOD OVERLOADING

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:

ademir5

Figure 3 Illustration of method overloading written using the Java Programming Language

CONCLUSION

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.

REFERENCES

Savitch, W, 2013. Absolute Java. 5th ed. USA: Pearson.

Horstmann & Cornell, 2008. Core Java – Volume 1 fundamentals. 8th ed. California, USA: Sun Microsystems Press.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s