• 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

command line argument

 
Ranch Hand
Posts: 144
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi



when i run above code through command prompt with java Home hi i don't get hi2,,,, any suggestion?
 
Ranch Hand
Posts: 45
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use this


== method means both the objects have same references
 
Hama Kamal
Ranch Hand
Posts: 144
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sandeep Kumar B wrote:Use this


== method means both the objects have same references



thanks Sandeep, i appreciate the quick response..
 
Sandeep Kumar B
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not a problem!
 
Ranch Hand
Posts: 40
Netbeans IDE Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good question! These type of questions are always there in the exam to trick us

equals() compares the object values and is case-sensitive
== compares the object references i.e. if they share same address in memory which in this case is false
 
Ranch Hand
Posts: 59
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Considering the concept of the string constant pool (which says that the String literals are created just once) , would not the string "hi" be created in the pool during the program launch?
Is not the reference to the literal "hi" assigned to the args[0] from the command line?


 
Anjali Vaidya
Ranch Hand
Posts: 40
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Is not the reference to the literal "hi" assigned to the args[0] from the command line?



The "hi" which is in the if condition is created in String pool but... The args[0] "hi" is created inside the String array args, which is on the heap.
 
Ranch Hand
Posts: 64
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
== compare references of two objects
equals compare two objects content.

what ever it is object's are always created in heap only whether it is literal object or any other.

String constant pool holds the references of literals only.

String[] array hold the string types only.



so here you are compare "hi" literal object which holds the reference in string constant pool and the reference of args[0] string object which holds the String[] array Object

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic