• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Enabling Assertions?

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

Any answers for the above code??

Regards,
Jothi Shankar Kumar. S
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

Any answers to my doubt above??
 
Normally trees don't drive trucks. Does this tiny ad have a license?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic