title: can the main thread die before the child thread
body: <p>I believe that the main thread cannot die before the child thread. But is there any way to check that ? I wrote a simple program below. Can anyone prove it practically leaving theory aside ?</p>
  
  <pre><code>class childre extends Thread
  {   
      public void run()
      {   
          for( int i=0 ; i&lt;10 ;i++)
          {
              System.out.println( " child " + i);
  
              try {
                  Thread.sleep(1000);
              } catch (InterruptedException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }   
          }
      }
  }
  
  public class ChildThreadb4main
  {
  
  /**
   * @param args
   */
      public static void main(String[] args)
      {
      // TODO Auto-generated method stub
  
          System.out.println("main");
  
          childre c1 = new childre();
  
          c1.start();
          for(int i=0;i&lt;5;i++)
          {
              try {
                  Thread.sleep(500);
              } catch (InterruptedException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }
          System.out.println( " child thread alive ? " + c1.isAlive());
      }
  }
  </code></pre>
  
  <hr>
  
  <p>After suggestion from James. I tried the following program.</p>
  
  <pre><code>public class MainChildDie {
  
      public static void main(String ar[]){
  
          final Thread mainThread = Thread.currentThread();
          System.out.println("main run ");
  
          new Thread(){           
  
              public void run(){
  
                  Thread childThread= Thread.currentThread();
                  for(int i=0; i&lt;10;i++){
                      System.out.println( "child"+i);
  
                      try {
                          Thread.sleep(1000);
                      } catch (InterruptedException e) {
                          e.printStackTrace();
                      }
                  }
                  System.out.println("main alive  " + mainThread.isAlive());
              }
          }.start();      
      }
  }
  </code></pre>