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 trialJan Lundeen
5,887 PointsWhy am I receiving a syntax error on the lines that run the compiler?
When working on challenge 2 of 3 (Call the printf method on the console object and make it write out "<YOUR NAME> can code in Java!")
for Strings and Variables in Java Basics, I got a syntax error after entering the following code:
String firstName = "Jan"; console.printf =(“Jan can code in Java!/n”);
javac Name.java Java Name
Bummer: There is a compiler error. Please click on preview to view your syntax errors.
Output.html:
JavaTester.java:75: error: ';' expected javac Name.java ^ JavaTester.java:76: error: ';' expected Java Name ^
2 errors
I hit enter after Java Name. Then, I clicked the Check Work button. It sounds like I'm not running the compile command properly. However, it's my understanding that compile commands do not need ; after each command.
Any ideas of how to correct this?
Thanks,
Jan
3 Answers
Jan Lundeen
5,887 PointsHi Steven,
I corrected the quotes, entered my compiler commands and hit the button to check my work. I checked my quotes and the look correct. I'm not sure why I'm still getting compiler errors. Please see the errors below.
JavaTester.java:73: error: ';' expected console printf ("Jan can code java!/n"); ^ JavaTester.java:74: error: ';' expected javac Name.java ^ JavaTester.java:75: error: ';' expected java Name// I have setup a java.io.Console object for you named console ^ 3 errors
I entered a separate question so it would pull in my code rather than me pasting my code to the question. That way, you can see what I actually typed in for the question. I'm wondering if something got corrupted.
Thanks,
Jan
Steven Parker
231,269 PointsThe two errors are:
- there should not be a "=" symbol between "printf" and the parentheses
- the quotes around the "printf" string are the wrong kind
Quotes can be either "curly" quotes (word-processor type) or normal (programmer type). Only the normal kind are recognised by most languages. The difference can be subtle, here they are in a larger font:
" use these, not these “
Also note that the quotes around "Jan" are the right kind.
Jan Lundeen
5,887 PointsHi Steven,
Thanks for your answer! It looks like I got rid of one error, but another one remains.
I took out the "=" symbol on the console printf statement. However, I can only type double quotes one way on my keyboard. I hit shift and the button with " and ' listed on it. How do you get the first quote to go the right way? How would I get programmer quotes?
Here is what I entered and the errors:
String firstName = "Jan"; console.printf (“Jan can code in Java!/n”);
javac Name.java Java Name
Bummer: There is a compiler error. Please click on preview to view your syntax errors! I clicked preview and got this error:
JavaTester.java:73: error: ';' expected console printf ("Jan can code in Java!/n"); ^ 1 error It seems like this error is saying that I forgot to put a ";" after one of the statements. Can you clarify this for me?
Thanks!
Jan
Steven Parker
231,269 PointsI don't know how you made them, but the quotes around the first "Jan" are the correct kind. If you just copy one and paste it over both of the ones in the last string, it will pass the challenge.
For future work, you should figure out how you originally created the quotes around "Jan" and use that kind for all coding.
Steven Parker
231,269 PointsSteven Parker
231,269 PointsTo make pasted code look right, use Markdown formatting.
Steven Parker
231,269 PointsSteven Parker
231,269 PointsJan Lundeen — Glad to help. But normally, one would choose a "best answer" on the answer the contained the information that helped most to solve the issue!
(You can always change that choice )