• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Correctly specified Identifiers

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Almost every book (the exception is Kahil & Rasmussen states that a correctly formed indentifier starts with an underscore, $, or letter (broadly conceived because of Unicode--I can't wait for a multi-lingual IDE that let's me use Chinese glyphs as identifiers--imagine single character meaningful identifiers that create built in job security! .
However, it turns out that _any_ currency symbol can be used to start an identifier which includes (in my character set) �, �, and � as well as $. But I don't know what to make of this with regard to the test because the "wrong" information is so often repeated.
We MacOS users are waiting for Java 2 with the release of MacOS X (10) so I'm using JDK 1.1.8. Can someone confirm that this is indeed the case in JDK 1.2.x--it works fine for me in JDK 1.1.8 (not that I'm going to start beginning my identifiers with � any time soon)? I'm more interested in terms of implication for the SCJP2 test.
Thanks.
Steve Butcher
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Steve,
That's an interesting observation indeed.
You can be assured such questions will not come for the SCJP test. What you will need to remember are the rules for valid identifiers formed with ascii characters only. ie., it can start with an underscore, $ or a letter and can contain numbers. No spaces, cannot be the same as a keyword.
Test questions are pretty simple, and there may not be more than max 3 questions on keywords and legal identifiers.
Hope that comforts you.
Ajith
 
sgwbutcher
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.
Until I hear differently, I'm going to assume that the $ sign definition is sufficient for the SCJP2 exam.
However, it is interesting to note:
The other currency signs are ASCII characters: � (180), � (163), and � (162).
The definition of "letter" is a little loose. � and � work in identifiers but Capital Delta *, Capital Sigma *, and Lowercase Delta* don't even though they are Greek letters although often used as mathematical symbols. [Actually they didn't show up on the webpage so maybe ASCII and Latin-1 are not the same, see below]
I thought that the first 256 characters of Unicode and Latin-1 were the same; maybe Latin-1 and ASCII 8-bit aren't the same. Who picks what is and isn't a letter? Sun or the vendor?
(To a mathematician programming something in Java, (Capital Sigma)squares is great identifier as is (Capital Delta)x but they are both invalid. )
Thanks again.
Steve
[This message has been edited by sgwbutcher (edited June 02, 2000).]
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Steve,
Here's what I found in the section 3.8 of JLS


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 Java programmers to use identifiers in their
programs that are written in their native languages.
A Java letter is a character for which the method
Character.isJavaLetter (�20.5.17) returns true. A Java letter-or-
digit is a character for which the method
Character.isJavaLetterOrDigit (�20.5.18) 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 Java code or, rarely, to access
preexisting names on legacy systems.
The Java digits include the ASCII digits 0-9 (\u0030-\u0039).


You can indeed use all those characters that youlove most .
I think this addresses all of your issues( or does it ? ). I was little lazy to look into JLS before.
Ajith
 
sgwbutcher
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It does and it doesn't.
No identifier with a greek letter would compile. This leads me to believe that they are being treated as "symbols" by whatever the actual Apple implementation of the JVM/JDK is. It may be because you cannot be guaranteed that any particular typefcea has implemented the complete ASCII character set. I'll ask on the MRJ forum.
It doesn't answer then why �, �, and � work as they are not "letters" per se. But it doesn't really matter, the main idea is that you _can_ start an identifer with these as well as the others.
BTW, I tried that link to the JLS last night, it was for Java 1.0 plus 1.1 updates. I could have sworn someone posted a link for a PDF Draft of the Java 1.2 JLS but I can't find it. Maybe it was a dream....
Thanks again.
Steve
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Steve,
I also came across the doubt SAME as yours during my SCJP preparation. From what I analyzed,
an identifier can start with any letter provided Character.isJavaIdentifierStart(char ch) of that char val returns true .
In order to verify this I wrote a small program. Please see this. Since a char has value range from \u0000 to \uffff,
I didn't put the WHOLE range as input for this prog. Just verified with 0 to 255 and got the result as follows. After seeing the result
I also used some of the chars which returned true for the above Character.isJavaIdentifierStart(char c) method. The compiler accepts them a valid identifiers and prints the content also. I tested with WIN98 using JDK1.2.2.
regds
maha anna
<pre>

class Test {
public static void main(String[] args) {
String \u0391\u0430 = "steve";
//String \u0000\u0001 = "ajith"; //compile error invalid char
String \u0024\u0041 = "ajith"; //This is VALID
String \u00ff\u00fe = "maha";
System.out.println(\u0391\u0430);
System.out.println(\u0024\u0041);
System.out.println(\u00ff\u00fe);
for(int i=0; i<0xff; i++) {
char c = (char)i;
if(Character.isJavaIdentifierStart(c))
System.out.println("Char with decimal val="+(int)c+ " is VALID START");
}
/*
System.out.println(Character.isJavaIdentifierStart('\u0391'));//true
System.out.println(Character.isJavaIdentifierStart('\u0041'));//true
System.out.println(Character.isJavaIdentifierStart('\u0061'));//true
System.out.println(Character.isJavaIdentifierStart('\u0430'));//true
System.out.println(Character.isJavaIdentifierStart('\udddd')); //false
System.out.println(Character.isJavaIdentifierStart('\ueeee')); //false
System.out.println(Character.isJavaIdentifierStart('\uffff')); //false
*/
}
}

</pre>
output
<pre>

