dequeue() in Queue implememtation that uses a circular linked list
dequeue2

This method works because, when there's just one remaining item in the queue, the line:


Node first = last.next;



sets first to be the same as last (because, for a 1-sized queue last.next is a pointer to last).

In the other dequeue() you set last to be null when there's nothing left, but this does not make a difference, really (other than Garbage Collection) because the enqueue function checks the empty queue using n == 0 and not last == null

static inner class

Your Node class does not have any need for a back-reference to the Queue. It should be a static inner class private static class Node....... To do that, though, you need to make it generic too. Use a letter other than T to represent the generic class...

 private static class Node&lt;U&gt; {
    U value;
    Node&lt;U&gt; next;
    Node(U val, Node&lt;U&gt; n) {
        value = val;
        next = n;
    }
}


This saves a small amount of memory, but it is good practice. When you create the Node instances now, the code will change from:


private Node last;



to

private Node&lt;T&gt; last;


and you will add the &lt;&gt; diamond operator here:

Node&lt;T&gt; tmp = new Node&lt;&gt;(item, last.next);


Constructor:

Your constructor:


public Queue() {
    last = null;
    n = 0;
}



should just be:

public Queue() {
}


as you don't need to explicitly supply the default values.

General

Your code is neat, your variable names are not bad, and the use of generics is good.

As a learning exercise you should spend some time seeing if you can make it implement java.util.Queue interface (it's not easy - fair warning) because that will teach you a bit about what the actual Java Collections API offers.