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

Printf

isnt java suppose to have System.out.println instead of printf?

Hi BIlal System.out.println print with a new line when you write more then 1...System.out.printf is for formating s% or %d

3 Answers

A Y
A Y
1,761 Points

BIlal Hachem,

println() only prints a line of text. printf() provides string formatting. You can't use format specifier like "$s" to print a variable value as string using println().

Regrads, Amir

Dane Parchment
MOD
Dane Parchment
Treehouse Moderator 11,077 Points

Yes. In fact there are multiple different print statements that Java allows developers to make use of. The reason we are learning printf here is because it gives us a lot more control over what our output will display like. So do not look at this as a case of Java not having a specific method you have used before, instead look at this as another tool to add to your java tool belt, in this case using printf to better format your output.

Davinderpal Rehal
Davinderpal Rehal
5,631 Points

Hi Bilal,

So the function that he is using in the video is System.console which he has assigned to a variable console. The documentation for the System.console class can be found below.

https://docs.oracle.com/javase/7/docs/api/java/io/Console.html

You are probably familiar with the System.out.println function that is the standard output and not specifically the console output. Documentation below.

https://docs.oracle.com/javase/7/docs/api/java/lang/System.html

Hope that helps