This is a really simple implementation of a Queue in java. Send your feedback to java@mandalivia.com
/**
 *
 * Queue class. A simple implementation of a Queue in Java
 * 
 * @author mandalivia.com
 * 
 *
 */

class Node
{
	public Node next;
	public Object payload;
}

public class Queue
{

	private Node head = null;
	private Node tail = null;
	
	private int size = 0;
	
	public Queue()
	{
		; // do nothing
	}

	public synchronized void enqueue(Object data)
	{
		size++;
		if(head == null)
		{
			head = new Node();
			head.payload = data;
			head.next = null;
			tail = head;
			return;
		}

		tail.next = new Node();
		tail.next.payload = data;
		tail.next.next = null;
		tail = tail.next;
		
	}


	public synchronized Object dequeue()
	{
		
		if(head == null)
			return null;

		size--;
		Object tmp = head.payload;
		if(head == tail)
		{
			head = tail = null;
			return tmp;
		}

		head = head.next;
		return tmp;
	}
	

	public synchronized int size()
	{
		return size;
	}



	public static void main (String arg[])
	{

		Queue q = new Queue();

		System.out.println("Queue created: size is "+q.size());
		
		q.enqueue(new String("1"));
		q.enqueue(new String("2"));
		q.enqueue(new String("3"));

		System.out.println("Queue size after 3 calls to enqueue: "+q.size());

		System.out.println("call #1 to dequeue "+ q.dequeue());
		System.out.println("call #2 to dequeue "+ q.dequeue());
		System.out.println("call #3 to dequeue "+ q.dequeue());
		System.out.println("call #4 to dequeue "+ q.dequeue());

		System.out.println("size of queue is "+q.size());
		
		System.out.println("test complete");
	}
}