Java - class name starts with numbers

WhoCares picture WhoCares · May 9, 2018 · Viewed 11k times · Source

I have done my HW already but our instructor wants us to submit our HWs as yourID_BFS_DFS.java. And I can't do that, it returns error. I know that numbers are not Java letters and it is illegal (I checked other answers already) but still I want to ask you guys if there is a way (maybe a trick) to do that or he simply wants us to accomplish something illegal? And if I am not wrong, java language is updated recent days, and maybe it is about that, I don't know really.

B.t.w. I can't reach him to ask, he never replies. That's why I am asking here again.

Answer

kutschkem picture kutschkem · May 9, 2018

The first character needs to be a "Java letter", which includes letters, underscore and dollar sign.

See https://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.8

An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter. [...]

The "Java letters" include uppercase and lowercase ASCII Latin letters A-Z (\u0041-\u005a), and a-z (\u0061-\u007a), and, for historical reasons, the ASCII underscore (_, or \u005f) and dollar sign ($, or \u0024). The $ character should be used only in mechanically generated source code or, rarely, to access pre-existing names on legacy systems. [...]

Letters and digits may be drawn from the entire Unicode character set, which supports most writing scripts in use in the world today, including the large sets for Chinese, Japanese, and Korean. This allows programmers to use identifiers in their programs that are written in their native languages.