This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma 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

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Strange behavior of length variable" Watch "Strange behavior of length variable" New topic

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.

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.
Have you checked out Aspose?
subject: Strange behavior of length variable
jQuery in Action, 3rd edition