To expand upon this point:
It is possible that the args variable itself will be null, but not via normal execution. Normal execution will use java.exe
as the entry point from the command line. However, I have seen some programs that use compiled C++
code with JNI to use the jvm.dll
, bypassing the java.exe entirely. In this case, it is possible to pass NULL
to the main method, in which case args will be null.
I recommend always checking if ((args == null) || (args.length == 0))
, or if ((args != null) && (args.length > 0))
depending on your need.