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

chris juillard
chris juillard
158 Points

What is a compiler error? I am trying the challenge from Java Basics, task.

The task is #2. call the printf, the code I used was. string fristName = "Chris"; console.printf("Hello, my name is %s\n", firstName); console.printf("%S is learning how to write Java\n", firstName); console.printf("%S can code in Java!\n", firstName);

Name.java
// I have setup a java.io.Console object for you named console
    string fristName = "Chris";
    console.printf("Hello, my name is %s\n", firstName);
    console.printf("%S is learning how to write Java\n", firstName);
    console.printf("Chris can code in Java!\n");

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Chris,

First off, I think you have too much code there for the second task. Challenges are very specific and very picky.

But, as to your question... you say it's for Task Two, but the Compiler Error (When the Java compiler doesn't understand what you have entered) is stemming from the code for Task one. This would have prevented you from even passing Task One, so I am assuming you altered the code from Task one after you passed?

The string declaration has two errors in it: one a syntax, which will result in a Compiler Error... and one a typo, which will throw an error from the code checker:

  1. "string" needs to be a capital "S" otherwise Java won't recognize the type.
  2. The name of the variable is misspelled.

You'll need to fix that up to get by the First Task again, and also the Second Task. Unless you are explicitly instructed to do so, don't alter code you already have entered on a previous task (or any preloaded code).

Task Two asks you only to

Call the printf method on the console object and make it write out "<YOUR NAME> can code in Java!"

which is this line in your code above. (Also, the challenge did not ask for a new line to be inserted, but for this challenge it will still pass with it there. However, this will cause most other challenges to produce a Bummer, because it wasn't asked for.

console.printf("Chris can code in Java!\n");

Now for the Third Task, this is one of the time that you are instructed to alter a line of code you already wrote. You need to change the line of code above to the second printf line you have... with one correction. The placeholder needs to be lower case (`%s not %S) or you will get another Compiler Error.

Just fix that up and you're good to go.

Keep coding! :) :dizzy:

chris juillard
chris juillard
158 Points

Thank you. You talk about having to much code, i have tried to remove one of the lines and just use the printf with my chris like is said. then i get another code so i dont know what to do. i have tried the %s with upper and lower case but then it did not make a difference at all. with line 2 i did what your asking it coded out again. i am so brand new to all this i dont know anything about anything so what are you asking i still have no idea why it keeps happening bc i have done everything you are asking.

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

The entire challenge (all three tasks) will only have 2 lines of code:

String firstName = "Chris";
console.printf("%s can code in Java!", firstName);

If you notice the typo corrections from your code, the proper sentence the challenge is asking for (including the Exclamation mark that was also missing in your code). And, yes %s and %S does matter. The compiler will not accept a capital 'S' as that is the incorrect syntax in Java.

If you are very new to coding, I wouldn't recommend jumping into a complex language like Java. Here on Treehouse, you should definitely start off with the Digital Literacy Track before anything else, as this will give you the basics needed to move forward. After that, maybe some HTML, CSS, and JavaScript (no that is not the same as Java). After that, if Java is your goal, then you could move there. Backend languages get very complex very quickly, and without at least basic knowledge of coding... it could get quite overwhelming quite fast.

Keep Coding and Good luck! :) :dizzy: