Browsing category Java

varargs in java

“varargs” argument in Java Methods


Earlier we discussed on method overloading, it gives same method name and differ by method signature.  If we are not sure about number of argument(but same type) for the method,  we can’t write one method of each combination of argument list.  Code quality recommends maximum 4 overloaded method(with same name) for easy to use and

High level Abstraction

Polymorphism in Java


“polymorphism” means ‘a state of having many shapes’ or ‘the capacity to take on different forms’.   In Java, Polymorphism is an ability to access objects of related classes through a single, uniform interface. Two types of polymorphism in Java,   Compile time polymorphism (static binding)   Run-time polymorphism (dynamic binding). Method overloading is an example

instanceof operation in java

instanceof – Know Object Type in Java


In Java, instanceof operator is used to check the type of an object at run-time.   instanceof operator is important in case of down-casting object at run-time. instanceof operator return boolean value, if an object reference is of specified type then it return true otherwise false. Simple rule is “instanceof” would return true for all the

Method overloading vs method overriding

Overloading and Overriding In Java


Method Overloading : Methods  have business logic that manipulates data(instances variable).   Methods would have method name, input arguments, return type and method body.   Sometimes we require to write two methods which are logically same but differ by input argument list.   Let us take class “Calculator”. public int add(int a, int b){ return a+ b; } public

For while do...while

Loops and Control Statements in Java


In this section we would discuss loops , control statements and decision making condition in java.  Always the loops and control statement are just explained as one of the language syntax. But there are so powerful in writing complex business logic. Breaking the loop using break and skipping the remaining part of loop statement by

Interfaces in Java

Interfaces In Java


In the previous post, we have discussed more on abstract class and code re-usability aspect. Now let us discuss on another important artifact of java “interfaces”. Abstract class and interfaces may look(but it is not and never) like same with few differences. But the actual use of interface is totally different from abstract class. An

Abstract Class in Java

Abstract Class in Java


An abstract class’s purpose is to provide an appropriate super class from which other classes can inherit and thus share a common design. Abstract class would be created to share code among several closely related classes. All the sub-classes extend the abstract class would get all the common methods or fields available in the super

OOPS inheritance design pattern

Inheritance In Java


Object oriented programming(OOPS) paradigm enforces code re-usability and avoid redundant code. To implement the code re-usability, OOPS introduces the concept of inheritance. Let see the “Inheritance” definition, A class that is derived from another class is called a subclass (also a derived class, extended class, or child class). The class from which the subclass is

Constructor in java

Constructors in Java


                A constructor in Java is a block of code similar to a method that’s called when an instance of an object is created. Constructors are used to initialize the object’s state. Like methods, a constructor also contains collection of statements that are executed at time of Object

Methods_In_Java

Methods in Java


Variables are used to store data in java run-time.  Methods are used to process access and manipulate the variables. Methods are primary building block in enterprise application as it holds the business logic of an enterprise. Each object in java talks with other objects by invoking methods. Good programmers write in a modular fashion which