Constructors in Java

In this post, we will learn about Constructors in Java. Constructors in Java are special member functions whose task is to initialize the objects of its class. It is treated as a special member function because its name is the same as the class name. A constructor resembles an instance method in java but it’s not a method as it doesn’t have a return type. The constructor is automatically called immediately after the object is created. A Constructor resembles an instance method in java but it’s not a method as…

Read More

Reflection in Java

In this post, we will learn about Reflection in Java with an example. Reflection in Java is the ability of a program to analyze itself. It is a process of examining or modifying the run time behavior of a class at run time. Reflection is an important capability, especially when using components called Java Beans. It allows you to analyze a software component and describe its capabilities dynamically, at run time rather than at compile time. For example, by using reflection, you can determine what methods, constructors, and fields a…

Read More

Cloning in Java

In this post, we will learn about Cloning in Java with an example. What is Cloning in Java ? Cloning is a way to create an exact copy of an object. Object class in Java provides a method clone(), that generates a duplicate copy of the object on which it is called. The syntax of clone() method is as below. Syntax of clone() method:

this method creates and returns a copy of this object. If we want to create a clone of an object, then the class must implement…

Read More

Inheritance in Java

In this tutorial, we will learn about Inheritance in Java. Different kinds of objects often have certain things common with each other. Let’s take an example of Car. A car can be of Sports car, Luxury Car or a normal Sedan Car. All these are cars having certain things in common such as seats, steering wheel, doors etc. Each car might have some extra features. For ex. Sports car can have dual-stage airbags, fog lamps. A Luxury car can have child seat anchor points, ride height adjustment. So the common…

Read More

Encapsulation in Java

In this tutorial, we will learn about Encapsulation in Java. Encapsulation is one of the four fundamental Object Oriented Programming (OOP’s) concepts. The other three are inheritance, polymorphism, and abstraction. Encapsulation in java is a process of wrapping code and data together into a single unit. In encapsulation, the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class. Therefore, it is also known as data hiding. In Java, a Class is a best example of encapsulation. We…

Read More

Transient keyword in Java

In this tutorial, we will learn about Transient keyword in Java. In Serialization, all the attributes/variables of an object are persisted. But if we don’t want to save the value of a particular variable, then this is the case where Transient keyword is used in Java. Transient keyword provides you some control over serialization process and gives you flexibility to exclude some of object properties from serialization process. The Transient keyword in java can be applied to member variables of a class to turn off serialization on these. Each variable marked…

Read More

Static keyword in Java

In this tutorial, we will learn about Static keyword in Java. In Java a Class member can be accessed only with an object of its class. Most of the times you want to define a class member that will be used independently of any object of that class. In short you want to create global variables. To create such a member, prefix its declaration with the Static keyword. When a member is declared static, it can be accessed before any objects of its class are created, and without reference to…

Read More

Final Keyword in Java

In this tutorial, we will learn about Final Keyword in Java. In java Final keyword is used in different ways. Final is not an access-modifier. Final keyword can be applied to a variable, a method and a class. Final keyword and its usages: Let’s learn about Final keyword in detail with an example. Final variable: If a variable is prefixed with final keyword, then the variable becomes a constant whose value cannot be changed. Hence when a constant needs to be created, prefix final keyword with the variable. Generally final…

Read More

Serialization and DeSerialization in Java

In this tutorial, we will learn about Serialization and DeSerialization in Java. It is known that an Object has a state and behavior. Behavior is associated with class but the state of an object is associated with an individual object. In day to day life we deal with objects and want to save the state of an object. Java provides a mechanism for this and it is called as Serialization. Serialization is the process of writing the state of an object to a byte stream so that the byte stream…

Read More

Method Overloading in Java

In this tutorial, we will learn about Method Overloading in Java. Method Overloading lets you define two or more methods with same name but different signatures where signature could differ by no. of input parameters or data type of input parameters or the sequence of the data type of input parameters. Overloading is one of the ways that Java supports polymorphism. Method overloading is also referred as Compile time Polymorphism or Static Polymorphishm. Why to overload a method ? You need method overloading when you want to perform the same operation…

Read More