in the following dayth...

阅读理解BWhether in the home or the workplace, social_英语_高考_试题之家
您现在的位置:&&&&&&&&&&&&&&&&&&&&&正文
阅读理解BWhether in the home or th…
编辑:佚名 查看次数:栏目:
阅读理解BWhether in the home or the workplace, social robots
are going to become a lot more common in the next few years. Social robots are
about to bring technology to the everyday world in a more humanized way, said
Cynthia Breazeal, chief scientist at the robot company Jibo.
While household robots today
do the normal housework, social robots will be much more like companions than
mere tools. For example, these robots will be able to distinguish when someone
is happy or sad. This allows them to respond more appropriately to the user.
The Jibo robot, arranged to
ship later this year, is designed to be a personalized assistant. You can talk
to the robot, ask it questions, and make requests for it to perform different
tasks. The robot doesn’t just deliver general
it responds
based on what it learns about each individual in the household. It can do
things such as reminding an elderly family member to take medicine or taking
family photos.
Social robots are not just finding
their way into the home. They have potential applications in everything from
education to health care and are already finding their way into some of these
Fellow Robots is one
company bringing social robots to the market. The company’s “Oshbot” robot is
built to assist customers in a store, which can help the customers find items
and help guide them to the product’s location in the store. It can also speak
different languages and make recommendations for different items based on what
the customer is shopping for.
The more interaction the
robot has with humans, the more it learns. But Oshbot, like other social
robots, is not intended to replace workers, but to work alongside other
employees. “We have technologies to train social robots to do things not for
us, but with us,” said Breazeal.
41. How are social robots different from household robots
A. They can control their
emotions. B. They are
more like humans.
C. They do the normal housework. D. They respond to users more
42. What can a Jibo robot do according to Paragraph 3
A. Communicate
with you and perform operations.
B. Answer your
questions and make requests.
C. Take your
family pictures and deliver milk.
D. Obey your
orders and remind you to take pills.
43. What can Oshbot work as
A. A language
teacher. B. A
tour guide.
assistant. D.
A private nurse.
44. We can learn from the last paragraph that social
robots will ______.
employees B.
be our workmates
C. improve technologies D. take the place
of workers
45. What does the passage mainly present
A. A new design
idea of household robots.
B. Marketing
strategies for social robots.
C. Information on
household robots.
introduction to social robots.
41. B 42. D 43. C 44. B 45. D
阅读理解A University Room Regulations Approved
and Prohibited Items
The following items are
approved for use in residential (住宿的) rooms: electric blankets,
hair dryers, personal computers, radios, televisions and DVD players. Items
that are not allowed in student rooms include: candles, ceiling fans,
fireworks, waterbeds, sun lamps and wireless routers. Please note that any
prohibited items will be taken away by the Office of Residence Life.
to Residential Rooms
Students are provided with a
combination (组合密码) for their room door locks upon check-in. Do not share your room door
lock combination with anyone. The Office of Residence Life may change the door
lock combination at any time at the expense of the resident if it is found that
the student has shared the combination with others. The fee is $25 to change a
room combination.
Students living in buildings
that have kitchens are only permitted to cook in the kitchen. Students must
clean up after cooking. This is not the responsibility of housekeeping staff.
Kitchens that are not kept clean may be closed for use. With the exception of
using a small microwave oven (微波炉) to heat food, students are
not permitted to cook in their rooms.
No pets except fish are permitted
in student rooms. Students who are found with pets, whether visiting or owned
by the student, are subject to an initial fine of $100 and a continuing fine of
$50 a day per pet. Students receive written notice when the fine goes into
effect. If, one week from the date of written notice, the pet is not removed,
the student is referred to the Student Court.  
Residential buildings must maintain
an atmosphere that supports the academic mission of the University. Minimum
quiet hours in all campus residences are 11:00 pm to 8:00 am Sunday through
Thursday. Quiet hours on Friday and Saturday nights are 1:00 am to 8:00 am.
Students who violate quiet hours are subject to a fine of $25.
36. Which of the following
items are allowed in student rooms
A. Ceiling fans and waterbeds.
B. Wireless routers and radios.
C. Hair dryers and candles. D.
TVs and electric blankets.
37. What if a student is found
to have told his combination to others
A. The combination should be changed.
B. The Office should be charged.
C. He should replace the door lock.
D. He should check out of the room.
38. What do we know about
the cooking policy
A. A microwave oven can be used.
B. Cooking in student rooms is permitted.
C. A housekeeper is to clean up the kitchen.
D. Students are to close kitchen doors after cooking.
39. If a student has kept a cat
in his room for a week since the warning, he will face _____.
A. parent visits
B. a fine of $100
C. the Student Court
D. a written notice
40. When can students enjoy
a party in residences
A. 7:00 am, Sunday.
B. 7:30 am, Thursday.
C. 11:30 pm, Monday. D.
00:30 am, Saturday.
阅读理解The values of artistic
works, according to cultural relativism(相对主义), are simply reflections
of local social and economic conditions. Such a view, however, fails to explain
the ability of some works of art to excite the human mind across cultures and
through centuries.
History has
witnessed the endless productions of Shakespearean plays in every major
language of the world. It is never rare to find that Mozart packs Japanese
concert halls, as Japanese painter Hiroshige does Paris galleries, Unique works
of this kind are different from today’s popular art, even if they began as
works of popular art. They have set themselves apart in their timeless appeal
and will probably be enjoyed for centuries into the future.
essay, the philosopher David Hume argued that because“the
general principles of taste are uniform(不变的) in human
nature,”the value of some works of art might be
essentially permanent. He observed that Homer was still admired after two
thousand years. Works of this type, he believed, spoke to deep and unvarying
features of human nature and could continue to exist over centuries.
researchers are applying scientific methods to the study of the universality of
art. For example, evolutionary psychology is being used by literary scholars to
explain the long-lasting themes and plot devices in fiction. The structures of
musical pieces are now open to experimental analysis as never before. Research
findings seem to indicate that the creation by a great artist is as permanent
an achievement as the discovery by a great scientist.
52.According to the
passage, what do we know about cultural relativism
A.It introduces
different cultural values.
B.It explains the
history of artistic works.
C.It relates artistic
values to local conditions.
D.It excites the human
mind throughout the world.
53.In Paragraph 2, the
artists are mentioned in order to show that
A.great works of art
can go beyond national boundaries
B.history gives art
works special appeal to set them apart
C.popular arts are
hardly distinguishable from great arts
D.great artists are skilled
at combining various cultures
54.According to Hume,
some works of art can exist for centuries because .
A.they are results of
scientific study
B.they establish some
general principles of art
C.they are created by
the world’s greatest artists
D.they appeal to
unchanging features of human nature
55.Which of the
following can best serve as the title of the passage
A.Are Artistic Values
Universal B.Are
Popular Arts Permanent
C.Is Human Nature
Uniform D.Is
Cultural Relativism Scientific
阅读理解There are many places
to go on safari(观赏野生动物)in Africa, but riding a horse through the flooded waters of
Botswana's Okavango Delta must rank as one of the world's most exciting
wildlife journeys.
safari camps operate as the base for this adventure, providing unique rides
twice a day to explore deep into the delta. The camps have excellent horses,
professional guides and lots of support workers. They have a reputation for
providing a great riding experience.
The morning
ride, when the guides take you to beautiful, shallow lakes full of water
lilies, tends to be more active. It is unlike any other riding experience. With
rainbows forming in the splashing water around you and the sound of huge drops
of water bouncing off your body and face. It is truly exciting. You are very
likely to come across large wild animals, too. On horseback it is possible to
get quite close to elephants, giraffes and many other animals. The sense of
excitement and tension levels rise suddenly though, as does your heart rate, as
you move closer to them.
evening, rides are usually at a more relaxed and unhurried pace. With golden
light streaming across the grassy delta and the animals coming out to eat and
drink. Sedate though they are, rides at this time of day are still very
impressive. As the sun's rays pass through the dust kicked up by the horses,
the romance of Africa comes to life.
Back at the
camp you can kick off your boots and enjoy excellent food and wine. Looking
back on your day, you will find it hard to deny that a horseback Safari is as
close as you will ever come to answering the call of the wild.
48. What does the
underlined word &They& refer to
A. Flooded waters B. Wildlife
C. Safari camps D.
Unique rides
49. What does the
author find most exciting about a horse safari
A. Seeing and feeling
the real African life.
B. Enjoying good food
and wine at the camp.
C. Hunting large
animals just as our ancestors did.
D. Being part of the
scene and getting close to animals.
50. What does the
underlined word &sedate& probably mean
A. Wild and romantic B. Slow and
C. Hurry and thirsty D.
Active and excited
51. The author
introduced the riding experience in the OKavango Delta mainly by________.
A. Following space
order B. Following
time order
classifications D.
Giving examples
阅读理解Join
the discussion…
LakeLander?2
Today, a man talked
very loud on his phone on a train between Malvern and Reading, making many
passengers upset. I wonder how he would react if I were to read my newspaperoutloudonthetrain,
Ihave never had the courage to do it, though.
Pak50 ??? ?57 minutes ago
not give it a try Perhaps you should take lessons on a
instrument. The late musician DennisBrian is said to have
a fellow train passenger to turn off his radio. When his
was refused, he took out his French horn(号) and started
Angie O’Edema?42
minutes ago
I don’t see how
musical instruments can help improve manners in public. Don’t do to others what
you wouldn’t like to be done to yourself. Once, a passenger next to me talked
out loud on his mobile phone. I left my seat quietly, giving him some privacy
to finish his conversation. He realized this and apologised to me. When his
phone rang again later, he left his seat to answer it. You see, a bit of
respect and cooperation can do the job better.
Taodas ?29 minutes ago
I did read my
newspaper out loud on a train, and it turned out well. The guy took it in good
part, and we chatted happily all the way to Edinbergh.
Sophie 76 ?13minutes ago
I have not tried
reading my newspaper out loud on a train, but ,several years ago, I read some
chapters from Harry Porter to my bored and noisy children. Several passengers
seemed to appreciate what I did.
44. The passenger made
an apology to Angie O’Edema because----____.
A. he offered his seat
to someone else
B. he spoke very
loudly on his phone
C. he refused to talk
with Angie
D. he ignored Angie’s
45. Who once read a
newspaper out loud on a train
A. Pak50 B. Angie O’Edema C. Taodas D. Sophie76
46. What is the
discussion mainly about
A. How to react to bad
behavior. B. How to kill
time on a train.
C. How to chat with
strangers. D. How to
make a phone call.
47.Where is the
passage most probably taken from
A. A webpage. B. A newspaper. C. A novel. D.
阅读理解In ancient Egypt, a shopkeeper discovered that
he could attract customers to his shop simply by making changes to its
environment. Modern businesses have been following his lead,with more tactics(策略).
One tactic involves
where to display the goods. Foe example, stores place fruits and vegetables in
the first section. They know that customers who buy the healthy food first will
feel happy so that they will buy more junk food(垃圾食品)later in their
trip. In department stores, section is generally next to the women’s cosmetics(化妆品) section:while the shop assistant is going back to find the right size shoe,
bored customers are likely to wander over cosmetics they might want to try
Besides, businesses
seek to appeal to customers’ senses. Stores notice that the smell of baked
goods encourages shopping, they make their own bread each morning and then fan
the bread smell into the store throughout the day. Music sells goods, too.
Researchers in Britain found that when French music was played, sales of French
wine went up.
When it comes to the
selling of houses, businesses also use highly rewarding tactics. They find that
customers make decision in the first few second upon walking in the door, and
turn it into a business opportunity. A California builder designed the
structure of its houses smartly. When entering the house, the customer would
see the Pacific Ocean through the windows, and then the poll through an open
stairway leading to the lower level. The instant view of water on both levels
helped sell these $10 million houses.
do stores usually display fruits and vegetables in the first section
To save customers times.
To show they are high quality foods.
To help sell junk food.
To sell them at discount prices.
41.According
to Paragraph 3, which of the following encourages customers to buy
Opening the store early in the morning.
Displaying British wines next to French ones.
Inviting customers to play music.
Filling the store with the smell of fresh bread.
is the California builder’s story intended to prove
The house structure is a key factor customers consider.
The more costly the house is, the better it sells.
An ocean view is much to the customers’ taste.
A good first impression increases sales.
is the main purpose of the passage
To explain how businesses turn people into their customers.
To introduces how businesses have grown from the past.
To report researches on customer behavior.
To show dishonest business practices.
Copyright ? 2014- Inc. All Rights Reserved.
试题之家是免费试题答案和解析网站,部分内容来源于网络,如无意中侵犯了您的版权,请及时告知,我们会第一时间处理。Internationalization: Understanding Locale in the Java Platform
Internationalization: Understanding Locale in the Java Platform
, September 20, 2005
Language and geographic environment are two important influences on our culture. They create the system in which we interpret other people and events in our life. They also affect, even define, proper form for presenting ourselves and our thoughts to others. To communicate effectively with another person, we must consider and use that person's culture, language, and environment.
Similarly, a software system should respect its users' language and geographic region to be effective. Language and region form a locale, which represents the target setting and context for localized software. The Java platform uses
java.util.Locale objects to represent locales. This article describes the
Locale object and its implications for programs written for the Java platform.
This article is divided into the following sections:
Definition
Locales identify a specific language and geographic region. Locale-sensitive objects use
java.util.Locale objects to customize how they present and format data to the user. Locales affect user interface language, case mapping, collation (sorting), date and time formats, and number and currency formats. Locales are critical to many culturally and linguistically sensitive data operations.
java.util.Locale is a lightweight object that contains only a few important members:
A language code
An optional country or region code
An optional variant code
When writing or talking about locales, you can use a text abbreviation for a convenient representation. This notation separates each component of a locale with an underscore character:
&language code&[_&country code&[_&variant code&]]
These three elements provide enough information to other locale-sensitive objects so that they can modify their behavior for a specific linguistic or cultural purpose. For example, a
java.text.NumberFormat object created for a German-speaking Swiss locale will format numbers differently than it would for a German-speaking Austrian locale. See Table 1.
Table 1. Formatted Output Varies by Locale
Formatted Numbers
German (Germany)
123.456,789
German (Switzerland)
123'456.789
English (United States)
123,456.789
Locale objects are just identifiers, locale-sensitive classes like
java.text.NumberFormat or
java.text.DateFormat do all the work to provide localized number or date formats. The
java.text.DateFormat class, for example, uses a
Locale object during its instantiation to decide how to format dates correctly.
The following sections describe each component of a locale.
Language Codes
Language codes are defined by
, an international standard that assigns two- and three-letter codes to most languages of the world. Locale uses the two-letter codes to identify the target language. Table 2 lists several of these language codes.
Table 2. Language Code Examples in the ISO 639 Standard
Language is an important component of a locale because it describes the language that a particular group of customers uses. Your applications will use this information to provide a user interface that conforms to your customer's language.
Of course, language doesn't paint the entire picture of a locale. For example, even though you may use
de as the locale language code,
de alone doesn't tell you anything about where German is spoken. Several countries use German as an official first or even second language. One of the differences in German from one country to another is sorting order. For this reason and others, language is not always sufficient to precisely define a locale.
Country (Region) Codes
Country codes are defined by ISO 3166, another international standard. It defines two- and three-letter abbreviations for each country or major region in the world. In contrast to the language codes, country codes are set uppercase. Table 3 shows a few of the defined codes. Locale uses the two-letter codes instead of the three-letter codes that this standard also defines.
Table 3. Some Country Codes Defined in the ISO 3166 Standard
United States
Country codes are an important locale component because
java.text.Format objects for dates, time, numbers, and currency are particularly sensitive to this element. Country codes add precision to the language component of a locale. For example, French is used in both France and Canada. However, precise usage and idiomatic expressions vary in the two countries. These differences can be captured with different locale designators in which only the country code is different. For example, the code
fr_CA (French-speaking Canada) is different from
fr_FR (French-speaking France).
Variant Code
Operating system (OS), browser, and other software vendors can use the code to provide additional functionality or customization that isn't possible with just a language and country designation. For example, a software company may need to indicate a locale for a specific operating system, so its developers may create an
es_ES_MAC or an
es_ES_WIN locale for the Macintosh or Windows platforms for customers in Spain.
One historical example from the Java platform itself is the use of the
EURO variant for European locales that use the euro currency. During the transition period for those countries, the Java 2 Platform, Standard Edition (J2SE) version 1.3 used this variant. For example, although a
de_DE (German-speaking Germany) locale existed, a
de_DE_EURO (German-speaking German locale with a euro variant) was added to the Java environment. Because the euro currency is now the standard for the affected countries, those variants were removed in J2SE 1.4. Most application designs will probably not require variant codes.
Construction
Locale class has several constructors:
Locale(String language)
Locale(String language, String country)
Locale(String language, String country, String variant)
The following shows how each constructor can be used:
// Create a generic English-speaking locale.
Locale locale1 = new Locale(&en&);
// Create an English-speaking, Canadian locale.
Locale locale2 = new Locale(&en&, &CA&);
// Create a very specific English-speaking, U.S. locale
// for Silicon Valley.
Locale locale3 = new Locale(&en&, &US&, &SiliconValley&);
Using the ISO 639 two-letter code, the
en represents English. The ISO 3166 codes
US represent Canada and the United States, respectively: The last code line above shows how to create a locale with an optional variant: an
en_US_SiliconValley locale. This locale is more specific than the first instance. Not only is the locale a U.S. English-speaking one, but it is also associated with an additional variant,
SiliconValley. Because one of its purposes is to provide developers the ability to define custom locales, the variant can be anything you need.
Although the compiler and runtime environment won't complain if you make up your own language and country or region identifiers, you should use only the codes that the ISO standards define. By constraining yourself to the ISO definitions, you'll ensure compatibility with other applications and coding standards. More importantly, locale-sensitive class libraries use only the ISO codes. For example, the
java.text.NumberFormat class will understand how to behave for the
de_DE (German language, Germany) locale, but it won't understand what to do with a fictitous
foo_biz locale. If you use non-ISO identifiers, you will have to write the locale-sensitive code to support them.
Preconstructed Locales
Locale class has many static fields that represent instantiated
Locale objects. For example,
Locale.FRANCE is a premade static
Locale object that represents French-speaking France. You can use
Locale.FRANCE anywhere you might use
new Locale(&fr&, &FR&). Table 4 shows some of the preconstructed
Locale objects that are available.
Table 4. Some of the Preconstructed Locale Objects
Locale Name
Locale.CHINA
Locale.CHINESE
Locale.SIMPLIFIED_CHINESE
Locale.TRADITIONAL_CHINESE
Locale.PRC
Locale.TAIWAN
Locale.ENGLISH
Locale.FRANCE
Locale.FRENCH
Preconstructed locales exist for convenience. However, the list of static class constants is small and incomplete. Not every important locale is represented. Locale-sensitive class support is not determined by whether the locale exists as a
Locale class constant. For example, no South American
Locale class constants exist, yet they have complete support by several locale-sensitive classes including
DateFormatand
NumberFormat.
Because so few premade locales exist, you should probably just avoid these static objects altogether. I have described them here because they exist and because you may see them in someone else's code. Although these shortcut identifiers are convenient, your code will be more consistent without them.
Identifying Supported Locales
What locales does the Java platform support? You can create any locale that you'd like. However, your runtime environment may not fully support the
Locale object you create.
If you want to know what
Locale objects you can create, the answer is simple: You can create any locale you'd like. The constructors won't complain about non-ISO arguments. However, a more helpful restatement of the question is this: For which locales do the class libraries provide more extensive information? For which locales can the libraries provide collation, time, date, number, and currency information? Also, you might ask what scripts or writing systems your runtime environment supports.
The following sections describe how to determine supported locales in the runtime libraries. Additionally, they describe the supported scripts that can be displayed by the text components. Finally, they enumerate the localizations that are available for the runtime libraries and the software development kit (SDK) itself.
Enabled Locales in
java.util and
java.text Packages
The runtime environment has no requirement that all locales be supported equally by every locale-sensitive class. Every locale-sensitive class implements its own support for a set of locales, and that set can be different from class to class. For example, a number-format class can support a different set of locales than can a date-format class.
Additionally, there is no requirement that all runtime implementations support the same set of locales. But all implementations must support a minimal list of them. This list is quite short: English (U.S.). Fortunately, the runtime environment that Sun provides is much more extensive. Although it is not formally required, Sun's runtime implementation supports the same set of locales in each of its locale-sensitive data format classes. This provides a consistent set of support across classes. The J2SE 5.0 platform's
guide provides a full list of all supported locales. Table 5 shows a few of the supported locales.
Table 5. Some of the Supported Locales in
java.util and
java.text Packages
Saudia Arabia
Chinese (simplified)
Chinese (traditional)
Netherlands
United Kingdom
United States
South Korea
Portuguese
Thai (Western digits)
Thai (Thai digits)
To find out what locales your Java Runtime Environment (JRE) supports, you have to ask each locale-sensitive class. Each class that supports multiple locales will implement the method
getAvailableLocales(). For example,
Locale[] localeList = NumberFormat.getAvailableLocales();
getAvailableLocales() method is implemented in many of the classes in the
java.text and
java.util packages. For example,
NumberFormat,
DateFormat,
Calendar, and
BreakIterator provide it.
Locale class itself is localized for several locales. In the example below, a German locale instance provides information about itself in English (the default on the author's host), German, and French:
Locale deLocale = new Locale(&de&, &DE&);
Locale frLocale = new Locale(&fr&, &FR&);
System.out.println(&Default language name (default): & +
deLocale.getDisplayLanguage());
System.out.println(&German language name (German): & +
deLocale.getDisplayLanguage(deLocale));
System.out.println(&German language name (French): & +
deLocale.getDisplayLanguage(frLocale));
The output would look like this:
German language name (default): German
German language name (German): Deutsch
German language name (French): allemand
Enabled Script Support
Text components don't usually support single locales. Instead, text widgets support a set of scripts that often cross locale boundaries. Although it is impossible to get a listing of supported scripts from the various text components themselves, the list is published as part of the J2SE 5.0 platform's
In general, peered AWT components can render scripts that the underlying host supports. If your host system is localized to Arabic, the AWT text components will display Arabic. On an Arabic system, you would also be able to enter Arabic text into components like
TextField or
TextArea. However, you cannot expect those same AWT components to display text that isn't in the same script as the localized host. An English host would not typically be able to display Arabic in a
TextField, for example. Java Foundation Classes/Swing (JFC/Swing) components, however, can often support multiple scripts because of their independence from the host platform and their use of Unicode as a multiscript character set. Therefore, Swing components can often display a script even when peered AWT components cannot. Table 6 shows some of the supported scripts.
Table 6. Some of the Supported Scripts for Text Display
Writing System
Chinese (simplified)
Chinese (traditional)
Devanagari
Latin: Western European subset
English, French, German, Italian, Spanish, Swedish, and so on
Belorussian, Russian, and so on
Latin: Baltic subset
Latvian, Lithuanian
Latin: Central European subset
Czech, Hungarian, Polish, and so on
Latin: Turkic subset
Turkish and so on
JRE and SDK Localizations
User interface elements in the runtime environment have been localized for several locales. These elements include AWT and Swing components and other messages generated by the JRE and included tools. Table 7 shows all the localizations provided for J2SE 5.0.
Table 7. User Interface Translations for the JRE
Chinese (simplified)
Chinese (traditional)
Some tools, such as the Javac compiler, come only with the J2SE Software Development Kit (SDK). These tools provide error, warning, and informational messages to the user. Those messages within the SDK utilities and tools, including the compiler, are translated into English and Japanese. These translations are available in the
Representing Locale as a String
Although most of your use of locale will require a
Locale object reference, it is sometimes convenient to use an alternative representation, especially for internal debugging purposes. A
Locale object's
toString() method returns a
String that is the concatenation of the language, region, and variant codes. The
toString() method separates each component with the underscore character,
_. You may want to use this method during debugging because it provides a convenient and readable representation.
Consider the locale created with this code:
Locale l = new Locale(&ja&, &JP&);
toString() method will return
ja_JP for this locale.
This string is not appropriate for presentation to most end users. Most customers are not familiar with the ISO 639 and 3166 standards for language and country codes and will think the string is too cryptic. Fortunately, more user-friendly text representations are available, and we will discuss those later in this article.
Using Locale
Although not always obvious,
Locale objects are used throughout the Java class libraries. Even when you don't explicitly ask for a locale preference, the Java environment uses default locale settings to provide you with localized information and behavior. When you use an explicit locale, you can use a different locale for each part of your application.
For example, you can use the
es_MX, Spanish (Mexico), locale for displaying localized messages in Spanish and use the
en_US, English (United States), locale for number and currency formatting. This type of support would be useful for Spanish speakers who live and work in the United States. Although the application user could view Spanish menus, prompts, and text, the rest of the application could format numbers and currency correctly for the United States. This is a simple example of how you can use multiple locales in a single application. If your applications ever require this level of locale support, you have the freedom to determine the behavior of every aspect of an application.
Some of the locale-sensitive classes format numbers, currencies, dates, and time. Others provide collation as well as word-breaking services. Classes will typically provide a constructor or factory method for creating instances. In each case, you usually have the option of providing an explicit locale preference.
Using a Default Locale
The default locale is used by locale-sensitive objects whenever your application doesn't specify an explicit locale choice. Depending on the default locale is not wise. In multiuser applications, a single default locale is usually not appropriate for everyone using the system. Instead your application should explicitly provide a preference to all locale-sensitive objects. The default locale is a systemwide resource, available throughout your application to any locale-sensitive object. As the default, it may be correct for your application's user, although you should be explicit in multilingual or multicultural environments. This is especially important when your application runs on a single host that supports many users.
Retrieve the default locale using the following method:
public static Locale getDefault()
The default locale of your application is determined in three ways. First, unless you have explicitly changed the default, the
getDefault() method returns the locale that was initially determined by the Java Virtual Machine (JVM) when it first loaded. That is, the JVM determines the default locale from the host environment. The host environment's locale is determined by the host operating system and the user preferences established on that system.
Second, on some Java runtime implementations, the application user can override the host's default locale by providing this information on the command line by setting the
user.language,
user.country, and
user.variant system properties.
The following code will print out a different locale depending on the value of these properties when it is invoked:
import java.util.L
public class Default {
public static void main(String[] args) {
System.out.println(Locale.getDefault());
You can experiment with the above code example. Running on a U.S. English system, the above code prints
en_US. If you provide command-line options as described above, you can coax your application into using any locale you need. For example, you can invoke the application like this:
java -Duser.language=fr -Duser.country=CA Default
This invocation prints
fr_CA as the default locale.
Third, your application can call the
setDefault(Locale aLocale) method. The
setDefault(Locale aLocale) method lets your application set a systemwide resource. After you set the default locale with this method, subsequent calls to
Locale.getDefault() will return the newly set locale.
Note: Take care not to call
setDefault() in applets. The Security Manager will not allow you to call this method because it affects a systemwide resource within the JVM that runs on the host.
In most cases, using the default locale with other classes means ignoring it altogether. For example, if you want to format a number for your default locale, you simply create a
NumberFormat without any arguments:
NumberFormat nf = NumberFormat.getInstance();
That's it. Using the default locale requires almost nothing on your part. Other locale-sensitive classes follow this same pattern. If you want the default locale behavior, do nothing special when creating the object. However, the default isn't always appropriate, and you'll need to be more explicit at those times.
Using an Explicit Locale
In some computing environments, applications use only a single locale throughout their life cycle. In other environments, applications use a global locale that can be changed. Those environments allow you to programmatically change the global locale preference, which remains in effect until you explicitly change it again. The Java application environment is unique, providing you with the ability to use a variety of locales throughout your application in any way you require.
Multinational companies have customers all around the globe. This means that both their customers and employees may speak different languages and have different expectations for how the company and its software should behave. Moreover, it is entirely possible, even common, to have a French employee handle a sales record for an Italian customer. In those situations, you will need absolute control over which locale your business and user interface objects use to manipulate and represent data. Your application may need to print sales receipts using Italian date and currency formats, yet sort customer lists for an English sales employee. The combinations are far too numerous to list, but Java technology provides you the flexibility to handle that complexity.
In order to get the most flexibility, you must explicitly request support for a target locale for each locale-sensitive class that you use. That means you must track the locale preferences for multiple aspects of the application or assign locale preferences to different users and customers.
If you have tracked the user's locale preference, you would create instances of locale-sensitive classes by explicitly providing a locale in a constructor or creation method. Imagine that a
preferences object stores your customer's locale choice:
Locale userLocale = preferences.getLocale();
NumberFormat nf = NumberFormat.getInstance(userLocale);
Retrieving Locale Information
Locale objects don't contain much information, they do provide a few interesting methods. As you might expect, the information is tightly related to the object's language, country, and variant. Some of this information is locale- some is locale-dependent. All this means is that the
Locale object has two different forms for most of its methods. One set of information is not customer-oriented or localized. The other set is localized and is suitable for presentation to the user.
Locale-Independent Information
getLanguage() method returns the ISO 639 two-letter abbreviation for the locale's language. For example, if you have created the locale
ja_JP, this method returns the code
ja. The method's full signature is
public String getLanguage()
An extension of the ISO 639 standard defines three-letter language codes. Although these codes are not currently used in J2SE 5.0, the codes are available. Use the following method to retrieve the three-letter language code:
public String getISO3Language()
An example shows the difference:
Locale aLocale = Locale.JAPAN;
System.out.println(&Locale: & + aLocale); System.out.println(&ISO 2 letter: &
+ aLocale.getLanguage());
System.out.println(&ISO 3 letter: & + aLocale.getISO3Language());
aLocale = Locale.US;
System.out.println(&Locale:& + aLocale);
System.out.println(&ISO 2 letter: & + aLocale.getLanguage());
System.out.println(&ISO 3 letter: & + aLocale.getISO3Language());
The output would look like this:
Locale: ja_JP
ISO 2 letter: ja
ISO 3 letter: jpn
Locale: en_US
ISO 2 letter: en
ISO 3 letter: eng
getCountry() method returns the ISO 3166 two-letter abbreviation for the locale's region or country member. Its full signature is the following:
public String getCountry()
An ISO extension defines a three-letter code for countries too:
public String getISO3Country()
An example demonstrates their difference:
Locale aLocale = Locale.CANADA_FRENCH;
System.out.println(&Locale: & + aLocale);
System.out.println(&ISO 2 letter: & + aLocale.getCountry());
System.out.println(&ISO 3 letter: & + aLocale.getISO3Country());
The output would look like this:
Locale: fr_CA
ISO 2 letter: CA
ISO 3 letter: CAN
Locale object has a variant field, the
getVariant() method will identify and return it as a
String. If the
Locale object has not defined a variant, this method returns an empty
String. This method's declaration is the following:
public String getVariant()
The following class methods can be used to retrieve arrays of all the valid language and country codes available:
public static String[] getISOCountries()
public static String[] getISOLanguages()
A developer is much more likely to appreciate and to use the code returned by
getLanguage() than is a customer. Your customer probably expects something different, as described in the next section.
Locale-Dependent Information
The codes supplied by the
getLanguage(),
getCountry(), and
getVariant() methods are not especially user-friendly. Your customer should probably not have to interpret these codes, so locale provides additional methods that provide more readable, customer-oriented information.
Locale objects provide methods that return human-understandable text representations. This text representation is different from what the
toString() method provides. Unlike the simple concatenation of the language, country, and variant fields, these methods provide human-readable, localized information about the locale:
public final String getDisplayLanguage()
public final String getDisplayCountry()
public final String getDisplayVariant()
Display Language
When you need to display a locale's language to your user, you should use the
Locale object's
getDisplayLanguage() method. This method returns the displayable, human-readable name of the locale's language. The display name is localized for the default locale if you don't provide a target locale argument. There are two forms of this method:
public final String getDisplayLanguage()
public final String getDisplayLanguage(Locale targetLocale)
The following examples show how these methods can be used:
Locale deLocale = Locale.GERMANY;
// Default system Locale is en_US for this method call.
String defaultLanguage = deLocale.getDisplayLanguage();
// Target de_DE is used as an explicit target language.
String targetLanguage = deLocale.getDisplayLanguage(deLocale);
System.out.println(defaultLanguage);
System.out.println(targetLanguage);
The output would look like this:
The output
German is the U.S. English word for the locale's language. That's not especially impressive, but notice how you can provide a target locale argument. In that situation,
getDisplayLanguage() tries to find and return a localized version of its language component.
This is important because you can show your customer the language of each locale that your application supports in the customer's target language. You can provide this list in your application to allow your customers to choose their preferred locale.
This brings up an interesting question: How do you present a locale's display language in the locale's language? You would do it with the following code:
String displayLang = aLocale.getDisplayLanguage(aLocale);
In other words, you simply provide the
Locale object to itself in the call to
getDisplayLanguage(). This same trick works with other displayable locale elements as well. For example, the display country and variant can be handled this way too. The following code snippet demonstrates this technique (see Figure 1):
Locale[] locales = { new Locale(&en&, &US&), new Locale(&ja&,&JP&),
new Locale(&es&, &ES&), new Locale(&it&, &IT&) };
for (int x=0; x& locales. ++x) {
String displayLanguage = locales[x].getDisplayLanguage(locales[x]);
println(locales[x].toString() + &: & + displayLanguage);
Figure 1. Displaying the Display Language in the Locale's Language
Display Country
Retrieve a locale's country or region component for user display with the following code:
public final String getDisplayCountry()
public final String getDisplayCountry(Locale targetLocale)
The first method form provides a localized country name for the default locale. The second form provides the same information localized for the target locale.
Locale deLocale = Locale.GERMANY;
// default en_US
String defaultCountry = deLocale.getDisplayCountry();
// target de_DE
String targetCountry = deLocale.getDisplayCountry(deLocale);
System.out.println(defaultCountry);
System.out.println(targetCountry);
The output would look like this:
Deutschland
Display Variant
Variants are less used than other elements of a Locale. However, at times you still need to access that information. The
getDisplayVariant() method returns the display name for the private variant member of Locale:
public final String getDisplayVariant()
public final String getDisplayVariant(Locale targetLocale)
One way the Java platform uses this variant is to support the Thai language. By convention, a
NumberFormat object for the
th_TH locales will use common Arabic digit shapes, or Arabic numerals, to format Thai numbers. However, a
NumberFormat for the
th_TH_TH locale uses Thai digit shapes. The following code demonstrates (see Figure 2):
Locale[] thaiLocale = {new Locale(&th&), new Locale(&th&,&TH&),
new Locale(&th&,&TH&, &TH&)};
for(Locale locale: thaiLocale) {
NumberFormat nf = NumberFormat.getNumberInstance(locale);
StringBuffer msgBuff = new StringBuffer();
msgBuff.append(locale.toString() + &: &);
msgBuff.append(nf.format(573.34));
textArea.append(msgBuff.toString() + &\n&);
Figure 2. Displaying Numbers in Arabic and Traditional Thai Digits
Display Name
The display name is simply a combination of the localized language, country, and variants demonstrated earlier. The method forms are the following:
public final String getDisplayName()
public final String getDisplayName(Locale targetLocale)
Unlike locale's
toString() method, which concatenates the individual components and separates them with an underscore character, the
getDisplayName() method uses parentheses to separate the elements.
Locale deLocale = Locale.GERMANY;
// default en_US
String defaultCountry = deLocale.getDisplayName();
// target de_DE
String targetCountry = deLocale.getDisplayName(deLocale);
System.out.println(defaultCountry);
System.out.println(targetCountry);
The output would look like this:
German (Germany)
Deutsch (Deutschland)
Locale is an identifier for a language, an optional country (or region), and an optional variant code. Locale objects provide several methods that provide information about the locale's state. Although a locale doesn't itself contain much functionality, locale-sensitive objects depend on locale for an indication on how to behave. Locale-sensitive objects use the locale to customize their behavior so that they meet the user's expectations. In the Java platform, each locale-sensitive object is responsible for its own locale-dependent behavior. By design, locale-sensitive classes are independent of each other. That is, the set of supported locales in one class does not need to be the same as the set in another class.
In traditional operating systems and localization models, only one locale setting is active at a time. In those systems, after you programmatically set the locale, all locale-sensitive functions use the specified locale, which remains active throughout the application as a global locale. It changes when there is another global locale activation through a
setlocale or similar call. The Java platform, however, treats locales a little differently. A Java application can actually have multiple locales active at the same time. That is, it is possible to use a U.S. date format and a German number format in the same application. The ability to use multiple
Locale objects with various
Format objects provides developers the opportunity to create complex combinations necessary for creating multicultural and multilingual applications.
For More Information
ISO 3166 country or region codes
guide for J2SE 5.0
documentation downloads
Rate and Review
Tell us what you think of the content of this page.
Excellent&&
Your email address (no reply is possible without an address):
Note: We are not able to respond to all submitted comments.
Oracle Cloud
Customers and Events
Email Subscriptions
Communities
Services and Store
Contact and Chat
US Sales: +1.800.633.0738

我要回帖

更多关于 the following day 的文章

 

随机推荐