To create threading there is an object
Thread.sleep();
Is Thread is an object ? sleep is a method? I never created a object called Thread then how can it exists.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
To create threading there is an object
Thread.sleep();
Is Thread is an object ? sleep is a method? I never created a object called Thread then how can it exists.
Thread is a class and sleep is a static method in that class.
Have you read the API doc for the Thread class?
The API doc is here: Java Platform SE 6
Find the Thread class in the lower left and click on it to bring the doc into the righthand frame.
Read in the tutorials about static methods and variables.
java.lang.Thread is a class. The Java compiler automatically resolves references to java.lang.* classes as though you had included the line "import java.lang.*;" in your source.
Thread (Java 2 Platform SE 5.0)
sleep(int) is declared static, so you can access the method from the class without needing an instance of Thread.
The Thread API is a bit of a mess. I wish the Sun developers had made sleep a member method so that to sleep your current thread, you'd have to use "Thread.currentThread().sleep(1000);" - which is probably what the current method does internally. Note that you can do this anyway, but the reference from currentThread() would be redundant.
edit: 1 minute later than Norm as usual. I'm going to have to start my own Java programming forum
Yea since sleep is a static method?
Are you asking a question?
yes because I'm very new to java.
What is the question?
you answered in #2 that what I understood is sleep is a static method hence it invoked with out actually creating an object reference variable. right?
Sorry, I don't understand your question. Do you understand the previous posts?right?
I'm asking what I have understand is right or wrong?
yes that sounds right.I understood is sleep is a static method hence it invoked with out actually creating an object reference variable
If you are beginner, you must not start with threads but with classes first.
sleep example:
... thread.sleep(2000); textarea.append("this Message displays after 2 seconds!"); thread.sleep(5000); textarea.append("This Message displays after 5 seconds!"); thread.sleep(1000); System.out.println("This Message will display on the console after 1 second!"); ...
Although i wouldn't recommend using sleep when appending to a JTextArea, Due to it causing your program to freeze for the ammount of sleep time. Instead you would use a "timer".
Timer example on oracle: http://download.oracle.com/javase/tu...isc/timer.html
@macko
What happens when you execute the code you posted?
Does it do what you want it to do? What do you want the code to do?
@Mr.777
correct....
Just a demonstration of a spot never to use a sleep