Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects Meet Objects Welcome Back

I don't know when to put the " " ? For example int age = Integer.parseInt("30"); int age = Integer.parseInt(AGE);


2 Answers

Steven Parker
Steven Parker
216,136 Points

It looks like you have it correct in your examples.

Quotes go around a literal string (like "30") but never around a variable name (AGE).

you mean by literal string just numbers ?

Steven Parker
Steven Parker
216,136 Points

A literal string can have anything ("Bob", "robots", "this is a test", etc.). But one that you might give to "parseInt" would just have numbers.

So what s the difference between the variable name and the literal string ?

Steven Parker
Steven Parker
216,136 Points

The variable name represents the value that was previously assigned to it.
A literal string only represents what is contained in the quotes.

Mike Meany
Mike Meany
3,988 Points

To reiterate what Steven said, a String will always have quotes around it, variables wont. To expand a bit; ints will always be numbers but never have quotes, strings can be/contain letters, symbols or numbers and will always have quotes. Lets take the example of;

int x = 1; int y = 2; System.out.println(x + y);

This will output 3 as it adds the two numbers together

now take this example

String x = "1"; String y = "2";

System.out.println(x + y);

This will output 12 as it concatenates the two strings together

If you wanted to add the two numbers together from example 2 then you would have to parse them and it would look something like this;

System.out.println(Integer.parseInt(x) + Integer.parseInt(y));


System.out.println(Integer.parseInt("1") + Integer.parseInt("2"));