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 Null string ..... 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 "Null string ....." Watch "Null string ....." New topic

Null string .....

Narasimha Rao B.
Ranch Hand

Joined: Aug 26, 2002
Posts: 205
When i executed the below code,
public class A{
public static void main (String[] args) {
String s1 = null; // 3
String s2 = new String(); // 4
String s3 = new String(); // 5
System.out.print(s1); // 1
System.out.print(s2); // 2
Output will be null(for line number 1 ) and there is no output for line number 2.
Can any of you explain me the difference, between declaring the string object on line numbers 3, 4 and 5. When can i use the reference of each these, can you explain me with the examples..
Thanks in Advance...
[ May 16, 2003: Message edited by: narasimha rao bandlamudi ]

Ryan Wilson
Ranch Hand

Joined: Apr 16, 2003
Posts: 65
public String()Initializes a newly created String object so that it represents an empty character sequence.

String API
I agree. Here's the link:
subject: Null string .....
It's not a secret anymore!