About Question enthuware.ocpjp.v7.2.1384 :
Moderator: admin
-
- Posts: 1
- Joined: Mon Jan 25, 2016 7:27 am
- Contact:
About Question enthuware.ocpjp.v7.2.1384 :
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?
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?
-
- Site Admin
- Posts: 10064
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1384 :
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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 97
- Joined: Wed Dec 28, 2016 9:00 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1384 :
So how to use assertions in java 1.4 then if it is not treated as keyword by default?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.
-
- Site Admin
- Posts: 10064
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1384 :
javac -source 1.4 TestClass.java
If you like our products and services, please help us by posting your review here.
-
- Posts: 8
- Joined: Thu Dec 07, 2017 4:43 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1384 :
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
-
- Posts: 125
- Joined: Thu Jul 05, 2018 6:44 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1384 :
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.It can be compiled using all the versions of Java compilers.
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.
-
- Posts: 11
- Joined: Fri Aug 17, 2018 8:52 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1384 :
The answer is wrong, NetBeans says this about the code from this question:
Eclipse says this about the code: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)
Please correct the answer by marking the last choice as the correct one.Syntax error on token "assert", Identifier expected
-
- Site Admin
- Posts: 10064
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1384 :
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.
Also, please use javac command line tool to compile the code instead of relying on IDEs, while preparing for the exam.
If you like our products and services, please help us by posting your review here.
-
- Posts: 33
- Joined: Sat Feb 15, 2020 12:44 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1384 :
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.
-
- Site Admin
- Posts: 10064
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1384 :
Well, you are using Java 11 compiler. Which exam are you preparing for?
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 101 guests