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

 

 

Get Modifiers from an Object

In this example we shall show you how to get the modifiers of a class. To get the modifiers of a class one should perform the following steps: Call getModifiers() API method of Class to get the Java language modifiers for this class or interface, encoded in an integer. The modifiers consist of the Java Virtual Machine’s constants for public, protected, private, ...

Read More »

Invoke Method with reflection

With this example we are going to demonstrate how to invoke a method using reflection. In short, to invoke a method using reflection you should: Create a new StringBuilder with no characters in it and an initial capacity of 16 characters. Append a specified String to the builder using append(String str) API method of StringBuilder. Use getClass() API method to ...

Read More »

Get Methods from an Object

This is an example of how to get methods of an Object. Getting the methods of an Object implies that you should: Get the array containing Method objects reflecting all the public member methods of the class or interface represented by this Class object, using getMethods() API method of Class. Then get the array of Method objects reflecting all the ...

Read More »

Get Fields from an Object

In this example we shall show you how to get the fields of a class represented by an object. To get the fields of a class represented by an object one should perform the following steps: Get an array containing Field objects reflecting all the accessible public fields of the class or interface represented by this Class object, with getFields() ...

Read More »

Create Proxy object

With this example we are going to demonstrate how to create a Proxy object. A proxy is a class functioning as an interface to a network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate. In short, to create a Proxy object we have followed the steps below: We have created ...

Read More »

Synchronization with multiple locks

The basic idea is to use separate locks to guard multiple independent state variables of a class, instead of having only one lock in class scope. public class Grocery { private final ArrayList fruits = new ArrayList(); private final ArrayList vegetables = new ArrayList(); public synchronized void addFruit(int index, String fruit) { fruits.add(index, fruit); } public synchronized void removeFruit(int index) ...

Read More »

Synchronized method and block

The first level of synchronization is on method scope: public class HelloSync { private Map dictionary = new HashMap(); public synchronized void boringDeveloper(String key, String value) { long startTime = (new java.util.Date()).getTime(); value = value + "_"+startTime; dictionary.put(key, value); System.out.println("I did this in "+ ((new java.util.Date()).getTime() - startTime)+" miliseconds"); } } However we should consider the basic rule of concurrency: ...

Read More »

Simple Do While loop Java Example

1. Introduction A do-while loop in Java is a control flow statement that executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given boolean condition at the end of the block. The do while construct consists of a process symbol and a condition. First, the code within the block is executed, and then the condition is evaluated. If the ...

Read More »

Sum Array of Numbers with for loop

This is an example of how to get the sum of the numbers in an array using a for loop. The for statement provides a compact way to iterate over a range of values. Getting the sum using a for loop implies that you should: Create an array of numbers, in the example int values. Create a for statement, with an ...

Read More »

Check for Palindrome Number with for loop

In this example we shall show you how to check if a palindrome number exists in an array, using a for loop. A palindrome number is a number that is equal to its reverse number. To check if a palindrome number exists in an array, using a for loop one should perform the following steps: Create an array of the numbers ...

Read More »