Write a Thread getName() program

Write a Thread getName() program

Program
class ThDemo  extends Thread
{
    public void run()
    {
        int x;
        try
        {
            for(x=1;x<=10;x++) 
            {
                Thread.sleep(2000);
                System.out.println("Hello Sateesh");
            }
                	
        }
        catch(Exception e)
        {
            System.out.println(e);
        } 
    }
}
public class Main
{
    public static void main(String args[])
    {
        ThDemo1 d=new ThDemo1();
        d.start();
        System.out.println("Thread Name is "+d.getName());
    }
}


Output:

Thread Name is Thread-0
Hello Sateesh
Hello Sateesh
Hello Sateesh
Hello Sateesh
Hello Sateesh
Hello Sateesh
Hello Sateesh
Hello Sateesh
Hello Sateesh
Hello Sateesh


Multi Threading In Java



More Questions


219 . Write a Java-program to Remove special characters in a given string ?
220 . Write a Java-program to Remove spaces in a given string ?
221 . Write a Java-program to Remove letters in a given string ?
222 . Write a Java-program to Remove numbers in a given string ?
223 . Write a Java-program to print duplicate characters from the string ?
224 . Write a Java-program to print unique(distinct (or non-repeating characters) ) characters from the string ?
225 . Write a java program How to check if two strings are anagrams of each other?
226 . How to reverse a string in Java without using the reverse method ?
227 . How to count the occurrence of the given character in a string?
228 . How to check if a string is a palindrome?
229 . How to count the number of words in a given string sentence?