Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

 

and many more ....

 

 

Default constructor calls superclass constructor

In this example we shall show you how to call the superclass constructor in a default class constructor. An easy way to call a superclass constructor in a class constructor is to create a class that extends another class, as shown below: We have created a class A that has a default constructor without fields. We have also created class ...

Read More »

Use serializable interface to perform deep copy

With this example we are going to demonstrate how to use the Serializable interface to perform a deep copy of a class. Classes implement the Serializable interface in order to have their state serialized or deserialized. In short, to use the Serializable interface to perform a deep copy of a class: We have created a class, Car that implements the ...

Read More »

Deep Copy example – Part 2

This is an example of how to create a deep copy of a class. In order to create a deep copy of a class we have overriden the clone() API method of Cloneable interface, as described in the following steps: We have created a class, Car that has a String field and a getter and setter method for it. It also ...

Read More »

Shallow Copy example

In this example we shall show you how to create a shallow copy of a class. To create a shallow copy of a class we have performed the following steps: We have created a class, Car that has a String field and a getter and setter method for it. It also has a constructor using its String field. We have also created ...

Read More »

Deep Copy example

With this example we are going to demonstrate how to create a deep copy of a class. In short, to create a deep copy of a class: We have created a class, Address that implements the Cloneable interface and in its overriden clone() method it uses its superclass clone(). It has String fields that uses in its constructors. In its ...

Read More »

Clonable Object example

With this example we are going to demonstrate how to create a cloneable object of a class. In short, to create a cloneable object of a class, we have created a class that implements the Cloneable interface, so that it can use the clone() method to create cloneable objects, as described in the following steps: We have created a class ...

Read More »

Implementing Cloneable interface

In this example we shall show you how to implement the Cloneable interface. A class implements the Cloneable interface to indicate to the Object.clone() method that it is legal for that method to make a field-for-field copy of instances of that class. To implement the Cloneable interface we have performed the following steps: We have created a class, Employee that implements the ...

Read More »

Clone class example

This is an example of how to create a clone class of a class. We have created Employee class to get its clone class, as shown below: The class Employee has two String fields and a Double field and getters and setters for the fields. It overrides the clone() method of Object, where it creates a new Employee object and ...

Read More »

Find a file in classpath

In this example we shall show you how to find a file in the classpath. To find a file in the classpath we have created a method, File findFileOnClassPath(final String fileName) that reads a fileName and returns the File. The method is described below: It uses the System.getProperty(String key) to find the classpath of java and the path separator used. It ...

Read More »

Get Classpath example

With this example we are going to demonstrate how to get the classpath using the System class. The System class contains several useful class fields and methods. Among the facilities provided by the System class are standard input, standard output, and error output streams, access to externally defined properties and environment variables, a means of loading files and libraries, and ...

Read More »