aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Assertion statements and their compilation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Assertion statements and their compilation" Watch "Assertion statements and their compilation" New topic
Author

Assertion statements and their compilation

Rajeev Trikha
Ranch Hand

Joined: Jan 29, 2010
Posts: 85
In K&B ch4/q19 (SCJP 5) there is a statement

As of Java version 1.4, assertion statements are compiled by default.


The answer says it is wrong because:
as of Java 1.4 you must add the argument –source 1.4 to the command line if you want the
compiler to compile assertion statements.


I don't get it. The default behaviour is surely 'javac -source 6' so it should be true. Where am I going wrong?

I just compiled a test program without any -source flag and it works fine. It correctly throws 'assert false' when -ea used. Lost!


Rajeev Trikha (SCJP 6)
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31057
    
232

Rajeev Trikha wrote:In K&B ch4/q19 (SCJP 5) there is a statement

Typo? Assertions are covered in chapter 5 and the self test goes up to question #16. Or maybe you are using the Java 1.4 version of the book?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31057
    
232

On to the question. Do they mean compiled or enabled? Assertions are always compiled; they are Java code.
Rajeev Trikha
Ranch Hand

Joined: Jan 29, 2010
Posts: 85
The exact question is:

19. Which two of the following statements are true? (Choose two.)

A. If assertions are compiled into a source file, and if no flags are included at runtime,
assertions will execute by default.

B. As of Java version 1.4, assertion statements are compiled by default.

C. With the proper use of runtime arguments, it is possible to instruct the VM to disable assertions for a certain class, and to enable assertions for a certain package, at the same time.

D. The following are all valid runtime assertion flags:
-ea, -esa, -dsa, -enableassertions,
-disablesystemassertions

E. When evaluating command-line arguments, the VM gives –ea flags precedence over –da flags.


The answer is: C and D.

Jeanne, you are right that the latest version doesn't have this question.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Assertion statements and their compilation