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!
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

Nick Kouzas
10,619 PointsDefine a string variable named firstName , illegal start of expression
Hello what i m doing wrong?
public class Name2 {
public static void main(String[] args){
Console console = System.console();
String firstName= "Nick";
}
}
Error Message :
JavaTester.java:56: error: illegal start of expression public class Name2 { ^
11 Answers

ISAIAH S
1,409 PointsIt worked when I added:
import java.io.Console;
before:
public class Name2 {
Let me know if it works!!

Admire Dhodho
5,411 Pointswe3 are on same stage nick lets work together

Stephen Bone
12,359 PointsHi Nick & Admire
Does this query relate to the first coding challenge in Getting started with Java?
If so and the question is Define a string variable named firstName that stores your name. Set the value to your name.
Then yes all of the fancy class work has been taken care of (at this point) all you need is the string declaration as below:
String firstName = "Stephen";
Hope it helps!
Stephen

Admire Dhodho
5,411 Pointsits giving me this error cannot find symbol string

Nick Kouzas
10,619 PointsThanks for the answer but not working again! I try many things and i am so confused!

ISAIAH S
1,409 PointsThis is the code that works for me:
import java.io.Console;
public class Name2 {
public static void main(String[] args) {
Console console = System.console();
String firstName = "Nick";
}}

Alexander Schott
8,318 PointsI can confirm that, if you include the proper package it will work.

Nick Kouzas
10,619 PointsI copy- paste you code and this happend in output.html.
JavaTester.java:52: error: illegal start of expression import java.io.Console; ^ JavaTester.java:52: error: not a statement import java.io.Console; ^ JavaTester.java:53: error: illegal start of expression public class Name2 { ^ 3 errors

Nick Kouzas
10,619 PointsAny answers ? i keep compile with erros and i can not find a solution.

ISAIAH S
1,409 PointsIs this on a challenge?
If so, Craig might have already done:
import java.io.Console;
public class Name2 {
public static void main(String[] args) {
Console console = System.console();
for you.

Admire Dhodho
5,411 PointsI am experiencing the same problem with nick help guys

Nick Kouzas
10,619 PointsHello Admire i love team spirit lets do ti , here is my code and ISAIAH S , is there any difference from yours:
import java.io.Console; public class Name { public static void main(String[] args) { Console console = System.console(); String firstName = "Nick"; }}
And please telle me the erros in output.html

ISAIAH S
1,409 PointsYes, I have Name2
and you have Name
.

Nick Kouzas
10,619 PointsNo matters ISAIAH S the output for both of them(Name or Name2) are the same.Admire have you found something?

Admire Dhodho
5,411 Pointsi did it just enter String firstName = "Nick"; as it is

Admire Dhodho
5,411 Pointsi am on it havent succeded yet