I was wondering in the program like Karel the Robot runs because it does not used main() method. Instead it used run() method:
import stanford.karel.Karel;
public class CollectNewspaperKarel extends Karel {
public void run() {
move();
}
}
How does it work?
The actual main method is somewhere else. For example, in the KarelRunner class. When java executes the program, it's actually executing the main method in the runner class. Your own run method is called from that runner code.
a "main" method is the starting point of every java program. What is going on with this class is that its not a java program by itself, is executed inside some type of framework (karel robot java implementation in this case), this frameworks off course have a "main" method but not this class, the framework knows how to load this class and execute his run method.
This "programs" are frameworks designed to do a specialized type of programs, i don't know this "karel framework", but for example, when you program a java web application you write a "servlet" but you don't write a "main" method. There are some programs called "application servers" that off course have a "main" method and take this servlet class and execute for response to some http message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With