Java Interview 16th Day

Source: Internet
Author: User
Tags locale string format

Internationalization: So that everyone in the world can read it.

Locale Class (under Java.util package): Includes all countries, regions, languages

There are many static properties that represent the country, language

Three methods of construction:

Locale (String language)

Constructs a locale based on the language code.

Locale (String language, String country)

Constructs a locale based on language and country.

Locale (String language, String country, string variant)

Constructs a locale based on language, country, and variables.

Common methods:

Locale Getdefault ()

Gets the current default locale value for this Java virtual machine instance.

String Getdisplaycountry ()

Returns the locale country name that is appropriate for displaying to the user.

void SetDefault (Locale newlocale)

Set the default locale for this Java virtual machine instance.

String GetLanguage ()

Returns the language code for this locale.

String Getcountry ()

Returns the country/region code for this locale.

Attention:

Countries will be compatible languages, but languages will not be compatible with countries.

Java.text.*: There are many formatting classes under this package

NumberFormat Abstract class:

Common methods:

NumberFormat getinstance ()

Returns the common number format for the current default locale.

NumberFormat getinstance (Locale inlocale)

Returns the common number format for the specified locale.

String format (double number)

According to the country, the format specification.

NumberFormat getcurrencyinstance (Locale inlocale)

Returns the currency format for the specified locale.

SimpleDateFormat class:

Pattern Letters:

Y years

Months in M-year

H number of hours in a day (0-23)

Hours in H am/pm (1-12)

Number of minutes in M-hour

Number of seconds in s minute

Constructor:

SimpleDateFormat (String pattern)

Constructs a simpledateformat with a given pattern and a date format symbol for the default locale.

Common methods:

String Format (date date)

Formats a date as a day/time string.

Attention:

When you see the corresponding pattern letter, the conversion occurs.

Achieve internationalization:

1, write each language corresponding to the text class, make it extends ListResourceBundle, and then rewrite getcontents (), return a two-dimensional array.

2, in the program according to the local and ListResourceBundle basename to select the corresponding resources, call GetString ()/getobject () to obtain value

ResourceBundle class:

ResourceBundle Getbundle (String baseName, locale locale)

BaseName is the class name of the corresponding ListResourceBundle (package name. Class name)

Gets the resource bundle using the specified base name and locale, as well as the caller's class loader.

Note: when the key is searched for value, no default is currently found, and no default will throw an exception

5.0 new Features:

1, automatic packing, automatic unpacking (Simple Type, object type)

Values less than 127 are boxed only once for automatic boxing and equal when "= =" is done.

Null does not automatically unpack the box.

It is important to be aware of the ability to match after packing and assigning values before unpacking.

2. Static Import

Used to import static properties and static methods in a class.

Format: import static package name. Class name. Properties/Methods/*

Attention:

Must be a static member.

Importing a method/property with the same name is not allowed at static import.

When used, the class name can be omitted. "Just like using this kind of method

3. Enhanced for Loop: for (:)

A uniform way to handle arrays and collections.

It is not possible to operate on more than two collections at a time.

Deleting elements is not supported.

4. Variable length parameters: (...)

Used to replace an array, which is actually handled by an array, allowing the non-array values to be passed (0 to N, separated by commas).

Variable-length parameters can occur only once, and must be placed at the end of the parameter list.

Variable-length arguments can be passed without a parameter, but the array is not available.

5. Format input and output: Scanner class

Understand the next can, know that the class is OK.

6. Enum Enum: Essentially a class with all the attributes of the class

Format:

Enum enum Name {

Enumeration value 1,

Enumeration value 2,

.....

}

Characteristics:

Displays some of the same types of manifests.

An enumeration value is an enumeration object.

can have constructors, but cannot be public.

With a private default parameterless constructor, the default constructor disappears when explicitly constructed.

Properties, like methods and classes.

Enumerations are final (cannot be inherited externally), but can be implemented internally.

Attention:

The class in the list will call the matching constructor, if none, it will be an error.

You can have an abstract method in an enumeration, but all subclasses in the manifest must implement him.

If you are writing properties and methods, the last enumeration value ends with a semicolon.

The values () method in the enumeration returns all the enumeration values in the enumeration: color[] ss = Color.values ();

7. Generic type

8, metadata (note), the Project promotion degree general

Java Interview 16th Day

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.