Implementation of a doubly linked list in Java I'd like to improve this code.

DoublyLinkList.java

public class DoublyLinkList&lt;T&gt; {

    private static class Node&lt;T&gt; {
        private T data;
        private Node next;
        private Node prev;

        public Node(T data) {
            this.data = data;
        }

        public void displayNode() {
            System.out.print(data + " ");
        }

        @Override
        public String toString() {
            return data.toString();
        }
    }

    public Node first = null;
    public Node last = null;

    public void addFirst(T data) {
        Node newNode = new Node(data);

        if (isEmpty()) {
            newNode.next = null;
            newNode.prev = null;
            first = newNode;
            last = newNode;

        } else {
            first.prev = newNode;
            newNode.next = first;
            newNode.prev = null;
            first = newNode;
        }
    }

    public boolean isEmpty() {
        return (first == null);
    }

    public void displayList() {
        Node current = first;
        while (current != null) {
            current.displayNode();
            current = current.next;
        }
        System.out.println();
    }

    public void removeFirst() {
        if (!isEmpty()) {
            Node temp = first;

            if (first.next == null) {
                first = null;
                last = null;
            } else {
                first = first.next;
                first.prev = null;
            }
            System.out.println(temp.toString() + " is popped from the list");
        }
    }

    public void removeLast() {
        Node temp = last;

        if (!isEmpty()) {

            if (first.next == null) {
                first = null;
                last = null;
            } else {
                last = last.prev;
                last.next = null;
            }
        }
        System.out.println(temp.toString() + " is popped from the list");
    }
}


DoublyLinkListDemo.java

public class DoublyLinkListDemo {

    public static void main(String[] args) {
        DoublyLinkList newList = new DoublyLinkList();
        newList.addFirst("arun");
        newList.addFirst("prakash");
        newList.addFirst(70);
        newList.addFirst(80);
        newList.addFirst(30);
        newList.displayList();
        newList.removeFirst();
        newList.removeFirst();
        newList.removeFirst();
        newList.removeLast();

        newList.displayList();
    }
}
removeLast() assigns last to temp, which may be null.  If the list is empty, you will call toString() on null.

Otherwise, it is a pretty well made list.

I would change the names of your functions/class.


DoublyLinkList becomes DoublyLinkedList
addFirst becomes pushFront
removeFirst becomes popFront
removeLast becomes popBack
displayList becomes display ( because we know a list is calling it )
displayNode becomes display


As general advise about naming, the words you are using to describe what is happening are good hints at what names the functions/class should be.  For example, you use Doubly Linked List in the title of this post, and you use the word "popped" as output to the remove functions.