Page 1 of 1

About Question enthuware.ocpjp.v7.2.1342 :

Posted: Thu Jul 25, 2013 2:19 pm
by exiart
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

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

Posted: Thu Jul 25, 2013 3:13 pm
by admin
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.

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

Posted: Wed May 07, 2014 8:33 am
by Elmcrest
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

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

Posted: Wed May 07, 2014 9:55 am
by admin
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.

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

Posted: Thu Oct 09, 2014 3:22 pm
by shcher
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.

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

Posted: Thu Oct 09, 2014 7:29 pm
by admin
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.

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

Posted: Thu Jan 22, 2015 11:23 pm
by gupta.v21
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

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

Posted: Fri Jan 23, 2015 12:22 am
by admin
Yes, it will work. Please see my post just above yours.

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

Posted: Thu Mar 12, 2015 8:43 am
by ArnobDe
Assertions are suppose to be disabled by default.

So, shouldn't we write:

Code: Select all

 javac -ea AssertTest.java 

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

Posted: Thu Mar 12, 2015 9:30 am
by admin
No, enabling and disabling of assertions is a run time thing. The question is about compilation.

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

Posted: Sun Mar 27, 2016 6:45 am
by Chen@ukr.net
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?

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

Posted: Sun Mar 27, 2016 10:40 am
by admin
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.

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

Posted: Tue Jun 21, 2016 7:29 am
by leorbarbosa
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 ???

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

Posted: Tue Jun 21, 2016 7:31 am
by leorbarbosa
You can't know what knowledge is being asked. If it is a Java 7 question, why ask about 1.6, 1.5., etc ????

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

Posted: Tue Jun 21, 2016 10:36 am
by admin
You are right. It is not very important to know. Will remove this question.
thank you for your feedback!