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

JavaTester.java:74: error: illegal start of expression public class Name { ^ 1 error what is this error please?

I am really struggling to solve my first objective test..please help.

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

 public class Name {
    public static void main(String[] args) {
      Console console = System.console();
        String firstname = "Craig";
          System.out.printf("Hello my name is %s\n", firstname);
            System.out.printf("%s is learning how to write Java\n", firstname);
    }
  }

2 Answers

Yanuar Prakoso
Yanuar Prakoso
15,196 Points

Hi There

The error is saying you do not need to add public class Name {. Basically you also do not need to write Console console = System.console() as it was already set (see the comment above your code). Those thing I mention already being given to you it just you cannot see it in this challenge.

A little hint this challenge just wanted to test you whether you can create String variable and print it according to the required format. Therefore you only need something like this:

// I have setup a java.io.Console object for you named console
String firstname = "Craig";

Just like that a simple single line of code and it will safely takes you pass the first part of the challenge. No class declaration no Console declaration needed. The rest of the challenge will be easy once you grasp these conscetp that the class already prepared for you as well as console.

I hope this will help

Moderator Edit: Moved response from "Comment" to "Answer"

Thank you.

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Yanuar is correct. However, you also have a typo in the variable name. firstname needs to be firstName (note the upper-cased "N").

A good thing to remember as you move forward with Treehouse is that the instructions are very specific and should be taken literally. Here you added much more code than was asked for. A good rule-of-thumb... If the instructions don't ask for it, don't do it. Also, spelling, punctuation, and case-sensitivity will affect the code checker as well. So, that lower-case "n" you have in the variable name will also cause the challenge to fail, because the instructions specifcally ask for a "variable named firstName."

Good work and welcome to Treehouse! :) :dizzy:

Thank you