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

Not able to figure out why I am getting the error "illegal start of expression"

Its throwing the same error again and again "illegal start of expression". Please refer the attachment and help me to get this fixed. Thanks

Name.java
public class Name {
  public void main(String[] args){
    Console console1 = System.console1();
    String firstName = "Anoop";
    console1.printf("%s can code Java ", firstName);
  }
}

2 Answers

Stefan Tihan
Stefan Tihan
22,541 Points

Try the following solution

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

P.S.: The console is already defined !

Thanks Stefan....but still I am getting the same error. This is my code and as suggested by you, I have made the changes but the same error. When I tried in eclipse it shows null pointer exception.

public class Name { public void main(String[] args){ Console console = System.console();

String firstName = "Anoop";

console.printf("%s can code in Java", firstName); } }