Chapter 14 Internationalization F Processing Date and Time –Locale –Date –TimeZone –Calendar and GregorianCalendar –DateFormat and SimpleDateFormat F Formatting.

Slides:



Advertisements
Similar presentations
Chapter 6 Objects and Classes F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and.
Advertisements

CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
L3:CSC © Dr. Basheer M. Nasef Lecture #3 By Dr. Basheer M. Nasef.
1 Chapter 8 Objects and Classes Lecture 2 Prepared by Muhanad Alkhalisy.
Chapter 3: Engage! Android User Input, Variables, and Operations
Session 8 JavaScript/Jscript: Objects Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
Class Locale 1/3 Constructor Locale(String, String) Construct a locale from language, country. Locale(String, String, String) Construct a locale from language,
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 1 Abstract Classes and Interfaces.
Chapter 3 - Java Programming With Supplied Classes1 Chapter 3 Java Programming With Supplied Classes.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Review of Java Applets Vijayan Sugumaran Decision and Information Sciences Oakland University.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
Processing Date and Time Date class Date currentTime = new Date(); DateFormat class The DateFormat class can be used to format date and time in a number.
Internationalization of Java Platform Presenter: Ataru Nakazawa Advisor: Xiaoping Jia Date: January 23, 2004.
Time & Date Representation in Java. Date class An object of type Date represents an instance in time Part of java.util.* (requires import statement) A.
Chapter 3b Standard Input and Output Sample Development.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: IO *Standard Output *Formatting Decimal.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
Object-oriented Programming in Java. © Aptech Ltd. Internationalization and Localization/Session 12 2  Describe internationalization  Describe localization.
Cupertino, CA, USA / September, 2000First ICU DeveloperWorkshop1 Date/Time/Number Formatting Alan Liu Globalization Center of Competency IBM Emerging Technology.
Programming with Microsoft Visual Basic 2012 Chapter 7: Sub and Function Procedures.
JSP Standard Tag Library
Java Programming, Second Edition Chapter Four Advanced Object Concepts.
Using Object-Oriented JavaScript CST 200- JavaScript 4 –
CIS 270—Application Development II Chapter 28—Formatted Output.
Sakai: Localization & Internationalization Beth Kirschner University of Michigan
SOFTWARE INTERNATIONALIZATION Dallas Ramsden. Internationalization GOAL Software that can run ANYWHERE in the world without having the source code changed.
Internationalization and the Java Stack Part 1 Matt Wheeler.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Internationalization and the Java Stack Matt Wheeler.
Internationalization in the Java Stack Matt Wheeler.
Chapter 14 Internationalization F Processing Date and Time –Locale –Date –TimeZone –Calendar and GregorianCalendar –DateFormat and SimpleDateFormat F Formatting.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 26 Internationalization.
Chapter 12: Internationalization Processing Date and Time Processing Date and Time  Locale  Date  TimeZone  Calendar and GregorianCalendar  DateFormat.
1 1 Abstract Classes and Interfaces. 22 Motivations You learned how to write simple programs to display GUI components. Can you write the code to respond.
Chapter 10: Applets and Advanced Graphics The Applet Class The Applet Class The HTML Tag The HTML Tag Passing Parameters to Applets Passing Parameters.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 1 Chapter 13 Abstract Classes and Interfaces.
1 Chapter 14 Object-Oriented Software Development Dale/Weems.
JAC444: Dates Tim McKenna Dates, Calendars, and what year is this? §Java tries to take an OOD approach to “when is now?” §import java.util.*;
Server-Side Scripting with JSP (2) ISYS 350. Java Array Examples of declaring an array: – int[] anArray = new int[10]; 10 elements index from 0 to 9 –
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Garside, JAVA: First Contact, 2ed Java First Contact – 2 nd Edition Garside and Mariani Chapter 6 More Java Data Types.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
CiS 260: App Dev I. 2 Introduction to Methods n A method (or ________) is a segment of code that performs a specific task. n Advantages of modular program.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
Mr C Johnston ICT Teacher
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 1 Chapter 13 Abstract Classes and Interfaces.
1 Chapter 20 Internationalization. 2 Objectives F To describe Java's internationalization features (§ 20.1). F To construct a locale with language, country,
BPJ444: Dates Peter Liu Tim McKenna Dates, Calendars, and what year is this? §Java tries to take an OOD approach to “when is now?” §import.
Internationalization Slide 1©SoftMoore Consulting.
Java Util Package Prepared by, S.Amudha AP/SWE. Calendar 1.The abstract Calendar class provides a set of methods that allows you to convert a time in.
Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Chapter 3: Using Classes and Objects Coming up: Creating Objects.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 1 Chapter 15 Abstract Classes and Interfaces.
Working with Date ISYS 350.
Chapter 13 Abstract Classes and Interfaces
Chapter 13 Abstract Classes and Interfaces
Chapter 14 Internationalization
Internationalization
Phonegap Bridge – Globalization
More About Objects and Methods
CS170 ygao JAVA, C7.
Java Date ISYS 350.
Chapter 12 Abstract Classes and Interfaces
Java Date ISYS 350.
Chapter 35 Internationalization
Phonegap Bridge – Globalization
Chapter 13 Abstract Classes and Interfaces Part 01
Java Date ISYS 350.
Java Date ISYS 350.
Putting Values into a Suitable Form for Display
Presentation transcript:

