This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K&B "assert " explanation" Watch "K&B "assert " explanation" New topic
Author

K&B "assert " explanation

Simon Cockayne
Ranch Hand

Joined: Dec 09, 2000
Posts: 214
Hi,

K&B book - Chapter 4, page 260 says:

to use assert as an indentifier use...

javac -source 1.3 myclass.java

...moreover that -source 1.3 is the default, so it is the same as using...

javac -source 1.3 myclass.java

...but I get an error in both cases:

C:\myjava>javac assertTest.java
assertTest.java:4: warning: as of release 1.4, assert is a keyword, and may not
be used as an identifier
int assert;

What's the score?

Cheers,

Si.


SCJP 1.4 (93%)<br />SCJD (In progress. It can run, but it can't hide...)
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
What compiler version are you running? That used to work in older 1.4 compilers, but I haven't used it for a while.


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Simon Cockayne
Ranch Hand

Joined: Dec 09, 2000
Posts: 214
Hi Jeff,

C:\myjava>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)

Cheers,

Simon
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
If you use assertions, compiling under -source 1.3 will generate a warning, but not an error. That's okay. But, assert must be used as a legal identifier, not in the format of an assertion check. Warnings don't interfere with the program running.

Does that help?
[ March 23, 2005: Message edited by: Jeff Bosch ]
Simon Cockayne
Ranch Hand

Joined: Dec 09, 2000
Posts: 214
Hi Jeff,

...and the fog lifts.

Jeff, thanks for pointing out that it is a warning and not an error.

I think I now understand all the variations of compile and run at 1.4 and prior, with and without assert, as a keyword and as an identifier.

Cheers,

Simon.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: K&B "assert " explanation
 
Similar Threads
Assertion again.
Question w.r.t Assertions
classpath for the .java
doubt in assert...
Assertion Doubt.