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 ....

 

Receive Java & Developer job alerts in your Area

I have read and agree to the terms & conditions

 

Deep Copy example

Bipartite Graph

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

Bipartite Graph

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

Bipartite Graph

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

Bipartite Graph

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

Bipartite Graph

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

Bipartite Graph

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 »

A wrapper class

Bipartite Graph

This is an example of how to create a wrapper class. A wrapper class is defined as a class in which a primitive value is wrapped up. Here, we create a wrapper class for an int value: We have a class IntVal, that has an int field, getter and setter for the field, a constructor using its field and a method, ...

Read More »

How the class loader works

Bipartite Graph

In this example we shall show you how the class loader works. To see how the class loader works we have performed the following steps: We have created three classes, A, B and C, that each one uses a static block to print a message. The code in a static block is executed when the class is loaded by the class ...

Read More »

Immutable object example

Bipartite Graph

With this example we are going to demonstrate how to create and use an immutable object. Immutable objects are objects whose state cannot change after construction. In short, we have created an immutable object, as described below: We have created a a class, ImmutableObject, that has an int field. It has a constructor using its field. The class has a ...

Read More »

Modify Immutable Objects

Bipartite Graph

This is an example of how to modify immutable objects. Immutable objects are objects whose state cannot change after construction. We have created two classes Mutable and ImutableObjectsExmp, that have the same field, but one is mutable and the other one immutable: Mutable class has an int field, integer. It has a constructor using its field. It has a method, Mutable ...

Read More »