This document discusses internationalization in Java programming. It covers key aspects like the Locale class, formatting dates, numbers and currencies based on locale, and using resource bundles to store locale-specific resources. The Locale class represents a specific geographical region and is used to customize program output for that locale. Classes like DateFormat and NumberFormat allow formatting dates, numbers and currencies according to the conventions of a locale. Resource bundles provide a way to externalize locale-specific resources so the same program can support multiple locales.
“The .NET Framework class library is a library of classes, interfaces, and value types that provide access to system functionality. It is the foundation on which .NET Framework applications, components, and controls are built.”
“The .NET Framework class library is a library of classes, interfaces, and value types that provide access to system functionality. It is the foundation on which .NET Framework applications, components, and controls are built.”
JSP technology has facilitated the segregation of the work of a Web designer and a Web developer.
A Web designer can design and formulate the layout for the Web page by using HTML.
On the other hand, a Web developer working independently can use java code and other JSP specific tags to code the business logic.
The simultaneous construction of the static and dynamic content facilitates development of quality applications with increased productivity.
Servlet is java class which extends the functionality of web server by dynamically generating web pages.
Servlet technology is used to create Dynamic web application. Servlet technology is robust and scalable. init() and service() methods are more important in life cycle of a servlet. doGet() and doPost() are methods used under service() method.
This session is all about - the mechanism provided by Java Virtual Machine to reclaim heap space from objects which are eligible for Garbage collection.
Java abstract class & abstract methods,Abstract class in java
Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods.
JSP technology has facilitated the segregation of the work of a Web designer and a Web developer.
A Web designer can design and formulate the layout for the Web page by using HTML.
On the other hand, a Web developer working independently can use java code and other JSP specific tags to code the business logic.
The simultaneous construction of the static and dynamic content facilitates development of quality applications with increased productivity.
Servlet is java class which extends the functionality of web server by dynamically generating web pages.
Servlet technology is used to create Dynamic web application. Servlet technology is robust and scalable. init() and service() methods are more important in life cycle of a servlet. doGet() and doPost() are methods used under service() method.
This session is all about - the mechanism provided by Java Virtual Machine to reclaim heap space from objects which are eligible for Garbage collection.
Java abstract class & abstract methods,Abstract class in java
Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods.
Named Entity Recognition for Telugu Using Conditional Random FieldWaqas Tariq
Named Entity (NE) recognition is a task in which proper nouns and numerical information are extracted from documents and are classified into predefined categories such as Person names, Organization names , Location names, miscellaneous(Date and others). It is a key technology of Information Extraction, Question Answering system, Machine Translations, Information Retrial etc. This paper reports about the development of a NER system for Telugu using Conditional Random field (CRF). Though this state of the art machine learning technique has been widely applied to NER in several well-studied languages, the use of this technique to Telugu languages is very new. The system makes use of the different contextual information of the words along with the variety of features that are helpful in predicting the four different named entities (NE) classes, such as Person name, Location name, Organization name, miscellaneous (Date and others). Keywords: Named entity, Conditional Random field, NE, CRF, NER, named entity recognition
Author Credits - Maaz Anwar Nomani
Semantic Role Labeler (SRL) is a semantic parser which can automatically identify and then classify arguments of a verb in a natural language sentence for Hindi and Urdu. For e.g. in the natural language sentence “Sara won the competition because of her hard work.”, ‘won’ is the main verb and there are 3 arguments for this verb; ‘Sara’ (Agent), ‘hard work’ (Reason) and ‘competition’ (Theme). The problem statement of a SRL revolves around the fact that how will you make a machine identify and then classify the arguments of a verb in a natural language sentence.
Since there are 2 sub problem statements here (Identification and Classification), our SRL has a pipeline architecture in which a binary classifier (Logistic Regression) is first trained to identify whether a word is an argument to a verb in a sentence or not (Yes or No) and subsequently a multi-class classifier (SVM with Linear kernel) is trained to classify the identified arguments by above binary classifier into one of the 20 classes. These 20 classes are the various notions present in a natural language sentence (for e.g. Agent, Theme, Location, Time, Purpose, Reason, Cause etc.). These ‘notions’ are called Propbank labels or semantic labels present in a Proposition Bank which is a collection of hand-annotated sentences.
In essence, SRL felicitates Semantic Parsing which essentially is the research investigation of identifying WHO did WHAT to WHOM, WHERE, HOW, WHY and WHEN etc. in a natural language sentence.
ON THE UTILITY OF A SYLLABLE-LIKE SEGMENTATION FOR LEARNING A TRANSLITERATION...cscpconf
Source and target word segmentation and alignment is a primary step in the statistical learning of a Transliteration. Here, we analyze the benefit of a syllable-like segmentation approach for learning a transliteration from English to an Indic language, which aligns the training set word pairs in terms of sub-syllable-like units instead of individual character units. While this has been found useful in the case of dealing with Out-of-vocabulary words in English-Chinese in the presence of multiple target dialects, we asked if this would be true for Indic languages which are simpler in their phonetic representation and pronunciation. We expected this syllable-like method to perform marginally better, but we found instead that even though our proposed approach improved the Top-1 accuracy, the individual-character-unit alignment model
somewhat outperformed our approach when the Top-10 results of the system were re-ranked using language modeling approaches. Our experiments were conducted for English to Telugu transliteration (our method will apply equally well to most written Indic languages); our training consisted of a syllable-like segmentation and alignment of a large training set, on which we built a statistical model by modifying a previous character-level maximum entropy based Transliteration learning system due to Kumaran and Kellner; our testing consisted of using the same segmentation of a test English word, followed by applying the model, and reranking the resulting top 10 Telugu words. We also report the dataset creation and selection since standard datasets are not available.
Improvement in Quality of Speech associated with Braille codes - A Reviewinscit2006
J. Anurag, P. Nupur and Agrawal, S.S.
School of Information Technology, Guru Gobind Singh Indraprastha University, Delhi, India
Centre for Development of Advanced Computing, Noida, India
Punjabi Text Classification using Naïve Bayes, Centroid and Hybrid Approachcscpconf
Punjabi Text Classification is the process of assigning predefined classes to the unlabelled text
documents. Because of dramatic increase in the amount of content available in digital form, text
classification becomes an urgent need to manage the digital data efficiently and accurately. Till
now no Punjabi Text Classifier is available for Punjabi Text Documents. Therefore, in this
paper, existing classification algorithm such as Naïve Bayes, Centroid Based techniques are
used for Punjabi Text Classification. And one new approach is proposed for the Punjabi Text
Documents which is the combination Naïve Bayes (to extract the relevant features so as to
reduce the dimensionality) and Ontology Based Classification (that act as text classifier that
used extracted features). These algorithms are performed over 184 Punjabi News Articles on
Sports that classify the documents into 7 classes such as ਿਕਕਟ (krikaṭ), ਹਾਕੀ (hākī), ਕਬੱ ਡੀ
(kabḍḍī), ਫੁਟਬਾਲ (phuṭbāl), ਟੈਿਨਸ (ṭainis), ਬੈਡਿਮੰ ਟਨ (baiḍmiṇṭan), ਓਲੰ ਿਪਕ (ōlmpik).
A NOVEL APPROACH FOR NAMED ENTITY RECOGNITION ON HINDI LANGUAGE USING RESIDUA...kevig
Many Natural Language Processing (NLP) applications involve Named Entity Recognition (NER) as an important task, where it leads to improve the overall performance of NLP applications. In this paper the Deep learning techniques are used to perform NER task on Hindi text data as it found that as compared to English NER, Hindi language NER is not sufficiently done. This is a barrier for resource-scarce languages as many resources are not readily available. Many researchers use various techniques such as rule based, machine learning based and hybrid approaches to solve this problem. Deep learning based algorithms are being developed in large scale as an innovative approach now a days for the advanced NER models which will give the best results out of it. In this paper we devise a Novel architecture based on residual network architecture for preferably Bidirectional Long Short Term Memory (BiLSTM) with fasttext word embedding layers. For this purpose we use pre-trained word embedding to represent the words in the corpus where the NER tags of the words are defined as the used annotated corpora. BiLSTM Development of an NER system for Indian languages is a comparatively difficult task. In this paper, we have done the various experiments to compare the results of NER with normal embedding and fasttext embedding layers to analyse the performance of word embedding with different batch sizes to train the deep learning models. Here we present a state-of-the-art results with said approach F1 Score measures.
Simon Cox (Researcher @ CSIRO) and I presented on outcomes of the CSIRO Summer of Vocabularies.
This project focused on:
- Examining the state of the management of various controlled vocabularies and developing reusable processes to clean & standardise those vocabularies.
- Developing standards & technologies for vocabulary management, curation & visualisation.
We presented on these Summer of Vocabularies activities and how they are being used now to further the work of the Vocram project and the improvement and development of ANDS vocabulary services.
Rule Based Transliteration Scheme for English to Punjabikevig
Machine Transliteration has come out to be an emerging and a very important research area in the field of
machine translation. Transliteration basically aims to preserve the phonological structure of words. Proper
transliteration of name entities plays a very significant role in improving the quality of machine translation.
In this paper we are doing machine transliteration for English-Punjabi language pair using rule based
approach. We have constructed some rules for syllabification. Syllabification is the process to extract or
separate the syllable from the words. In this we are calculating the probabilities for name entities (Proper
names and location). For those words which do not come under the category of name entities, separate
probabilities are being calculated by using relative frequency through a statistical machine translation
toolkit known as MOSES. Using these probabilities we are transliterating our input text from English to
Punjabi.
RULE BASED TRANSLITERATION SCHEME FOR ENGLISH TO PUNJABIijnlc
Machine Transliteration has come out to be an emerging and a very important research area in the field of
machine translation. Transliteration basically aims to preserve the phonological structure of words. Proper
transliteration of name entities plays a very significant role in improving the quality of machine translation.
In this paper we are doing machine transliteration for English-Punjabi language pair using rule based
approach. We have constructed some rules for syllabification. Syllabification is the process to extract or
separate the syllable from the words. In this we are calculating the probabilities for name entities (Proper
names and location). For those words which do not come under the category of name entities, separate
probabilities are being calculated by using relative frequency through a statistical machine translation
toolkit known as MOSES. Using these probabilities we are transliterating our input text from English to
Punjabi.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Welcome to the first live UiPath Community Day Dubai! Join us for this unique occasion to meet our local and global UiPath Community and leaders. You will get a full view of the MEA region's automation landscape and the AI Powered automation technology capabilities of UiPath. Also, hosted by our local partners Marc Ellis, you will enjoy a half-day packed with industry insights and automation peers networking.
📕 Curious on our agenda? Wait no more!
10:00 Welcome note - UiPath Community in Dubai
Lovely Sinha, UiPath Community Chapter Leader, UiPath MVPx3, Hyper-automation Consultant, First Abu Dhabi Bank
10:20 A UiPath cross-region MEA overview
Ashraf El Zarka, VP and Managing Director MEA, UiPath
10:35: Customer Success Journey
Deepthi Deepak, Head of Intelligent Automation CoE, First Abu Dhabi Bank
11:15 The UiPath approach to GenAI with our three principles: improve accuracy, supercharge productivity, and automate more
Boris Krumrey, Global VP, Automation Innovation, UiPath
12:15 To discover how Marc Ellis leverages tech-driven solutions in recruitment and managed services.
Brendan Lingam, Director of Sales and Business Development, Marc Ellis
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
Removing Uninteresting Bytes in Software FuzzingAftab Hussain
Imagine a world where software fuzzing, the process of mutating bytes in test seeds to uncover hidden and erroneous program behaviors, becomes faster and more effective. A lot depends on the initial seeds, which can significantly dictate the trajectory of a fuzzing campaign, particularly in terms of how long it takes to uncover interesting behaviour in your code. We introduce DIAR, a technique designed to speedup fuzzing campaigns by pinpointing and eliminating those uninteresting bytes in the seeds. Picture this: instead of wasting valuable resources on meaningless mutations in large, bloated seeds, DIAR removes the unnecessary bytes, streamlining the entire process.
In this work, we equipped AFL, a popular fuzzer, with DIAR and examined two critical Linux libraries -- Libxml's xmllint, a tool for parsing xml documents, and Binutil's readelf, an essential debugging and security analysis command-line tool used to display detailed information about ELF (Executable and Linkable Format). Our preliminary results show that AFL+DIAR does not only discover new paths more quickly but also achieves higher coverage overall. This work thus showcases how starting with lean and optimized seeds can lead to faster, more comprehensive fuzzing campaigns -- and DIAR helps you find such seeds.
- These are slides of the talk given at IEEE International Conference on Software Testing Verification and Validation Workshop, ICSTW 2022.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
The Metaverse and AI: how can decision-makers harness the Metaverse for their...Jen Stirrup
The Metaverse is popularized in science fiction, and now it is becoming closer to being a part of our daily lives through the use of social media and shopping companies. How can businesses survive in a world where Artificial Intelligence is becoming the present as well as the future of technology, and how does the Metaverse fit into business strategy when futurist ideas are developing into reality at accelerated rates? How do we do this when our data isn't up to scratch? How can we move towards success with our data so we are set up for the Metaverse when it arrives?
How can you help your company evolve, adapt, and succeed using Artificial Intelligence and the Metaverse to stay ahead of the competition? What are the potential issues, complications, and benefits that these technologies could bring to us and our organizations? In this session, Jen Stirrup will explain how to start thinking about these technologies as an organisation.
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
Enhancing Performance with Globus and the Science DMZGlobus
ESnet has led the way in helping national facilities—and many other institutions in the research community—configure Science DMZs and troubleshoot network issues to maximize data transfer performance. In this talk we will present a summary of approaches and tips for getting the most out of your network infrastructure using Globus Connect Server.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
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)
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)
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)
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)
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)
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)