• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

string

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sting s = new string("abc");
a new string object is created by the above statement.

String s = "abc";
does this statement also create a new string object or it is refering to a object in the string pool?
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
definately you can use static and native modifier are used to load any native files they may be required to run the program.
 
Rohit Suman
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi i happened to answer the wrong question
the answer to yours question is that when we write String a=new String("abc");
a new String object is created. And when we write String b="abc"; the jvm searches in string pool and if a String object containing abc is present then it returns the reference to that string and if not present it creates a new String object and adds it to the pool and returns a reference to that obect.
Here is an example which will clear your doubt
public static void main(String a[])
{
String a=new String("abc");
String b="abc";
String c="abc";
System.out.print(a==b);//prints false
System.out.print(a==c);//prints false
System.out.print(c==b);//prints true
System.out.print(a.equals(b));//prints true
System.out.print(a.equals(c));//prints true
System.out.print(c.equals(b));//prints true
}
 
Ranch Hand
Posts: 1252
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by arivu mathi:
Sting s = new string("abc");
a new string object is created by the above statement.

String s = "abc";
does this statement also create a new string object or it is refering to a object in the string pool?



I think you have created two thread with same question but in different language..... Didn't you check out this one...

String Object.

One more thing to notice to all moderators..

Well the question is different then the reply of Rohit Suman as

Originally posted by Rohit Suman:
[Q]definately you can use static and native modifier are used to load any native files they may be required to run the program
[/Q]




Earlier when I check this thread the Name of this thread was "static", but now it has been changed to "String".

Could you please justify.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rohit wrote:

hi i happened to answer the wrong question



No you answered the correct question There was a topic about "static" and "native". The bulletin board seems to be a little confused and mixing stuff up today - we are investigating the problem.
 
Rohit Suman
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes i think so when i got the question of static and native i posted the reply for that and the answer to that question appeared somewhere else.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic