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

 

Safe collection iteration example

Bipartite Graph

In this example we shall show you how to obtain a safe Collection iteration. We are using the List implementation of Collection, but the Collections API provides methods for such operations in other Collection implementations too, such as Map and Set. To obtain a safe Collection iteration one should perform the following steps: Call synchronizedList(List list) API method of Collections ...

Read More »

Vector copy example

Bipartite Graph

With this example we are going to demonstrate how to get a copy of a Vector. We are using the synchronized statement in order to take a safe copy of the Vector’s elements. In short, to get a copy of a Vector you should: Create a new Vector. Populate the vector with elements, using addElement(Object obj) API method of Vector. Set ...

Read More »

List copy example

Bipartite Graph

This is an example of how to make a safe List copy. Making a safe List copy implies that you should: Create a new synchronized ArrayList, using the synchronizedList(List list) API method of Collections. Add elements to the list, using add(Object e) API method of List. Create a new array from the list, using toArray(T[] a) API method of List. ...

Read More »

PriorityQueue example

Bipartite Graph

In this example we shall show you how to use a PriorityQueue. To use a PriorityQueue one should perform the following steps: Create a new Comparator for Integer objects, that is a comparison function, which imposes a total ordering on some collection of objects. Override the compare(Integer i, Integer j) method of Comparator in order to make a specified comparison. Create ...

Read More »

BlockingQueue example

Bipartite Graph

With this example we are going to demonstrate how to use a BlockingQueue. The steps of the example are described in short: We have created two classes that implement the Runnable interface and override its run() API method. The first runnable, FileEnumerationTask has a BlockingQueue of Files, a File that is an empty dump file and another File. It also ...

Read More »

Unbounded work queue example

Bipartite Graph

This is an example of an unbounded work queue. The steps of creating and using an unbounded work queue are described below: We have created a class, WorkQueue that has a LinkedList of Objects and two methods in synchronized statement. The first one is addWork(Object o) and appends an object to the end of the list, using addLast(Object o) API ...

Read More »

Bounded work queue example

Bipartite Graph

In this example we shall show you how to create a use a bounded work queue. To create and use a bounded work queue we have followed the below steps: We have created a Worker that extends the Thread and overrides its run() API method. It has a BlockingQueue of Integers and in the run() method it keeps retrieving and ...

Read More »

Sleep Thread

Bipartite Graph

With this example we are going to demonstrate how to make a Thread sleep. In short, to make a Thread sleep you should: Call sleep(long millis) API method of Thread. The method causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds, subject to the precision and accuracy of system timers and schedulers. In the ...

Read More »

Set Thread Name

Bipartite Graph

This is an example of how to set a Thread‘s name. Setting a Thread’s name implies that you should: Get a reference to the currently executing thread object, using currentThread() API method of Thread. Get the thread’s name, using getName() API method of Thread. Change the name of the thread to be equal to a specified name, using setName(String name). Get ...

Read More »

Current Thread Information

Bipartite Graph

In this example we shall show you how to get the current Thread‘s information, such as id, name group and priority. To get the current Thread’s information one should perform the following steps: Get a reference to the currently executing thread, using currentThread() API method of Thread. Get the identifier of this Thread, its name, the thread group to which ...

Read More »