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

Dmitriev Denis
Dmitriev Denis
1,281 Points

I don't understand what wrong?

I constantly get that: JavaTester.java:74: error: illegal start of expression public class { ^ JavaTester.java:74: error: expected public class { ^ 2 errors

Name.java
// I have setup a java.io.Console object for you named console

  public class {
  public static void main(String[] args){
    String firstName="Eric";
      console console= System.console();
      console.printf("Hello, my name is %s\n ", firstName);
    console.printf("%s is learning how to write java\n",firstName );
  }
}

1 Answer

In this code challenge I don't think you even need to add the Class declaration as well as the main method declaration. You can just declare your String variable and printf to the console, and I think it will still accept it.

//I'm pretty sure this will still pass just by itself
String firstName = "Eric";
console.printf("Hello, my name is %s\n", firstName);
console.printf("%s is learning how to write java\n", firstName);

You might've accidentally deleted it or not put in. But your class name declaration is missing. After the line "public class" you need to add the name of the java class itself which is "Name".

public class Name {
  //code here
}

Also, in this challenge the Console object variable isn't necessary since it already told you in the comments "// I have setup a java.io.Console object for you named console"

It is worth noting however that when you do create a Console object variable, you need to capitalize the first 'C' in "Console".
EXAMPLE: Console console = System.console();