Java Notes
Java Notes
An array is typically a grouping of elements of the same kind that are stored in a single, contiguous
block of memory.
Java array is an object which contains elements of a similar data type. Additionally, The elements of
an array are stored in a contiguous memory location. It is a data structure where we store similar
elements. We can store only a fixed set of elements in a Java array.
Array in Java is index-based, the first element of the array is stored at the 0th index, 2nd element is
stored on 1st index and so on.
In contrast to C/C++, the length member allows us to obtain the array's length. We must utilise the
sizeof operator in C/C++.
Method overloading in Java is the feature that enables defining several methods in a class having the
same name but with different parameters lists. These algorithms may vary with regard to the number
or type of parameters. When a method is called, Java decides which version of it to execute
depending on the arguments given. If we have to perform only one operation, having the same name
of the methods increases the readability of the program.
Suppose you have to perform the addition of the given numbers, but there can be any number of
arguments if you write the method such as a(int,int) for two parameters, and b(int,int,int) for three
parameters then it may be difficult for you as well as other programmers to understand the behavior
of the method because its name differs. Here's an explanation with real-life examples:
Math Operations: