About Question enthuware.ocpjp.v7.2.1322 :

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

Moderator: admin

Post Reply
Danny Sheridan
Posts: 30
Joined: Sat May 02, 2015 4:48 pm
Contact:

About Question enthuware.ocpjp.v7.2.1322 :

Post by Danny Sheridan »

No change is required in the JVM for supporting assertions.
The new usage of command line switches (-ea -da -esa -dsa) must have required changes to vm launch.
Were there not also actual JVM changes then too?

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

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

Post by admin »

As per http://docs.oracle.com/javase/7/docs/te ... ssert.html
assertions require only a runtimr library change , not a jvm change. That is also whhy old code that uses assert as user defined token will work with new jvm.

Chen@ukr.net
Posts: 9
Joined: Sat Feb 27, 2016 1:17 pm
Contact:

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

Post by Chen@ukr.net »

Besides the 'assert' keyword, new methods are added in java.lang.Class and java.lang.ClassLoader classes.
i didn`t get that statement, explain it more.

(as i understand Assertions require changes at the API level.- mean that you must modify you method api, thats wrong)
can you explain:
Besides the 'assert' keyword, new methods are added in java.lang.Class and java.lang.ClassLoader classes.

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

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

Post by admin »

I am not sure I understand your question. They added more methods to the two classes. You can compare the classes accross java 2 and java 3/4.

dieterdde
Posts: 19
Joined: Wed May 25, 2016 4:33 am
Contact:

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

Post by dieterdde »

Hi, question,

Option #4: Code that uses Assertions cannot be run on version below 1.4

In the book I'm studying, it said that if you use the assert identifier, on 1.3 it will compile but with warnings.

How should one interpret "uses Assertions" for the exam? Does it only refer to the assert as a keyword?

I thought this question was in general about assertions, whether in the old style with an identifier or with the newer style with the keyword. Does the capital "A" in Assertions refers then only to the keyword style?

Cheers,
Dieter

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

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

Post by admin »

The phrase "Using assertions" implies using the assertions feature of Java language and not using assert as an identifier.
"Using assert as an identifier" means using assert as an identifier and not as a keyword.

dieterdde
Posts: 19
Joined: Wed May 25, 2016 4:33 am
Contact:

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

Post by dieterdde »

admin wrote:The phrase "Using assertions" implies using the assertions feature of Java language and not using assert as an identifier.
"Using assert as an identifier" means using assert as an identifier and not as a keyword.
Ok good, that'll come in handy for the exam!

Btw, when do you ever sleep, Paul, you posted this after 3AM!?!

Cheers,
Dieter

dalvir
Posts: 9
Joined: Mon Apr 15, 2024 11:36 pm
Contact:

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

Post by dalvir »

Hi

I've the following addition to the explanation given for Option #4 of this question:

"Option #4: Code that uses Assertions cannot be run on version below 1.4".

---------------------
I believe when assert as a keyword was added in Java 1.4 then by default javac compiler used the old semantics as its default behavior (that is, allowing assert to be used as an identifier) was done for maximal source compatibility. As per exact quotes from this link : https://docs.oracle.com/javase/1.5.0/do ... ssert.html

" 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"
---------------------
Hence, the explanation to Option#4 :"It can be compiled by using -source flag: javac -source 1.3 classname.java" is OK but even if we don't specify the -source 1.3 switch in this case, javac would've no problem since it was behaving by default as a source 1.3 mode to allow for compatibility in that era.

Just my 2 cents as an addition to the explanation of why Option#4 is correct.

Please suggest if mine interpretations are correct.

Thanks

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

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

Post by admin »

Option 4 is talking about using assertions (and not about using the assert keyword as an identifier.
As mentioned in the comment above,
The phrase "Using assertions" implies using the assertions feature of Java language and not using assert as an identifier. "Using assert as an identifier" means using assert as an identifier and not as a keyword.
That is why option 4 is incorrect.

Option 5 is, "Code written for JDK version 1.3 cannot be compiled under JDK version 1.4". Note that the problem statement asks you to pick the statements are not NOT correct. That is why this option is correct because Code written for JDK version 1.3 CAN be compiled under JDK version 1.4 using the -source flag. This is irrespective of assertions although it is the main cause.

dalvir
Posts: 9
Joined: Mon Apr 15, 2024 11:36 pm
Contact:

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

Post by dalvir »

Thanks for your reply.

I totally get your points. They are all valid. I agree with all the answers and explanations as well.
-----------------------------------------------------------------------------------------------------------------------------------
But I just want to confirm whether the use of -source flag in the following statement is a "must" condition or is it "optional" condition?
That is why this option is correct because Code written for JDK version 1.3 CAN be compiled under JDK version 1.4 using the -source flag.
I mean can we paraphrase above statement as below:
"That is why this option is correct because Code written for JDK version 1.3 CAN be compiled under JDK version 1.4 using the -source flag but use of
-source flag wasn't mandatory in JDK version 1.4 to specifically compile code written for JDK version 1.3 since by default such relaxation exited "only" in JDK version 1.4 release to allow for compatibility reasons"
javac -source1.3 AssertTest.java // code being executed on 1.4 but was written for 1.3 (compiles fine) ( though use of -source 1.3 is optional) --(1)

javac AssertTest.java // code being executed on 1.4 but was written for 1.3 (compiles fine) ( even without explicit -source 1.3 switch) -----(2)

Both statements (1) and (2) are equivalent in terms of final results.
-------------------------------------------------------------------------------------------------------------------------------------

I tried to be as specific as possible. My earlier post was vague.

Please provide your suggestions.

Thanks

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

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

Post by admin »

Ok, yes, I get what you mean now and you are right. For Java 1.4 , -source 1.3 flag is optional. So, Java 1.4 tools i.e javac will compile the code as if it is written as per java 1.3 without specifying the -source flag.

Just for the sake of others who are reading this discussion, assertions is no more on the OCA or OCP exams and 1.4 is way too in the past to worry about. For all practical purposes, assert is a keyword and it cannot be used as an identifier.

dalvir
Posts: 9
Joined: Mon Apr 15, 2024 11:36 pm
Contact:

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

Post by dalvir »

Thanks for clarifying. I appreciate.

Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests