Here are my two classes:
public class Firstclass {
public static void main(String args[]) throws InterruptedException {
System.out.println(\"Main sta
Your first question,
When main method is called by default one main thread is created. And main thread is a non-dameon thread. When threads created by the main method it inherits it's parant's property. That means they are all non-daemon threads. As you know JVM waits until all non-daemon threads to complete. So it will executes even after the main thread completes.
See here : daemon vs non-daemon Java Stack for each thread creation
and your second question: join method joins the currently running thread at the end of the thread which is calling the join method. That means the current thread will be stopped and it start after the thread referenced by the join method.
Synchronization stops two threads executing the same code at the same time.