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

 

 

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 »

A wrapper class

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

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

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

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

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

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

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

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 »