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

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
228,001 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
228,001 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
228,001 Points

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

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"));