Thread getName() method in java

Method declaration – public String getName().

This method returns the Thread name.

Output is –¬†Thread name is :- main

Inside getName() method we are returning name variable which is defined as volatile.

Let’s see another example where we will define a custom thread.

Output is –

Using Thread class Thread-0
Using Runnable interface Thread-1

 

Top