String

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Feb 2007
Posts: 871
Reputation: vinod_javas is an unknown quantity at this point 
Solved Threads: 7
vinod_javas's Avatar
vinod_javas vinod_javas is offline Offline
Practically a Posting Shark

String

 
1
  #1
Sep 20th, 2007
hi everyone
i have a very a very basic question in mind .. i wanted to discuss ..

Difference Between these?

String s1= new String("java") ;
String s2="java" ;

and also

what for 2 different classes are there in garbage collection?

System.gc and runtime.gc ( both are doing the same job)
what is their individual role?

please anyone explain me....
Adios,

Vinod......
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,515
Reputation: Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future 
Solved Threads: 523
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: String

 
0
  #2
Sep 20th, 2007
Originally Posted by vinod_javas View Post
hi everyone
i have a very a very basic question in mind .. i wanted to discuss ..

Difference Between these?

String s1= new String("java") ;
String s2="java" ;
Strings are immutable in Java and the String class maintains a pool of String objects that have been created. Using a String literal, as with s2 above, the String class will return the reference of the existing String, so all references to equivalent String literals will point to the same String object. When you create the String with the new String("java") constructor, you will actually get a new copy of the String "java", not the reference from the String pool. The following fragment of code will demonstrate this
  1. String a = "java";
  2. String b = new String("java");
  3. String c = "java";
  4. System.out.println("a==b : "+(a==b)); // false
  5. System.out.println("a.equals(b) : "+(a.equals(b))); // true
  6. System.out.println("a==c : "+(a==c)); //true
what for 2 different classes are there in garbage collection?

System.gc and runtime.gc ( both are doing the same job)
what is their individual role?

please anyone explain me....
They are effectively the same. This is stated in the API documentation for the two methods.
The call System.gc() is effectively equivalent to the call:
Runtime.getRuntime().gc()

The method System.gc() is the conventional and convenient means of invoking this method.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 871
Reputation: vinod_javas is an unknown quantity at this point 
Solved Threads: 7
vinod_javas's Avatar
vinod_javas vinod_javas is offline Offline
Practically a Posting Shark

Re: String

 
0
  #3
Sep 21st, 2007
thanks
Adios,

Vinod......
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum


Views: 850 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC