Monday, February 2, 2015

1. Show Main Thread

1. Write a program to display the name of thread while executing the main() method.
Solution

class ShowMyName{
      public static void main(String[] args){
             String threadName = Thread.currentThread().getName();
             System.out.println("The name of current thread is "+threadName);
      }
}

after compilation, run the program and see the result as follows:
prompt>java ShowMyName
The name of current thread is main

1 comment: