- Number formations
- Date formations
- Message formations
1.Number formations
- To represent a number w.r.to a particular local we have to use a predefined class java. Text. Number format
- To use number format class in java applications. We have to use the following steps
- Prepare number format class object
To prepare number format class object, we have to use the following static factory method public static number format get instance(Local l)
2.Format a number w.r.to a local
To format number, we have to use the following method public string format(XXX NUMBER)Where xxx may be byte, short, int, float,…
Import java. Text*;
Import java. util*;
Public class Test
{
Public static void main(strin[]args) throws exception
{
Local l=new local(“it”,”It”);
Number format nf=number format. Get instance(l);
s.o.p(nf.format(12345.234567));
}
}
- Date formations
If we want to represent date w.r.to a particular local. We have to use a predefined class java.text. date formal
- It we want to use data format in java applications we have to use the following steps
- prepare local object -
Local i= new locale(“en”,”us”);
- Create data format object
To create data format object, we have to use the following static factory method. Public static data format get data insurance
(int data- sty, local i)
- Format data w.r.t the specified local
To represent data. W.r.t the specified local, public string format(date d)
àImport java. text.*;
Import java. util.*;
Public class test
{
p.s.v.m() throws exception
{
Locale l=new locale(“It”,”IT”);
Data format dt= Date format. Get date insurance.col);
s.o.p(dt. format; new date())));
}
}
- Message formations
To represent a message w.r.to a particular local we have to use a predefined class provided by java java. util. Resource bundle
It we want to use resource bundle in java application we have to use the following steps
- Prepare properties files with the local messages
To prepare properties files we have to take a text file and provide locale messages in the from of key- value pairs and we must save properties file with the following naming conversion
<base-name>-<long>-<country><sys-var>. prepare files
Abc-en-us. Properties
Uname= user name
Upwd= password
- prepare locale object
Local I = new locale(“en”,”us”);
- prepare resource bundle object
To prepare resource bundle class object we have to use the following static factory method public static resource bundle[string base – name locale()
- Get message from resource bundle object on basis of key
To get a message on the basis of a key, we have to use the following method public string get string(string key)
Abc-en-us. Properties
Welcome=welcome to en us users
Abc –it IT Properties
Welcome=welcome to it It USERS.
Public class test
{
p.S.V.M()THROWS Exception
{
Locate I = new locale(“it”,”IT”);
Resource bundle rb = resourceBundle. GetBundle(“abc”,i);
s.o.p(rb. get string(“welcome”));
}
}