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

hot to write text in java

how do i print words that the program can read? html was much simpler all it was, was <p>hi</p>

public class "solomon"
String firstName = "Solomon";

2 Answers

public class "solomon" String firstName = "Solomon";


thank you but thats not the way the program wants me to do it now.

thanks I got it

Yes, Java is harder than html. It is also much more powerful and can be very fun. It can also feel very inefficient when you are starting out. ;)

In the challenge you are working on here, they are asking you to use the console object with the printf method in order to print out your name. As jungkeekim said, in Java you can print something with the System.out.print() method, but in this challenge they want you to use the console.printf() method. So, it would look like this:


They then want you to concatenate strings in the second challenge, which is done like this:

console.printf(firstName + " I am concatenating!");

To format Strings, remember:

String favoriteFood = "cookies";
console.printf(String.format("I like %s for breakfast", favoriteFood));

In the third example above, keep a special eye on the two parantheses at the end, you must have those or you will get a compiler error. Java is very strict about these things, which is a good thing usually, but can be frustrating. When you become a real Java developer, you will be working with programs called IDE's that correct your silly mistakes for you, kind of like Microsoft Word. ;)

its still not working

What error are you getting? In this challenge you do not need the public class "solomon", that is an incorrect way of declaring a class and is probably the reason for the errors. When you have removed the public class "solomon" Make sure you have it exactly right, the challenge checker is very picky:

String firstName = "Solomon";
console.printf(firstName + " is writing Java!");
//will print "Solomon is writing Java!"

Notice the space after the first quotation mark in the phrase " is writing Java!". You need that space - (again, the challenge checker is very picky).

console.printf(String.format("%s is writing Java!", firstName));
//will print "Solomon is writing Java!"