Get your CodeRanch badge!*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Assigining Null TO Strings" Watch "Assigining Null TO Strings" New topic
Author

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é
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.


    OCPJP6
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Assigining Null TO Strings
     
    Similar Threads
    Dan's thread exam - question 23
    not able to establish connection for jdbcodbcdriver
    How to read and write data with excel?
    Concatenation of null keyword to a String
    A challenge while formatting date value from the database