This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Strange behavior of length variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Strange behavior of length variable" Watch "Strange behavior of length variable" New topic
Author

Strange behavior of length variable

Jagdev Singh
Ranch Hand

Joined: Jan 12, 2010
Posts: 71

During my preparation of assertions I came across the strange behavior of length variable for array.
When the code below is executed without commandLine arguments then it gives 0 as output.
But when line 2 is uncommented it gives nullPointerException, that is what I expect.
Why it is not giving any nullPointerException in the case of commandLine arguments.



Jagdev
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
Command line arguments will never be null. If no argument is passed, there will simply be a zero-length array.
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
Null pointer exception because s is not initialized and is null.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Strange behavior of length variable
 
Similar Threads
main method
Three dim array
Output of 'args' gives some wierd info...?
Some confusion
random argument!!!