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

Why do I get an error for the first line?

While compiling, I'm getting an error for the public class Intro line, but I couldn't realize why. Thanks

Name.java
// I have setup a java.io.Console object for you named console
public class Intro {
  public static void main(String[] args){
    String firstName = "piril";
    System.out.printf("My name is %s", firstName);
  }
}

3 Answers

Hi Piril,

I just tried this out in the Workspace and I get the error "Name.java:1: error: class Intro is public, should be declared in a file named Intro.java
public class Intro {"

So it sounds like you need to either name your File "Intro.java" or name your class "Name". I tried with this change and the code runs properly.

I tried to name my class "Name", but again it doesn't work. And the error is illegal start of expression for the first line.

Ah, maybe I wasn't specific enough, the line should read...

public class Name {

Don't include the quotes like it's a string

Alexander Nikiforov
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 Points

In this challenge you don't need to define public class.

Consider you are already inside public class {, inside public static void main(String[] args).

Just type:

    String firstName = "piril";
    System.out.printf("My name is %s", firstName);

Thanks Alexander, it worked !