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

Enyang Mercy
PLUS
Enyang Mercy
Courses Plus Student 2,339 Points

What does this mean? JavaTester.java:74: error: illegal start of expression public class Name{ ^ 1 error

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

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();
    //Welcome to my introduction program!Check code below here.
   String firstName = " Mercy ";
console.printf("%s can code in Java!",firstName);
          }
       }

3 Answers

Enyang Mercy
PLUS
Enyang Mercy
Courses Plus Student 2,339 Points

pls i need help with this line as i can't compile and run. JavaTester.java:74: error: illegal start of expression public class Name{ ^ 1 error what does it really mean? Thanks

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hi There,

The problem is you have way too much code there.

For starters, the challenge says that it has "setup a java.io.Console object for you named console", so you don't have to.

Challenges are very specific and the instructions must be followed exactly or an error will arise. If you add code that wasn't asked for or change code that was pre-loaded, or deleted code... Even if you misspell something or forgot a period, it will error with the Bummer!
Here you are getting that error because the challenge created the Console object for you behind the scenes, but then you are trying to create another one, and there cannot be two in a class, so that is where the error is coming from.

Also, watch spacing inside of strings. Whitespace doesn't matter in Java, but inside of string literals, it makes a big difference in the formatting of the strings.

All in all, you have all the correct code there! :thumbsup: You just need to get rid of all those lines that were not asked for.

The final answer will only be two lines of code.

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

Hope this helps to clear some things up for you.
Keep Coding! :) :dizzy: