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

 

Singleton Object example

Bipartite Graph

With this example we are going to demonstrate how to create and use a Singleton class. The Singleton’s purpose is to control object creation, limiting the number to one but allowing the flexibility to create more objects if the situation changes. Since there is only one Singleton instance, any instance fields of a Singleton will occur only once per class, just ...

Read More »

Protected Keyword

Bipartite Graph

This is an example of how to use the protected keyword in a class. In order to use the protected keyword, we have created a class with a protected method and a subclass that uses its protected method: We have created a class, BadGuy that has a String field, myname and a protected void set(String nm) method that sets its field to ...

Read More »

Overriding Fields

Bipartite Graph

In this example we shall show you how to override a super class field in a subclass. To override a super class field in a subclass we have performed the following steps: We have created a class, A that has a final int field set to 1, and an int field. It has an int getAttr() that prints a message and ...

Read More »

Java Overloading Methods

Bipartite Graph

With this example we are going to demonstrate how to use Overloading Java Methods in a class. Overloaded methods are methods with the same name signature but either a different number of parameters or different types in the parameter list. We have created a class, that has constructors and methods with the same names but with different arguments and use ...

Read More »

Generic Constructor

Bipartite Graph

This is an example of how to use a generic constructor of a class. In order to see how a generic constructor works we have created a class with a generic constructor and then created instances of the class to use its constructor. GenericClass class has a double field, val. It has a constructor using an object of T class that ...

Read More »

Static Initialization Block example

Bipartite Graph

In this example we shall show you how to use a static block for initialization of a classe’s fields. To show how a static block works in a class we have performed the following steps: We have created a class StaticInitializationBlock that has a static int array initialized with 10 fields. It uses a static block, where it puts to ...

Read More »

Polymorphism Java Example (with video)

Bipartite Graph

In this post, we feature a comprehensive Polymorphism Java Example. 1. Introduction In word Polymorphism, the word Poly stands for ‘many’ and the word morph stands for ‘forms’. Polymorphism is the ability of an object to take on many forms. Polymorphism is the capability of an action or method to do different things based on the object that it is ...

Read More »

List the interfaces a class implements

Bipartite Graph

This is an example of how to list the interfaces that a class implements in Java. We are using the TreeMap class to get the list of all the interfaces implemented by the class. We get the TreeMap class and use getInterfaces() API method of Class to get its interfaces. It returns a new array of the interfaces implemented by ...

Read More »

Get the super-class of an object

Bipartite Graph

In this example we shall show you how to get the superclass of an Object. We can try to get the superclass of any Java class, as shown in the steps below: We create an Object and a new Class object. We create a new String object. We set to the Class object the String object’s superclass, using getClass() API ...

Read More »

Get an object’s class name

Bipartite Graph

With this example we are going to demonstrate how to get an object’s class name. We can get the class name for any object as shown in the steps below: We create a new Class object. We set the Class object to String.class and get its name using getName() API method of Class. We follow the same steps for other ...

Read More »