That depends on how you decide to compile your code. If you wish to compile to enable assertions (-1.4) then, yes it's a keyword and you can't use it. If you wish to compile without assertions, then it's not a keyword and you can use it. But, since it's a potential keyword, why ask for trouble? Why not just use another name?
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...)
The default compilation option is "assertions disabled" or -source 1.3 flag to enforce it explicitly. With JDK 1.4.2, if assert is used as an identifier rather than a keyword, a compiler gives a warning. assert in the code can be used as either identifier or a keyword, but never both.
Joined: May 16, 2001
If I get a question on certification exam 1.4 Should answere assert as keyword or not a keyword.? I could not find assert keyword in language spec. Which is correct ans for 1.4 exam.
Joined: Jul 30, 2003
Hi, Mohana - "assert" was not in my exam as a keyword, and it's not listed in the keywords table in The Java Tutorial from Sun. According to The Java Language Specification at 3.9, "assert" is not a keyword:
The following character sequences, formed from ASCII letters, are reserved for use as keywords and cannot be used as identifiers (�3.8): abstract default if private this boolean do implements protected throw break double import public throws byte else instanceof return transient case extends int short try catch final interface static void char finally long strictfp volatile class float native super while const for new switch continue goto package synchronized The keywords const and goto are reserved, even though they are not cur-rently used.
Hope that helps. [ October 30, 2003: Message edited by: Jeff Bosch ]
Originally posted by mohana konakanchi: If I get a question on certification exam 1.4 Should answere assert as keyword or not a keyword.? I could not find assert keyword in language spec. Which is correct ans for 1.4 exam.
Hi mohana http://www.jchq.net has a mock exam with a question on this (Question Bank Id No 149). It says: The Correct Answer is 3) Starting with jdk 1.4 assert is a keyword If you attempt to use the word assert as an identifier and compile it with JDK1.4 from Sun the following message is produced. warning: as of release 1.4, assert is a keyword, and may not be used as an identifier