I'm pretty new in Java so, from what I've read, you need a public static void main function to run a Java applications. However, using Selenium WebDriver and TestNG I have Java code but with no main function. Who decides and where what methods to run, in what order and everything? I know that there are xml files where you can mention what methods to run, what classes, etc. but I'm interested in what happens "behind the scenes". There are cases when only the class is specified is the xml file so how does the compiler know in what order to run the methods and which class to use (there are classes derived from other classes, there are instances of webdriver but I have no idea where is the code for these instances, etc.)? 

In C++ you knew you need the main function from which the applications starts. In PHP the code was read in the order it was written. But using Eclipse the methods seem to be called in alphabetical order.