• 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 doubt

 
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even using 'new' with Strings seems like a lot of work. The JVM has really spoiled us .

John.
 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome

But I don't think it's Mr Nassnahoj
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's probably nassnahoJ .rM

John.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, it's not .rM either. At least I don't think it is.
 
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems the assumption around here is that everyone is male. Makes me crazy.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ohk is it Mrs Johanssan then

why to have your name upside down its not a password
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic