• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

CH8 PG.439 format() and printf()  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see that these methods are described as using a Locale object, but looking at the Java documentation for SE8 I noticed that these only take a String as a formatting text tool and not a Locale which actually makes more sense.

This was the only reference to formatting I found, but I misunderstood this text before rereading this chapter a second time and really looking at what was said. Perhaps the below comment makes sense, but I still find it confusing if you're not sure what is meant because it makes no mention of Locale objects, just format being referenced from chapter 5. Perhaps the errata can be updated to include something like "The Locale object is not part of the format() and printf() methods, and is instead handled by a String formatter"
Various Chapter 8 Ignore the references to format being in chapter 5. You do not need to know String formatting on the exam. Old text Seb Cano 2016-02-20 Pending

Formatter javadoc:


Posts: 61766
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please always supply full details of the book, to prevent copyright problems, and also details of the question. I don't have that book, so I might not know what the question says.
In this case, however, you have provided lots of details about the answer, so I think I can guess what the problem is. The System.out.printf(), System.out.format(), String#format() and Formatter#format() methods all work the same way. I believe they all call the Formatter version behind the scenes. If you go through those links, you will see they all do use a Locale.

Two of those four API links wrote:The locale always used is the one returned by Locale.getDefault()...

In the case of Formatter, you would have to look at its constructors; all the constructors not taking a Locale parameter say:-

The locale used is the default locale . . . .

If you look up System.out.printf(), it says it does the same as System.out.format().

So, when we have investigated all versions of format() and printf(), we find they use the default Locale unless you have specified another Locale.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!