SlideShare a Scribd company logo
Advanced Java Programming
Topic: Internationalization
By
Ravi Kant Sahu
Asst. Professor, LPU
Contents
 Introduction
 Locale Class
 Displaying Date and Time
 Formatting Numbers
 Resource Bundles
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Introduction
 Problem of customizing a program or page for different
countries or languages.
 It would be highly problematic to create and maintain
enough different versions to meet the needs of all clients
everywhere.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Internationalization
 Internationalization is the process of designing an
application so that it can be adapted to various languages
and regions without engineering changes.
 Java is the first language designed to support
Internationalization.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Characteristics
 An internationalized program has the following characteristics:
1. With the addition of localized data, the same executable can run
worldwide.
2. Textual elements, such as status messages and the GUI component
labels, are not hardcoded in the program. Instead they are stored
outside the source code and retrieved dynamically.
3. Support for new languages does not require recompilation.
4. Culturally-dependent data, such as dates and currencies, appear in
formats that conform to the end user's region and language.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Java Features to Support
Internationalization
1. Unicode
2. Locale Class
3. Resource Bundles
Note: Java characters use Unicode, a 16-bit encoding scheme
established by the Unicode Consortium to support the interchange,
processing, and display of written texts in the world’s diverse
languages.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
LocaLe cLass
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Locale
 A Locale object represents a geographical, political, or cultural
region in which a specific language or custom is used.
For example, Americans speak English, and the Chinese speak
Chinese.
 The conventions for formatting dates, numbers, and currencies
may differ from one country to another.
For example, The Chinese use year/month/day to represent the
date, while Americans use month/day/year.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Locale
 Locale class encapsulates information about a specific locale.
 A Locale object determines how locale-sensitive information,
such as date, time, and number, is displayed.
 The classes for formatting date, time, and numbers, and for
sorting strings are grouped in the java.text package.
 Every Swing class has a locale property inherited from the
Component class.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Creating Locale Object
 Constructor:
Locale (String Language)
Locale (String Language, String Country)
Locale (String Language, String Country, String Variant)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Language and Country Codes
Country Country Code Language Code
Spain ES es
Denmark DK da
Germany DE de
Greece GR el
China CN zh
Sweden SE sv
France FR fr
Norway NO no
Japan JP ja
United Kingdom GB en
Korea KR ko
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Methods of Locale Class
String getCountry()
String getLanguage()
String getVariant()
Locale getDefault()
String getDisplayCountry()
String getDisplayLanguage()
String getDisplayName()
String getDisplayVariant()
Locale[] getAvailableLocales()
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Locale Constants
 Predefined Country Constants
Locale.US, Locale.UK, Locale.FRANCE, Locale.GERMANY,
Locale.ITALY, Locale.CHINA, Locale.KOREA, Locale.JAPAN
 Predefined Language Constants
Locale.CHINESE, Locale.ENGLISH, Locale.FRENCH,
Locale.GERMAN, Locale.ITALIAN, Locale.JAPANESE,
Locale.KOREAN, Locale.SIMPLIFIED_CHINESE, and
Locale.TRADITIONAL_CHINESE
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Displaying Time and Date
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Displaying Date and Time
 Java provides a system independent encapsulation of date
and time in the java.util.Date class.
 It also provides java.util.TimeZone class for dealing with
time zones.
 java.util.Calendar can be used for extracting detailed
information from Date.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
TimeZone Class
 TimeZone is an abstract class.
Constructor:
There is only default Constructor for TimeZone.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Methods of TimeZone Class
 static String[] getAvailableIDs()
used to find all the available time-zones supported in Java.
 static TimeZone getDefault()
used to obtain the default time-zone on host machine.
 static TimeZone getTimeZone(String ID)
used to get TimeZone object for specified TimeZoneID.
 String getID()
This method gets the ID of this time zone.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
DateFormat Class
 An abstract class for date/time formatting subclasses which formats
and parses dates or time in a language-independent manner.
 Constructor:
protected DateFormat()
 Constants:
 SHORT is completely numeric, such as 01.12.52 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 pretty completely specified, such as Tuesday, April 12, 1952
AD or 3:30:42pm IST.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Methods of DateFormat Class
 String format(Date date)
Formats a Date into a date/time string.
 static DateFormat getInstance()
Get a default date/time formatter that uses the SHORT style for both
the date and the time.
 void setTimeZone(TimeZone zone)
Sets the time zone for the calendar of this DateFormat object.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Methods of DateFormat Class
 static DateFormat getDateInstance()
Gets the date formatter with the default formatting style for the default
locale.
 static DateFormat getDateInstance(int style)
Gets the date formatter with the given formatting style for the default
locale.
 static DateFormat getDateInstance(int style, Locale aLocale)
Gets the date formatter with the given formatting style for the given
locale.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Methods of DateFormat Class
 static DateFormat getDateTimeInstance()
Gets the date/time formatter with the default formatting style for the
default locale.
 static DateFormat getDateTimeInstance(int dateStyle, int timeStyle)
 Gets the date/time formatter with the given date and time formatting styles
for the default locale.
 static DateFormat getDateTimeInstance(int dateStyle, int timeStyle,
Locale aLocale)
Gets the date/time formatter with the given formatting styles for the given
locale.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
SimpleDateFormat Class
 Defined in java.text package.
 Enables to choose any user-defined pattern for date and time
formatting.
public SimpleDateFormat(String Pattern)
Example: SimpleDateFormat formatter = new
SimpleDateFormat("yyyy.MM.dd G 'at' hh:mm:ss z");
Note: G represents Era designator, and z is TimeZone.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
DateFormatSymbols Class
 Constructors:
DateFormatSymbols()
DateFormatSymbols(Locale locale)
 Methods:
String[] getAmPmStrings()
String[] getEras()
String[] getMonths()
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Methods
void setMonths(String[] newMonths)
String[] getShortMonths()
void setShortMonths(String[] newShortMonths)
String[] getWeekdays()
void setWeekdays(String[] newWeekdays)
String[] getShotWeekdays()
void setShortWeekdays(String[] newWeekdays)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Formatting numbers
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Formatting Numbers
 Numbers are formatted using an abstract base class
java.text.NumberFormat .
 Formatting numbers is highly locale dependent.
Number: 5000.555
United States: 5,000.555
France: 5000,555
Germany: 5.000,555
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Methods
 getInstance(): NumberFormat
 getInstance(locale: Locale): NumberFormat
 getIntegerInstance(): NumberFormat
 getIntegerInstance(locale: Locale): NumberFormat
 getCurrencyInstance(): NumberFormat
 getNumberInstance(): NumberFormat
 getNumberInstance(locale: Locale): NumberFormat
 getPercentInstance(): NumberFormat
 getPercentInstance(locale: Locale): NumberFormat
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Methods
 format (number: double): String
 format (number: long): String
 getMaximumFractionDigits(): int
 setMaximumFractionDigits(newValue: int): void
 getMinimumFractionDigits(): int
 setMinimumFractionDigits(newValue: int): void
 getMaximumIntegerDigits(): int
 setMaximumIntegerDigits(newValue: int): void
 getMinimumIntegerDigits(): int
 setMinimumIntegerDigits(newValue: int): void
 parse(source: String): Number
 getAvailableLocales(): Locale[]
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Formatting Numbers
 Plain Number Format:
NumberFormat nf = NumberFormat.getInstance(Locale l);
System.out.println(nf.format(1010.1055));
 Currency Format:
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale l);
 Percent Format:
NumberFormat nf = NumberFormat.getPercentInstance(Locale l);
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Parsing Numbers
 format(numericalValue) method is used to format a number into
a string.
 parse(String) method can be used to convert a formatted
plain number, currency value, or percent number with the
conventions of a certain locale into an instance of
java.lang.Number.
 The parse method throws a java.text.ParseException, if
parsing fails.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example
U.S. $5,000.56 can be parsed into a number using the following
statements:
NumberFormat currencyFormat =
NumberFormat.getCurrencyInstance(Locale.US);
try {
Number number = currencyFormat.parse("$5,000.56");
System.out.println(number.doubleValue());
}
catch (java.text.ParseException ex) {
System.out.println("Parse failed");
}
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
DecimalFormat Class
 We can use the applyPattern(String pattern) method of the
DecimalFormat class to specify the patterns for displaying the
number.
 A pattern can specify the minimum number of digits before the
decimal point and the maximum number of digits after the
decimal point.
 The characters '0‘ and '#' are used to specify a required digit and
an optional digit, respectively.
 The optional digit is not displayed if it is zero.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example
 The pattern "00.0##" indicates minimum two digits before the
decimal point and maximum three digits after the decimal point.
 If there are more actual digits before the decimal point, all of
them are displayed.
 If there are more than three digits after the decimal point, the
number of digits is rounded.
Example:
1987.16920 will be formatted as: 1987.169
1389.2387 will be formatted as: 1389.239
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Resource Bundles
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Resource Bundles
 A resource bundle is a Java class file or text file that provides
locale-specific information.
 This information can be accessed by Java programs dynamically.
 Resource bundles allows to write programs that separate the
locale-sensitive part of our code from the locale-independent
part.
 When a locale-specific resource is needed, our program can load
it from the resource bundle appropriate for the desired locale.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Resource Bundles
 The resources are placed inside the classes that extend the
ResourceBundle class or a subclass of ResourceBundle.
 Resource bundles contain key/value pairs.
 Each key uniquely identifies a locale-specific object in the bundle.
 Key is used to retrieve the object.
 ListResourceBundle is a subclass of ResourceBundle that is often
used to simplify the creation of resource bundles.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example
public class MyResource extends java.util.ListResourceBundle
{
static final Object[][] contents = {
{"nationalFlag", "us.gif"},
{"nationalAnthem", "us.au"},
{"nationalColor", Color.red},
{"annualGrowthRate", new Double(7.8)}
};
public Object[][] getContents() {
return contents; }
}
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Properties File
 If all the resources are strings, they can be placed in a convenient
text file with the extension .properties.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Resource Bundle Naming Conventions
1. BaseName_language_country_variant.class
2. BaseName_language_country.class
3. BaseName_language.class
4. BaseName.class
5. BaseName_language_country_variant.properties
6. BaseName_language_country.properties
7. BaseName_language.properties
8. BaseName.properties
 The getBundle method attempts to load the class that matches the
specified locale by language, country, and variant by searching the file
names in the order shown above.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Retrieving Values from Resource Bundle
 To retrieve values from a ResourceBundle in a program, we need
to create an instance of ResourceBundle using one of the following
two static methods:
public static final ResourceBundle getBundle(String
baseName) throws MissingResourceException
public static final ResourceBundle getBundle (String
baseName, Locale locale) throws MissingResourceException
 The first method returns a ResourceBundle for the default locale,
and second returns a ResourceBundle for the specified locale.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
 getObject() method can be used to retrieve the value according to
the key.
ResourceBundle res = ResourceBundle.getBundle("MyResource");
String flagFile = (String)res.getObject("nationalFlag");
 If the resource value is a string, then getString() method is more
convenient to use.
String flagFile = res.getString("nationalFlag");
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Character Encoding
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Character Encoding
 Java programs use Unicode. When we read a character using text
I/O, the Unicode code of the character is returned.
 The encoding of the character in the file may be different.
 Java automatically converts it to the Unicode.
 When we write a character using text I/O, Java automatically
converts the Unicode of the character to the encoding specified for
the file.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Character Encoding
 We can specify an encoding scheme using a constructor of
Scanner/PrintWriter for text I/O, as follows:
public Scanner(File file, String encodingName)
public PrintWriter(File file, String encodingName)
Encoding Names:
https://docs.oracle.com/javase/1.5.0/docs/guide/intl/encoding.doc.
html
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
All the Best
for
Mid-Term exams

More Related Content

What's hot

Java collections concept
Java collections conceptJava collections concept
Java collections concept
kumar gaurav
 
Data types in php
Data types in phpData types in php
Data types in phpilakkiya
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
Vikas Jagtap
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
Dhruvin Nakrani
 
Common language runtime clr
Common language runtime clrCommon language runtime clr
Common language runtime clr
SanSan149
 
Creating an executable jar file
Creating an executable jar fileCreating an executable jar file
Creating an executable jar fileAnkush Srivastava
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
BG Java EE Course
 
Java awt
Java awtJava awt
Java awt
Arati Gadgil
 
Java Garbage Collection - How it works
Java Garbage Collection - How it worksJava Garbage Collection - How it works
Java Garbage Collection - How it works
Mindfire Solutions
 
Introduction to java beans
Introduction to java beansIntroduction to java beans
Introduction to java beans
Hitesh Parmar
 
Javascript operators
Javascript operatorsJavascript operators
Javascript operatorsMohit Rana
 
Layout manager
Layout managerLayout manager
Java rmi
Java rmiJava rmi
Java rmi
kamal kotecha
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
Shraddha
 
Java beans
Java beansJava beans
Java beans
Rajkiran Mummadi
 
Servlets
ServletsServlets
Servlets
ZainabNoorGul
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
priya_trivedi
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
Rajkumarsoy
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
Shubham Dwivedi
 
Event handling
Event handlingEvent handling

What's hot (20)

Java collections concept
Java collections conceptJava collections concept
Java collections concept
 
Data types in php
Data types in phpData types in php
Data types in php
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 
Common language runtime clr
Common language runtime clrCommon language runtime clr
Common language runtime clr
 
Creating an executable jar file
Creating an executable jar fileCreating an executable jar file
Creating an executable jar file
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Java awt
Java awtJava awt
Java awt
 
Java Garbage Collection - How it works
Java Garbage Collection - How it worksJava Garbage Collection - How it works
Java Garbage Collection - How it works
 
Introduction to java beans
Introduction to java beansIntroduction to java beans
Introduction to java beans
 
Javascript operators
Javascript operatorsJavascript operators
Javascript operators
 
Layout manager
Layout managerLayout manager
Layout manager
 
Java rmi
Java rmiJava rmi
Java rmi
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
 
Java beans
Java beansJava beans
Java beans
 
Servlets
ServletsServlets
Servlets
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Event handling
Event handlingEvent handling
Event handling
 

Viewers also liked

Sms several papers
Sms several papersSms several papers
Sms several papersArjun Shanka
 
Distributed Programming (RMI)
Distributed Programming (RMI)Distributed Programming (RMI)
Distributed Programming (RMI)Ravi Kant Sahu
 
Questions for Class I & II
Questions for Class I & IIQuestions for Class I & II
Questions for Class I & II
Saloni Jaiswal
 
Classes and Nested Classes in Java
Classes and Nested Classes in JavaClasses and Nested Classes in Java
Classes and Nested Classes in JavaRavi_Kant_Sahu
 

Viewers also liked (16)

Jdbc
JdbcJdbc
Jdbc
 
Packages
PackagesPackages
Packages
 
List classes
List classesList classes
List classes
 
Collection framework
Collection frameworkCollection framework
Collection framework
 
Basic IO
Basic IOBasic IO
Basic IO
 
Sms several papers
Sms several papersSms several papers
Sms several papers
 
Networking
NetworkingNetworking
Networking
 
Jun 2012(1)
Jun 2012(1)Jun 2012(1)
Jun 2012(1)
 
Swing api
Swing apiSwing api
Swing api
 
Distributed Programming (RMI)
Distributed Programming (RMI)Distributed Programming (RMI)
Distributed Programming (RMI)
 
Questions for Class I & II
Questions for Class I & IIQuestions for Class I & II
Questions for Class I & II
 
Multi threading
Multi threadingMulti threading
Multi threading
 
Event handling
Event handlingEvent handling
Event handling
 
Servlets
ServletsServlets
Servlets
 
Classes and Nested Classes in Java
Classes and Nested Classes in JavaClasses and Nested Classes in Java
Classes and Nested Classes in Java
 
Generics
GenericsGenerics
Generics
 

Similar to Internationalization

Named Entity Recognition for Telugu Using Conditional Random Field
Named Entity Recognition for Telugu Using Conditional Random FieldNamed Entity Recognition for Telugu Using Conditional Random Field
Named Entity Recognition for Telugu Using Conditional Random Field
Waqas Tariq
 
Methods and constructors
Methods and constructorsMethods and constructors
Methods and constructorsRavi_Kant_Sahu
 
Towards Building Semantic Role Labeler for Indian Languages
Towards Building Semantic Role Labeler for Indian LanguagesTowards Building Semantic Role Labeler for Indian Languages
Towards Building Semantic Role Labeler for Indian Languages
Algoscale Technologies Inc.
 
ON THE UTILITY OF A SYLLABLE-LIKE SEGMENTATION FOR LEARNING A TRANSLITERATION...
ON THE UTILITY OF A SYLLABLE-LIKE SEGMENTATION FOR LEARNING A TRANSLITERATION...ON THE UTILITY OF A SYLLABLE-LIKE SEGMENTATION FOR LEARNING A TRANSLITERATION...
ON THE UTILITY OF A SYLLABLE-LIKE SEGMENTATION FOR LEARNING A TRANSLITERATION...
cscpconf
 
Java J2EE by Fairline
Java J2EE by FairlineJava J2EE by Fairline
Java J2EE by Fairline
Pranjalisoni1
 
