-5

Is it allowed to name a string e.g. 0_Ahnung?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • 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
  • 1
    beside 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 Answers2

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