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

Why do we start with console and then printf? Do I use this console command everywhere? Is printf universal?

My code seems to be running well, but I don't understand why everything starts with console, then dot then printf. What is printf? Why not just print? Also, why does everything start with console, is that universal?

2 Answers

Hi Surya,

Console is a Class in Java that allows input and output through the Console window. You only need to include it when you are using a method that's provided by Console.

One of the methods (functions) that the console class provides is printf(), which takes an argument of a format string as its first parameter. If the format string provides any format specifiers within it - special sequences of characters which can be used to change how that string is displayed to the console window - then additional arguments may be used to replace parts of the string.

For additional information, you can check out the Java Documentation on Console or the Java Documentation on printf.

Hope that helps!

Can you give me some examples of methods that aren't provided by the console (console substitutes)? -Thanks

You can interact with your program using other ways; for example, if you wrote a JavaFX or Android program in Java, you could have it generate a popup message, or you could have them write messages to a logfile.

But if you're interacting with a console window, there's no better way than using the console class provided by Java.