title: Understanding Linked List in Java
body: <p>I am currently learning to implement linked list in Java when I came across sample code which counts nodes in a linked list</p>
  
  <pre><code> class ListNodes { int item; ListNodes next; }
  
     int count(Node ptr_start)
     {
        int c=0;
        Node ptr = new Node();
        ptr = ptr_start;
        while(ptr != null)
        {
           c++;
           ptr = ptr.next;
        }
        return c;
     }
  </code></pre>
  
  <p>I have few questions here what exactly is </p>
  
  <blockquote>
    <p>ListNodes next;</p>
  </blockquote>
  
  <p>and 'ListNodes' has same name as that of it's class ?</p>
  
  <p>what is </p>
  
  <blockquote>
    <p>ptr = ptr_start;
    i think it's for pointer to start with a value , but can it have other values other than 'ptr_start' ? 
    and </p>
    
    <p>ptr = ptr.next;</p>
  </blockquote>
  
  <p>I think it moves to next pointer but 'next' moves it to other pointer , it 'next' Java defined or user defined thing? 
  It sort of seems like I don't understand anything is this code , please help?</p>