package samplelist; // remember to create a list directory--all the classes in a package must // be stored in a directory named after that package. In this case the // Node class must be placed in a directory named samplelist class Node { // All "class" variables in Java are actually pointer variables. Hence // value is a pointer to a String object and next is a pointer to a Node // object. Java does not allocate an object for you when you declare // a variable of that type. Instead you need to allocate an object // from the heap using new and assign a pointer to that object to // the variable String value; Node next = null; // null in Java is all lowercase Node prev = null; // It is easy to pass the value of a pointer to a function in Java. // All you need to do is pass the value of a pointer variable to // a function. Here the Node constructor expects a pointer to a String // object. Also note that there is no risk to making value point to // the String object that is passed in because String objects are // immutable and therefore there is no chance of either the "value" // variable or any other variable modifying and thus inadvertently // changing the value of the String object. Node(String v) { // remember that constructors do not have return types value = v; } }