Archive for the ‘Technical’ Category

Highlights of J2SE 5.0

  • Metadata: Additional data or annotations can be associated with classes, interfaces, methods and fields. This can be read by annotation tools or at runtime through Java Reflection API. This can be used for generating additional source code or for providing additional debugging information.

@debug(devbuild=production,counter=1) public void testMethod()

  • Generic Types:  Earlier version’s Collection API stored the values as the instances of ‘OBJECT’ and so required type casting while fetching the objects. The mismatch of data types therefore could not be discovered until runtime. This is now replaced with a possibility to declare the Collection with <> notation that will detect the mismatch of data types at compile time.  

ArrayList<Integer> list =  new ArrayList<Integer>();
list.add(0, new Integer(42));
int total = list.get(0).intValue();

  • Auto-boxing and auto-unboxing of primitive type variables: The conversion between primitive type variables and their object based counterparts is left to the compiler now and will not require extra coding effort.

ArrayList<Integer> list = new ArrayList<Integer>();
list.add(0, 42);
int total = list.get(0);

  • Enhanced for Loop: The enhanced for loop will now replace the traditional iteration code used to traverse a collection. There is no need of looping code and type casting as the collection objects will be converted to generic types.

ArrayList<Integer> list = new ArrayList<Integer>();  
for (Integer i : list) { … }

  • Enumerated types: Enumerated type is introduced as an alternative to static final constants.

public enum StopLight { red, amber, green };

  • Static import: The static import feature enables to refer to static constants from a class without needing to inherit it.

import static java.awt.BorderLayout.*;
getContentPane().add(new JPanel(), CENTER);

  • Formatted Output:  The traditional C specific ‘printf’ functionality can be used for formatted output.

System.out.printf(“name count%n”);
System.out.printf(“%s %5d%n”, user,total);

  • Formatted Input:   In contrast to the heavy code used to get input from standard input in earlier versions, the scanner API provides basic input functionality for reading data from standard input or other data stream.

Scanner s= new Scanner(System.in);
String param= s.next();
int value=s.nextInt();

  • Varargs:  It allows to pass flexible number of arguments to a method.

void argtest(Object … args){}

  • Concurrency utilities:  The new version comes with more powerful concurrency control techniques like semaphores. It can be used to restrict access to a block of code, allows a defined number of concurrent thread accesses, and allows testing a lock before acquiring it.

final  private Semaphore s= new Semaphore(1, true);
s.acquireUninterruptibly(); //for non-blocking version use s.acquire()
try {    
      balance=balance+10; //protected value
} finally {
     s.release(); //return semaphore token

  • RMI compiler-rmic: There is no need to pre-generate stubs using rmic tool as the new version comes with the support of dynamic generation of stubs at runtime.
  • Class-data sharing:  This feature of class-data sharing enables the sharing of read-only data between multiple running JVMs and also improves startup time as core JVM classes are pre-packed.

  • Monitoring:   The JVM Monitoring and Management API enables monitoring and managing the Java virtual machine and the underlying operating system.  The API enables applications to monitor themselves and enables JMX-compliant tools to monitor and manage a virtual machine locally and remotely including low memory detector.
  • JVM Profiling API (JVMTI):  It includes byte code instrumentation. The advantage of this technique is that it allows more focused analysis and limits the interference of the profiling tools on the running JVM. The instrumentation can even be dynamically generated at runtime, as well as at class loading time, and pre-processed as class files.
  • Improved diagnostic capability:  New APIs are introduced to provide complete stack trace in case of any failure. The HotSpot JVM includes a fatal error handler that can run a user-supplied script or program if the JVM aborts.
  • Desktop Client:  New look and feel like introduction of a new theme for swing toolkit called ‘Ocean’.
  • Core XML support:  Several revisions to core XML support including XML 1.1, SAX 2.02, DOM level 3 support and XSLT with a fast XLSTC compiler.
  • Supplementary character support:  32-bit supplementary character support has been added. Supplementary characters are encoded as a special pair of UTF16 values to generate a different character A surrogate pair is a combination of a high UTF16 value and a following low UTF16 value. In general, when using a String or sequence of characters, the core API libraries will transparently handle the new supplementary characters for you.

String u=”\uD840\uDC08″;

  • JDBC rowsets:  There are five new rowset objects added in the new version.
    Two of the most valuable are:

    • Cached rowset: It contains an in-memory collection of rows retrieved from the database that can, if needed, be synchronized at a later point in time.
    • Web rowset: It can write and read the RowSet in XML format.

Read Full Post »

CSS Frames

One of the arguments for using frames has always been that they allow you to keep parts of the layout on-screen at all times. This can be emulated with CSS, as described here

read more | digg story

Read Full Post »

This is a collection of HTML elements I’ve found to be very under-represented in markup on the web today.

read more | digg story

Read Full Post »

   1. What is the servlet?

      Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet may be responsible for taking data in an HTML order-entry form and applying the business logic used to update a company’s order database.

   2. What’s the difference between servlets and applets?

      Servlets are to servers; applets are to browsers. Unlike applets, however, servlets have no graphical user interface.

   3. What’s the advantages using servlets than using CGI?

      Servlets provide a way to generate dynamic documents that is both easier to write and faster to run. It is efficient, convenient, powerful, portable, secure and inexpensive. Servlets also address the problem of doing server-side programming with platform-specific APIs: they are developed with Java Servlet API, a standard Java extension.

   4. What are the uses of Servlets?

      A servlet can handle multiple requests concurrently, and can synchronize requests. This allows servlets to support systems such as on-line conferencing. Servlets can forward requests to other servers and servlets. Thus servlets can be used to balance load among several servers that mirror the same content, and to partition a single logical service over several servers, according to task type or organizational boundaries.

   5. What’s the Servlet Interface?

      The central abstraction in the Servlet API is the Servlet interface. All servlets implement this interface, either directly or, more commonly, by extending a class that implements it such as HttpServlet. Servlets–>Generic Servlet–>HttpServlet–>MyServlet. The Servlet interface declares, but does not implement, methods that manage the servlet and its communications with clients. Servlet writers provide some or all of these methods when developing a servlet.

   6. When a servlet accepts a call from a client, it receives two objects. What are they?

      ServeltRequest: which encapsulates the communication from the client to the server.
      ServletResponse: which encapsulates the communication from the servlet back to the client.
      ServletRequest and ServletResponse are interfaces defined by the javax.servlet package.

Read Full Post »


   1. What is JSP technology?

      Java Server Page is a standard Java extension that is defined on top of the servlet Extensions. The goal of JSP is the simplified creation and management of dynamic Web pages. JSPs are secure, platform-independent, and best of all, make use of Java as a server-side scripting language.

   2. What is JSP page?

      A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format such as HTML, SVG, WML, and XML, and JSP elements, which construct dynamic content.

   3. What are the implicit objects?

      Implicit objects are created by the web container and contain information related to a particular request, page, or application. They are request, response, pageContext, session, application, out, config, page and exception.

   4. How many JSP scripting elements and what are they?

      There are three scripting language elements: declarations, scriptlets, and expressions.

   5. Why are JSP pages the preferred API for creating a web-based client program?

      Because no plug-ins or security policy files are needed on the client systems(applet does). Also, JSP pages enable cleaner and more module application design because they provide a way to separate applications programming from web page design. This means personnel involved in web page design do not need to understand Java programming language syntax to do their jobs.

   6. Is JSP technology extensible?

      YES. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries.

Read Full Post »

Knowledge about Struts Validator Plugin & Message Resources.


Most of the project tend to group the resources into more than one resource bundles.
And specify all the message resources with ‘key’ attribute in <message-resources> tag.

<message-resources key=”en” parameter=”resources”/>
<message-resources parameter=”ValidationErrors” null=”false” key=”err”/>

In ValidationErrors.properties I have the following messages,

errors.required={0} is required.

If I intend to use Validator with ‘required’ type for ‘Name’, and use <html:errors bundle=”err” />
I get the following message displayed in screen..

???en_US.errors.missing.Name??? is required.

The reason being “errors.required” is extracted correctly from bundle ‘err’ as it is specified in <html:errors/> tag.
Whereas the argument of the message ‘errors.missing.Name’ is taken from the default bundle of struts, and
sicne Validator cannot find the key…it returns the above message.


Configure your <field> tag validation.xml like the following…

<field property=”activeApplicationId” depends=”required“>
       <msg name=”required” bundle=”err” key=”errors.required”/>
        <arg0 key=”missing.applicationId” bundle=”err”/>

Specify bundle in <msg> tag with name = “validation type”
and key = “your message resources key for that validation type”

I know that this actually sucks, but this is the only workaround for the problem.

Read Full Post »

The Java programming language is strongly-typed, which means that all variables must first be declared before they can be used.
This involves stating the variable’s type and name, as you’ve already seen:

int gear = 1;

Read Full Post »

Java Variables

Home Java Tutorial

int cadence = 0; 
int speed = 0; 
int gear = 1;

The Java programming language defines the following kinds of variables:

  • Instance variables (non-static fields) – are unique to each instance of a class.
  • Class variables (static fields) – are fields declared with the static modifier; there is exactly one copy of a class variable, regardless of how many times the class has been instantiated.
  • Local variables - store temporary state inside a method.
  • Parameters - are variables that provide extra information to a method; both local variables and parameters are always classified as “variables” (not “fields”).


  • Variable names are case-sensitive A variable’s name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign “$”, or the underscore character “_”.
  • Subsequent characters may be letters, digits, dollar signs, or underscore characters.
  • If the name you choose consists of only one word, spell that word in all lowercase letters. If it consists of more than one word, capitalize the first letter of each subsequent word.

Read Full Post »

Home Java Tutorial

UPDATE: For all my blog readers who are requesting for more information on OOPS Concepts with example. Please refer the ‘More On Concepts’ section. It has more explanations with examples.

More On Concepts

1. Introduction
2. Inheritance
3. Polymorphism
4. Encapsulation

What is an Object?
An object is a software bundle of related state and behavior.
Software objects are often used to model the real-world objects that you find in everyday life.Real-world objects share two characteristics: They all have state and behavior.

Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail).

Software objects are conceptually similar to real-world objects:
they too consist of state and related behavior.
An object stores its state in fields (variables in some programming languages)
and exposes its behavior through methods (functions in some programming languages).

Methods operate on an object’s internal state and serve as the primary mechanism for object-to-object communication.

Hiding internal state and requiring all interaction to be performed through an object’s methods is known as
data encapsulation — a fundamental principle of object-oriented programming

What Is a Class?
A class is a blueprint or prototype from which objects are created.
What Is Inheritance?
Inheritance provides a powerful and natural mechanism for organizing and structuring your software.
What Is an Interface?
An interface is a contract between a class and the outside world.
When a class implements an interface, it promises to provide the behavior published by that interface. What Is a Package?
A package is a namespace for organizing classes and interfaces in a logical manner.
Placing your code into packages makes large software projects easier to manage.

Read Full Post »

From the security blog over at cnet “Mozilla is now using technology that automates the bug-checking process for Firefox, its popular open-source Web browser.” Sounds like it could be a good or bad thing….

read more | digg story

Read Full Post »

« Newer Posts - Older Posts »


Get every new post delivered to your Inbox.

Join 165 other followers