CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Location
    Chennai, INDIA
    Posts
    27

    Clarification Needed

    Hi,
    I am learning JAVA. Basically I am from C++ environment. I have some doubts on JAVA Programming.


    1. How the Memory Management is done in JAVA. I am not clear on that.

    Consider the Piece of Code

    public Object pop()
    {
    return Storage[index--];
    }

    If the Value of "index" is 2, the 3rd Object is returned but it will not be eligible for Garbage Collection. We need to write the Statement "Storage[index] = null" to make it free. Then how is the Garbage Collection is powerful. I am not clear on this.

    2. Where to write the "main" function if we have more than one class (for example in a Subsystem)

    3. How does the Object reference work?. How the contents of Object only gets changed when passed as an argument to a method and not other data types.

    4. What is the idea behind the "Transient" variables.

    Please clarify my doubts. Appreciate immediate reply.

    Thanks in Advance,
    Kalyan


  2. #2
    Join Date
    May 1999
    Location
    Pune, MH, India.
    Posts
    453

    Re: Clarification Needed

    1. 3rd object shouldn't be garbage collected obviously. Garbage collector frees only those objects which are not referenced by anyone. And its quite obvious. If u want to free a object u will have to remove all the references. That's why GC is powerful. In C++, programmers need to take care of freeing all the objects. And in some cases, like when u want to pass a object point to other classes and those classes are going to reference the object afterwards, it makes programmer confuse as who will release the object. In this confusion sometimes some objects don't get freed at all and some objects get freed when they r referenced by another class/object. But in JAVA, it takes care of freeying the object. So programmer is free of that burden.

    2. U can write it anywhere, but normally u should write it in ur main class (say where u create the main UI for the appln/applet). And in other classes u may have 'main' methods which will let u test that class only. So when testing just that module u can give that class to interpreter instead of loading the whole UI (or whole software) may be.

    3. As far as I know all the objects in JAVA r passed by reference and all the basic data-types are passed by value. (That's why writing 'swap' function for basic data-types is not possible in JAVA, u have to create a object somehow and do swapping!).

    4. I'm sorry. I'm not sure about it.


    - UnicMan
    http://members.tripod.com/unicman

  3. #3
    Join Date
    Apr 1999
    Location
    Chennai, INDIA
    Posts
    27

    Re: Clarification Needed

    Hi UnicMan,
    Thanks for your reply.

    Regards,
    Kalyan


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured