|Home |Login |Registration |Struts Step by Step Tutorial |Hibernate Step by Step Tutorial |Spring Step by Step Tutorial |JSP Step by Step Tutorial |JDBC Step by Step Tutorial |Web Services Step by Step Tutorial |EJB fundamentals | ORACLE Step by Step Tutorial | SCJP 5.0 and SCJP 6.0 Study Guide | SCWCD 5.0 Study Guide | SCJP Tips
Java mock test | SCJP mock test | SCJP DUMP | SCBCD mock test | SCWCD mock test | JSP mock test | ORACLE mock test | OCP mock test | Hibernate mock test | Servlet mock test | Struts mock test | EJB mock test | C mock test | C++ mock test | Aptitude mock test | PMP mock test Exam |Java online test | JSP online test | ORACLE online test | Hibernate online test | Servlet online test | Struts online test | EJB online test | C online test | C++ online test | Aptitude online test
***Java Code Examples*** |Technical Talk
Java interview questions | JSP interview questions | ORACLE interview questions | Hibernate interview questions | Servlet interview questions | Struts interview questions | JDBC interview questions | C/C++ interview questions | Spring interview questions | JMS interview questions | Informatica interview questions | EJB interview questions | OOPS and Design Pattern interview questions

Download java,jsp,servlet,hibernate,spring,jdbc,jms,struts,EJB,oracle,c,c++,informatica interview questions and answers in pdf format

Download 1600 PMP Questions Free

Download 800 SCJP Questions Free

Download 600 SCWCD Questions Free

Jobs Walkin

                                                                                                                                 

Add/View Reviews , Comments
Tutorial Home
SCJP 5.0 Simulator 642+ Questions With Explanations
SCJP 6.0 Simulator 664+ Questions With Explanations
SCWCD 5.0 Simulator 556+ Questions With Explanations
SCWCD 4.0 Simulator 500+ Questions With Explanations
OCA 10g Simulator 594+ Questions With Explanations
Struts Tutorial Home
Spring Tutorial Home
Hibernate Tutorial Home
JSP Tutorial Home
JDBC Tutorial Home
Webservices Tutorial Home
EJB Fundamentals

Hibernate

  1. Advantage of Hibernate over JDBC
  2. Hibernate Setup with an web Application
  3. First Hibernate Application
  4. Hibernate mapping with Database TABLE
  5. Hibernate Data Type-Java Data Type - SQL Data Type mapping
  6. One to Many Relation in Hibernate
  7. One to Many Relation in Hibernate bi-directional
  8. Many to Many Relation in Hibernate
  9. HQL: The Hibernate Query Language
  10. Criteria Queries
  11. Criteria Queries : Equal (eq), Not Equal(ne), Less than (le), greater than (gt),greater than or equal(ge) and Ordering the results
  12. Criteria Queries: And OR conditions
  13. Hibernate generator to generate id (primary key)
  14. prevent concurrent update in Hibernate,slate object updatation in Hibernate,version checking in Hibernate

    Struts


  1. Model View Controller (MVC)
  2. Model View Controller (MVC)
  3. Struts Flow-How Struts Works?
  4. Struts Tutorial - Struts Setup- First Struts Action class setup
  5. Message Resources
  6. Validation Framework
  7. Validation Framework-client side
  8. ForwardAction
  9. IncludeAction
  10. DispatchAction
  11. LookupDispatchAction
  12. DynaActionForm
  13. DynaActionForm
  14. Struts Tutorial - Mutli-click prevention using struts tokens-Prevent Duplicate Submission
  15. Logic Iterate Map and List

JSP


  1. JSP Tutorial
  2. Introduction to JSP
  3. JSP Comments
  4. JSP Syntax
  5. JSP Scripting Elements :Scriptlet, expression, declaration
  6. JSP Directives
  7. implicit objects in JSP
  8. JSP Actions
  9. Introduction to JSP
  10. jsp:useBean
  11. The jsp:setProperty Action
  12. The jsp:getProperty Action
  13. Introduction to JSP

Spring


  1. Spring Tutorial
  2. Introduction to Spring
  3. Benefits of Using Spring Framework
  4. Inversion of Control in Spring
  5. Introduction to BeanFactory
  6. Dependency Injection in Spring
  7. Collections Setter Injection
  8. Bean Scopes in Spring
  9. Spring IOC Setup Step by Step
  10. Bean Lifecycle in Spring
  11. ApplicationContext
  12. MessageSources in Spring
  13. Web Spring MVC framework
  14. Developing Your First Spring Web Application
  15. Developing Your Second Spring Web Application with Spring Form
  16. Developing Your First Spring Web Application with Spring Validation Framework with Code Example
  17. Spring integration with Hibernate

SCJP : java.text java.util.Locale

SCJP 1.5/1.6 Exam Kit

Use standard J2SE APIs in the java.text package to correctly format or parse dates, numbers, and currency values for a specific locale; and, given a scenario, determine the appropriate methods to use if you want to use the default locale or a specific locale. Describe the purpose and use of the java.util.Locale class.

Formatting and parsing a Date using default formats

Every locale has four default formats for formatting and parsing dates. They are called SHORT, MEDIUM, LONG, and FULL. The SHORT format consists entirely of numbers while the FULL format contains most of the date components. There is also a default format called DEFAULT and is the same as MEDIUM.

This example formats dates using the default locale (which is "ru_RU"). If the example is run in a different locale, the output will not be the same:

import static java.lang.System.out;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.Locale;

public class DateFormatExample1 {

    public static void main(String[] args) {
        // Format
        Date date = new Date();
        
        String s = DateFormat.getDateInstance(DateFormat.SHORT).format(date);
        out.println("DateFormat.SHORT : " + s);

        s = DateFormat.getDateInstance(DateFormat.MEDIUM).format(date);
        out.println("DateFormat.MEDIUM : " + s);
	    
        s = DateFormat.getDateInstance(DateFormat.LONG).format(date);
        out.println("DateFormat.LONG : " + s);

        s = DateFormat.getDateInstance(DateFormat.FULL).format(date);
        out.println("DateFormat.FULL : " + s);
	    
        s = DateFormat.getDateInstance().format(date);
        out.println("default : " + s);
	    
        s = DateFormat.getDateInstance(DateFormat.DEFAULT).format(date);
        out.println("DateFormat.DEFAULT : " + s);
	    
        // Parse
        try {
            date = DateFormat.getDateInstance(DateFormat.DEFAULT).parse("08.02.2005");
            out.println("Parsed date : " + date);
        } catch (ParseException e) {
            out.println(e);
        }
    }
}
					
The output:
DateFormat.SHORT : 08.02.05
DateFormat.MEDIUM : 08.02.2005
DateFormat.LONG : 8 Февраль 2005 г.
DateFormat.FULL : 8 Февраль 2005 г.
default : 08.02.2005
DateFormat.DEFAULT : 08.02.2005
Parsed date : Tue Feb 08 00:00:00 EET 2005					
					

DateFormat is an abstract class for date/time formatting subclasses which formats and parses dates or time in a language-independent manner. The date/time formatting subclass, such as SimpleDateFormat, allows for formatting (i.e., date -> text), parsing (text -> date), and normalization. The date is represented as a Date object or as the milliseconds since January 1, 1970, 00:00:00 GMT.

DateFormat helps you to format and parse dates for any locale. Your code can be completely independent of the locale conventions for months, days of the week, or even the calendar format: lunar vs. solar.

To format a date for the current Locale, use one of the static factory methods:

myString = DateFormat.getDateInstance().format(myDate);
					

To format a date for a different Locale, specify it in the call to getDateInstance():

DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.US);
					

You can use a DateFormat to parse also:

myDate = df.parse(myString);
					
NOTE, the parse(...) method throws ParseException if the beginning of the specified string cannot be parsed. The ParseException is a checked exception, so parsing always should be done inside try-catch block.

Formatting and parsing a date for a Locale

To format and parse in a particular locale, specify the locale when creating the DateFormat object:

import static java.lang.System.out;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.Locale;

public class DateFormatExample2 {

    public static void main(String[] args) {
        //  Format
        Date date = new Date();
        Locale locale = Locale.US;
	    
        String s = DateFormat.getDateInstance(DateFormat.SHORT, locale).format(date);
        out.println("DateFormat.SHORT : " + s);
	    
        s = DateFormat.getDateInstance(DateFormat.MEDIUM, locale).format(date);
        out.println("DateFormat.MEDIUM : " + s);
	    
        s = DateFormat.getDateInstance(DateFormat.LONG, locale).format(date);
        out.println("DateFormat.LONG : " + s);
	    
        s = DateFormat.getDateInstance(DateFormat.FULL, locale).format(date);
        out.println("DateFormat.FULL : " + s);
	    
        s = DateFormat.getDateInstance(DateFormat.DEFAULT, locale).format(date);
        out.println("DateFormat.DEFAULT : " + s);
	    
        // Parse
        try {
            date = DateFormat.getDateInstance(DateFormat.DEFAULT, locale).parse("Feb 8, 2005");
            out.println("Parsed date : " + date);
        } catch (ParseException e) {
            out.println(e);
        }
    }
}					
The output will be:
DateFormat.SHORT : 2/8/05
DateFormat.MEDIUM : Feb 8, 2005
DateFormat.LONG : February 8, 2005
DateFormat.FULL : Tuesday, February 8, 2005
DateFormat.DEFAULT : Feb 8, 2005
Parsed date : Tue Feb 08 00:00:00 EET 2005					
					

Formatting and parsing a number using a default format

NumberFormat is the abstract base class for all number formats. This class provides the interface for formatting and parsing numbers. NumberFormat also provides methods for determining which locales have number formats, and what their names are.

NumberFormat helps you to format and parse numbers for any locale. Your code can be completely independent of the locale conventions for decimal points, thousands-separators, or even the particular decimal digits used, or whether the number format is even decimal.

To format a number for the current Locale, use one of the factory class methods:

myString = NumberFormat.getInstance().format(myNumber);
					

To format a number for a different Locale, specify it in the call to getInstance():

NumberFormat nf = NumberFormat.getInstance(Locale.US);
					

Use getInstance() or getNumberInstance() to get the normal number format. Use getIntegerInstance() to get an integer number format. Use getCurrencyInstance to get the currency number format. And use getPercentInstance to get a format for displaying percentages. With this format, a fraction like 0.53 is displayed as 53%.

import static java.lang.System.out;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.ParseException;

public class NumberFormatExample1 {

    public static void main(String[] args) {
        // Format
        long iii = 1000;
        Long jjj = 1000L;
        NumberFormat format = NumberFormat.getInstance();
        out.println("Format long : " + format.format(iii));
        out.println("Format Long : " + format.format(jjj));

        // Parse
        try {
            Number nnn1 = format.parse("1000");
            out.println("Parsed Number 1  : " + nnn1);
			
            Number nnn2 = format.parse("1 000");
            out.println("Parsed Number 2  : " + nnn2);			
        } catch (ParseException e) {
            out.println(e);
        }
    }
}
					
The output is:
Format long : 1 000
Format Long : 1 000
Parsed Number 1  : 1000
Parsed Number 2  : 1					
					

Formatting and parsing a number for a Locale

A formatted number consists of locale-specific symbols such as the decimal point. This example demonstrates how to format a number for a particular locale:


import static java.lang.System.out;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;

public class NumberFormatExample2 {

    public static void main(String[] args) {
        // Format
        double iii = 1000.123;
        Double jjj = 1000.123;
		
        NumberFormat formatUS = NumberFormat.getInstance(Locale.US);
        out.println("Format double (US): " + formatUS.format(iii));
        out.println("Format Double (US): " + formatUS.format(jjj));

        NumberFormat formatDE = NumberFormat.getInstance(Locale.GERMANY);
        out.println("Format double (DE): " + formatDE.format(iii));
        out.println("Format Double (DE): " + formatDE.format(jjj));
  
        // Parse
		try {
            Number nnn1 = formatUS.parse("1234.1234");
            out.println("Parsed Number 1 (US) : " + nnn1);
			
            Number nnn2 = formatUS.parse("1234,1234");
            out.println("Parsed Number 2 (US) : " + nnn2);

            Number nnn3 = formatDE.parse("1234.1234");
            out.println("Parsed Number 3 (DE) : " + nnn3);
			
            Number nnn4 = formatDE.parse("1234,1234");
            out.println("Parsed Number 4 (DE) : " + nnn4);
        } catch (ParseException e) {
            out.println(e);
        }
    }
}
					
The output will be:
Format double (US): 1,000.123
Format Double (US): 1,000.123
Format double (DE): 1.000,123
Format Double (DE): 1.000,123
Parsed Number 1 (US) : 1234.1234
Parsed Number 2 (US) : 12341234
Parsed Number 3 (DE) : 12341234
Parsed Number 4 (DE) : 1234.1234
					

