I have some doubt ,i want to know that is int π; is a valid syntax in Java Or Not because Java support UNICODE so according to me it can be valid but I want to make sure
Asked
Active
Viewed 239 times
-8
-
syntax for what, identifiers ? – vikingsteve Mar 05 '13 at 10:12
-
2Did you try it? And **why not**? Also even if it is valid _syntactically_, it is not wise because of the _semantics_ to use an `int` with the name `π`. As you might have heard of it, `π` is a mathemathical constant... – ppeterka Mar 05 '13 at 10:12
-
4Should surely be **double** π? Unless you want to redefine it as 3 or something. ;) – Matthew Watson Mar 05 '13 at 10:13
-
Yes, its a valid syntax. reffer this link http://stackoverflow.com/questions/12857340/naming-restrictions-of-variables-in-java – NPKR Mar 05 '13 at 10:13
-
Yes it's a valid variable name. [Refference link][1] [1]: http://stackoverflow.com/questions/12857340/naming-restrictions-of-variables-in-java – NPKR Mar 05 '13 at 10:14
-
Yes it's a valid variable name. [Refference link][1] [1]: http://stackoverflow.com/questions/12857340/naming-restrictions-of-variables-in-java – NPKR Mar 05 '13 at 10:15
1 Answers
7
int π;
is perfectly valid - as you say Java supports unicode so anything not reserved is fair game for identifiers.

Sean Landsman
- 7,033
- 2
- 29
- 33
-
2Still, I would be careful about using 'weird' characters in method names that you expose. Some unit testing frameworks, for example, can freak out about that. Just be careful... – vikingsteve Mar 05 '13 at 10:14
-
1`double π;` is even better, if you do not want to loose precision and do not want to aggravate the mathematicians around you... – Costis Aivalis Mar 05 '13 at 10:22
-
2@CostisAivalis except that a `double` ofcourse also is not infinitely precise, so that it cannot contain the exact value of π. – Jesper Mar 05 '13 at 10:26
-
-
`π` is valid because it's a letter and identifiers may start with a letter, not solely because java supports unicode. `♟` cannot be used in identifiers for example even though it's unicode and not reserved. – Esailija Mar 06 '13 at 12:47