Program for Naming a Thread

This program demonstrates you how to change the thread name. The setName(String) method of Thread class is used to set the name of thread.

public class NamingThread {

 public static void main(String[] args) {
  Thread thread = Thread.currentThread();
  System.out.println("Main thread's original name is : "+thread.getName());
  thread.setName("The Main Thread");
  System.out.println("Main thread's new name is : "+thread.getName());

C:\>java NamingThread
Main thread's original name is : main
Main thread's new name is : The Main Thread

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