I haven't had the chance to take any serious low-level programming courses in school. (I know I really should get going on learning the "behind-the-scenes" to be a better programmer.) I appreciate the conveniences of Java, including the ability to stick anything into a System.out.print
statement. However, is there any reason why you would want to use System.out.printf
instead?
Also, should I avoid print calls like this in "real applications"? It's probably better to to print messages to the client's display using some kind of UI function, right?
Best Solution
The
printf
method of the PrintStream class provides string formatting similar to theprintf
function in C.The formatting for
printf
uses theFormatter
class' formatting syntax.The
printf
method can be particularly useful when displaying multiple variables in one line which would be tedious using string concatenation:Also, writting Java applications doesn't necessarily mean writing GUI applications, so when writing console applications, one would use
print
,println
,printf
and other functions that will output toSystem.out
.