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

 

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 »

Reference Objects example

Bipartite Graph

In this example we shall show you how to create and use Reference Objects. A reference object encapsulates a reference to some other object so that the reference itself may be examined and manipulated like any other object. Three types of reference objects are provided, each weaker than the last: soft, weak, and phantom. Each type corresponds to a different level of ...

Read More »

Passing an object to a method example

Bipartite Graph

With this example we are going to demonstrate how to pass an object to a method. In short, we have created a class and a method to pass the object of the class: We have created a class, Character with a char field. We have created another class, PassObject, that has a static method, void setCh(Character y). The method gets a ...

Read More »

Anonymous inner class – Part 2

Bipartite Graph

This is an example of how to use an anonymous inner class. We have created a class, TalkingClock, that is a clock that prints the time in regular intervals and use it in another class, as described in the following steps: TalkingClock has a method start(int interval, final boolean beat). The method creates a new ActionListener object that overrides the actionPerformed(ActionEvent event) ...

Read More »

Run time Type Identification example

Bipartite Graph

In this example we shall show you how to check a type identification in run time. To check a type identification in run time we have performed the following steps: We have created a class A, with two methods a1() and a2(). We have also created a class B that extends A that overrides the inherited method from A class and ...

Read More »

Class casting example

Bipartite Graph

With this example we are going to demonstrate how to cast an object of a class to another class. In short, to cast an object of a class to another class we have followed the steps below: We have created class A, class B that extends A and has an int field and class C that extends B and also ...

Read More »

Anonymous inner class

Bipartite Graph

This is an example of how to use an anonymous inner class inside a class. In order to use an anonymous inner class we are using the javax.swing package to create a window with a button: We create a new JButton that is an implementation of a “push” button with the message “Close Window”. A new ActionListener object is created ...

Read More »

Anonymous class

Bipartite Graph

In this example we shall show you how to use an anonymous class. To use an anonymous class we are using an interface and override its method when creating a new object, as described in the steps below: We create a new interface AnonClass with a void call() method. We create a new instance of AnonClass, where we override its call() ...

Read More »

Abstract class example

Bipartite Graph

With this example we are going to demonstrate how to create and use an abstract class. In short, we have created an abstract class with an abstract method, that is extended by two other classes, as described below: We have created an abstract class Person, with a String field and a constructor using its field. It has an abstract method ...

Read More »

Use the keyword this to call a constructor – Part 2

Bipartite Graph

This is an example of how to use the keyword this to call a constructor of a class. Within an instance method or a constructor, this keyword is a reference to the current object, that is the object whose method or constructor is being called. You can refer to any member of the current object from within an instance method or a constructor ...

Read More »