go to previous page   go to home page   go to next page highlighting

Answer:

Yes. Type wrapper objects a and b are created using autoboxing.


Changing the Locale

import java.text.*;
import java.util.Locale;

public class IODemoGermany
{
  public static void main ( String[] args )
  {
    Integer i = new Integer( 7654321 );
    Double  d = new Double ( 11000.0008 );
    
    Locale.setDefault( Locale.GERMANY );
    DecimalFormat numform = new DecimalFormat(); 
    
    System.out.println( "Default Locale = " + Locale.getDefault() );    
    System.out.println( "integer = " + numform.format(i) + " double = " + numform.format(d) );
  }
}

Usually you would not write a program that changes the locale. But if you want to experiment, do this:

Locale.setDefault( Locale newLocale )

The example program sets the locale to Locale.GERMANY so it will write numbers in the format appropriate for Germany no matter where it is run.

The default locale remains set to the new locale (GERMANY in the above program) only as long as the Java virtual machine is running. When it starts up again (perhaps when you run another program) it will use the original default locale. Here are some Locale constants to play with: CANADA, CHINA, FRANCE, GERMANY, UK, and US. For others, look in the Java documentation.

To make a permanent change to the default locale you need to change some operating system parameters. This is not a good idea.


QUESTION 5:

What do you suspect that the following fragment writes in your default locale:

DecimalFormat numform = new DecimalFormat(); 
System.out.println( "Third = " + numform.format(1.0/3.0) );


go to previous page   go to home page   go to next page