File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Assigining Null TO Strings 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 "Assigining Null TO Strings" Watch "Assigining Null TO Strings" New topic

Assigining Null TO Strings

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

compiles and runs fine
shouldn't there be NullpointerException

OCPJP 6.0 93%
OCPJWCD 5.0 98%
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

15.18.1 String Concatenation Operator +
If only one operand expression is of type String, then string conversion is performed on the other operand to produce a string at run time. The result is a reference to a String object (newly created, unless the expression is a compile-time constant expression (§15.28))that is the concatenation of the two operand strings. The characters of the left-hand operand precede the characters of the right-hand operand in the newly created string. If an operand of type String is null, then the string "null" is used instead of that operand.

[My Blog]
All roads lead to JavaRanch
Trivikram Kamat
Ranch Hand

Joined: Sep 26, 2010
Posts: 155
NullPointerException is thrown when an application attempts to use null in a case where an object is required.
These include:
  • Calling the instance method of a null object.
  • Accessing or modifying the field of a null object.
  • Taking the length of null as if it were an array.
  • Accessing or modifying the slots of null as if it were an array.
  • Throwing null as if it were a Throwable value.

  • None of these happens in the given code.

    I agree. Here's the link:
    subject: Assigining Null TO Strings
    jQuery in Action, 3rd edition