Write a Thread setName() program

Write a Thread setName() 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 Demp3
{
    public static void main(String args[])
    {
        ThDemo1 d=new ThDemo1();
        d.start();
        d.setName("Rain");
        System.out.println("Thread Name is "+d.getName());
    }
}


Output:

Thread Name is Rain
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


218 . Write a Java-program to Remove consonants in a given string ?
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?