File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Compilation errors on assert key word Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Compilation errors on assert key word" Watch "Compilation errors on assert key word" New topic

Compilation errors on assert key word

Sekhar Kadiyala
Ranch Hand

Joined: Feb 17, 2004
Posts: 170
Hi Guys, till now i was working on 1.2.2 version and today to test few assert examples, i D/L 1.4.2.
Wrote the below program but it is giving errors while i try to compile. Compiler errors are

D:\JAVACE~1\ASSERT~1>javac warning: as of release 1.4, assert is a keyword, and may not be
used as an identifier
assert true;
^ not a statement
assert true;
^ ';' expected
assert true;
2 errors
1 warning

When i check the java version it is showing 1.4.2 only. PLEASE HELP

D:\JAVACE~1\ASSERT~1>java -version
java version "1.4.2_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_02-b03)
Java HotSpot(TM) Client VM (build 1.4.2_02-b03, mixed mode)

Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
Hi Shekhar,
Please checkout pages 260 & 261 in K&B book. It helps.
From text...
Remember, assertions are diabled by default in 1.4, both at compile time and run time.
Hope this helps.
Bojan Knezovic
Ranch Hand

Joined: Nov 20, 2003
Posts: 90
Try compiling and running your class with the -ea or -enableassertions parameter. Compiler sees this like

fethi makhlouf
Ranch Hand

Joined: Feb 16, 2004
Posts: 50
Hi Sekhar
When you run your program on sdk 1.4 or above, u have a possibility to use assertion, but you should diasable them, 'cause by default they are not!
in compilation you should tape
> javac -source 1.4
and for running
> java -ea Example.class
hope u understood me!

SCJP 1.4
Sekhar Kadiyala
Ranch Hand

Joined: Feb 17, 2004
Posts: 170
Hey, Thanks fethi. I wass home today and read the K&B for this. It also says the same. So tomorrow i am gonna try that.
I can't wait any more. Its just 3 more days!!!
I agree. Here's the link:
subject: Compilation errors on assert key word
It's not a secret anymore!