I'm just learning Java and I have a problem understanding what the run() method does. I decided to ask this question after 3 days of trying to get it myself, and it's already frustrating. Is the run() method built-in or user defined? In one of the tutorials that I'm reading it says that the run() method has the followind instructions:
move();
pickObject();
move();
and then the tutorial says that I can define other methods as I need them so as to not write again and again another long piece of code, but then when it uses the run() method it still has those 3 lines of instructions, and sometimes other lines, so: is it a stand alone method or not? Sorry if the question seems complicated but it's so frustrating.
EDIT: after reading the answers that have come until now (thank you all for that) I must say that (as I am beginner, as in: I'm just learning what a method is) I have no idea what a Thread is or Runnable or any of the terms presented.
public void run() {
move(); \
pickBeeper(); = if these are the commands for the run() method then why are they being written
move(); / again here? isn't that the point of a method as not to write the code again?
turnLeft();
move();
turnLeft();
turnLeft();
turnLeft();
move();
move();
putBeeper();
move();
}
shouldn't it be:
public void run() {
run();
turnLeft();
move();
turnLeft();
turnLeft();
turnLeft();
move();
move();
putObject();
move();
}
Also, can the run() method be inside itself?, and shouldn't the rest of the code be put separately? between other brackets or something? And, can the run() method have 2 instances with different commands? Like the first run() has the 3 commands and then it has the same 3 and some more...