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?
The
printfmethod of the PrintStream class provides string formatting similar to theprintffunction in C.The formatting for
printfuses theFormatterclass’ formatting syntax.The
printfmethod 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,printfand other functions that will output toSystem.out.