I'm a computer scientist and been programming for a while but I realize that I don't know how e.g. Java does "under the hood" to compute the length of let's say the String array typically called args
in public static main(String[] args) {...}
. Everyone uses args.length of course but the question is, if one had to program as if only allowed to use imperative procedural static methods (no OO constructs, not even the foreach loop and no try catch blocks), how would you do it?
I was not able to find this anywhere. In C for example, we have the main's arguments as argv
and argc
since it seems that otherwise it would be impossible to know the length of the argv
array (no objects). Of course C also 'magically' populates argc with the length of argv. So my guess is that it's kind of the same with Java but that it puts it in the length attribute of the args object?
However maybe someone can explain what happens more precisely under the hood with this? (I imagine that the command-line somehow parses the arguments since they have to be separated by spaces, so of course, spaces are an indication of how many arguments are passed)
The idea is to do that in a 'procedural' way, juste for the sake of comparison with C.