Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

string doubt

 
Vishal Hegde
Ranch Hand
Posts: 1077
Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String a ="Arnold";

now a is an reference variable or object,if object hows that possible because new keyword is used whenever we create an object
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anything between "quotes" in your source code is a String object.

It would be really annoying if Java did not have native support for strings and you'd have to do difficult things just to have a string in your source code. It would become really tedious if you'd have to write something like this every time:
 
John de Michele
Rancher
Posts: 600
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even using 'new' with Strings seems like a lot of work. The JVM has really spoiled us .

John.
 
Embla Tingeling
Ranch Hand
Posts: 237
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vishal Hegde wrote:String a ="Arnold";

now a is an reference variable or object,if object hows that possible because new keyword is used whenever we create an object


Although String is a class, it has been given special language support to behave almost like a primitive. The String literal "Arnold" will be represented by an internal String object which reference is used every time "Arnold" appears.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and using the new keyword for Strings will cause unintended results, eg two identical Strings. This is quite unnecessary for 99.9% of applications.
 
Vishal Hegde
Ranch Hand
Posts: 1077
Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you


Campbell Ritchie
Mr. nossnahoj
John De Michele
Jesper Young


love you all
guys i am able to unable to learn java in a simpler way

 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome

But I don't think it's Mr Nassnahoj
 
John de Michele
Rancher
Posts: 600
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's probably nassnahoJ .rM

John.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it's not .rM either. At least I don't think it is.
 
Janeice DelVecchio
Saloon Keeper
Posts: 1802
12
Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems the assumption around here is that everyone is male. Makes me crazy.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33697
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Janeice DelVecchio wrote:It seems the assumption around here is that everyone is male. Makes me crazy.

I make a point of correcting that false assumption when it comes up for me. I've noticed other moderators do the same when someone calls me "he." As does my co-blogger.

Don't let it bother you . It's much more interesting to think of it as teaching people about female techies....
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right to make a point of correcting it, Jeanne; I also make sure to tell people not to call you or Joanne Neal "Sir".
 
Janeice DelVecchio
Saloon Keeper
Posts: 1802
12
Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I'll just break down and donate $$ to get a custom title...

I think "Java Princess" or "Drama Queen" would do it
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Janeice DelVecchio wrote:Maybe I'll just break down and donate $$ to get a custom title...

I think "Java Princess" or "Drama Queen" would do it
We have enough drama queens on "beginning Java" already. Please don't turn into one But Paul will be all over you if you threaten to donate $$
 
Vishal Hegde
Ranch Hand
Posts: 1077
Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohk is it Mrs Johanssan then

why to have your name upside down its not a password
 
Deepak Nayak
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote: . . . and using the new keyword for Strings will cause unintended results, eg two identical Strings. This is quite unnecessary for 99.9% of applications.


yes correct. Becasue if you make string object like this String s1= "John", it creates string object in String pool and when you create String s2 ="John", JVM doesn't create new object, instead it gives the reference of the same object to s2. it means both s1 and s2 will point to the same string object in String pool.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic