Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Isam Al-Abbasi
Isam Al-Abbasi
2,058 Points

Hello World on Mac not working!!

Hello everyone, please note that I was trying to print Hello world on my mac using Text edit & terminal but it's not working for some reason? here is my class:

public class HelloWorld {
    public static void main(String[] args){
    System.out.printf(Hello World!);
    }
}

When I'm trying to save the file on desktop I add java extension to the name HelloWorld.java but I gets saved without .java extension so I have to rename it and once I do and try to compile I keep getting the below error:

Last login: Mon Apr 11 09:36:33 on ttys001 Apples-MacBook-Air:~ apple$ cd desktop Apples-MacBook-Air:desktop apple$ javac HelloWorld.java HelloWorld.java:3: error: illegal character: '\u201c' System.out.printf(“Hello World!”); ^ HelloWorld.java:3: error: ';' expected System.out.printf(“Hello World!”); ^ HelloWorld.java:3: error: not a statement System.out.printf(“Hello World!”); ^ HelloWorld.java:3: error: ';' expected System.out.printf(“Hello World!”); ^ HelloWorld.java:3: error: illegal character: '\u201d' System.out.printf(“Hello World!”); ^ 5 errors Apples-MacBook-Air:desktop apple$

7 Answers

Maria Nygren
Maria Nygren
10,021 Points

Have you tried saving your file in UTF-8 format?
Saving a Text File in UNICODE UTF-8 Format - Scroll down to the last example

It could have to do with your text editor. I think it's changing your quotation marks to another unicode character. That means your text editor it's using another type of encoding than UTF-8, which is the encoding I think you might need to be able to run your java files. If you're new to programming this might be a little confusing at first, but it's something you have to be aware of.

Maybe you should try and use an IDE like Eclipse instead? I'm using Eclipse Luna and it's working great for me. I'm on Windows and have never tried to install it on a mac, but you could try this youtube-tutorial on how to install Eclipse Luna for MAC OS X.

If you want to know more about character encoding...
https://en.wikipedia.org/wiki/UTF-8
https://en.wikipedia.org/wiki/Unicode
https://en.wikipedia.org/wiki/Character_encoding

Isam Al-Abbasi
Isam Al-Abbasi
2,058 Points

Same error with UTF-16!! let's see if Craig Dennis can give us a little help :)

Maria Nygren
Maria Nygren
10,021 Points

Hi Isam,

I think you might be getting this error because of the quotation marks. You should use neutral quotation marks http://www.fileformat.info/info/unicode/char/0022/index.htm which has the unicode U+0022

If you look at the error you can see that it has to do with "illegal characters" , u201c and u201d.
u201d is the unicode for a right double quotation mark http://www.fileformat.info/info/unicode/char/201d/index.htm and u201c is for the left double quotation mark http://www.fileformat.info/info/unicode/char/201c/index.htm

Isam Al-Abbasi
Isam Al-Abbasi
2,058 Points

Hello Maria, thank you for your answer. But I'm not really familiar with quotations marks just yet and following your link didn't help me :D I'm sorry but I'm new to programming and I don't think I'm really do dive into quotation marks just yet!! I watched video on Youtube and I did exactly the same and I was able to print Hello World but it's not working now!! The question is where can I change these quotation marks you were referring to please?

Thank you

Isam Al-Abbasi
Isam Al-Abbasi
2,058 Points

Ok I understand now, even though I did the format to UNICODE UTF-8 when I saved the file but I will re-do the whole process and hope it will work.

I will let you know the results :)

Maria Nygren
Maria Nygren
10,021 Points

If that doesn't work. Try UTF-16 , if you have that as an option in your text editor.

Isam Al-Abbasi
Isam Al-Abbasi
2,058 Points

Still not working, btw I do have NetBeans on my mac and it's working. but I just wanted to see if I can do that on text editor!!

I will see UTF-16 and give it one last shot.