Win a copy of Practical SVG this week in the HTML/CSS/JavaScript 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
Sheriff
Posts: 15715
73
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
Marshal
Posts: 52636
119
  • 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.
 
The moth suit and wings road is much more exciting than taxes. Or this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!