Forums Register Login

Assertion statements and their compilation

+Pie Number of slices to send: Send
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!

+Pie Number of slices to send: Send
 

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?
+Pie Number of slices to send: Send
On to the question. Do they mean compiled or enabled? Assertions are always compiled; they are Java code.
+Pie Number of slices to send: Send
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.
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1258 times.
Similar Threads
My problem wif Java questionssss
Whizlabs assert question
Assertion Question
About Running Assertion Programs
kb Q19 page 283
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:31:55.