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 Java Basics Getting Started with Java Strings, Variables, and Formatting

Java tester? What is it saying?

I've never seen a Java tester or editor before. It's trying to tell me what's wrong but I don't understand what it wants. I think my statement is identical to the statements we made during the video. Do the carets mean the mistake is in that place? If so, I cannot see a mistake there. Please point out my errors so that I can progress. Thanks for your help. Last time I asked for help, the code attached was for the first task. Please note, I am on the third task. I have copied my code and the editor output below to be sure you see what I see. Code: String firstName = "Dee"; [First task, approved] console.printf"<YOUR NAME> can code in Java!\n"; [Don't know why it insisted on <YOUR NAME>, which is not what we did in the video, but approved] console.printf("%s can code in Java!\n", firstName); [Third task returns errors below]

Editor says: JavaTester.java:74: error: not a statement console.printf" can code in Java!\n"; ^ JavaTester.java:74: error: ';' expected console.printf" can code in Java!\n"; ^ Thanks again for your help.

Name.java
// I have setup a java.io.Console object for you named console
String firstName = "Dee";
console.printf"<YOUR NAME> can code in Java!\n";
console.printf("%s can code in Java!\n", firstName);

2 Answers

andren
andren
28,558 Points

The caret in the error message is indeed pointing at the place where Java thinks the error occurred. The issue with your code is that you forgot to wrap parenthesis around the arguments for your first printf call.

Take a close look at the parenthesis you have on your second printf (which is correct) and compare it to the first. If you add them around the argument then your code will work.

Yup, of course that was it. It shows that looking at it a hundred times I could still see what I thought I wrote instead of what was there. I still don't understand why the editor is pointing the caret at the dot in console.printf. I hope future videos introduce us to the editor and its workings. My experience with programming is very slim and decades old. Also, the line that has the error was okayed during the second task, then became the problem on the third task. But that can just be the nature of code. It was disappointing to be so stuck on the very first assignment so thanks much for your help.

andren
andren
28,558 Points

I still don't understand why the editor is pointing the caret at the dot in console.printf.

The error message that went with that "not a statement" would suggest that Java though that you were trying to execute the command console.printf on it's own, which as it states is not a meaningful statement. That's also why it states that you are missing a closing semicolon. It thinks you meant the line to look like this console.printf; Since it took the opening quote as being the start of a new separate statement.

Java is a complex language which tends to become quite confused if your code does not perfectly conform to it's expectations.

I hope future videos introduce us to the editor and its workings.

The error message is technically not really a part of the editor, it comes from the Java compiler itself. Which would be present no matter where you were using Java.

Also, the line that has the error was okayed during the second task, then became the problem on the third task.

This on the other hand is more of a problem with the editor than with Java itself. The code checker that these challenges use can be at times very picky (not accepting acceptable code as correct) but at other times it can also let a bad solution though due to bad testing criteria.

But that can just be the nature of code.

The code only went though due to the way the code checker verified the task, if you ran the code though the Java compiler it would fail, always. Java is a pretty strict language.

It was disappointing to be so stuck on the very first assignment so thanks much for your help.

The beginning is usually the hardest part, especially with something like Java where a lot of the complex concepts have to be thought upfront due to how fundamental they are to the language.

But I'm sure you'll get the hang of it, it just takes a bit of practice.

It's really kind of you to answer again and help me this much. Thank you very much, Andren. Peace, Dee