my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Enabling Assertions? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Enabling Assertions?" Watch "Enabling Assertions?" New topic
Author

Enabling Assertions?

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Hi Ranchers,

Given the following command, which classes would have assertions enabled?
java -ea -da:com... net.example.LaunchTranslator
Select the two correct answers,

(a) com.example.Translator
(b) java.lanh.String
(c) dot.com.Boot
(d) net.example.LaunchTranslator
(e) java.lang.AssertionError

Please help me fellas.

Regards,
Jothi Shankar Kumar. S


SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Hi Guys,

Any answers for the above code??

Regards,
Jothi Shankar Kumar. S
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi ranchers,

java -ea -da:com... net.example.LaunchTranslator


the first part is
-ea without specified packages or classes enables assertions in all classes in all packages and subpackages.

the second part
-da:com... disables assertions in package com and all of its sub-packages.

the third part
net.example.LaunchTranslator

runs class LaunchTranslator in package net.example


net.example as package name shows, that it isn't a subpackage of com, otherwise com would be part of the package name, so the class runs with assertions enabled.

a) com.example.Translator subpack of com -> disabled

b) java.lang.String not a subpack of com -> enabled

c) dot.com.Boot
Tricky. the package dot.com is not a subpackage of com!
It is a subpackage of dot. To disable assertions in this package, you'd need to write
java -ea -da:com... dot.com... net.example.LaunchTranslator
as we didn't write so, assertions are enabled.

d) net.example.LaunchTranslator not a subpack of com -> enabled, and this is the class that will run

e) java.lang.AssertionError not a subpack -> enabled.



I don't think that java.lang.String and java.lang.AssertionError actually have assertions, but if they had, they were enabled.


Yours,
Bu.


all events occur in real time
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Hi Bu,

Your Quote,

dot.com.Boot
Tricky. the package dot.com is not a subpackage of com!
It is a subpackage of dot. To disable assertions in this package, you'd need to write
java -ea -da:com... dot.com... net.example.LaunchTranslator
as we didn't write so, assertions are enabled.


From the above explnation, dosnt it mean that the class Boot is inside the package com which is inside the package dot?? So already the assertions are disabled in the com package which applies to its classes as well?? So how come this option is correct???
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
When we have

package com;
public class Any {}


and

package dot.com;
public class Boot {}



then we have this directory / file structure:


-da com... means
that in folder com (and possible subfolders)
so in package com (possible subpackages)
the insertions are disabled.

the assertions are not disabled in folder dot/com i.e. in package dot.com

this is because from the package names you can know, that the file Boot.java must be in a folder com that must be in a folder dot.


-da com... finds only the com folder on top of the root, not the folder com that is inside another folder.

What also is a bit tricky about answer c is just the
dot.com


Packages follow the tree of the folders.
But in real life, such a package name dot.com should NOT occur. Because if you are a dot com company (jothi.dot.com), the folder (and package!) tree should be reversed,
it should be
package com.dot; and possibly com.dot.jothi;
and not as in answer c!

If it were so, the -de com... would also had disabled the assertions in com.dot.


But the answer in c was as given, so in package dot.com, assertions are not disabled through -da: com...


I'm not sure if I remember this on the actual exam...


Yours,
Bu.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Hi Bu,

As per my understanding from your post is that, we have two packages com and dot where dot is the superpackage and com subpackage and Boot is a class in the com package. So far good. Now if we disable assertions in the dot package like -da dot... this means assertions will be disabled for dot and it's subpackage which here is com. So the class Boot will run with assertions disabled. Am I right over here??? Please correct me if I'm wrong. So how does one can say from the above question that after saying -da:com... , the option dot.com.Boot would have assertions enabled??? Havn't we already disabled the com.Boot part when we said -da:com... ???Disableing assertions on packages means disabling them for the classes inside them as well...Am I right here...Please help me guys.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Hi Guys,

Any answers to my doubt above??
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Enabling Assertions?
 
Similar Threads
assertions
Khalid Mughal : Assertions
Enabling Assertions
Assertion question (in programmer's guide to Java)
assertions