Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

What are valid characters to use in an identifier?

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a study guide I was reading it states.
An identifier can begin with a letter, a dollar sign ($), or an underscore character (_).
I did not see much on this in the K & B book.
Is this going to be covered in the exam?
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The valid characters in an identifiers are all alphabets, numbers, dollar sign($) and underscore(_). Though an identifier can contain a numeric value but can not start with a number. Yes it is in the exam objectives and hence in the exam.
[ May 21, 2003: Message edited by: Anupam Sinha ]
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
to be more specific... it can be ANY currency symbol... ex. $ � � �
The objective states "Identify all Java programming language keywords and correctly constructed identifiers."
So I believe that means it can ask you questions like:
Which of the following are valid identifiers: (choose 6)
a.) alpha
b.) �eta
c.) �ow
d.) 2uesday
e.) _MINI
f.) Java1
g.) goto
h.) micro$oft
i.) app!es
[ May 21, 2003: Message edited by: Jessica Sant ]
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why is �eta a valid identifier
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So � in �eta is a currency char? I didn't recognize it but it compiled and ran fine.
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so $ is not allowed axcept in first position?
what about _ (underscore)?
 
Brett Turner
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Barkat Mardhani:
so $ is not allowed axcept in first position?
what about _ (underscore)?


'$' can be anywhere in the identifier. same with '_'
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In that case which three are not valid. I figure 2uesday and goto....what about third one?
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh I see it now apple is a bad app!e .....
[ May 21, 2003: Message edited by: Barkat Mardhani ]
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by S Goyal:
why is �eta a valid identifier


because � is an alphabetic character (maybe not in English -- but it is in Greek)
 
stable boy
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have any doubt what characters can be used then you check if the letter is a Java Letter.
You can check that a Java Letter can be used at the start of the identifier, when the method Character.isJavaIdentifierStart returns true.
You can check that a Java Letter can be used at any place in the identifier when the method Character.isJavaIdentifierPart returns true.
 
S Goyal
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx thomas
but how do u i know when writing the exam!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jessica Sant:

because � is an alphabetic character (maybe not in English -- but it is in Greek)


In fact, "�" is not Greek but German. But nowadays it must be officially be written as "ss".
 
reply
    Bookmark Topic Watch Topic
  • New Topic