Questions

java reference to a static method

Tags:
+
0 Votes
Locked

java reference to a static method

rajagitam
NumberFormat nf=NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(6);


what does the above code mean?
whats the nf reference refering to?
  • +
    0 Votes
    choehne

    Do this google search: java api NumberFormat, you get a pointer to http://java.sun.com/j2se/1.4.2/docs/api/java/text/NumberFormat.html

    +
    0 Votes
    geosan

    The code means that you are invoking a method that belongs to the class not an instance of a class. The method will return a NumberFormat instance which defaults to the number format of the current locale.
    Since NumberFormat is an abstract class, the instance of the NumberFormat class that you get when invoking the NumberFormat.getNumberInstance will provide you an interface for formatting and parsing numbers for the current locale.

    You can change your locale by getting the instance like this
    NumberFormat nf = NumberFormat.getInstance(Locale.FRENCH);

  • +
    0 Votes
    choehne

    Do this google search: java api NumberFormat, you get a pointer to http://java.sun.com/j2se/1.4.2/docs/api/java/text/NumberFormat.html

    +
    0 Votes
    geosan

    The code means that you are invoking a method that belongs to the class not an instance of a class. The method will return a NumberFormat instance which defaults to the number format of the current locale.
    Since NumberFormat is an abstract class, the instance of the NumberFormat class that you get when invoking the NumberFormat.getNumberInstance will provide you an interface for formatting and parsing numbers for the current locale.

    You can change your locale by getting the instance like this
    NumberFormat nf = NumberFormat.getInstance(Locale.FRENCH);