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 Objects (Retired) Harnessing the Power of Objects Exceptions

Jari Koopman
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jari Koopman
Python Web Development Techdegree Graduate 29,349 Points

printf or println

In the video of Exceptions (Java, Craig Dennis) there is the part about when you put in too many PEZ. The following is written:

System.out.println(β€œWhoa there!); System.out.printf(β€œThe error was: %s\n”, iae.getMessage());

I think somewhere in the course I missed something, cause I don't get the difference between println and printf. So is there anyone who can tell me the difference and when you use println and when printf?? Thank you!

1 Answer

Hi Jari,

printf prints a formatted string - that's why you can use %s and a load of other formatters within your output string.

println just prints out some text with a new line.

I hope that helps,

Steve.

Here is some helpful documentation on how the formatter works.