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.
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.
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.
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?
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.
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.
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.
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.
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."
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?
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.