Improvement in Quality of Speech associated with Braille codes - A Review
Improvement in Quality of Speech associated with Braille codes - A ReviewImprovement in Quality of Speech associated with Braille codes - A Review
Improvement in Quality of Speech associated with Braille codes - A Review
inscit2006
 
Punjabi Text Classification using Naïve Bayes, Centroid and Hybrid Approach
Punjabi Text Classification using Naïve Bayes, Centroid and Hybrid ApproachPunjabi Text Classification using Naïve Bayes, Centroid and Hybrid Approach
Punjabi Text Classification using Naïve Bayes, Centroid and Hybrid Approach
cscpconf
 
javaopps concepts
javaopps conceptsjavaopps concepts
javaopps concepts
Nikhil Agrawal
 
Python Namespace.pdf
Python Namespace.pdfPython Namespace.pdf
Python Namespace.pdf
SudhanshiBakre1
 
A NOVEL APPROACH FOR NAMED ENTITY RECOGNITION ON HINDI LANGUAGE USING RESIDUA...
A NOVEL APPROACH FOR NAMED ENTITY RECOGNITION ON HINDI LANGUAGE USING RESIDUA...A NOVEL APPROACH FOR NAMED ENTITY RECOGNITION ON HINDI LANGUAGE USING RESIDUA...
A NOVEL APPROACH FOR NAMED ENTITY RECOGNITION ON HINDI LANGUAGE USING RESIDUA...
kevig
 
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
Chuk-Munn Lee
 
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptxINDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
Indu65
 
CSIRO Summer of Vocabularies
CSIRO Summer of VocabulariesCSIRO Summer of Vocabularies
CSIRO Summer of Vocabularies
Jane Frazier
 
Rule Based Transliteration Scheme for English to Punjabi
Rule Based Transliteration Scheme for English to PunjabiRule Based Transliteration Scheme for English to Punjabi
Rule Based Transliteration Scheme for English to Punjabi
kevig
 
RULE BASED TRANSLITERATION SCHEME FOR ENGLISH TO PUNJABI
RULE BASED TRANSLITERATION SCHEME FOR ENGLISH TO PUNJABIRULE BASED TRANSLITERATION SCHEME FOR ENGLISH TO PUNJABI
RULE BASED TRANSLITERATION SCHEME FOR ENGLISH TO PUNJABI
ijnlc
 

Similar to Internationalization (20)

Gui programming (awt)
Gui programming (awt)Gui programming (awt)
Gui programming (awt)
 
Java beans
Java beansJava beans
Java beans
 
Named Entity Recognition for Telugu Using Conditional Random Field
Named Entity Recognition for Telugu Using Conditional Random FieldNamed Entity Recognition for Telugu Using Conditional Random Field
Named Entity Recognition for Telugu Using Conditional Random Field
 
Inheritance
InheritanceInheritance
Inheritance
 
Methods and constructors
Methods and constructorsMethods and constructors
Methods and constructors
 
Towards Building Semantic Role Labeler for Indian Languages
Towards Building Semantic Role Labeler for Indian LanguagesTowards Building Semantic Role Labeler for Indian Languages
Towards Building Semantic Role Labeler for Indian Languages
 
ON THE UTILITY OF A SYLLABLE-LIKE SEGMENTATION FOR LEARNING A TRANSLITERATION...
ON THE UTILITY OF A SYLLABLE-LIKE SEGMENTATION FOR LEARNING A TRANSLITERATION...ON THE UTILITY OF A SYLLABLE-LIKE SEGMENTATION FOR LEARNING A TRANSLITERATION...
ON THE UTILITY OF A SYLLABLE-LIKE SEGMENTATION FOR LEARNING A TRANSLITERATION...
 
Ijetcas14 444
Ijetcas14 444Ijetcas14 444
Ijetcas14 444
 
Java J2EE by Fairline
Java J2EE by FairlineJava J2EE by Fairline
Java J2EE by Fairline
 
Improvement in Quality of Speech associated with Braille codes - A Review
Improvement in Quality of Speech associated with Braille codes - A ReviewImprovement in Quality of Speech associated with Braille codes - A Review
Improvement in Quality of Speech associated with Braille codes - A Review
 
Punjabi Text Classification using Naïve Bayes, Centroid and Hybrid Approach
Punjabi Text Classification using Naïve Bayes, Centroid and Hybrid ApproachPunjabi Text Classification using Naïve Bayes, Centroid and Hybrid Approach
Punjabi Text Classification using Naïve Bayes, Centroid and Hybrid Approach
 
