title: Why a multithreading C++ program crashes if we don't use join(), while a similar Java program doesn't
body: <p>Let's say we have the following C++ program </p>
  
  <pre><code>void hello (){
     std :: cout &lt;&lt; "HELLO"&lt;&lt;std::endl ;
  }
  
  int main(){
  
      std:: thread t(hello) ;
      t.join() ;
  
  }
  </code></pre>
  
  <p>If we don't call join in this code, our program will crash because the main thread will terminate before the thread t1 is done. 
  But if we have the same program in Java, the program executes normally even if the main doesn't wait for the thread. </p>
  
  <pre><code>public class HelloWorld {
      public static void main(String[] args) {
          Thread t = new Thread(new Hello());
          t.start();
  
      }
  
  }
  
  class Hello implements Runnable {
  
      public void run() {
  
            System.out.println("Hello") ;
  
  }
  }
  </code></pre>
  
  <p>So why in Java the program doesn't crash? how the thread is executed even if the main finishes first ? </p>