Page 1 of 1

About Question enthuware.ocpjp.v8.2.1342 :

Posted: Wed Dec 16, 2015 9:55 am
by mrmuiz
Explanation says
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)
shouldn't it be
From Java 1.4 onwards, [...] (as opposed to Java 1.3 version [...]
instead?

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

Posted: Wed Dec 16, 2015 10:45 am
by admin
No, "by default" is the key part here.

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

Posted: Wed Dec 16, 2015 10:56 am
by mrmuiz
But in Java 1.4 assert is a keyword

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

Posted: Wed Dec 16, 2015 10:57 am
by admin
It is. But it is not treated as a keyword "by default".

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

Posted: Wed Dec 16, 2015 11:00 am
by admin
As per : https://docs.oracle.com/javase/8/docs/t ... ssert.html
Unless you specifically request source mode 1.4 with the -source 1.4 flag, the compiler operates in source mode 1.3. If you forget to use this flag, programs that use the new assert statement will not compile. Having the compiler use the old semantics as its default behavior (that is, allowing assert to be used as an identifier) was done for maximal source compatibility. Source mode 1.3 is likely to be phased out over time.

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

Posted: Wed Dec 16, 2015 11:00 am
by mrmuiz
I was missing this point, tanks for clarifications!

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

Posted: Thu Jun 23, 2016 3:51 am
by sahoo007tm
The question says

"You have just written a Java class named AssertTest.java that uses the assertion facility."

It does not mention anywhere that the code contains "assert" as an identifier in it.

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

Posted: Thu Jun 23, 2016 8:22 am
by admin
I am not sure I understand your point.
Paul

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

Posted: Thu Jun 23, 2016 8:27 pm
by sahoo007tm
When I read this question I think possible content of AssertTest.java as following.

Do we need to provide the -source option while compiling below class to be able to use the assert?

public class AssertTest{

public static void main(String[] args){
int i=1;
assert i==1: "blah..";
}

}

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

Posted: Thu Jun 23, 2016 8:40 pm
by admin
No, you don't need source option for java 1.4 and above. You should try it out.

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

Posted: Sun Jul 31, 2016 7:18 am
by badbishop
Shouldn't the list of correct answers be updated or generalized? The correct answers end up at 1.6 currently.

Code: Select all

:~$ javac -source 1.8 asserttest/AssertTest.java 
:~$ java -ea -cp /Users/tom asserttest.AssertTest 
Exception in thread "main" java.lang.AssertionError
	at asserttest.AssertTest.main(AssertTest.java:6)

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

Posted: Sun Jul 31, 2016 11:03 am
by admin
Yes, added. Although as noted in the explanation -source switch is not needed.
thank you for your feedback!
Paul.