Program to getting the main thread

This is a simple program in which we are getting the reference of currently executing thread object. The currentThread( ) method returns the reference of currently executing thread. The getName( ) returns the thread name.


PROGRAM
class GettingMainThread {

 public static void main (String[] args) {
  Thread thread = Thread.currentThread();
  System.out.println("Main thread is named : "+thread.getName());
 }
}
OUTPUT
C:\>javac GettingMainThread.java
C:\>java GettingMainThread
Main thread is named : main

Popular posts from this blog

Program to define a class 'employee' with data members as empid, name and salary. Accept data for 5 objects using Array of objects and print it.

Define a class Student with four data members such as name, roll no.,sub1, and sub2. Define appropriate methods to initialize and display the values of data members. Also calculate total marks and percentage scored by student.

Program to input age from user and throw user-defined exception if entered age is negative