About Question enthuware.ocpjp.v7.2.1490 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
sinapse
Posts: 27
Joined: Sat Aug 31, 2013 5:38 pm
Contact:

About Question enthuware.ocpjp.v7.2.1490 :

Post 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 . ?

tn1408
Posts: 28
Joined: Wed Dec 04, 2013 7:57 pm
Contact:

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

Post 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,

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

SepticInsect
Posts: 20
Joined: Tue Nov 04, 2014 1:13 am
Contact:

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

Post by SepticInsect »

I agree with @sinapse
Shouldn't the correct answer be

Code: Select all

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

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

ewebxml
Posts: 78
Joined: Sun Jun 30, 2013 10:04 pm
Contact:

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

Post by ewebxml »

Is the * for option b) invalid syntax for assertions?

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


Please confirm.

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

What happened when you tried it out?
If you like our products and services, please help us by posting your review here.

ewebxml
Posts: 78
Joined: Sun Jun 30, 2013 10:04 pm
Contact:

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

Post 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

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

insider
Posts: 29
Joined: Wed Apr 17, 2013 9:22 am
Contact:

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

Post 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.

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

insider
Posts: 29
Joined: Wed Apr 17, 2013 9:22 am
Contact:

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

Post by insider »

But that does not imply that one modifies another?

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 12 guests