Search code examples
javamacosterminalosx-mavericks

Nothing with quotes seems to work in Java


Everytime I try to do....

System.out.println("Hello World");

Then it gives an error saying "; expected" I am lost to the point that I want to give up on this . Java seems to work fine in Eclipse and Netbeans but in the Mac Terminal it keeps giving this problem

I even tried this

String s = "Hello World";
System.out.println(s);

But it gives "illegal character" error on the String s line . HOW IS " \" " AN ILLEGAL CHARACTER!

This problem has started arising since the time I updated to Mavericks

My specifications:

JAVA VERSION 
{ 
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
}

Running from TERMINAL on OSX MAVERICKS


Solution

  • I believe it has something to do with your code editor. If you use a simple text editor rather than a code editor, your quote characters might be replaced with similar looking unicode characters that will make your code uncompilable.

    Solution: make sure you use an established code editor.

    EDIT: As you can see here, the "illegal character" error will pop up when you use an invalid Unicode character in the code.