Formatting and parsing currency

The NumberFormat provides 2 factory methods for currency format instances:

public static final NumberFormat getCurrencyInstance()
public static NumberFormat getCurrencyInstance(Locale inLocale)
					


import static java.lang.System.out;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;

public class CurrencyFormatExample {

    public static void main(String[] args) {
        // Format
        double iii = 999.99;
		
        NumberFormat format = NumberFormat.getCurrencyInstance();
        NumberFormat formatUS = NumberFormat.getCurrencyInstance(Locale.US);
        NumberFormat formatDE = NumberFormat.getCurrencyInstance(Locale.GERMANY);
		
        out.println("Format currency (default): " + format.format(iii));
        out.println("Format currency (US): " + formatUS.format(iii));
        out.println("Format currency (DE): " + formatDE.format(iii));
		
        // Parse
        try {
            Number nnn1 = format.parse("1234,12 руб.");
            out.println("Parsed currency 1 : " + nnn1);
		
            Number nnn2 = formatUS.parse("$1234.12");
            out.println("Parsed currency 2 (US) : " + nnn2);

            Number nnn3 = formatDE.parse("1234,12 €");
            out.println("Parsed currency 3 (DE) : " + nnn3);
	
        } catch (ParseException e) {
            out.println(e);
        }
    }
}
					
The output will be similar to the following:
Format currency (default): 999,99 руб.
Format currency (US): $999.99
Format currency (DE): 999,99 €
Parsed currency 1 : 1234.12
Parsed currency 2 (US) : 1234.12
Parsed currency 3 (DE) : 1234.12
					

java.util.Locale class

A Locale object represents a specific geographical, political, or cultural region. An operation that requires a Locale to perform its task is called locale-sensitive and uses the Locale to tailor information for the user. For example, displaying a number is a locale-sensitive operation - the number should be formatted according to the customs/conventions of the user's native country, region, or culture.

Create a Locale object using the constructors in this class:

Locale(String language)
Locale(String language, String country)
Locale(String language, String country, String variant)
					

The Locale class provides a number of convenient constants that you can use to create Locale objects for commonly used locales. For example, the following creates a Locale object for the United States:

Locale locale = Locale.US;
					

You can get the default locale using static Locale.getDefault() method:

Locale locale = Locale.getDefault();
					

The Java 2 platform provides a number of classes that perform locale-sensitive operations. For example, the NumberFormat class formats numbers, currency, or percentages in a locale-sensitive manner. Classes such as NumberFormat have a number of convenience methods for creating a default object of that type. For example, the NumberFormat class provides these three convenience methods for creating a default NumberFormat object:

// default locale
NumberFormat.getInstance()
NumberFormat.getCurrencyInstance()
NumberFormat.getPercentInstance()
					
These methods have two variants; one with an explicit locale and one without; the latter using the default locale.
// custom locale					
NumberFormat.getInstance(myLocale)
NumberFormat.getCurrencyInstance(myLocale)
NumberFormat.getPercentInstance(myLocale)
					

A Locale is the mechanism for identifying the kind of object (NumberFormat) that you would like to get. The locale is just a mechanism for identifying objects, not a container for the objects themselves.

SCJP 5.0 Simulator Exam Kit
SCJP 6.0 Simulator Exam Kit
SCWCD5.0 Simulator Exam Kit
SCWCD4.0 Simulator Exam Kit
OCA 10g Simulator Exam Kit
SCJP 5.0 Simulator Free Trial
SCJP 6.0 Simulator Free Trial
SCWCD5.0 Simulator Free Trial
SCWCD4.0 Simulator Free Trial
OCA 10g Simulator Free Trial
The information you are posting should be related to java and ORACLE technology. Not political. Your Ad Here SCJP 5.0 Simulator 642+ Questions With Explanations
SCJP 6.0 Simulator 664+ Questions With Explanations
SCWCD 5.0 Simulator 556+ Questions With Explanations
SCWCD 4.0 Simulator 500+ Questions With Explanations
OCA 10g Simulator 594+ Questions With Explanations


Click to join PMP_FOURTH_EDITION

Subscribe to PMP_FOURTH_EDITION

Click to join SCJP_Mock_techFAQ360

Subscribe to techfaq360