Saturday, October 6, 2012

What Is a Locale ? (JAVA)

Courtesy:  JAVA Internationalization
                  - Andrew Deitsch & David Czarnecki

In software internationalization, we use the term locale when we talk about local markets. A locale embraces a specific language in combination with a given cultural, geographical and political region. A French Canadian locale refers to the French Speaking part of Canada (Quebec Province), and is associated with the language and information such as the date, currency, and number formats for that particular region. A different local would be used for the English speaking part of Canada. In addition to the language and formatting information, important data that you might not immediately associate with a locale is usually included, such as:


  • Names of the months
  • Days of the week
  • The first day of the week
  • Collation sequencing (sort order)
  • Time zone information
In JAVA, locale information is maintained in the java.util.Locale object and represents:


  • A language
  • A country or region 
  • An optional variant

 Working with the Locale Class :

The Locale class in Java is easy to use. It is meant to be an identification class that is ultimately used by other classes performing locale-sensitive operation.


Monday, October 1, 2012

JSP Implicit Objects

Implicit Objects in JSP are those objects which are created/instantiated implicitly by the JSP Engine or the container (part of the underlying Web Container and the container makes them available to the developers,) as a convenience feature for the JSP page writers who can use them without having to instantiate them. The developer do not need to create them explicitly. Since these objects are created automatically by the container and are accessed using standard variables; hence, they are called implicit objects. The implicit objects are parsed by the container and inserted into the generated servlet. But we can pass them to our own method if we wish to use them locally in those functions. These implicit objects implement the interfaces defined in the JSP/Servlet APIs.  


There are nine implicit objects:
Object Class
Application Javax.servlet.ServletContext
Config Javax.servlet.ServletConfig
Exception Java.lang.Throwtable
Out Javax.servlet.jsp.JspWriter
Page Java.lang.Object
PageContext Javax.servlet.jsp.PageContext
Request Javax.servlet.ServletRequest
Response Javax.servlet.ServletResponse
Session Javax.servlet.http.HttpSession



1. Session: Session object has a session scope that is an instance of javax.servlet.http.HttpSession class. Perhaps it is the most commonly used object to manage the state contexts. This objects persists information across multiple user connection.
2. Responce: This object has a page scope that allows direct access to the HTTPServletResponce class object. Responce object is an instance of the classes that implements the javax.servlet.ServletResponse class. Container generates to this object and passes to the _jspService() method as a parameter.
 3. Request: Request object has a request scope that is used to access the HTTP request data, and also provides a context to associate the request-specific data. Request object implements javax.servlet.ServletRequest interface. It uses the getParameter() method to access the request parameter. The container passes this object to the _jspService() method.
4. Pagecontext: PageContext has a page scope. Pagecontext is the context for the JSP page itself that provides a single API to manage the various scoped attributes. This API is extensively used if we are implementing custom tag handlers. PageContext also provides access to several page attributes like including static or dynamic resource. 
5. Page:This object has a page scope and is an instance of the JSP page's servlet class that processes the current request. Page object represents the current page that is used to call the methods defined by the translated servlet class. First type cast the servlet before accessing any method of the servlet through the page. 
6. Application: These objects has an application scope. These objects are available at the widest context level, that allows to share the same information between the JSP page's servlet and any Web components with in the same application.  
7. Config: These object has a page scope and is an instance of javax.servlet.ServletConfig class. Config object allows to pass the initialization data to a JSP page's servlet. Parameters of this objects can be set in the deployment descriptor (web.xml) inside the element <jsp-file>. The method getInitParameter() is used to access the initialization parameters.  
8. Exception: This object has a page scope and is an instance of java.lang.Throwable class. This object allows the exception data to be accessed only by designated JSP "error pages."
9. Out: This object allows us to access the servlet's output stream and has a page scope. Out object is an instance of javax.servlet.jsp.JspWriter class. It provides the output stream that enable access to the servlet's output stream.