title: How does the pop and isEmpty methods work in a Stack class
body: <p>I was reading about stacks in java. I found this code . I do not understand the isEmpty method and the pop method .. I commented next to each line in the code below .. can you describe to me the pop and isEmpty methods ..
  thanks</p>
  
  <pre><code>  public class Stack {
  
      int [] sk = new int[5];
      int top =-1;
  
  public static void main(String[] args) {    
      Stack s = new Stack();
      s.push(34);
      s.push(-44);
      s.push(7);
  
      while (!s.isEmpty())
      {
      System.out.println(s.pop());
      }
  }
  
  public int pop() {
      return sk[top--]; // what happens here? why not we use a for loop like for(int r=sk.length; r&gt;0; r--) return sk[r];
  }
  
  public boolean isEmpty() {
      return (top==-1);      // why we return top==-1 , what is the purpose of it? should not we return sk[sk.length]==0; ?
  }
  
  public void push(int i) {
      sk[++top]=i;
  
  }
  }
  </code></pre>