Is it allowed to name a string e.g. 0_Ahnung?
Asked
Active
Viewed 132 times
-5
-
Do you mean the string's content or its name? – TDG Nov 12 '16 at 09:56
-
You can have the *content* of the string be anything you want: `String myString = "0_Ahnung";` is OK. However that's *not* allowed for the *name* of the string: `String 0_Ahnung = "myString";` isn't OK. It's not clear which you're asking about. You could of course have found this out by **simply trying it**. – jonrsharpe Nov 12 '16 at 09:57
-
1beside trying as @jonrsharpe suggested you could also read the free tutorials: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/index.html – Timothy Truckle Nov 12 '16 at 09:59
-
"0_Ahnung" is German and means "0_knowledge". Something is wrong with this question... – ventiseis Nov 12 '16 at 13:06
2 Answers
4
Yes, a string can begin with a digit. A variable cannot.
String myString = "0_abc";
is a valid string.
String 0_abc = "aaa";
is not a valid defenition.

TDG
- 5,909
- 3
- 30
- 51
3
The answer is found in section 3.8 of the Java Language Specification - which clearly states that the first character of a Java identifier name (such as a variable name) cannot be a digit.

Dawood ibn Kareem
- 77,785
- 15
- 98
- 110