The addition of the assert keyword to the Java programming language does not cause any problems with preexisting binaries (.class files). If you try to compile an application that uses assert as an identifier, however, you will receive a warning or error message. In order to ease the transition from a world where assert is a legal identifier to one where it isn't, the compiler supports two modes of operation in this release:
* source mode 1.3 (default) � the compiler accepts programs that use assert as an identifier, but issues warnings. In this mode, programs are not permitted to use the assert statement.
* source mode 1.4 � the compiler generates an error message if the program uses assert as an identifier. In this mode, programs are permitted to use the assert statement.
Unless you specifically request source mode 1.4 with the -source 1.4 flag, the compiler operates in source mode 1.3. If you forget to use this this flag, programs that use the new assert statement will not compile. Having the compiler use the old semantics as its default behavior (that is, allowing assert to be used as an identifier) was done for maximal source compatibility. Source mode 1.3 is likely to be phased out over time.
Piyush Jain wrote:According to Kathy S and Bert B book java will treat assert as a legal identifier if the assertion is not turned on.
now in the exam if its asked about whether assert is a keyword or used assert as an identifier. What the answer should be, if they don't say anything about turning on the assertion.
Ramesh Kumar Koyya wrote:
Before 1.4 version or lower version like 1.3 or 1.2 versions assert is treated as a identifier
In 1.4 version assert is a keyword
so use lower versions to compile the keyword
you can't compile 1..4 or above version assert is a identifier it gives compile time error
public static void main(String args)
compile javac -source 1.3 Test.java
it shows some warnings but it works
run it java Test
i hope you understand it
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton