Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

valid identifier

 
pras
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
newState


is this a valid identifier? because it contains new
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is. but if you leave space between new State then it is not.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is valid. myClass is valid, myStaticBoots is valid, myAbstractDog is valid. newYork is also valid As long as the given name is not a reserved keyword.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you write a small program with a variable named "newState", try to compile it and see what the compiler says?
 
pras
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you mean to say that newState is valid because it is not a keyword, even if new is keyword and it is part of identifier?

and one more thing guys, how do you identify whether ti use lowercase or uppercase letters when declaring variables?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Names are usually consisting of word, whose first letter is upper-case.
Like "isRainFalling", "carColour", "dayOfMonth"....
 
pras
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is carcolor and Carcolor valid?
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both "Carcolor" and "carcolor" will get past the compiler as valid identifiers, but (as you already know) they don't match the coding conventions for people who have to read the code.
 
pras
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you mean to say it is a set standard?

not a strict rule or error?


thank you so much.


i am learning so much from here
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can check some common naming conventions here :
http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html#367

Note that this is mandatory, but it really helps to make your code clean and readable to others.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic