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 Basics Getting Started with Java Strings and Variables

simon k
simon k
592 Points

Double Quotes in String variable

Hi, I'd like to know why double quotes used in the string variable & not parentheses ?

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there! I think I understand what you're asking, but I'm not 100% sure. Double quotes is how we refer to a string literal. I believe the parentheses you're referring to are the ones he uses console.printf which is a method run on the console object. I promise you'll learn more about that later. But let's take a look at an example:

String greeting = "Hi there, Simon.";
console.printf("  How are you?")

The result of this will be two messages printed out one after another. It will look like: Hi there, Simon. How are you?. Because we send in the greeting variable directly in the first print statement, we don't need the quotes. The quotes are there in the variable declaration. That's how we define a string. The second print out needs quotes because we're not sending in a variable rather we're sending in a string literal directly.

Hope this helps! :sparkles: