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 and Variables

Learning coding
seal-mask
.a{fill-rule:evenodd;}techdegree
Learning coding
Front End Web Development Techdegree Student 9,937 Points

Question about video at 6.36 on datatype and values

Hi,

At 6.36 min you will see that datatype is a String. "Craig" is also a String. It think it's confusing. Can someone expand on this terminology? Why are two seemingly different things called the same? (a String)

I am delving into this basics course and want to understand everything here before I move on. Basics first. So I might ask more (dumb) questions.

So thanks in advance, RenΓ©

2 Answers

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

When you write String name, you declare variable called name of Type string.

That is left side of expression.

You can leave it even like this, just declaration, nothing else:

String name;

When you write equals, you assign to variable on the left what ever is on the right side.

And as you can infer, because you are declaring variable name with dataType String you have to specify something on the right side that is also string.

You write:

String oneString = otherString;

otherString was declared elswehere...

You see that both sides left and right have to be strings.

Coming back to Craig's code:

String can be also defined literally, which means when you write

String string = "Craig";

As if you are saying create new String from literal expresssion in quotemarks "Craig"...

So, to sum up:

You declare the variable String firstName on the left, and assign to this variable result of the expression on the right.

That means that whatever is on the right side has to be the same as on the left.

That is all I can say... It is hard to understand what do you mean ...

May be you can re-phrase once again...