Results 1 to 6 of 6

Thread: Access memory address in java

  1. #1
    Join Date
    Jul 2009
    Posts
    188

    Access memory address in java

    Hi Friends,
    I am programming in java, till now I am on the intermediate level in programming in java now. But I had some doubts in java, how to access the memory address in java. I think the memory allocation concept in java is little confusing. If I am not wrong there are no printers in java, like they are C language. The how to access the address of the memory, that is the value of the address.

  2. #2
    Dr. V Guest

    Re: Access memory address in java

    Hello,
    Yes, you are correct there are no pointers in java, but there are soft form of pointers in java, and they are called as references, though they are not exactly pointers, they are just references to memory allocation.
    Suppose you create and object in java, just look at the following example
    Code:
          Beta var1 = new Beta();
          Beta var2 = var1;
    Beta var1 = new Beta(); Beta var2 = var1;
    here both the objects var1 and var2 refer to the smae object which is of the class beta. I recommend you to try some examples and then you will understand this concept.

  3. #3
    Join Date
    Jul 2009
    Posts
    188

    Re: Access memory address in java

    Hello,
    I am trying a program where I need to give the address of the memory to a variable. In some of the books I have read that, it is not impossible to access address of memory directly in java. Is this true, can the memeory address be accessed directly. If it is so, then please post me how can I do this? Doing this requires some special packages or some classes or interfaces, then I will import then.

  4. #4
    Dr. V Guest

    Re: Access memory address in java

    Hello,
    If you want to fetch the memory address to the variable, then you have to use the Object.toString() method. The Object.toString() method will return you the memory address. Just have a look at the example below.
    Code:
          public static void main(String... args)
          {
          Object ob = new Object();
          System.out.println(ob.toString());
          }
    Try using this method and then if you have any more problems then post back.

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Access memory address in java

    Hello,
    Code:
         public static void main(String... args)
          {
          Object ob = new Object();
          System.out.println(ob.toString());
          }
    Yes, the above code will return you the memory address, but remember that it will be in the string format that is it will be the string representation of the memory address. This means that you can not access or modify the memory address directly. Like you can in c or c++. You can not allocate memory by a function directly in java. Though you can do it other way round, but not sure how effectively it works.

  6. #6
    Join Date
    May 2008
    Posts
    2,012

    Re: Access memory address in java

    Hello,
    If you want to print the address of the memory you can use the following example.
    class Node {
    int dt;
    Node nt;
    }
    class Node { int dt; Node nt; }
    This will make clear that how references are handled in java. Java does not give access to the address of the memory directly because, it is one of its security features. But it is not impossible to do it. Though it may be a long procedure to do it

Similar Threads

  1. How to access network pc through mac address?
    By Kazek in forum Networking & Security
    Replies: 2
    Last Post: 03-07-2011, 08:51 AM
  2. How to get MAC address of a host using java program?
    By Juany in forum Software Development
    Replies: 5
    Last Post: 20-04-2011, 12:58 AM
  3. Can I use a 56k modem to access IP address
    By Federer in forum Networking & Security
    Replies: 4
    Last Post: 25-03-2011, 07:14 AM
  4. How to get IP address of localhost in java?
    By MKAIF in forum Software Development
    Replies: 4
    Last Post: 05-02-2010, 10:01 PM
  5. Memory mapped address
    By lolguy in forum Software Development
    Replies: 2
    Last Post: 20-10-2009, 03:38 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,167,227.20173 seconds with 17 queries