heartin's blog

[Problems] Summary of Problems Based on Sequences

Problems related to sequence generation and finding if an element fits in a sequence.



  1. Generate the below sequence with n elements.

    • 1, 10, 11, 100, 110, 111, 1000.

    • Note:

      • Every element in the sequence is a series of 1 or more 1's followed by zero or more 0's.

        • For example 101 is an invalid element and does not belong to the sequence, but 1, 10, 11, 100, 110, 111, 1000 etc. belong to the sequence.

LinkedHashMap Class

LinkedHashMap extends HashMap and has a predictable iteration order.


Properties of LinkedHashMap

  1. LinkedHashMap implementation maintains a doubly-linked list running through all of its entries.

  2. The doubly linked list maintained by the LinkedHashMap implementation defines the iteration ordering.

  3. By default, the order is the order in which keys were inserted into the map.

[Assignment Problem] Multi-threaded Series Printer


Write a multi-threaded program to print data from four series of data in alternating order.

There are four series of data are as below:

Series 1:              0,            4,            8,            12,          …

Series2:               1,            5,            9,            13,          …

Series3:               2,            6,            10,          14,          …

[Lab-Analysis] Setting Up For Rest Web Services Development Using Maven Jersey Archetype

In the lab @ http://javajee.com/setting-up-the-environment-for-developing-rest-web-services-with-jersey-using-maven, you setup the environment and executed a REST service.

Below are the important files generated, as you can see from the eclipse Project Explorer:

[Lab] Setting Up For Rest Web Services Development Using Maven Jersey Archetype

Jersey is a popular JAX-RS implementation.

Jersey is the open source, production quality, JAX-RS (JSR 311) Reference Implementation for building RESTful Web services.

In addition to being the Reference Implementation, Jersey also provides an API so that developers may extend Jersey to suit their needs.

You can download JAX-RS from Jersy Homepage at jersey.java.net. You can also set it up using a build tool such a maven.


REST Based Web Services Development with JAX-RS

Java API for XML – Restful web services (JAX–RS) is the standard specification for developing REST web services.

JAX-RS uses annotations to simplify the development and deployment of web service clients and endpoints. Important JAX-RS annotations can be used @ http://javajee.com/important-jax-rs-annotations.


Getting Familiar with the BlockingQueue Interface

A Queue is a first in first out (FIFO) data structure, as we have already seen.

BlockingQueue is a queue that additionally supports operations that wait for the queue to become non-empty when retrieving an element, and wait for space to become available in the queue when storing an element.

BlockingQueue methods come in four forms:

  1. those that throws an exception,

[Problem] Three Thread Synchronization Using State Pattern


Create three threads

  • one that print '1' for 5 times.

  • one that print '2' for 5 times.

  • one that print '3' for 5 times.

Need to implement coordination between them so that  1, 2 and 3 should be printed in order from the three threads:








Hint: The order should be same theoretically and practically. Putting a sleep while printing might work in some cases, but it cannot be guaranteed always.

Find All Paths Whose Sum of Data nodes will be Equal to a Given Value


Given a binary tree with an integer data element; find all paths whose sum of data nodes will be equal to a given value.

Path can start or end anywhere in the tree.

Example: If the sum given is 5 and a  path is 2->3->1>-1. There you should print two paths here: 2->3 and 2->3->1>-1.


Create a Linked List of All Nodes at Each Level of Binary Tree Without Using Recursion


Given a binary tree, create a linked list of all nodes at each level of binary tree without using recursion.

If there are n levels, there will be n linked lists.

You can create an ArrayList of linked lists.



We can use a modified version of BFS.

  1. We will add all elements in a level to a linked list.

  2. Add the current linked list to the arraylist

  3. Save a pointer to the current list as previous list.


Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!