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

 

Get Fields from an Object

Bipartite Graph

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

Bipartite Graph

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

Bipartite Graph

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

Bipartite Graph

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

Bipartite Graph

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

Bipartite Graph

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

Bipartite Graph

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 »

Generate Prime Numbers with for loop

Bipartite Graph

With this example we are going to demonstrate how to generate prime numbers with a simple for loop. A prime number is a number that has no positive divisors other than 1 and itself. In short, to generate a prime number using a for loop you should: Create a for statement with an int i variable from 1 to a ...

Read More »

Simple for loop

Bipartite Graph

This is an example of a simple for statement. The for statement provides a compact way to iterate over a range of values. Programmers often refer to it as the “for loop” because of the way in which it repeatedly loops until a particular condition is satisfied. Creating a simple for loop implies that you should: Create a for statement with an ...

Read More »

Calculate Fibonacci Series with for loop

Bipartite Graph

In this example we shall show you how to calculate Fibonacci series using a for loop in Java. To calculate Fibonacci series with for loop one should perform the following steps: Create a long array with the numbers to be calculated. Create a for statement where the Fibonacci numbers are calculated and stored in the array. Then in another for statement ...

Read More »