javaopps concepts
javaopps conceptsjavaopps concepts
javaopps concepts
 
Python Namespace.pdf
Python Namespace.pdfPython Namespace.pdf
Python Namespace.pdf
 
A NOVEL APPROACH FOR NAMED ENTITY RECOGNITION ON HINDI LANGUAGE USING RESIDUA...
A NOVEL APPROACH FOR NAMED ENTITY RECOGNITION ON HINDI LANGUAGE USING RESIDUA...A NOVEL APPROACH FOR NAMED ENTITY RECOGNITION ON HINDI LANGUAGE USING RESIDUA...
A NOVEL APPROACH FOR NAMED ENTITY RECOGNITION ON HINDI LANGUAGE USING RESIDUA...
 
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
 
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptxINDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
 
FIRE2014_IIT-P
FIRE2014_IIT-PFIRE2014_IIT-P
FIRE2014_IIT-P
 
CSIRO Summer of Vocabularies
CSIRO Summer of VocabulariesCSIRO Summer of Vocabularies
CSIRO Summer of Vocabularies
 
Rule Based Transliteration Scheme for English to Punjabi
Rule Based Transliteration Scheme for English to PunjabiRule Based Transliteration Scheme for English to Punjabi
Rule Based Transliteration Scheme for English to Punjabi
 
RULE BASED TRANSLITERATION SCHEME FOR ENGLISH TO PUNJABI
RULE BASED TRANSLITERATION SCHEME FOR ENGLISH TO PUNJABIRULE BASED TRANSLITERATION SCHEME FOR ENGLISH TO PUNJABI
RULE BASED TRANSLITERATION SCHEME FOR ENGLISH TO PUNJABI
 

Recently uploaded

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
UiPathCommunity
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
Jen Stirrup
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
Globus
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 

Recently uploaded (20)

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 

Internationalization

  • 1. Advanced Java Programming Topic: Internationalization By Ravi Kant Sahu Asst. Professor, LPU
  • 2. Contents  Introduction  Locale Class  Displaying Date and Time  Formatting Numbers  Resource Bundles Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 3. Introduction  Problem of customizing a program or page for different countries or languages.  It would be highly problematic to create and maintain enough different versions to meet the needs of all clients everywhere. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 4. Internationalization  Internationalization is the process of designing an application so that it can be adapted to various languages and regions without engineering changes.  Java is the first language designed to support Internationalization. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 5. Characteristics  An internationalized program has the following characteristics: 1. With the addition of localized data, the same executable can run worldwide. 2. Textual elements, such as status messages and the GUI component labels, are not hardcoded in the program. Instead they are stored outside the source code and retrieved dynamically. 3. Support for new languages does not require recompilation. 4. Culturally-dependent data, such as dates and currencies, appear in formats that conform to the end user's region and language. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 6. Java Features to Support Internationalization 1. Unicode 2. Locale Class 3. Resource Bundles Note: Java characters use Unicode, a 16-bit encoding scheme established by the Unicode Consortium to support the interchange, processing, and display of written texts in the world’s diverse languages. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 7. LocaLe cLass Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 8. Locale  A Locale object represents a geographical, political, or cultural region in which a specific language or custom is used. For example, Americans speak English, and the Chinese speak Chinese.  The conventions for formatting dates, numbers, and currencies may differ from one country to another. For example, The Chinese use year/month/day to represent the date, while Americans use month/day/year. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 9. Locale  Locale class encapsulates information about a specific locale.  A Locale object determines how locale-sensitive information, such as date, time, and number, is displayed.  The classes for formatting date, time, and numbers, and for sorting strings are grouped in the java.text package.  Every Swing class has a locale property inherited from the Component class. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 10. Creating Locale Object  Constructor: Locale (String Language) Locale (String Language, String Country) Locale (String Language, String Country, String Variant) Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 11. Language and Country Codes Country Country Code Language Code Spain ES es Denmark DK da Germany DE de Greece GR el China CN zh Sweden SE sv France FR fr Norway NO no Japan JP ja United Kingdom GB en Korea KR ko Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 12. Methods of Locale Class String getCountry() String getLanguage() String getVariant() Locale getDefault() String getDisplayCountry() String getDisplayLanguage() String getDisplayName() String getDisplayVariant() Locale[] getAvailableLocales() Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 13. Locale Constants  Predefined Country Constants Locale.US, Locale.UK, Locale.FRANCE, Locale.GERMANY, Locale.ITALY, Locale.CHINA, Locale.KOREA, Locale.JAPAN  Predefined Language Constants Locale.CHINESE, Locale.ENGLISH, Locale.FRENCH, Locale.GERMAN, Locale.ITALIAN, Locale.JAPANESE, Locale.KOREAN, Locale.SIMPLIFIED_CHINESE, and Locale.TRADITIONAL_CHINESE Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 14. Displaying Time and Date Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 15. Displaying Date and Time  Java provides a system independent encapsulation of date and time in the java.util.Date class.  It also provides java.util.TimeZone class for dealing with time zones.  java.util.Calendar can be used for extracting detailed information from Date. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 16. TimeZone Class  TimeZone is an abstract class. Constructor: There is only default Constructor for TimeZone. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 17. Methods of TimeZone Class  static String[] getAvailableIDs() used to find all the available time-zones supported in Java.  static TimeZone getDefault() used to obtain the default time-zone on host machine.  static TimeZone getTimeZone(String ID) used to get TimeZone object for specified TimeZoneID.  String getID() This method gets the ID of this time zone. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 18. DateFormat Class  An abstract class for date/time formatting subclasses which formats and parses dates or time in a language-independent manner.  Constructor: protected DateFormat()  Constants:  SHORT is completely numeric, such as 01.12.52 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 pretty completely specified, such as Tuesday, April 12, 1952 AD or 3:30:42pm IST. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 19. Methods of DateFormat Class  String format(Date date) Formats a Date into a date/time string.  static DateFormat getInstance() Get a default date/time formatter that uses the SHORT style for both the date and the time.  void setTimeZone(TimeZone zone) Sets the time zone for the calendar of this DateFormat object. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 20. Methods of DateFormat Class  static DateFormat getDateInstance() Gets the date formatter with the default formatting style for the default locale.  static DateFormat getDateInstance(int style) Gets the date formatter with the given formatting style for the default locale.  static DateFormat getDateInstance(int style, Locale aLocale) Gets the date formatter with the given formatting style for the given locale. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 21. Methods of DateFormat Class  static DateFormat getDateTimeInstance() Gets the date/time formatter with the default formatting style for the default locale.  static DateFormat getDateTimeInstance(int dateStyle, int timeStyle)  Gets the date/time formatter with the given date and time formatting styles for the default locale.  static DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale aLocale) Gets the date/time formatter with the given formatting styles for the given locale. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 22. SimpleDateFormat Class  Defined in java.text package.  Enables to choose any user-defined pattern for date and time formatting. public SimpleDateFormat(String Pattern) Example: SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd G 'at' hh:mm:ss z"); Note: G represents Era designator, and z is TimeZone. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 23. DateFormatSymbols Class  Constructors: DateFormatSymbols() DateFormatSymbols(Locale locale)  Methods: String[] getAmPmStrings() String[] getEras() String[] getMonths() Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 24. Methods void setMonths(String[] newMonths) String[] getShortMonths() void setShortMonths(String[] newShortMonths) String[] getWeekdays() void setWeekdays(String[] newWeekdays) String[] getShotWeekdays() void setShortWeekdays(String[] newWeekdays) Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 25. Formatting numbers Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 26. Formatting Numbers  Numbers are formatted using an abstract base class java.text.NumberFormat .  Formatting numbers is highly locale dependent. Number: 5000.555 United States: 5,000.555 France: 5000,555 Germany: 5.000,555 Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 27. Methods  getInstance(): NumberFormat  getInstance(locale: Locale): NumberFormat  getIntegerInstance(): NumberFormat  getIntegerInstance(locale: Locale): NumberFormat  getCurrencyInstance(): NumberFormat  getNumberInstance(): NumberFormat  getNumberInstance(locale: Locale): NumberFormat  getPercentInstance(): NumberFormat  getPercentInstance(locale: Locale): NumberFormat Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 28. Methods  format (number: double): String  format (number: long): String  getMaximumFractionDigits(): int  setMaximumFractionDigits(newValue: int): void  getMinimumFractionDigits(): int  setMinimumFractionDigits(newValue: int): void  getMaximumIntegerDigits(): int  setMaximumIntegerDigits(newValue: int): void  getMinimumIntegerDigits(): int  setMinimumIntegerDigits(newValue: int): void  parse(source: String): Number  getAvailableLocales(): Locale[] Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 29. Formatting Numbers  Plain Number Format: NumberFormat nf = NumberFormat.getInstance(Locale l); System.out.println(nf.format(1010.1055));  Currency Format: NumberFormat nf = NumberFormat.getCurrencyInstance(Locale l);  Percent Format: NumberFormat nf = NumberFormat.getPercentInstance(Locale l); Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 30. Parsing Numbers  format(numericalValue) method is used to format a number into a string.  parse(String) method can be used to convert a formatted plain number, currency value, or percent number with the conventions of a certain locale into an instance of java.lang.Number.  The parse method throws a java.text.ParseException, if parsing fails. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 31. Example U.S. $5,000.56 can be parsed into a number using the following statements: NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(Locale.US); try { Number number = currencyFormat.parse("$5,000.56"); System.out.println(number.doubleValue()); } catch (java.text.ParseException ex) { System.out.println("Parse failed"); } Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 32. DecimalFormat Class  We can use the applyPattern(String pattern) method of the DecimalFormat class to specify the patterns for displaying the number.  A pattern can specify the minimum number of digits before the decimal point and the maximum number of digits after the decimal point.  The characters '0‘ and '#' are used to specify a required digit and an optional digit, respectively.  The optional digit is not displayed if it is zero. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 33. Example  The pattern "00.0##" indicates minimum two digits before the decimal point and maximum three digits after the decimal point.  If there are more actual digits before the decimal point, all of them are displayed.  If there are more than three digits after the decimal point, the number of digits is rounded. Example: 1987.16920 will be formatted as: 1987.169 1389.2387 will be formatted as: 1389.239 Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 34. Resource Bundles Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 35. Resource Bundles  A resource bundle is a Java class file or text file that provides locale-specific information.  This information can be accessed by Java programs dynamically.  Resource bundles allows to write programs that separate the locale-sensitive part of our code from the locale-independent part.  When a locale-specific resource is needed, our program can load it from the resource bundle appropriate for the desired locale. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 36. Resource Bundles  The resources are placed inside the classes that extend the ResourceBundle class or a subclass of ResourceBundle.  Resource bundles contain key/value pairs.  Each key uniquely identifies a locale-specific object in the bundle.  Key is used to retrieve the object.  ListResourceBundle is a subclass of ResourceBundle that is often used to simplify the creation of resource bundles. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 37. Example public class MyResource extends java.util.ListResourceBundle { static final Object[][] contents = { {"nationalFlag", "us.gif"}, {"nationalAnthem", "us.au"}, {"nationalColor", Color.red}, {"annualGrowthRate", new Double(7.8)} }; public Object[][] getContents() { return contents; } } Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 38. Properties File  If all the resources are strings, they can be placed in a convenient text file with the extension .properties. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 39. Resource Bundle Naming Conventions 1. BaseName_language_country_variant.class 2. BaseName_language_country.class 3. BaseName_language.class 4. BaseName.class 5. BaseName_language_country_variant.properties 6. BaseName_language_country.properties 7. BaseName_language.properties 8. BaseName.properties  The getBundle method attempts to load the class that matches the specified locale by language, country, and variant by searching the file names in the order shown above. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 40. Retrieving Values from Resource Bundle  To retrieve values from a ResourceBundle in a program, we need to create an instance of ResourceBundle using one of the following two static methods: public static final ResourceBundle getBundle(String baseName) throws MissingResourceException public static final ResourceBundle getBundle (String baseName, Locale locale) throws MissingResourceException  The first method returns a ResourceBundle for the default locale, and second returns a ResourceBundle for the specified locale. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 41.  getObject() method can be used to retrieve the value according to the key. ResourceBundle res = ResourceBundle.getBundle("MyResource"); String flagFile = (String)res.getObject("nationalFlag");  If the resource value is a string, then getString() method is more convenient to use. String flagFile = res.getString("nationalFlag"); Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 42. Character Encoding Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 43. Character Encoding  Java programs use Unicode. When we read a character using text I/O, the Unicode code of the character is returned.  The encoding of the character in the file may be different.  Java automatically converts it to the Unicode.  When we write a character using text I/O, Java automatically converts the Unicode of the character to the encoding specified for the file. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 44. Character Encoding  We can specify an encoding scheme using a constructor of Scanner/PrintWriter for text I/O, as follows: public Scanner(File file, String encodingName) public PrintWriter(File file, String encodingName) Encoding Names: https://docs.oracle.com/javase/1.5.0/docs/guide/intl/encoding.doc. html Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 45.