944,180 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 983
  • Java RSS
Sep 20th, 2007
1

String

Expand 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" ;

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....
Similar Threads
Reputation Points: 119
Solved Threads: 7
Practically a Posting Shark
vinod_javas is offline Offline
871 posts
since Feb 2007
Sep 20th, 2007
0

Re: String

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
Java Syntax (Toggle Plain Text)
  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
Quote ...
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.
Quote ...
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.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Sep 21st, 2007
0

Re: String

thanks
Reputation Points: 119
Solved Threads: 7
Practically a Posting Shark
vinod_javas is offline Offline
871 posts
since Feb 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: MasterMind novice
Next Thread in Java Forum Timeline: Java home work help (long post)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC