@jjnguy's answer is correct in most circumstances. You won't ever see a null
String in the argument array (or a null
array) if main
is called by running the application is run from the command line in the normal way.
However, if some other part of the application calls a main
method, it is conceivable that it might pass a null
argument or null
argument array.
However(2), this is clearly a highly unusual use-case, and it is an egregious violation of the implied contract for a main
entry-point method. Therefore, I don't think you should bother checking for null
argument values in main
. In the unlikely event that they do occur, it is acceptable for the calling code to get a NullPointerException
. After all, it is a bug in the caller to violate the contract.