steve
ajith
maha
Char with decimal val=36 is VALID START
Char with decimal val=65 is VALID START
Char with decimal val=66 is VALID START
Char with decimal val=67 is VALID START
Char with decimal val=68 is VALID START
Char with decimal val=69 is VALID START
Char with decimal val=70 is VALID START
Char with decimal val=71 is VALID START
Char with decimal val=72 is VALID START
Char with decimal val=73 is VALID START
Char with decimal val=74 is VALID START
Char with decimal val=75 is VALID START
Char with decimal val=76 is VALID START
Char with decimal val=77 is VALID START
Char with decimal val=78 is VALID START
Char with decimal val=79 is VALID START
Char with decimal val=80 is VALID START
Char with decimal val=81 is VALID START
Char with decimal val=82 is VALID START
Char with decimal val=83 is VALID START
Char with decimal val=84 is VALID START
Char with decimal val=85 is VALID START
Char with decimal val=86 is VALID START
Char with decimal val=87 is VALID START
Char with decimal val=88 is VALID START
Char with decimal val=89 is VALID START
Char with decimal val=90 is VALID START
Char with decimal val=95 is VALID START
Char with decimal val=97 is VALID START
Char with decimal val=98 is VALID START
Char with decimal val=99 is VALID START
Char with decimal val=100 is VALID START
Char with decimal val=101 is VALID START
Char with decimal val=102 is VALID START
Char with decimal val=103 is VALID START
Char with decimal val=104 is VALID START
Char with decimal val=105 is VALID START
Char with decimal val=106 is VALID START
Char with decimal val=107 is VALID START
Char with decimal val=108 is VALID START
Char with decimal val=109 is VALID START
Char with decimal val=110 is VALID START
Char with decimal val=111 is VALID START
Char with decimal val=112 is VALID START
Char with decimal val=113 is VALID START
Char with decimal val=114 is VALID START
Char with decimal val=115 is VALID START
Char with decimal val=116 is VALID START
Char with decimal val=117 is VALID START
Char with decimal val=118 is VALID START
Char with decimal val=119 is VALID START
Char with decimal val=120 is VALID START
Char with decimal val=121 is VALID START
Char with decimal val=122 is VALID START
Char with decimal val=162 is VALID START
Char with decimal val=163 is VALID START
Char with decimal val=164 is VALID START
Char with decimal val=165 is VALID START
Char with decimal val=170 is VALID START
Char with decimal val=181 is VALID START
Char with decimal val=186 is VALID START
Char with decimal val=192 is VALID START
Char with decimal val=193 is VALID START
Char with decimal val=194 is VALID START
Char with decimal val=195 is VALID START
Char with decimal val=196 is VALID START
Char with decimal val=197 is VALID START
Char with decimal val=198 is VALID START
Char with decimal val=199 is VALID START
Char with decimal val=200 is VALID START
Char with decimal val=201 is VALID START
Char with decimal val=202 is VALID START
Char with decimal val=203 is VALID START
Char with decimal val=204 is VALID START
Char with decimal val=205 is VALID START
Char with decimal val=206 is VALID START
Char with decimal val=207 is VALID START
Char with decimal val=208 is VALID START
Char with decimal val=209 is VALID START
Char with decimal val=210 is VALID START
Char with decimal val=211 is VALID START
Char with decimal val=212 is VALID START
Char with decimal val=213 is VALID START
Char with decimal val=214 is VALID START
Char with decimal val=216 is VALID START
Char with decimal val=217 is VALID START
Char with decimal val=218 is VALID START
Char with decimal val=219 is VALID START
Char with decimal val=220 is VALID START
Char with decimal val=221 is VALID START
Char with decimal val=222 is VALID START
Char with decimal val=223 is VALID START
Char with decimal val=224 is VALID START
Char with decimal val=225 is VALID START
Char with decimal val=226 is VALID START
Char with decimal val=227 is VALID START
Char with decimal val=228 is VALID START
Char with decimal val=229 is VALID START
Char with decimal val=230 is VALID START
Char with decimal val=231 is VALID START
Char with decimal val=232 is VALID START
Char with decimal val=233 is VALID START
Char with decimal val=234 is VALID START
Char with decimal val=235 is VALID START
Char with decimal val=236 is VALID START
Char with decimal val=237 is VALID START
Char with decimal val=238 is VALID START
Char with decimal val=239 is VALID START
Char with decimal val=240 is VALID START
Char with decimal val=241 is VALID START
Char with decimal val=242 is VALID START
Char with decimal val=243 is VALID START
Char with decimal val=244 is VALID START
Char with decimal val=245 is VALID START
Char with decimal val=246 is VALID START
Char with decimal val=248 is VALID START
Char with decimal val=249 is VALID START
Char with decimal val=250 is VALID START
Char with decimal val=251 is VALID START
Char with decimal val=252 is VALID START
Char with decimal val=253 is VALID START
Char with decimal val=254 is VALID START

</pre>

[This message has been edited by maha anna (edited June 02, 2000).]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Missed one.
 
sgwbutcher
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
maha anna...what can I say? Incredible.
I found out about the Uppercase Delta and Sigma, they are called, in Unicode, the "Increment" and "Summation over N" symbols despite the fact that they look like well known Greek letters...
Only mu works...too bad. It seems really odd that ? is a valid starting character. I think I'll go lie down now.
Steve Butcher
[This message has been edited by sgwbutcher (edited June 03, 2000).]
 
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic