In Java, every thread has a name, the name can be either the default name provided by JVM or the customized name given by the programmer.
public class ThreadName extends Thread {
}
class ThreadNameDemo {
public static void main(String[] args) {
System.out.println(Thread.currentThread().getName());
ThreadName object = new ThreadName();
System.out.println(object.getName());
Thread.currentThread().setName("TheCodeData main method");
object.setName("TheCodeData Thread name demo");
System.out.println(Thread.currentThread().getName());
System.out.println(object.getName());
}
}
Similar Java Tutorials
- Odd Even in Java
- Method to print exception information in Java
- Exception Handling by Using try-catch in Java
- Checked Exception vs Unchecked Exception
- Exception Hierarchy in Java
- Java Exception Handling Interview Questions
- final finally finalize in java
- User Defined Exception in Java
- Exception Handling Keyword in Java
- throw throws in Java
- try with multiple catch block in Java
- Threads in Java