Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

delay some code

 
dale con
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all

can someone tell me the best way to wait, say 5 seconds before the next line of code executes

e.g.

system.out.println("first line of code");

wait 5 seconds and run next line of code

system.out.println("second line of code after waiting 5 seconds");


thanks
 
Rajasekar Elango
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread.sleep(5000)

Regards,
E. Rajasekar
 
Stuart Ash
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a fairly fundamental concept in Java, something everyone is expected to know well about. You may want to spend some time reading about Threading. If you are a beginner just getting into Java, you will encounter this chapter eventually in your course.

All the best.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic