About Question enthuware.ocajp.i.v7.2.1297 :

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

Moderator: admin

Post Reply
ETS User

About Question enthuware.ocajp.i.v7.2.1297 :

Post by ETS User »

Hello, folk, and thank you for the great work.

In this question, the third option says "angstrom", but the comment to it declares "All unicode characters are valid". Did you mean to put there a single unicode letter 0x00E5 ?

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

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Post by admin »

Yes, but since some users had difficulty in displaying it, it was changed to a regular a.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Guest

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Post by Guest »

That sort of dries the juice out of the question, doesn'it? The note about "all unicode characters" is useful in any case, and I am grateful.
:-)

SirZed
Posts: 7
Joined: Sun Apr 07, 2013 9:45 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Post by SirZed »

Isn't there a contradiction between these statements?
"All unicode characters are valid."
"No special chars except $ and _ are allowed."

The first one would indicate that @ is valid, since it is an unicode character.
Or is there a list of special characters that aren't allowed?

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

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Post by admin »

Unicode characters are written using \u syntax. For example, \uD800. $ and _ are just ascii characters.

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

SirZed
Posts: 7
Joined: Sun Apr 07, 2013 9:45 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Post by SirZed »

So @ is valid if written as \u0040 ?

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

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Post by admin »

Sorry, I misunderstood your question. I see what you mean. No, it would not be valid.

The complete rule is as follows (added to the explanation now):

As per JLS section 3.8: A valid identifier must start with a Java letter followed by a Java letter or a digit.

A "Java letter" is a character for which the method Character.isJavaIdentifierStart(int) returns true.

A "Java letter-or-digit" is a character for which the method Character.isJavaIdentifierPart(int) returns true.

The "Java letters" include uppercase and lowercase ASCII Latin letters A-Z (\u0041-\u005a), and a-z (\u0061-\u007a), and, for historical reasons, the ASCII underscore (_, or \u005f) and dollar sign ($, or \u0024). The $ character should be used only in mechanically generated source code or, rarely, to access pre-existing names on legacy systems.

The "Java digits" include the ASCII digits 0-9 (\u0030-\u0039).

Letters and digits may be drawn from the entire Unicode character set, which supports most writing scripts in use in the world today, including the large sets for Chinese, Japanese, and Korean. This allows programmers to use identifiers in their programs that are written in their native languages.

An identifier cannot have the same spelling (Unicode character sequence) as a keyword (§3.9), boolean literal (§3.10.3), or the null literal (§3.10.7), or a compile-time error occurs.

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

pfilaretov
Posts: 35
Joined: Mon Jul 28, 2014 2:05 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Post by pfilaretov »

Isn't there a contradiction between these statements?

1. The "Java letters" include uppercase and lowercase ASCII Latin letters A-Z (\u0041-\u005a), and a-z (\u0061-\u007a), and, for historical reasons, the ASCII underscore (_, or \u005f) and dollar sign ($, or \u0024).

2. Letters and digits may be drawn from the entire Unicode character set

pfilaretov
Posts: 35
Joined: Mon Jul 28, 2014 2:05 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Post by pfilaretov »

what about the question above?

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

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Post by admin »

I don't think there is any contradiction. Specially if you read the complete section in its entirety. It clearly says, "A "Java letter" is a character for which the method Character.isJavaIdentifierStart(int) returns true."

Statement 1 that you've quoted is just an elaboration. Also, it says "includes". It is not an exhaustive list.

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

boonnick
Posts: 9
Joined: Fri Jan 31, 2014 8:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Post by boonnick »

re special characters, isn't it currency signs in general that are allowed rather than just $. E.g. int £ = 10; is ok?

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

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Post by admin »

What happened when you tried it?
If you like our products and services, please help us by posting your review here.

boonnick
Posts: 9
Joined: Fri Jan 31, 2014 8:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Post by boonnick »

Well it works, I was really asking about the principle behind it working. If you can confirm that currency signs in general are allowed this would be a useful rule of thumb.

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

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Post by admin »

Although the JLS doesn't specify the rule in these terms, it is clear that all currency signs are valid because they belong fall under the rule:
A "Java letter" is a character for which the method Character.isJavaIdentifierStart(int) returns true.
A "Java letter-or-digit" is a character for which the method Character.isJavaIdentifierPart(int) returns true.

You may check this out : http://docs.oracle.com/javase/specs/jls ... ml#jls-3.8
If you like our products and services, please help us by posting your review here.

boonnick
Posts: 9
Joined: Fri Jan 31, 2014 8:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Post by boonnick »

Ah thanks!

pfilaretov
Posts: 35
Joined: Mon Jul 28, 2014 2:05 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Post by pfilaretov »

admin wrote:Statement 1 that you've quoted is just an elaboration. Also, it says "includes". It is not an exhaustive list.
This elaboration confused me. Now it's clear, thank you.

Post Reply

Who is online

Users browsing this forum: Google [Bot], marpiva and 30 guests