While reading about Java Programming I couldn’t get why it states Java static main necessity reason is because “before you’re program starts,there aren’t any objects to send messages to” as said in slide 8 of static variables.
The reason why I couldn’t get this is why do you need an object to execute a program. I think in C program they haven’t invoked any object to perform execution of C program.
Also since machine language is a sequence of instructions why should we consider objects here when the Java bytecode is also almost an machine language.
5
The fundamental problem is that you need to have an entry point – the earliest of your code that will run once the program is started. That must be something allowed by the language of choice. Non-member functions are allowed in C and C++ but not in Java.
However static member functions are very close to non-member functions (you can simply call a public static member function of any class without instantiating an object just as you would call a non-member function) and are allowed in Java and so that’s the choice for how the entry point is defined.
Yes, you could perhaps have a non-static member function being used as an entry point, but which object would it be invoked on? This could be done for example by specifying a specific class as holding an entry point function (using some attribute or program configuration file or whatever else) and the runtime would instantiate it and call the member function on the object. However this is an unnecessary complication – you can have all that with a static member function used as an entry point. Once control gets there – just instantiate whatever you want and call member functions thereof.
11