This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Java programmers tend to declare a main class to be public. I think I recall seeing a situation several months ago where "public" was necessary for a class that included a main method, but I can't remember the situation. I thought it was in an Ant build(?) Anyway, is there a good reason for doing
public class Hello
when the purpose of the Hello class is only to contain a main method?
As far as I know, there are no good reasons, other than maybe for some reflective purposes? I'm not sure, I never really use reflection that much.
The reason why the main class is public is because it's simply a habit for most people. As a matter of fact, many programmers have the bad habit of declaring too much public anyway.
I changed the template for a new class in my NetBeans to read final instead of public. Much better! I also added an empty private constructor. Implicit constructors have always been a bad idea in my book.
The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.