File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt in DateFormat & NumberFormat class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt in DateFormat & NumberFormat class" Watch "doubt in DateFormat & NumberFormat class" New topic

doubt in DateFormat & NumberFormat class

Srividhya Kiran
Ranch Hand

Joined: Feb 17, 2008
Posts: 166

Can someone explain me what does this mean with an example. Its given in K & B page no 468 exam watch

Both DateFormat and Number Format objects can have their locales set only at the time of instantiation. Watch for code that attempts to change the locale of an existing instance.

manny singh

Joined: Jan 18, 2008
Posts: 28
It means there are no setters for both once instansciated!!

as i understand?

Locale locin = new Locale("hi","IN");
Locale locit = new Locale("it","IT");
DateFormat df=DateFormat.getDateInstance(DateFormat.FULL,locin);

//what would you do to change locale above to locit??
[ April 04, 2008: Message edited by: manny singh ]
Srividhya Kiran
Ranch Hand

Joined: Feb 17, 2008
Posts: 166
Hello manny

I cant get you. Can you please explain it to me.
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
It might help to think of it in this way: the only way to set the Locale in one of those objects is with the constructor. Thus, the only way that you can set the Locale is to instantiate a new one. There is no setLocale() method or any other means of changing an object's locale. So if you must change locale, you must instantiate a new object.

SCJP - 86% - June 11, 2009
Sandeep Bhandari
Ranch Hand

Joined: Apr 16, 2004
Posts: 201
or the point being emphasized is like the question in exam is written to fool you like

d.setLocale("en","US"); //this is wrong (compiler error)

SCJP 96% | SCWCD 90%| SCJP mock exams | My SCJP blog
Srividhya Kiran
Ranch Hand

Joined: Feb 17, 2008
Posts: 166
Thanks for everyone I got it....
I agree. Here's the link:
subject: doubt in DateFormat & NumberFormat class
It's not a secret anymore!