Reputation: 73
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
Upvotes: 2
Views: 1032
Reputation: 1
I am new to Java and had the exact same issue, but I managed to figure it out.
I am following a code example in the text book and although it looked identical it would fail at compile. When I downloaded and copied/pasted the code sample from the publisher into my Example.java file in Text editor it would compile fine, so obviously it was something with my code. When I did an undo and went back to my code it failed again. My code is:
/*
This is a simple Java program.
Call this file Example.java.
*/
class Example {
// A Java program begins with a call to main().
public static void main(String args[]) {
System.out.println("Java drives the Web.");
}
}
I installed a different text editor - TextWrangler, set the format to Java at the bottom of the screen, re-wrote the code and it worked fine. I found the quotes in Textedit were slanted and in TextWrangler they were straight.
I don't know enough about it - maybe i had to set the unicode different in textedit or something, but I'm using textWrangler now anyway because it's easier to read the code because it highlights by colour.
Hope it helps.
Upvotes: 0
Reputation: 926
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.
Upvotes: 5