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

Illegal start of expression

Why does the java program I write in the first challenge in Java basics give a syntax error like Illegal start of expression for the lines: import java.io.Console; public class FirstProgram

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

public class FirstProgram {

    public static void main(String[] args)
    {
      Console con =  System.console();
      String firstName = "Shilpa";
      con.printf("My First Name is %s \n", firstName);
    }

}

2 Answers

David Lacedonia
David Lacedonia
13,627 Points

I guess that the name of the class has to be exactly the same name of the file.

Hi David, Thanks for the reply. I tried that but, didn't work. Reason, the exercise already had everything built and had to add only the printf statement as asked.

Hi Shilpa Venugopal,

you have done a great job and only did too much for this exercise :-).

Everything is already set up for you. This means you don't have to define a class nor create a console object nor import the Console class.

So, only define a string variable, initialize it with your name and print it out, using the console object named 'console', which is already there.

I am pretty sure you will finish this exercise in no time.