The Java code demonstrates how to create a thread and retrieve its name using the Thread.getName() method. The code is straightforward and prints the name of the thread after starting it. Here's what happens when you run this code:
Since the thread runs concurrently with the main thread, the order of the output is not guaranteed. It may vary based on the thread scheduler and system behavior. However, you will always see the thread name being printed to the console.
public class ThreadName { public static void main(String[] args) { String threadName; Thread thrd = new Thread("Thread"); thrd.start(); threadName = thrd.getName(); System.out.println("Thread Name : " + threadName); } }
Thread Name : Thread
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions