title: Why do I get `IllegalMonitorStateException` exception
body: <p>I have the following Java code:</p>
  
  <pre><code>public class Lean extends Thread   
  {
      public static void main(String args[]) throws InterruptedException  
      {
          Lean lean = new Lean();
          System.out.println("starting");
          lean.start();
          lean.join();
          System.out.println("end");
  
      }
  
      public void run()
      {
          try
          {
              System.out.println("waiting");
              wait(20000);
          } 
          catch (InterruptedException e)
          {
              e.printStackTrace();
          }
          finally
          {
              System.out.println("waiting finished");
          }
      }
  }
  </code></pre>
  
  <p>Output is (keeps on changing -- sometimes I do not even see "end" printed )</p>
  
  <pre><code>starting
  waiting
  waiting finished
  end
  Exception in thread "Thread-1" java.lang.IllegalMonitorStateException
      at java.lang.Object.wait(Native Method)
      at Lean.run(Lean.java:18)
  </code></pre>
  
  <p>Questions: </p>
  
  <ol>
  <li><p>Why do I get <code>IllegalMonitorStateException</code> exception?</p></li>
  <li><p>Why does thread.join not work the way it is expected to be? (I do not see see "end" printed sometimes)</p></li>
  </ol>