Page 1 of 1

About Question enthuware.ocpjp.v7.2.1384 :

Posted: Thu Feb 18, 2016 10:22 am
by MarcolinoPT
The explanation for this question:

Here assert it being used as an identifier (a method name is also an identifier). However, beginning Java 1.4 assert is a keyword. Therefore, to use 'assert' as an identifier, you have to tell the compile that your code is 1.3 compliant. It will generate a warning but it will compile.

Remember that you CANNOT use 'assert' as a keyword as well as an identifier at the same time.

The explanation for a similar question:

From Java 1.5 onwards, assert is treated as a keyword by default (as opposed to Java 1.4 version where it is treated as an identifier) so there is no need for -source 1.x switch. It is valid though.

Aren't both answers contradicting?

Re: About Question enthuware.ocpjp.v7.2.1384 :

Posted: Thu Feb 18, 2016 11:48 am
by admin
Why do you think they are contradictory? In 1.4, assert is a keyword but it is not treated as a keyword by default. It is treated as an identifier. In 1.5, assert is treated as a keyword by default.

Re: About Question enthuware.ocpjp.v7.2.1384 :

Posted: Sun Jan 01, 2017 10:53 am
by jagoneye
admin wrote:Why do you think they are contradictory? In 1.4, assert is a keyword but it is not treated as a keyword by default. It is treated as an identifier. In 1.5, assert is treated as a keyword by default.
So how to use assertions in java 1.4 then if it is not treated as keyword by default? :?

Re: About Question enthuware.ocpjp.v7.2.1384 :

Posted: Sun Jan 01, 2017 11:07 am
by admin
javac -source 1.4 TestClass.java

Re: About Question enthuware.ocpjp.v7.2.1384 :

Posted: Fri Mar 30, 2018 5:09 am
by yassine
I tried this code in my IDE and the code doesn't compile because assert is a keyword :
Syntax error on token "assert", Identifier expected

Re: About Question enthuware.ocpjp.v7.2.1384 :

Posted: Fri Jul 27, 2018 2:28 pm
by __JJ__
It can be compiled using all the versions of Java compilers.
This is interesting. I take (or at least, I took, until I read the answer to this question) "versions of Java compilers" to mean, the version of Java under which compilation takes place, not the physical javac.exe file that exists on my hard disk.

If you read it as the latter, then yes, it will compile using any version of javac; if you read it as "the version of java that a compiler assumes when compiling the code", then it will not compile under all versions of such compilers.

If it comes up in the exam, I am grateful for being forewarned.

Re: About Question enthuware.ocpjp.v7.2.1384 :

Posted: Mon Sep 24, 2018 5:46 am
by Touciuciu
The answer is wrong, NetBeans says this about the code from this question:
as of release 1.4, 'assert' is a keyword, and may not be used as an identifier
(use -source 1.3 or lower to use 'assert' as an identifier)
Eclipse says this about the code:
Syntax error on token "assert", Identifier expected
Please correct the answer by marking the last choice as the correct one.

Re: About Question enthuware.ocpjp.v7.2.1384 :

Posted: Mon Sep 24, 2018 5:51 am
by admin
Please read the question and the explanation fully and carefully. It is correct.
Also, please use javac command line tool to compile the code instead of relying on IDEs, while preparing for the exam.

Re: About Question enthuware.ocpjp.v7.2.1384 :

Posted: Tue Feb 25, 2020 11:30 am
by bvrulez
I get the following. Did I do something wrong? (javac -version: 11.0.5.)

Code: Select all

$ javac -source 1.4 Assertion.java
warning: [options] bootstrap class path not set in conjunction with -source 1.4
error: Source option 1.4 is no longer supported. Use 6 or later.

Re: About Question enthuware.ocpjp.v7.2.1384 :

Posted: Tue Feb 25, 2020 11:43 am
by admin
Well, you are using Java 11 compiler. Which exam are you preparing for?