Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

equals method overridden in String and Wrapper classes

 
Prathima gaitonde
Ranch Hand
Posts: 130
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  • I wanted to see the coding of Equals method in String class and Wrapper class that has been overridden from Object class, In Java.


  • Is there any way I can print address of the variable, i.e memory location where they are stored?


  • example:

    In the above code I know there is no method called address, I am just stating is there any method, which can return me the address(memory location) of s?
     
    Sergej Smoljanov
    Ranch Hand
    Posts: 467
    10
    • Likes 3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    - equals from String;


    equals from Character

    equals from Boolean

    equals from Byte

    equals from Short

    equals from Integer

    equals from Float

    equals from Double
     
    Sergej Smoljanov
    Ranch Hand
    Posts: 467
    10
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    (tip: in NetBeans -press <Ctrl> and click on type declaration you will go to class, i just copy equals method from this)
    Is there any way I can print address of the variable, i.e memory location where they are stored?


    i don`t know way to do this.
     
    Prathima gaitonde
    Ranch Hand
    Posts: 130
    3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for the code from Wrapper classes and String class. @Sergej Smoljanov . I use Eclipse. I dont know Netbeans. Do you know any other way of achieving the same in eclipse?
     
    Jeanne Boyarsky
    author & internet detective
    Marshal
    Posts: 35279
    384
    Eclipse IDE Java VI Editor
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    In Eclipse, it is F3. Alternatively, you can right click the class and choose "open declaration"
     
    Prathima gaitonde
    Ranch Hand
    Posts: 130
    3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The eclipse has opened a code for String class something like this

    [color=red]// Stack: 1, Locals: 1
    public static java.lang.String valueOf(java.lang.Object arg0);
    0 aload_0 [arg0]
    1 ifnonnull 9
    4 ldc <String "null"> [16]
    6 goto 13
    9 aload_0 [arg0]
    10 invokevirtual java.lang.Object.toString() : java.lang.String [450]
    13 areturn
    [/color]

    How can I go to particular method? Example equals(). I can see the method name listed in outline window, but was unable to open it.
     
    Sergej Smoljanov
    Ranch Hand
    Posts: 467
    10
    • Likes 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    some tips for Eclipse:
    0-Eclipse.png
    [Thumbnail for 0-Eclipse.png]
    1-Eclipse.png
    [Thumbnail for 1-Eclipse.png]
    3-Eclipse.png
    [Thumbnail for 3-Eclipse.png]
     
    Sergej Smoljanov
    Ranch Hand
    Posts: 467
    10
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    One more
    4-Eclipse.png
    [Thumbnail for 4-Eclipse.png]
    5-Eclipse.png
    [Thumbnail for 5-Eclipse.png]
    6-Eclipse.png
    [Thumbnail for 6-Eclipse.png]
     
    Sergej Smoljanov
    Ranch Hand
    Posts: 467
    10
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    finally
    7-Eclipse.png
    [Thumbnail for 7-Eclipse.png]
     
    Prathima gaitonde
    Ranch Hand
    Posts: 130
    3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi @Sergej Smoljanov, It was really a great effort from you, for a person whom you don't even know. Hats off to all people like you. I am not able to locate src.zip file. I searched within my whole c-drive. Search results say file not found. Any idea what might be wrong? Can I ask you for a favour? In your last post you said something about flash cards, can you explain me how to use it? If you can post some links regarding this, to my mail id I would take it from there. My mail id is help.java@yahoo.co.uk.

    Thanks in advance.
     
    Sergej Smoljanov
    Ranch Hand
    Posts: 467
    10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    i sent on post you give. (src.zip file)
    also may be you not install wiht JDK. if so try this:
    http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
    when you download you must check radio button (Accept License Agreement )
    and when install: (i select install all, as was by default)
    0-install.png
    [Thumbnail for 0-install.png]
    1-install.png
    [Thumbnail for 1-install.png]
     
    Prathima gaitonde
    Ranch Hand
    Posts: 130
    3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks @Sergej Smoljanov, It did work. Thanks very much once again.
     
    Roel De Nijs
    Sheriff
    Posts: 10662
    144
    AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
    • Likes 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Prathima gaitonde wrote:I wanted to see the coding of Equals method in String class and Wrapper class that has been overridden from Object class, In Java.

    Be careful: Equals method (with capital E) doesn't exist in the String class. It's with lower case e. Java is case-sensitive!

    When I don't have an IDE available, I use a website like GrepCode to quickly browse the source of a class from the JDK.

    Prathima gaitonde wrote:Is there any way I can print address of the variable, i.e memory location where they are stored?

    Getting the memory addresses of variables is meaningless within Java, since the JVM is at liberty to implement objects and move them as it seems fit (your objects may/will move around during garbage collection etc.). You don't want nor need them

    But if you really want some code, have a look here. Disclaimer: this is far beyond the scope of the OCAJP7 exam (it's even outside the scope of the more advanced OCPJP7 exam).

    Hope it helps!
    Kind regards,
    Roel
     
    Prathima gaitonde
    Ranch Hand
    Posts: 130
    3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Oh!!! nice to know about the link to know the insight of java classes without having IDE. I think I will leave the address printing circus here, as I wanted to know that, in order to know the difference between, String s="abc" and String s=new String("abc"). Which is now clear to me, through the link mentioned by you. Thanks for the help and support @Roel De Nijs.
     
    Sergej Smoljanov
    Ranch Hand
    Posts: 467
    10
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic