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

Kleomenis Rousias
Kleomenis Rousias
196 Points

For some reason my program won't compile.

This program is giving errors for some reason. Also i have some experience with java from other websites and this course seems to be using a somewhat different java(for example instead of System.out.println it uses console.printf and etc).

Name.java
// I have setup a java.io.Console object for you named console
public class Name{
  public static void main(String [] args){
    String firstName = "kleomenis";
    console.printf(firstName);
  }
}

1 Answer

andren
andren
28,558 Points

For these challenges Treehouse has setup the workspace such that they take care of a lot of the boilerplate code for you. You are therefore not meant to add things like classes of methods (unless prompted to do so in the task instructions) but instead just add the line of code that will accomplish what is asked. For the first task for example that asks you to create a name string they simply want this code:

String firstName = "kleomenis";

Nothing more than that.

Another thing to be noted is that the tasks are very picky about strings and names, if they tell you to print a certain thing or name something a certain way your code will often be marked as invalid if there is even a tiny discrepancy between your writing and the one the task expects, even if your code functions perfectly fine.

Also as far as the console stuff is concerned, it's not a different Java, it's just a different way of printing and getting input in Java. In programming there is rarely (almost never) just one way to accomplish the same task. And that is true for things like printing output and prompting input in Java. The console class makes it easier to prompt for input compared to using the Scanner class, which is the common alternative

Did your prior experience with Java involve using an IDE like IntelliJ or Eclipse? If so that would likely be the reason why you were never introduced to the console class as it (for various reasons) does not work when you run your program though most Java IDEs. That is not an issue for Treehouse since they don't use an IDE for these basic courses but it would be an issue for any course that does.