Chapter 14 Internationalization F Processing Date and Time –Locale –Date –TimeZone –Calendar and GregorianCalendar –DateFormat and SimpleDateFormat F Formatting Numbers F Resource Bundles

Java’s International Support 1. Use Unicode 2. Provide the Locale class to encapsulate information about a specific locale. 3. Use the ResourceBundle class to separate locale-specific information such as status messages and the GUI component labels from the program.

The Locale Class A Locale object represents a specific geographical, political, or cultural region. An operation that requires a Locale to perform its task is called locale-sensitive. You can use Locale to tailor information to the user.

Creating a Locale To create a Locale object, you can use the following constructor in Locale class: Locale(String language, String country) Locale(String language, String country, String variant) Example: new Locale(“en”, “US”); new Locale(“fr”, “CA”);

The Date Class The Date class represents a specific instant in time, with millisecond precision. You can construct a Date object using one of the following two constructors in this class: F public Date(); F public Date(long time);

The TimeZone Class The class TimeZone represents a time zone offset; it also figures out daylight-saving time. Typically, you can get a TimeZone object using its class method getDefault(), which creates a TimeZone object based on the time zone in which the program is running.

Creating a TimeZone You can also get a TimeZone object by using the class method getTimeZone(), along with a time zone ID. For example, the time zone ID for central standard time is CST. Therefore, you can get a CST TimeZone object with the following: TimeZone tz = TimeZone.getTimeZone("CST");

The Calendar Class A Date object represents a specific instant in time with millisecond precision. Calendar is an abstract base class for converting between a Date object and a set of integer fields, such as year, month, day, hour, minute, and second.

The GregorianCalendar Class Subclasses of Calendar interpret a Date according to the rules of a specific calendar system. For example: GregorianCalendar(TimeZone tz, Locale locale) This constructs a GregorianCalendar object based on the current time in the given time zone with the given locale.

The get() Method public final int get(int field) This retrieves the value for a given time field. The parameter field is a constant, such as YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, DAY_OF_WEEK, DAY_OF_MONTH, DAY_OF_YEAR, WEEK_OF_MONTH, WEEK_OF_YEAR, and so on.

GregorianCalendar Example GregorianCalendar rightNow = new GregorianCalendar(); System.out.println("week of the year is "+rightNow.get(GregorianCalendar.WEEK_OF_YEAR)); This displays the week of the year for the current time.

The DateFormat Class The DateFormat class is an abstract class that provides many class methods for obtaining default date and time formatters based on the default or a given locale and a number of formatting styles, including FULL, LONG, MEDIUM, and SHORT.

DateFormat Formats  SHORT is completely numeric, such as or 3:30pm  MEDIUM is longer, such as Jan 12, 1952  LONG is even longer, such as January 12, 1952 or 3:30:32pm  FULL is completely specified, such as Tuesday, April 12, 1952 AD or 3:30:42pm PST

Creating a DateFormat You can use the getDateTimeInstance() method to obtain a DateFormat object: public static final DateFormat getDateTimeInstance (int dateStyle, int timeStyle, Locale aLocale) This gets the date and time formatter with the given formatting styles for the given locale.

The SimpleDateFormat Class The date and time formatting subclass, such as SimpleDateFormat, enables you to choose any user- defined patterns for date and time formatting. To specify the time format, use a time pattern string: formatter = new SimpleDateFormat("yyyy.MM.dd G 'at' hh:mm:ss Z"); AD at 04:10:18 PST

Example 14.1 Displaying a Clock F Objective: Display current time based on the specified locale and time zone. The program can run as applet or application. The language, country, and time zone are passed to the program as command-line arguments like this: javaw CurrentTimeApplet en US CST CurrentTimeApplet Run as AppletRun as Application

Example 14.2 Displaying a Calendar  Objective: D isplay the calendar based on the specified locale. The user can specify a locale from a combo box that consists of a list of all the available locales supported by the system. CalendarApplet Run as AppletRun as Application

Formatting Numbers Formatting numbers as currency or percentages is highly locale dependent. For example, number is displayed as $5, in the US currency, but the same number is displayed as 5 000,50 F in the French currency.

The NumberFormat Class use one of the factory class methods to get a formatter. Use getInstance() or getNumberInstance() to get the normal number format. Use getCurrencyInstance() to get the currency number format. Use getPercentInstance() to get a format for displaying percentages. With this format, a fraction like 0.53 is displayed as 53%.

The NumberFormat Class (cont.) For example, to display a number in percentages, you can use the following code to create a formatter for the given locale. NumberFormat percForm = NumberFormat.getPercentInstance(locale); You can then use percForm to format a number into a string like this: String s = percForm.format(0.075);

Example 14.3 Formatting Numbers  Objective: This example creates a mortgage calculator similar to the one in Example 10.1, "Using Applets." This new mortgage calculator allows the user to choose locales, and displays numbers in locale-sensitive format. NumberFormattingDemo Run as AppletRun as Application

Resource Bundles (Optional) A resource bundle is a Java class file or a text file that provides locale-specific information. This information can be accessed by Java programs dynamically. When your program needs a locale-specific resource, a message string for example, your program can load the string from the resource bundle that is appropriate for the desired locale. In this way, you can write program code that is largely independent of the user's locale isolating most, if not all, of the locale-specific information in resource bundles.

Example 14.4 Using Resource Bundles  Objective: This example modifies the NumberFormattingDemo program in Example 14.3 to display messages, title, and button labels in English and French languages. ResourceBundleDemo Run as Applet Run as Application Res.properties Res_fr.properties