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

 

 

Overloading Methods

With this example we are going to demonstrate how to use overloaded 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 them ...

Read More »

Generic Constructor

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

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 example

With this example we are going to demonstrate how to polymorphism works in Java. Polymorphism is the ability of an object to take on many forms. In Java, polymorphism is the capability of an action or method to do different things based on the object that it is acting upon. In short, to see how polymorphism works we have created the ...

Read More »

List the interfaces a class implements

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

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

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 »

Check where a class was loaded from

This is an example of how to check where a class was loaded from. To check where a class was loaded from we have created a class, CheckWhereAClassWasLoadedFrom. It has a method void getLocation() that gets the location of the class. The steps of the method are described below: It gets the runtime class of this Object using getClass() API ...

Read More »

Simple validation example

In this example we shall show you how to make a simple validation of a String, using a Matcher against a specified Pattern. To make a simple String validation one should perform the following steps: Create a new Pattern, by compiling to it a regular expression. The regular expression constructed here is the word “Java” followed by a space character ...

Read More »

Find duplication in strings example

With this example we are going to demonstrate how to find duplication in Strings. In order to check if there are duplications in a String we have created a Matcher against a specified Pattern and used the Matcher API in boolean hasDuplicateWord(String phrase) method. In short the steps of the method are: Compile a String regular expression to a Pattern, ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns