public class ThreadJoin { public static void main(String[] args) throws InterruptedException { // Creating a new thread Thread thread = new Thread(() -> { try { // Simulating a task that takes one second Thread.sleep(1000); System.out.println("Thread finished its execution."); } catch (InterruptedException e) { e.printStackTrace(); } }); // Starting the thread thread.start(); System.out.println("Waiting for the thread to finish."); // Waiting for the thread to finish its execution thread.join(); System.out.println("Main thread continues after the other thread has finished."); } }