aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes help with marcus questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "help with marcus questions" Watch "help with marcus questions" New topic
Author

help with marcus questions

Gauri Tilloo
Greenhorn

Joined: Jun 22, 2005
Posts: 5
Given the following code, how many objects will be eligible for garbage collection on the line with the comment //here

OPTIONS:
1)0
2)1
3)2
4)3
Answer is 0. Can any one explain how?


2)What will happen when you attempt to compile and run the following code?

options:
1)compile time error, the call to col has the wrong type
2)compilation and output of 1010
3)Compile time error Object cannot be cast to Integer
4)Compilation and output of 2020

Answer is 4. Pl. explain how?

( tags added, fixed formatting and missing brace)

[ July 08, 2005: Message edited by: Barry Gaunt ]
[ July 08, 2005: Message edited by: Barry Gaunt ]
Rocky Jaiswal
Greenhorn

Joined: Jul 08, 2005
Posts: 10
Hi,
I think i know the answer to the second one. It is because the variable is static the variable belongs to the class and not to the object so the variable value is what you assign to it last, which is 20.

Am i right javaranch?

Thanks,
Rocky
Kedar Dravid
Ranch Hand

Joined: May 28, 2004
Posts: 333
The answer is 0, because x still refers to an Integer object with value 10,
and the object reference pointed to by y still refers to an Integer object with value 99. Setting z=null does not make any object eligible for GC.
[ July 08, 2005: Message edited by: Kedar Dravid ]
Fes D Gaur
Ranch Hand

Joined: Apr 29, 2005
Posts: 54
As long as an object has a live thread referencing it, the object will not become eligible for garbage collection. In case of question 1 the reference x is passed to a method. Objects are passed by reference so a copy of the reference was passed. That copy in the method became null while the original reference still was attached to the object. Same case applies to reference y.

Fess D Gaur
Marcus Green
arch rival
Rancher

Joined: Sep 14, 1999
Posts: 2813
I try not to make questions available without including an explanation of the answer. In the case of that first question I have included the explanation ...

"A reference passed into a method is passed as if it were a copy of a pointer pointer rather than the actual object. Thus if that reference is assigned to a null it makes no difference to any other copy of that pointer. Thus the code within the method findOut makes no difference to any other references. Although reference z is assigned to null reference y still points to the object so no objects are eligible for garbage collection."

Was this explanation availible/visible/correct/meaningful. Your feedback is greatly appreciated.

(This question is one that is publicly visible from the database at
http://www.jchq.net/phezam and is from the JDK1.4 subject set)
Marcus
[ July 08, 2005: Message edited by: Marcus Green ]

SCWCD: Online Course, 50,000+ words and 200+ questions
http://www.examulator.com/moodle/course/view.php?id=5&topic=all
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
I read both the question and explanation given by Marcus Green. I found it satisfactory. I appreciate if you can avoid words like pointer(even though it makes sense).


Note: Thanks Marcus for offering such an wonder mock site freely. You work is phenomenal. Continue your good work. God Bless U.



Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
latha yeduguri
Greenhorn

Joined: Jun 24, 2005
Posts: 17
I am getting the following exception when I try to compile the above Code

Exception in thread "main" java.lang.NoClassDefFoundError: Csturt (wrong name: C
Sturt)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
3)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Originally posted by latha yeduguri:
I am getting the following exception when I try to compile the above Code

Exception in thread "main" java.lang.NoClassDefFoundError: Csturt (wrong name: C
Sturt)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
3)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)



Did you read what the error was and check your typing?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Seems that your class file name should be CSturt.java instead of Csturt.java.

Class/File names are case sensitive.

Nick


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
 
jQuery in Action, 2nd edition
 
subject: help with marcus questions