aspose file tools*
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 Spring in Action this week in the Spring 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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strange behavior of length variable