This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
This is from test: Java Programmer Certification Mock Exam No 3 Last Updated August 2002 60 Questions The question is: Question 4) Which of the following statements are true? 1) The garbage collection algorithm in Java is vendor implemented 2) The size of primitives is platform dependent 3) The default type for a numerical literal with decimal component is a float. 4) You can modify the value in an Instance of the Integer class with the setValue method
The aswere is 1. I guess the phrase vendor implemented is pretty wide open. I would assume that Java dictates groud rules for GC. When actually it kicks in is plateform depended. I answer 1. to be false. Any comments...
Hi Barkat. There are many algorithms for garbage collection out there. Which one is used in a particular JVM is chosen by the vendor of the JVM. Provided the vendor satisfies the contracts specified in JLS and JVM Specifications he is free to implement whatever algorithm he wants. It could be that there is a concensus as to which algorithm is optional, in that case the behaviour of vendors' JVMs would converge, but don't rely on it. It is in that sense I would say answer 1 is true. -Barry For more infomation check this: Garbage Collection FAQ (JVMs are implemented in C++/C usually) [ September 06, 2002: Message edited by: Barry Gaunt ]
example of such algo is Mark & Sweep. But it depends upon the platform. bharat
Joined: Aug 05, 2002
. There are many algorithms for garbage collection out there. Which one is used in a particular JVM is chosen by the vendor of the JVM. Provided the vendor satisfies the contracts specified in JLS and JVM Specifications he is free to implement whatever algorithm he wants.
If you refer to "mark and sweep", "stop and copy" or "adoptive (combination of two)" when you say algorithms, my understanding from "Thinking in Java" is that these are various technics evolved in the area of garbage collection. Furthermore if you say "algorithms are plateform implemented", one of the conotation of this statement could be that for example "mark and sweep" is only avaialble on unix plateform". The way I look at it is that these techniques (algorithms) are independent concept from the plateform. The implementation of these concepts (mark and sweep or stop and copy or adoptive) is matter of a particular version of JVM for a particular plateform. I know we are playing with words here but in exam when questions are using these abstract phrases, someone can inevitably make wrong assumptions and suffer....
Joined: Aug 03, 2002
Hi Barkat, "mark and sweep", "stop and copy" or "adaptive (combination of two)" are indeed algorithms for implementing garbage collection. The choice of algorithm is vendor dependent, for example IBM could implement a different method to Sun. It could even be possible that IBM implements a different algorithm on it's RISC architecture unix workstations to that it implements for intel windows systems. (Please note that these are hypotheses, not facts) BTW. You know garbage collection operates as a low priority daemon thread, and you know that thread behaviour is also non-deterministic, so you can see that predicting the behaviour of garbage collection is not possible. Interesting points you have made, but I would risk saying true to the first answer. -Barry [ September 07, 2002: Message edited by: Barry Gaunt ]
Is a Java garbage collector required to guarantee to collect circular data structures (A points to B which points back to A, but there are no other references to either A or B)?
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Joined: Aug 03, 2002
Happy to see you here Ron, I have just found the following in David Flanagan's Java in a Nutshell, 1.4ed, p 99.
The garbage collector can also detect and destroy cycles of objects that refer to each other, but are not referenced by any other objects. Any such cycles are also reclaimed.
The JVM Spec (beginning of Chap 3) states:
For example, the memory layout of run-time data areas, the garbage-collection algorithm used, and any internal optimization of the Java virtual machine instructions (for example, translating them into machine code) are left to the discretion of the implementor.
And a little later:
Heap storage for objects is reclaimed by an automatic storage management system (known as a garbage collector); objects are never explicitly deallocated. The Java virtual machine assumes no particular type of automatic storage management system, and the storage management technique may be chosen according to the implementor's system requirements.
So an implementation of the JVM does not have to implement any GC at all. So the JAVA OS for Lego Mindstorms RSX block is conformant in this repect. -Barry [ September 08, 2002: Message edited by: Barry Gaunt ] [ September 08, 2002: Message edited by: Barry Gaunt ]
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com