About Question enthuware.ocpjp.v7.2.1384 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
MarcolinoPT
Posts: 1
Joined: Mon Jan 25, 2016 7:27 am
Contact:

About Question enthuware.ocpjp.v7.2.1384 :

Post 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?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

jagoneye
Posts: 97
Joined: Wed Dec 28, 2016 9:00 am
Contact:

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

Post 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? :?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

javac -source 1.4 TestClass.java
If you like our products and services, please help us by posting your review here.

yassine
Posts: 8
Joined: Thu Dec 07, 2017 4:43 am
Contact:

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

Post 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

__JJ__
Posts: 125
Joined: Thu Jul 05, 2018 6:44 pm
Contact:

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

Post 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.

Touciuciu
Posts: 11
Joined: Fri Aug 17, 2018 8:52 am
Contact:

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

Post 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.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

bvrulez
Posts: 33
Joined: Sat Feb 15, 2020 12:44 am
Contact:

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

Post 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.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

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.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 33 guests