About Question enthuware.ocpjp.v7.2.1490 :
Moderators: Site Manager, fjwalraven
-
- Posts: 27
- Joined: Sat Aug 31, 2013 5:38 pm
- Contact:
About Question enthuware.ocpjp.v7.2.1490 :
"You want to disable assertions for all classes of bad.* as well as good.* but at the same time want to enable them for Main.class."
With this:
java -ea:... -da:good... -da:bad... Main
You are enable assertion for the whole default package, which is different from what you were asking . ?
With this:
java -ea:... -da:good... -da:bad... Main
You are enable assertion for the whole default package, which is different from what you were asking . ?
-
- Posts: 28
- Joined: Wed Dec 04, 2013 7:57 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1490 :
#4 is correct.
However could #1 be correct also?
Because assertion is by default disabled so we don't have to do anything to packages good and bad. All we have to do is enable assertion for main. Which is #1: java -ea Main
Thanks
Tony,
However could #1 be correct also?
Because assertion is by default disabled so we don't have to do anything to packages good and bad. All we have to do is enable assertion for main. Which is #1: java -ea Main
Thanks
Tony,
-
- Site Admin
- Posts: 10113
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1490 :
If you just do -ea without specifying any package or class using the colon syntax, assertions will be enabled for all. That is my #1 is wrong.
If you like our products and services, please help us by posting your review here.
-
- Posts: 20
- Joined: Tue Nov 04, 2014 1:13 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1490 :
I agree with @sinapse
Shouldn't the correct answer be
Shouldn't the correct answer be
Code: Select all
java -ea:Main -da:good... -da:bad... Main
-
- Site Admin
- Posts: 10113
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1490 :
Yes, this can do the job as well. But the question doesn't ask you to disable assertions for the default package. Neither does it asks you to enable assertions for ONLY for Main.class. So the given solution works as well.SepticInsect wrote:I agree with @sinapse
Shouldn't the correct answer beCode: Select all
java -ea:Main -da:good... -da:bad... Main
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 78
- Joined: Sun Jun 30, 2013 10:04 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1490 :
Is the * for option b) invalid syntax for assertions?
java -ea:* -da:good.* -da:bad.* Main
Please confirm.
java -ea:* -da:good.* -da:bad.* Main
Please confirm.
-
- Site Admin
- Posts: 10113
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1490 :
What happened when you tried it out?
If you like our products and services, please help us by posting your review here.
-
- Posts: 78
- Joined: Sun Jun 30, 2013 10:04 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1490 :
Code: Select all
/*
I placed this code into C:\java.
When you run this code from the command prompt using
C:\java>java -ea: AssertionTest
it will print
done
*/
public class AssertionTest {
public static int y;
public static int foo(int x) {
System.out.print("foo");
return y = x;
}
public static int bar(int z) {
System.out.print("bar");
return y = z;
}
public static void main(String[] args) {
int t = 2;
assert t < 4 : bar(7);
assert t > 1 : foo(8);
System.out.print("done");
}
}
Did it again using
C:\java>java -ea:* -da:good.* -da:bad.* AssertionTest
done
C:\java>
Oracle Docs has no mention of * "Asterisk" in notation.
Is this to throw the test taker off or is it actually used somewhere?
Please clarify.
http://docs.oracle.com/cd/E19683-01/806 ... index.html
-
- Site Admin
- Posts: 10113
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1490 :
-ea:* is not valid usage. Yes, -ea:* doesn't generate any error but it doesn't enable assertions for Main either. That is why this is an incorrect option.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 29
- Joined: Wed Apr 17, 2013 9:22 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1490 :
The explanation states that "Each enable or disable modifies the one before it."
Does it imply having some kind of order involved? It doesn't seem so.
Consider having a runnable (main) class with "assert false;" as the only line.
"-ea", "-ea:com.Test -da" and "-da -ea:com.Test" all result in AssertionError.
Does it imply having some kind of order involved? It doesn't seem so.
Consider having a runnable (main) class with "assert false;" as the only line.
"-ea", "-ea:com.Test -da" and "-da -ea:com.Test" all result in AssertionError.
-
- Site Admin
- Posts: 10113
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1490 :
As per Oracle's Assertion tutorial
-Paul.
So there is some kind of order.If a single command line contains multiple instances of these switches, they are processed in order before loading any classes. For example, the following command runs the BatTutor program with assertions enabled in package com.wombat.fruitbat but disabled in class com.wombat.fruitbat.Brickbat:
java -ea:com.wombat.fruitbat... -da:com.wombat.fruitbat.Brickbat BatTutor
-Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 29
- Joined: Wed Apr 17, 2013 9:22 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1490 :
But that does not imply that one modifies another?
-
- Site Admin
- Posts: 10113
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1490 :
You are right. That statement is confusing. Updated.insider wrote:But that does not imply that one modifies another?
thank you for your feedback!
Paul.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 3 guests