Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2016
    Posts
    21
    Rep Power
    0

    Default Pass by reference and viewing contents in memory location

    I am trying to understand the concept of pass by reference more.

    Let's say I have the line:

    Java Code:
    dog d1= new dog();
    Then I want to view what is actually in the computer's physical memory.

    1. I want to view the memory address of the variable d1.
    2. I also want to see the actual contents of the physical location in memory that corresponds to d1.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    5,739
    Rep Power
    10

    Default Re: Pass by reference and viewing contents in memory location

    First, passing a reference is not "pass by reference." You are passing by value. As far as getting the address of the object (not the address of the reference), the documentation for hashCode() says this:

    "As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the Java™ programming language.)"

    So the return of an unoverridden hashcode "could" be the address of the object you are looking for.

    As far as getting the actual memory contents of the class, I don't believe you can do it. You could write out the class in a serialized form and examine the byte code. But I don't believe that the object file would necessarily reflect the internal organization of that object once it is loaded.

    Also, why would you want to do all this anyway?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Don't pass by reference
    By Lyven in forum Advanced Java
    Replies: 6
    Last Post: 11-16-2009, 07:06 PM
  2. Pass-by-reference
    By popjava in forum New To Java
    Replies: 1
    Last Post: 10-19-2009, 03:45 PM
  3. Viewing contents of zip file
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-03-2008, 06:16 PM
  4. Viewing contents of JAR file
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-21-2007, 04:12 PM
  5. viewing the contents of a text file in JTextArea
    By warship in forum New To Java
    Replies: 0
    Last Post: 07-17-2007, 02:29 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •