Search code examples
javasyntaxsemanticslexical-analysis

Lexical, Syntactical, or Semantic Error differences in Java


I'm practicing lexical, syntactical, and semantic differences (using Java language). For the set below I wanted to identify if they are lexical, syntactical, or semantic errors. Just wanted to make sure I am doing them right and wanted some feedback.

a) double if;             Syntactical Error
b) doif (1 ==1);          Syntactical Error
c) x12 = “x12”;           Semantic Error
d) int double = 1.0;      Syntactical Error
e) 0-;                    Syntactical Error
f) int a = 09 – 90;       Syntactical Error
g) int $10 = 10;          No Error
h) char $dollar = ‘$’;    No Error

I feel like I am missing something in the last two. I checked using Eclipse though and it is not showing any errors. Is it really "no error"?


Solution

  • "No error" is indeed correct. The dollar sign is permissible in -- including at the start of -- Java identifiers (although the JLS recommends that it's only used in mechanically-generated code or to access pre-existing names on legacy systems).