*
The moose likes Beginning Java and the fly likes assert Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "assert" Watch "assert" New topic
Author

assert

Masha Klimenko
Ranch Hand

Joined: Feb 04, 2004
Posts: 31
I'm studying for the exam using the JAVA2 study guide by Kathy Sierra and Bert Bates. Their book says that compiler will comile code with assert statements as if you were running 1.3 unless you specify version 1.4 explicitly. My compiler does not compile at all unless I specify which version I want to use. It probably is not that important, but I would like to know if this is JVM specific, and there are compilers that default to 1.3 when there are assert statements in the code. Thanks.


SCJP
Thomas Autera
Greenhorn

Joined: Nov 10, 2003
Posts: 14
Mariya,
Which JVM are you running?
I am studying for the same exam, using the same book, and when I went through the assert lesson in the book, it worked just as explained:
javac -source 1.4 Pgmname.java (enable use of java assert keyword)
javac -source 1.3 Pgmname.java (allow user defined assert variable)
java -ea Pgmname (enable java assert)
-Thomas
Thomas Autera
Greenhorn

Joined: Nov 10, 2003
Posts: 14
oops ... forgot to mention I'm using Suns j2sdk1.4.2_03, on a MS XP OS.
Masha Klimenko
Ranch Hand

Joined: Feb 04, 2004
Posts: 31
Yes, I know, but if I compile:
javac Pgmname.java
without specifying version, and I use assert statements in my code
I get a compiler error. The book said if you don't specify version compiler will default to 1.3. Please try and let me know. May be I misread. Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: assert
 
Similar Threads
Question w.r.t Assertions
javac -target 1.3 hello.java
SCJP
Assert Question
assertion doubt