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

What am I forgetting?

I am unsure what I am doing wrong

Name.java
String firstName = "Aven";
console printf("firstName can code in Java!");
// I have setup a java.io.Console object for you named console

2 Answers

Hi Aven.

String firstName = "Aven";

console.printf("%s can code in Java!", firstName);

When you call any kind of a method on any kind of an object you denote the method call with a "."

Like in my code above: console"."printf -> this denotes that you are calling the printf method (which prints to the screen) on the console object.

This line ("%s can code in Java!", firstName); uses the Java string formatting -> a way you format/input variables into a string.

Hope this helped.

Happy Coding!!!

Dyrhoi .
Dyrhoi .
3,173 Points

Your question in unclear, but judging from your code I reckon you want to print the string firstName

Now you can't in Java print out a variable that is inside quotes.

To get around this problem you need to use something called concatenation, which adds an element to another element. In this case, string to string.

In Java you do this by adding a simple plus sign.

Example:

String fish = 'Gold Fish';
printf(fish + " is a cute fish");

More advanced way is using the String.format built in Java.

Example:

String fish = 'Gold Fish';
printf("I love %s", fish);