Page 1 of 1

About Question enthuware.ocpjp.v7.2.1490 :

Posted: Tue Sep 03, 2013 5:49 am
by sinapse
"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 . ?

Re: About Question enthuware.ocpjp.v7.2.1490 :

Posted: Fri Apr 04, 2014 3:32 pm
by tn1408
#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,

Re: About Question enthuware.ocpjp.v7.2.1490 :

Posted: Fri Apr 04, 2014 8:13 pm
by admin
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.

Re: About Question enthuware.ocpjp.v7.2.1490 :

Posted: Sat Dec 06, 2014 8:22 am
by SepticInsect
I agree with @sinapse
Shouldn't the correct answer be

Code: Select all

java -ea:Main -da:good... -da:bad... Main

Re: About Question enthuware.ocpjp.v7.2.1490 :

Posted: Sat Dec 06, 2014 9:23 am
by admin
SepticInsect wrote:I agree with @sinapse
Shouldn't the correct answer be

Code: Select all

java -ea:Main -da:good... -da:bad... Main
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.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v7.2.1490 :

Posted: Mon Aug 10, 2015 8:53 pm
by ewebxml
Is the * for option b) invalid syntax for assertions?

java -ea:* -da:good.* -da:bad.* Main


Please confirm.

Re: About Question enthuware.ocpjp.v7.2.1490 :

Posted: Mon Aug 10, 2015 9:23 pm
by admin
What happened when you tried it out?

Re: About Question enthuware.ocpjp.v7.2.1490 :

Posted: Tue Aug 11, 2015 2:04 am
by ewebxml

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");
 }
}
I compiled and ran the above code from a C:\java> directory

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

Re: About Question enthuware.ocpjp.v7.2.1490 :

Posted: Tue Aug 11, 2015 8:39 am
by admin
-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.

Re: About Question enthuware.ocpjp.v7.2.1490 :

Posted: Sat Aug 06, 2016 5:35 am
by insider
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.

Re: About Question enthuware.ocpjp.v7.2.1490 :

Posted: Sun Aug 07, 2016 7:13 am
by admin
As per Oracle's Assertion tutorial
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
So there is some kind of order.
-Paul.

Re: About Question enthuware.ocpjp.v7.2.1490 :

Posted: Sun Aug 07, 2016 8:45 am
by insider
But that does not imply that one modifies another?

Re: About Question enthuware.ocpjp.v7.2.1490 :

Posted: Sun Aug 07, 2016 11:36 am
by admin
insider wrote:But that does not imply that one modifies another?
You are right. That statement is confusing. Updated.
thank you for your feedback!
Paul.