• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Assertion statements and their compilation

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!

 
author & internet detective
Posts: 42152
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Jeanne Boyarsky
author & internet detective
Posts: 42152
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On to the question. Do they mean compiled or enabled? Assertions are always compiled; they are Java code.
 
Rajeev Trikha
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic