About Question enthuware.ocpjp.v7.2.1342 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
exiart
Posts: 3
Joined: Sun Dec 02, 2012 10:56 am
Contact:

About Question enthuware.ocpjp.v7.2.1342 :

Post by exiart » Thu Jul 25, 2013 2:19 pm

you wrote:
Correct answer(s) is(are):

Code: Select all

javac AssertTest.java
javac -source 1.6 AssertTest.java
javac -source 1.5 AssertTest.java
javac -source 1.7 AssertTest.java
and explanation:
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.5 or 1.6 switch. It is valid though.
But beginning with version 1.4, assert is a keyword - http://docs.oracle.com/javase/1.4.2/doc ... ssert.html (Compatibility With Existing Programs)

I tested it:

Code: Select all

public class AssertTest {
    public static void main(String[] args) {
        assert (true);
    }
}
and compile this code:

Code: Select all

javac -version
javac 1.7.0_02

javac -source 1.3 AssertTest.java
AssertTest.java:10: error: cannot find symbol
      assert (true);
and no error:

Code: Select all

javac -source 1.4 AssertTest.java
javac -source 1.5 AssertTest.java
javac -source 5 AssertTest.java
javac -source 1.6 AssertTest.java
javac -source 6 AssertTest.java
javac -source 1.7 AssertTest.java
javac -source 7 AssertTest.java
javac AssertTest.java

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

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

Post by admin » Thu Jul 25, 2013 3:13 pm

Yes, it is a keyword in 1.4 but it is not treated as a keyword in 1.4 by default, which is what the explanation says.

If you compile code containing assert using JDK 1.4, it will be treated as an identifier by default and not as a keyword. To treat it as keyword, you have to specify -source 1.4. That is what the link you gave also says.


HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Elmcrest
Posts: 12
Joined: Sat Apr 20, 2013 10:06 am
Contact:

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

Post by Elmcrest » Wed May 07, 2014 8:33 am

So am I right in assuming that "javac -source 1.4 AssertTest.java" would also work? Shouldn't it then be included in the correct answers list as well?
Also as mentioned by exiart, -source 5/6/7 should work as well. I don't know how common these "abbreviations" are, however since the other "version-versions" (1.x) are presented as correct answers, maybe these should be too?

Kind regards

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

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

Post by admin » Wed May 07, 2014 9:55 am

The question does not mean to list all the possible correct answers. Just the ones that are most likely to be written by the user. The purpose is to make sure that the users answer is evaluated correct.
So yes, -source 1.4 is valid as well but unless you are testing the simulator instead of your own knowledge, I think it is highly unlikely that a user would write that as a correct answer.
I have added it as a correct answer nonetheless.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

shcher
Posts: 4
Joined: Tue Oct 07, 2014 9:49 am
Contact:

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

Post by shcher » Thu Oct 09, 2014 3:22 pm

If we answer the question logically, then
"javac -source 1.4 AssertTest.java
javac -source 1.5 AssertTest.java
javac -source 1.6 AssertTest.java
javac -source 1.7 AssertTest.java"
are NOT correct answers. The question says "Do not write the classpath or any other switches, just use the one/ones that is/are absolutely needed."
"-source" switch is not needed in Java SE 7.
PS: recall question 12 from Test Exam 3.

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

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

Post by admin » Thu Oct 09, 2014 7:29 pm

Yes, you are right. -source is not needed. That is why if you write javac AssertTest.java, you will be awarded full credit. However, the objective here is not to select all correct answers. The options that you are talking about are there in case someone writes a command line with -source option. It is not logically correct because of the wording of the question but is correct from java perspective. That is why we want it to be evaluated as correct.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

gupta.v21
Posts: 17
Joined: Wed Jan 07, 2015 11:33 pm
Contact:

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

Post by gupta.v21 » Thu Jan 22, 2015 11:23 pm

Hey Paul,

This question does not specify anything about version. i remember there was a question regarding driver loading and in the explanation
we were requested to assume latest version . So if you assume latest version then javac XXX.java would also work.

Please correct my statement if i said wrong.

Vivek Gupta

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

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

Post by admin » Fri Jan 23, 2015 12:22 am

Yes, it will work. Please see my post just above yours.
If you like our products and services, please help us by posting your review here.

ArnobDe
Posts: 8
Joined: Tue Jan 27, 2015 3:33 pm
Contact:

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

Post by ArnobDe » Thu Mar 12, 2015 8:43 am

Assertions are suppose to be disabled by default.

So, shouldn't we write:

Code: Select all

 javac -ea AssertTest.java 

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

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

Post by admin » Thu Mar 12, 2015 9:30 am

No, enabling and disabling of assertions is a run time thing. The question is about compilation.
If you like our products and services, please help us by posting your review here.

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

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

Post by Chen@ukr.net » Sun Mar 27, 2016 6:45 am

Answer is right. But explanation for my opinion is wrong:
"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."
https://docs.oracle.com/javase/8/docs/t ... patibility
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.
How it can be identifier when you use it for this purpose code will not compile?

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

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

Post by admin » Sun Mar 27, 2016 10:40 am

I am not sure I understand your question but, the next line in the link that you've quoted says:
Unless you specifically request source mode 1.4 with the -source 1.4 flag, the compiler operates in source mode 1.3.

That is what this question is talking about.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

leorbarbosa
Posts: 17
Joined: Wed Nov 26, 2014 1:59 pm
Contact:

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

Post by leorbarbosa » Tue Jun 21, 2016 7:29 am

This question is very confuse. You can't know what knowledge is being asked. If Java 7 is being asked, why ask about java 1.6, 1.5, ..., etc ???

leorbarbosa
Posts: 17
Joined: Wed Nov 26, 2014 1:59 pm
Contact:

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

Post by leorbarbosa » Tue Jun 21, 2016 7:31 am

You can't know what knowledge is being asked. If it is a Java 7 question, why ask about 1.6, 1.5., etc ????

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

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

Post by admin » Tue Jun 21, 2016 10:36 am

You are right. It is not very important to know. Will remove this question.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests