How Does Java Find the "main" Method?
In my third ever Java program I ran into the problem, discussed here before, that my "main" method was not found. I forget the exact error message but it was clearly complaining about not finding "main". The previous discussions did not help much but one suggested that there might be something magical about the name of the class containing the "main" method. So I fumbled about with that and finally got the program to execute without error when I changed the name of the class to "SwitchExperiment". What I guess is magical about that is that the name of the file containing the source is "SwitchExperiment.java". So my problem, apparently, was not that it couldn't find my "main" but that it couldn't find the class in which it expected to find "main". I hope that most of the error messages are more clear.
If it matters I am using NetBeans IDE 7.0 on Windows Vista and running my program from the IDE (as opposed to a command line).
What I am asking is: 1) am I right that the name of the class containing the "main" method is critical and must be the same as the name of the file containing it (minus the ".java" extension)?
And 2) is there some similar magic involving the name of my package? I am using some code I found on the internet which has the statement "package pkgswitch.experiment". I have no idea at this point what the package statement does. I have it only because I copied some code from the Internet. But since it is included in code intended for beginners I assume it has some fundamental and important purpose and I am wondering if soon I will encounter another confusing error message because I have not used the right magical name for my package.
Thanks for whatever help anyone can offer.