2

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.

WhoCares
  • 225
  • 1
  • 5
  • 16
  • 6
    Java class names cannot start with numbers. Maybe he wants an alphabetic ID? Not sure what "ID" precisely means at your educational institution. – k_ssb May 09 '18 at 09:15
  • 1
    Maybe he just wants you to rename the file before submitting it, then he will remove the prefix before compiling it. – Arnaud May 09 '18 at 09:17
  • Just a bit dfferent, you can try submit as `class Three1120298466_BFS_DFS`. – Harshit May 09 '18 at 09:19
  • It's not a good way to do it, but you could start with an underscore. – Federico klez Culloca May 09 '18 at 09:19
  • 5
    Ask your instructor aboud this. If they don't provide details, just use `_` as prefix befor your id, it's a common practice. – lexicore May 09 '18 at 09:19
  • 1
    @Downvoter What exactly is the problem with this question? Seems perfectly valid for me. – lexicore May 09 '18 at 09:21
  • 1
    @egazi not to detract from your feelings but "everyone" is three people, against 5 that actually gave you advice :) – Federico klez Culloca May 09 '18 at 09:21
  • use underscore _! – Kovacic May 09 '18 at 09:22
  • I agree with all of you but I think he has some kind of script file to evaluate everyone's HWs, and he especially wrote down that to the handout: "Save your file as yourID_ BFS_DFS.java and upload only yourID_ BFS_DFS.java file" – WhoCares May 09 '18 at 09:22
  • @lexicore An image of code often attracts down votes. – Ivar May 09 '18 at 09:26
  • Sounds like your instructor likes to write code with notepad. I'd use a proper class name, then just for submission rename the file using a filemanager, not touching the class name. – zapl May 09 '18 at 09:28
  • @Ivar Image usage is OK in this case - it shows the error the OP get in the IDE. – lexicore May 09 '18 at 09:28

2 Answers2

4

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.

kutschkem
  • 7,826
  • 3
  • 21
  • 56
0

Not possible to begin java class with number. I guess he means you should do it in this format "IDxxxxxx_BFS_DFS"

But the best way to understand is ask him for clarifications.

GlobalCitezen
  • 59
  • 1
  • 6