<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3690933364718152435</id><updated>2011-11-27T16:08:56.770-08:00</updated><category term='Struts'/><category term='Xml'/><category term='GWT'/><category term='Jdbc'/><category term='Multi Threading'/><category term='Unix Commands'/><category term='Hibernate'/><category term='JMS'/><category term='Core Java'/><category term='JUnit'/><category term='Spring'/><category term='Ejb'/><category term='Jsp'/><category term='Ajax'/><category term='Servlet'/><category term='Sql'/><title type='text'>java j2ee interview questions</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>35</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-1379288319746437474</id><published>2009-07-15T17:54:00.000-07:00</published><updated>2009-07-15T17:55:34.807-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='GWT'/><title type='text'>GWT Interview Questions</title><content type='html'>&lt;strong&gt;What is Google Web Toolkit?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Google Web Toolkit (GWT) is an open source Java development framework that lets you escape the matrix of technologies that make writing AJAX applications so difficult and error prone. With GWT, you can develop and debug AJAX applications in the Java language using the Java development tools of your choice. When you deploy your application to production, the GWT compiler translates your Java application to browser-compliant JavaScript and HTML.&lt;br /&gt;&lt;br /&gt;Here's the GWT development cycle:&lt;br /&gt;&lt;br /&gt;Use your favorite Java IDE to write and debug an application in the Java language, using as many (or as few) GWT libraries as you find useful. &lt;br /&gt;Use GWT's Java-to-JavaScript compiler to distill your application into a set of JavaScript and HTML files that you can serve with any web server. &lt;br /&gt;Confirm that your application works in each browser that you want to support, which usually takes no additional work. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Write a Sample GWT programm ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;public class Slicr implements EntryPoint {&lt;br /&gt;&lt;br /&gt;  public void onModuleLoad() {&lt;br /&gt;    final Button button = new Button("Click me");&lt;br /&gt;    final Label label = new Label();&lt;br /&gt;    button.addClickListener(new ClickListener() {&lt;br /&gt;      public void onClick(Widget sender) {&lt;br /&gt;        if (label.getText().equals(""))&lt;br /&gt;          label.setText("Hello World!");&lt;br /&gt;        else&lt;br /&gt;          label.setText("");&lt;br /&gt;      }&lt;br /&gt;    });&lt;br /&gt;    RootPanel.get("slot1").add(button);&lt;br /&gt;    RootPanel.get("slot2").add(label);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are the different listeners in GWT ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Here is the list of listeners HistoryListener,Changes to Browser History,WindowCloseListener,WindowResizeListener,ChangeListener,ClickListener,&lt;br /&gt;FormHandler,FocusListener,KeyBoardListener,LoadListener,MouseListener,PopupListener,&lt;br /&gt;ScrollListener,TableListener,TabListener,TreeListener &lt;br /&gt;&lt;a href="http://java-j2ee-interview-questions-book.blogspot.com/2009/07/gwt-event-listeners.html"&gt;&lt;strong&gt;More about listeners&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why doesn't GWT provide a synchronous server connection option?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;GWT's network operations are all asynchronous, or non-blocking. That is, they return immediately as soon as called, and require the user to use a callback method to handle the results when they are eventually returned from the server. Though in some cases asynchronous operators are less convenient to use than synchronous operators, GWT does not provide synchronous operators.&lt;br /&gt;&lt;br /&gt;The reason is that most browsers' JavaScript engines are single-threaded. As a result, blocking on a call to XMLHTTPRequest also blocks the UI thread, making the browser appear to freeze for the duration of the connection to the server. Some browsers provide a way around this, but there is no universal solution. GWT does not implement a synchronous network connection because to do so would be to introduce a feature that does not work on all browsers, violating GWT's commitment to no-compromise, cross-browser AJAX. It would also introduce complexity for developers, who would have to maintain two different versions of their communications code in order to handle all browsers. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is AsyncCallback Interface?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;public interface AsyncCallback&lt;T&gt;The primary interface a caller must implement to receive a response from a remote procedure call. &lt;br /&gt;&lt;br /&gt;If an RPC is successful, then onSuccess(Object) is called, otherwise onFailure(Throwable) is called. &lt;br /&gt;&lt;br /&gt;Each callable asynchronous method corresponds to a method in the correlated service interface. The asynchronous method always takes an AsyncCallback&lt;T&gt; as its last parameter, where T is the return type of the correlated synchronous method. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A call with a typical use of AsyncCallback might look like this: &lt;br /&gt;&lt;br /&gt; service.getShapes(dbName, new AsyncCallback() {&lt;br /&gt;   public void onSuccess(Shape[] result) {&lt;br /&gt;     // It's always safe to downcast to the known return type. &lt;br /&gt;     controller.processShapes(result);&lt;br /&gt;   }&lt;br /&gt; &lt;br /&gt;   public void onFailure(Throwable caught) {&lt;br /&gt;     // Convenient way to find out which exception was thrown.&lt;br /&gt;     try {&lt;br /&gt;       throw caught;&lt;br /&gt;     } catch (IncompatibleRemoteServiceException e) {&lt;br /&gt;       // this client is not compatible with the server; cleanup and refresh the &lt;br /&gt;       // browser&lt;br /&gt;     } catch (InvocationException e) {&lt;br /&gt;       // the call didn't complete cleanly&lt;br /&gt;     } catch (ShapeException e) {&lt;br /&gt;       // one of the 'throws' from the original method&lt;br /&gt;     } catch (DbException e) {&lt;br /&gt;       // one of the 'throws' from the original method&lt;br /&gt;     } catch (Throwable e) {&lt;br /&gt;       // last resort -- a very unexpected exception&lt;br /&gt;     }&lt;br /&gt;   }&lt;br /&gt; });&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are the language differences between web mode and hosted mode?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Typically, if your code runs as intended in hosted mode and compiles to JavaScript without error, web mode behavior will be equivalent. Occasional different problems can cause subtle bugs to appear in web mode that don't appear in hosted mode. Fortunately those cases are rare.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How do I make a call to the server if I am not using GWT RPC?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The heart of AJAX is making data read/write calls to a server from the JavaScript application running in the browser. GWT is "RPC agnostic" and has no particular requirements about what protocol is used to issue RPC requests, or even what language the server code is written in. Although GWT provides a library of classes that makes the RPC communications with a J2EE server extremely easy, you are not required to use them. Instead you can build custom HTTP requests to retrieve, for example, JSON or XML-formatted data.&lt;br /&gt;&lt;br /&gt;To communicate with your server from the browser without using GWT RPC:&lt;br /&gt;&lt;br /&gt;Create a connection to the server, using the browser's XMLHTTPRequest feature. &lt;br /&gt;Construct your payload according to whatever protocol you wish to use, convert it to a string, and send it to the server over the connection. &lt;br /&gt;Receive the server's response payload, and parse it according to the protocol. &lt;br /&gt;You must use an asynchronous server connection.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can I use GWT with my favorite server-side templating tool? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Yes, you are free to use GWT with any server-side templating tool. &lt;br /&gt;&lt;br /&gt;With GWT development, your Java client code gets compiled into equivalent JavaScript that is loaded into your host pages. The generated product is totally independent from the server-side technology that you choose to use in your web application. &lt;br /&gt;&lt;br /&gt;You can go ahead and use your favorite server-side templating tool and include your template directives into your host pages along with your GWT-generated JavaScript files. The server-side technology you're using to realize the templates is invisible to the browser and works just as it does without your GWT modules. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is Gwt Sever Side RemoteServiceServlet?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;public class RemoteServiceServletextends javax.servlet.http.HttpServletimplements SerializationPolicyProvider&lt;br /&gt;&lt;br /&gt;The servlet base class for your RPC service implementations that automatically deserializes incoming requests from the client and serializes outgoing responses for client/server RPCs.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-1379288319746437474?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/1379288319746437474/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/07/gwt-interview-questions_15.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/1379288319746437474'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/1379288319746437474'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/07/gwt-interview-questions_15.html' title='GWT Interview Questions'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-1496324394657570654</id><published>2009-07-15T17:15:00.001-07:00</published><updated>2009-07-15T17:26:13.441-07:00</updated><title type='text'>GWT event listeners</title><content type='html'>&lt;html&gt;&lt;br /&gt;&lt;body&gt;&lt;br /&gt;&lt;p&gt;GWT defines event listeners that you can attach to your widgets to monitor browser events. Event Listeners are just interfaces that you can implement in your widget. If you want to trap mouse click events, then your widget should implement the &lt;code&gt;ClickListener&lt;/code&gt; interface and define the &lt;code&gt;onClick(Widget sender)&lt;/code&gt; method. The code inside this method will be fired every time the user clicks on your widget.&lt;br&gt; &lt;br&gt; You can create a new anonymous &lt;code&gt;ClickListener&lt;/code&gt; every time you want to assign it to a widget as given in the &lt;code&gt;Hello&lt;/code&gt; gwt example.&lt;br&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code&gt;button.addClickListener(new ClickListener() {&lt;br&gt; public void onClick(Widget sender) {&lt;br&gt;  processData(sender.getText());&lt;br&gt;  reportData(sender.getText());&lt;br&gt;  logResults();&lt;br&gt; }&lt;br&gt;});&lt;br&gt;&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt; But this results in localized code and lesser code reusability. Let us say we want to add another widget (a HTML link), which has to run the same code as in the &lt;code&gt;onClick()&lt;/code&gt; method. We would be using the &lt;code&gt;addClickListener&lt;/code&gt; method for this link and would be rewriting the same code again separately. And if we need to add another method in the &lt;code&gt;onClick()&lt;/code&gt; method code between &lt;code&gt;processData()&lt;/code&gt; and &lt;code&gt;reportData()&lt;/code&gt; we will have to change each instance of &lt;code&gt;onClick()&lt;/code&gt;.&lt;br&gt; &lt;br&gt; Alternatively, we can implement the listeners in the container widget to handle the events of contained widgets as shown below, making the code more reusable.&lt;br&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code&gt;public class MainPanel extends Composite &lt;br&gt; implements ClickListener{&lt;br&gt;&lt;br&gt; private Button button=new Button("Button");&lt;br&gt; public MainPanel(){&lt;br&gt; &lt;br&gt;  //...&lt;br&gt;  button.addClickListener(this);&lt;br&gt; }&lt;br&gt;&lt;br&gt; public void onClick(Widget sender){&lt;br&gt;  if(sender==button){&lt;br&gt;   processData(sender.getText());&lt;br&gt;   reportData(sender.getText());&lt;br&gt;   logResults();&lt;br&gt;  }&lt;br&gt; }&lt;br&gt;}&lt;br&gt;&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt;With this approach, if we want to add a &lt;code&gt;HTML&lt;/code&gt; widget &lt;code&gt;link&lt;/code&gt; that implements the same function, we would just have to add the line&lt;br&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code&gt;link.addClickListener(this);&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt;in &lt;code&gt;MainPanel()&lt;/code&gt; and modify one line in the &lt;code&gt;onClick(Widget sender)&lt;/code&gt; method&lt;br&gt; &lt;blockquote&gt; &lt;pre&gt;&lt;code&gt;if(sender==button||sender==link)&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt;Given Below is a listing of GWT Event listeners for handling various events:&lt;br&gt; &lt;br&gt; &lt;div&gt;   &lt;table border="1" bordercolor="#ffffff" cellpadding="3" cellspacing="0" height="329" width="454"&gt;     &lt;tbody&gt;     &lt;tr&gt;       &lt;td width="120"&gt;&lt;b&gt;         Listener&lt;br&gt;       &lt;/b&gt;&lt;/td&gt;       &lt;td width="165"&gt;&lt;b&gt;         Event notifications&lt;br&gt;       &lt;/b&gt;&lt;/td&gt;       &lt;td width="165"&gt;&lt;b&gt;         Methods Defined&lt;br&gt;       &lt;/b&gt;&lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td width="120"&gt;         HistoryListener&lt;br&gt;       &lt;/td&gt;       &lt;td width="165"&gt;         Changes to Browser History&lt;br&gt;       &lt;/td&gt;       &lt;td width="165"&gt;         onHistoryChanged(String historyToken)&lt;br&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td width="120"&gt;         WindowCloseListener&lt;br&gt;       &lt;/td&gt;       &lt;td width="165"&gt;         Window Closure Events&lt;br&gt;       &lt;/td&gt;       &lt;td width="165"&gt;         onWindowClosed()&lt;br&gt;         onWindowClosing()&lt;br&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td width="120"&gt;         WindowResizeListener&lt;br&gt;       &lt;/td&gt;       &lt;td width="165"&gt;         Window Resizing Events&lt;br&gt;       &lt;/td&gt;       &lt;td width="165"&gt;         onWindowResized(int width, int height)&lt;br&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td width="120"&gt;         ChangeListener&lt;br&gt;       &lt;/td&gt;       &lt;td width="165"&gt;         fires when a widget changes&lt;br&gt;       &lt;/td&gt;       &lt;td width="165"&gt;         onChange(Widget sender)&lt;br&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td width="120"&gt;         ClickListener&lt;br&gt;       &lt;/td&gt;       &lt;td width="165"&gt;         fires when a widget receives a 'click'&lt;br&gt;       &lt;/td&gt;       &lt;td width="165"&gt;         onClick(Widget sender)&lt;br&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td width="120"&gt;         FormHandler&lt;br&gt;       &lt;/td&gt;       &lt;td width="165"&gt;         fires on receiving Form events from the FormPanel to which it is         attached&lt;br&gt;       &lt;/td&gt;       &lt;td width="165"&gt;         onSubmit(FormSubmitEvent event)&lt;br&gt;         onSubmitComplete( FormSubmitCompleteEvent event)&lt;br&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td width="120"&gt;         FocusListener&lt;br&gt;       &lt;/td&gt;       &lt;td width="165"&gt;         Focus Events&lt;br&gt;       &lt;/td&gt;       &lt;td width="165"&gt;         onFocus(Widget sender)&lt;br&gt;         onLostFocus(Widget sender)&lt;br&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td width="120"&gt;         KeyBoardListener&lt;br&gt;       &lt;/td&gt;       &lt;td width="165"&gt;         Keyboard Events&lt;br&gt;       &lt;/td&gt;       &lt;td width="165"&gt;         onKeyDown(Widget sender, char keycode, int modifiers)&lt;br&gt;         onKeyPress(Widget sender, char keycode, int modifiers)&lt;br&gt;         onKeyUp(Widget sender, char keycode, int modifiers)&lt;br&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td width="120"&gt;         LoadListener&lt;br&gt;       &lt;/td&gt;       &lt;td width="165"&gt;         listens to 'load' event of a widget&lt;br&gt;       &lt;/td&gt;       &lt;td width="165"&gt;         onLoad(Widget Sender)&lt;br&gt;         onError(Widget Sender)&lt;br&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td style="vertical-align: top;"&gt;         MouseListener&lt;br&gt;       &lt;/td&gt;       &lt;td style="vertical-align: top;"&gt;         listens to mouse events of a widget&lt;br&gt;       &lt;/td&gt;       &lt;td style="vertical-align: top;"&gt;         onMouseEnter(Widget sender)&lt;br&gt;         onMouseLeave(Widget sender)&lt;br&gt;         onMouseDown(Widget sender, int x, int y)&lt;br&gt;         onMouseUp(Widget sender, int x, int y)&lt;br&gt;         onMouseMove(Widget sender, int x, int y)&lt;br&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td style="vertical-align: top;"&gt;         PopupListener&lt;br&gt;       &lt;/td&gt;       &lt;td style="vertical-align: top;"&gt;         listens to the events of a PopupPanel widget&lt;br&gt;       &lt;/td&gt;       &lt;td style="vertical-align: top;"&gt;         onPopupClosed(PopupPanel sender, boolean autoClose)&lt;br&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td style="vertical-align: top;"&gt;         ScrollListener&lt;br&gt;       &lt;/td&gt;       &lt;td style="vertical-align: top;"&gt;         listens to Scroll events&lt;br&gt;       &lt;/td&gt;       &lt;td style="vertical-align: top;"&gt;         onScroll(Widget widget, int scrollLeft, int scrollTop)&lt;br&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td style="vertical-align: top;"&gt;         TableListener&lt;br&gt;       &lt;/td&gt;       &lt;td style="vertical-align: top;"&gt;         listens to events pertaining to a Table widget&lt;br&gt;       &lt;/td&gt;       &lt;td style="vertical-align: top;"&gt;         onCellClicked( SourcesTableEvents sources, int row, int cell)&lt;br&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td style="vertical-align: top;"&gt;         TabListener&lt;br&gt;       &lt;/td&gt;       &lt;td style="vertical-align: top;"&gt;         listens to the events of a Tab Widget&lt;br&gt;       &lt;/td&gt;       &lt;td style="vertical-align: top;"&gt;         onBeforeTabSelected( SourcesTabEvents sender, int tabIndex)&lt;br&gt;         onTabSelected( SourcesTabEvents sender, int tabIndex)&lt;br&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;       &lt;td style="vertical-align: top;"&gt;         TreeListener&lt;br&gt;       &lt;/td&gt;       &lt;td style="vertical-align: top;"&gt;         listens to the events of a Tree Widget&lt;br&gt;       &lt;/td&gt;       &lt;td style="vertical-align: top;"&gt;         onTreeItemSelected( TreeItem item)&lt;br&gt;         onTreeItemChanged( TreeItem item)&lt;br&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;/tbody&gt;   &lt;/table&gt; &lt;/div&gt; &lt;br&gt; The &lt;code&gt;Button&lt;/code&gt; widget defines the &lt;code&gt;addClickListener&lt;/code&gt; method which attaches a &lt;code&gt;ClickListener&lt;/code&gt; object to it. Similarly, the &lt;code&gt;Tree&lt;/code&gt; widget defines the &lt;code&gt;addTreeListener&lt;/code&gt; method. Not all event listeners are available for all widgets - for example, the &lt;code&gt;addMouseListener&lt;/code&gt; method is not defined for a &lt;code&gt;DockPanel&lt;/code&gt; Widget. One way to add the &lt;code&gt;MouseListener&lt;/code&gt; functionality to this &lt;code&gt;DockPanel&lt;/code&gt; is to create a composite that includes a &lt;code&gt;FocusPanel&lt;/code&gt; widget (which supports &lt;code&gt;addMouseListener&lt;/code&gt;) and wrap the &lt;code&gt;DockPanel&lt;/code&gt; widget within it.&lt;br&gt;&lt;/p&gt;&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-1496324394657570654?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/1496324394657570654/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/07/gwt-event-listeners.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/1496324394657570654'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/1496324394657570654'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/07/gwt-event-listeners.html' title='GWT event listeners'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-9089290285589594110</id><published>2009-06-24T14:18:00.000-07:00</published><updated>2009-07-15T17:29:52.355-07:00</updated><title type='text'>GWT Examples and Tutorials</title><content type='html'>&lt;a href="http://java-j2ee-interview-questions-book.blogspot.com/2009/07/gwt-event-listeners.html"&gt;&lt;strong&gt;GWT event listeners &lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://java-j2ee-interview-questions-book.blogspot.com/2009/06/gwt-numberformat-example.html"&gt;&lt;strong&gt;GWT NumberFormat Example&lt;/strong&gt;&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;&lt;a href="http://java-j2ee-interview-questions-book.blogspot.com/2009/06/gwt-file-upload.html"&gt;&lt;strong&gt;GWT File UPLOAD Example&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://java-j2ee-interview-questions-book.blogspot.com/2009/06/gwt-file-download.html"&gt;&lt;strong&gt;GWT File DownLoad Example&lt;/strong&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-9089290285589594110?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/9089290285589594110/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/gwt-examples-and-tutorials.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/9089290285589594110'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/9089290285589594110'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/gwt-examples-and-tutorials.html' title='GWT Examples and Tutorials'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-4550725170341187590</id><published>2009-06-24T13:44:00.000-07:00</published><updated>2009-06-24T14:18:00.715-07:00</updated><title type='text'>Core Java Examples and Tutorials</title><content type='html'>&lt;a href="http://java-j2ee-interview-questions-book.blogspot.com/2009/06/method-overloading.html"&gt;&lt;strong&gt;Method overloading&lt;/strong&gt;&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;&lt;a href="http://java-j2ee-interview-questions-book.blogspot.com/2009/06/method-overriding.html"&gt;&lt;strong&gt;Method overriding&lt;/strong&gt; &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://java-j2ee-interview-questions-book.blogspot.com/2009/06/inheritance-example.html"&gt;&lt;strong&gt;Inheritance Example&lt;/strong&gt;&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;&lt;a href="http://java-j2ee-interview-questions-book.blogspot.com/2009/06/interface-example.html"&gt;&lt;strong&gt;Interface Example&lt;/strong&gt; &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://java-j2ee-interview-questions-book.blogspot.com/2009/06/abstract-methods-and-classes.html"&gt;&lt;strong&gt;Abstract Methods and Classes&lt;/strong&gt;&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;&lt;a href="http://java-j2ee-interview-questions-book.blogspot.com/2009/06/arraylist-example.html"&gt;&lt;strong&gt;&lt;strong&gt;ArrayList Example&lt;/strong&gt;&lt;/strong&gt;&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;&lt;a href="http://java-j2ee-interview-questions-book.blogspot.com/2009/06/vector-example.html"&gt;&lt;strong&gt;Vector Example&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://java-j2ee-interview-questions-book.blogspot.com/2009/06/singleton-class-example.html"&gt;&lt;strong&gt;Singleton class Example &lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://java-j2ee-interview-questions-book.blogspot.com/2009/06/convert-string-to-int-in-java.html"&gt;&lt;strong&gt;Convert string to int in java&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://java-j2ee-interview-questions-book.blogspot.com/2009/06/convert-date-to-string-in-java.html"&gt;&lt;strong&gt;Convert Date to String in java&lt;/strong&gt; &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://java-j2ee-interview-questions-book.blogspot.com/2009/06/convert-string-to-date-in-java.html"&gt;&lt;strong&gt;Convert String to Date in java&lt;/strong&gt; &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://java-j2ee-interview-questions-book.blogspot.com/2009/06/decimalformat-roundoff-upto-two-digits.html"&gt;&lt;strong&gt;DecimalFormat Roundoff upto two digits&lt;/strong&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-4550725170341187590?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/4550725170341187590/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/core-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/4550725170341187590'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/4550725170341187590'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/core-java.html' title='Core Java Examples and Tutorials'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-7693513788953402130</id><published>2009-06-23T19:26:00.001-07:00</published><updated>2009-06-24T13:37:54.720-07:00</updated><title type='text'>Singleton class Example</title><content type='html'>&lt;strong&gt;Singleton Class&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Ensure that only one instance of a class is created &lt;br /&gt;Provide a global point of access to the object &lt;br /&gt;Allow multiple instances in the future without affecting a singleton class's clients &lt;br /&gt;&lt;br /&gt;Example 1 shows a classic Singleton design pattern implementation:&lt;br /&gt;&lt;br /&gt;Example 1. The classic singleton&lt;br /&gt;&lt;br /&gt;public class ClassicSingleton {&lt;br /&gt;private static ClassicSingleton instance = null;&lt;br /&gt;protected ClassicSingleton() {&lt;br /&gt;// Exists only to defeat instantiation.&lt;br /&gt;}&lt;br /&gt;public static ClassicSingleton getInstance() {&lt;br /&gt;if(instance == null) {&lt;br /&gt;instance = new ClassicSingleton();&lt;br /&gt;}&lt;br /&gt;return instance;&lt;br /&gt;}&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-7693513788953402130?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/7693513788953402130/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/singleton-class-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/7693513788953402130'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/7693513788953402130'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/singleton-class-example.html' title='Singleton class Example'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-2345609772108744098</id><published>2009-06-23T19:25:00.002-07:00</published><updated>2009-06-24T13:47:49.492-07:00</updated><title type='text'>Convert string to int in java</title><content type='html'>public class ConvertStringToInt {&lt;br /&gt;public static void main(String[] args) {&lt;br /&gt;String aString = "78";&lt;br /&gt;int aInt = Integer.parseInt(aString);&lt;br /&gt;&lt;br /&gt;System.out.println(aInt);&lt;br /&gt;}&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-2345609772108744098?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/2345609772108744098/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/convert-string-to-int-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/2345609772108744098'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/2345609772108744098'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/convert-string-to-int-in-java.html' title='Convert string to int in java'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-4706331235440153954</id><published>2009-06-23T19:25:00.001-07:00</published><updated>2009-06-24T13:50:13.917-07:00</updated><title type='text'>Convert Date to String in java</title><content type='html'>package org.kodejava.example.java.util;&lt;br /&gt;&lt;br /&gt;import java.text.DateFormat;&lt;br /&gt;import java.text.SimpleDateFormat;&lt;br /&gt;import java.util.Calendar;&lt;br /&gt;import java.util.Date;&lt;br /&gt;&lt;br /&gt;public class DateToString &lt;br /&gt;{&lt;br /&gt;public static void main(String[] args)&lt;br /&gt;{&lt;br /&gt;// Create an instance of SimpleDateFormat used for formatting &lt;br /&gt;// the string representation of date (month/day/year)&lt;br /&gt;DateFormat df = new SimpleDateFormat("MM/dd/yyyy");&lt;br /&gt;&lt;br /&gt;// Get the date today using Calendar object.&lt;br /&gt;Date today = Calendar.getInstance().getTime(); &lt;br /&gt;// Using DateFormat format method we can create a string &lt;br /&gt;// representation of a date with the defined format.&lt;br /&gt;String reportDate = df.format(today);&lt;br /&gt;&lt;br /&gt;// Print what date is today!&lt;br /&gt;System.out.println("Report Date: " + reportDate);&lt;br /&gt;}&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-4706331235440153954?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/4706331235440153954/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/convert-date-to-string-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/4706331235440153954'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/4706331235440153954'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/convert-date-to-string-in-java.html' title='Convert Date to String in java'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-1876546865791623353</id><published>2009-06-23T19:24:00.000-07:00</published><updated>2009-06-24T13:52:21.022-07:00</updated><title type='text'>Convert String to Date in java</title><content type='html'>import java.util.Date;&lt;br /&gt;import java.text.SimpleDateFormat;&lt;br /&gt;... ... ... ...&lt;br /&gt;&lt;br /&gt;public void testConvertDateToString() {&lt;br /&gt;&lt;br /&gt;// Allocates a Date object and initializes it so that it represents the time&lt;br /&gt;// at which it was allocated, measured to the nearest millisecond.&lt;br /&gt;Date dateNow = new Date ();&lt;br /&gt;&lt;br /&gt;SimpleDateFormat dateformatYYYYMMDD = new SimpleDateFormat("yyyyMMdd");&lt;br /&gt;SimpleDateFormat dateformatMMDDYYYY = new SimpleDateFormat("MMddyyyy");&lt;br /&gt;&lt;br /&gt;StringBuilder nowYYYYMMDD = new StringBuilder( dateformatYYYYMMDD.format( dateNow ) );&lt;br /&gt;StringBuilder nowMMDDYYYY = new StringBuilder( dateformatMMDDYYYY.format( dateNow ) );&lt;br /&gt;&lt;br /&gt;System.out.println( "DEBUG: Today in YYYYMMDD: '" + nowYYYYMMDD + "'");&lt;br /&gt;System.out.println( "DEBUG: Today in MMDDYYYY: '" + nowMMDDYYYY + "'");&lt;br /&gt;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-1876546865791623353?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/1876546865791623353/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/convert-string-to-date-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/1876546865791623353'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/1876546865791623353'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/convert-string-to-date-in-java.html' title='Convert String to Date in java'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-3359673301170220236</id><published>2009-06-23T19:19:00.001-07:00</published><updated>2009-06-24T13:55:09.880-07:00</updated><title type='text'>DecimalFormat Roundoff upto two digits</title><content type='html'>public static  String decimalRoundoff(Double value){  &lt;br /&gt;      //DecimalFormat myFormatter = new DecimalFormat(".00");&lt;br /&gt;       DecimalFormat myFormatter = new DecimalFormat("#,##0.00");&lt;br /&gt;      String output = myFormatter.format(value);&lt;br /&gt;      return output;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-3359673301170220236?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/3359673301170220236/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/decimalformat-roundoff-upto-two-digits.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/3359673301170220236'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/3359673301170220236'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/decimalformat-roundoff-upto-two-digits.html' title='DecimalFormat Roundoff upto two digits'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-8008453530696350672</id><published>2009-06-23T19:18:00.003-07:00</published><updated>2009-07-25T13:40:58.859-07:00</updated><title type='text'>GWT NumberFormat Example</title><content type='html'>&lt;dl&gt;&lt;dt&gt;&lt;pre&gt;public class &lt;b&gt;&lt;span style="color:#33cc00;"&gt;NumberFormat&lt;/span&gt;&lt;/b&gt;&lt;dt&gt;extends java.lang.Object &lt;/dt&gt;&lt;/pre&gt;&lt;/dt&gt;&lt;/dl&gt;&lt;p&gt;Formats and parses numbers using locale-sensitive patterns.&lt;br /&gt;&lt;br /&gt;This class provides comprehensive and flexible support for a wide variety of&lt;br /&gt;localized formats, including &lt;ul&gt;&lt;li&gt;&lt;b&gt;Locale-specific symbols&lt;/b&gt; such as decimal point, group separator,&lt;br /&gt;digit representation, currency symbol, percent, and permill&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;b&gt;Numeric variations&lt;/b&gt; including integers ("123"), fixed-point&lt;br /&gt;numbers ("123.4"), scientific notation ("1.23E4"), percentages ("12%"), and&lt;br /&gt;currency amounts ("$123")&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;b&gt;Predefined standard patterns&lt;/b&gt; that can be used both for parsing&lt;br /&gt;and formatting, including decimal,&lt;br /&gt;currency,&lt;br /&gt;percentages, and&lt;br /&gt;scientific&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;b&gt;Custom patterns&lt;/b&gt; and supporting features designed to make it&lt;br /&gt;possible to parse and format numbers in any locale, including support for&lt;br /&gt;Western, Arabic, and Indic digits&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;span style="color:#33ff33;"&gt;Patterns&lt;/span&gt;&lt;/h3&gt;&lt;p&gt;Formatting and parsing are based on customizable patterns that can include a&lt;br /&gt;combination of literal characters and special characters that act as&lt;br /&gt;placeholders and are replaced by their localized counterparts. Many&lt;br /&gt;characters in a pattern are taken literally; they are matched during parsing&lt;br /&gt;and output unchanged during formatting. Special characters, on the other&lt;br /&gt;hand, stand for other characters, strings, or classes of characters. For&lt;br /&gt;example, the '&lt;code&gt;#&lt;/code&gt;' character is replaced by a localized digit. &lt;/p&gt;&lt;p&gt;Often the replacement character is the same as the pattern character. In the&lt;br /&gt;U.S. locale, for example, the '&lt;code&gt;,&lt;/code&gt;' grouping character is&lt;br /&gt;replaced by the same character '&lt;code&gt;,&lt;/code&gt;'. However, the replacement&lt;br /&gt;is still actually happening, and in a different locale, the grouping&lt;br /&gt;character may change to a different character, such as '&lt;code&gt;.&lt;/code&gt;'.&lt;br /&gt;Some special characters affect the behavior of the formatter by their&lt;br /&gt;presence. For example, if the percent character is seen, then the value is&lt;br /&gt;multiplied by 100 before being displayed. &lt;/p&gt;&lt;p&gt;The characters listed below are used in patterns. Localized symbols use the&lt;br /&gt;corresponding characters taken from corresponding locale symbol collection,&lt;br /&gt;which can be found in the properties files residing in the&lt;br /&gt;&lt;code&gt;&lt;nobr&gt;com.google.gwt.i18n.client.constants&lt;/nobr&gt;&lt;/code&gt;. To insert&lt;br /&gt;a special character in a pattern as a literal (that is, without any special&lt;br /&gt;meaning) the character must be quoted. There are some exceptions to this&lt;br /&gt;which are noted below. &lt;/p&gt;&lt;p&gt;A &lt;code&gt;NumberFormat&lt;/code&gt; pattern contains a postive and negative&lt;br /&gt;subpattern separated by a semicolon, such as&lt;br /&gt;&lt;code&gt;"#,##0.00;(#,##0.00)"&lt;/code&gt;. Each subpattern has a prefix, a&lt;br /&gt;numeric part, and a suffix. If there is no explicit negative subpattern, the&lt;br /&gt;negative subpattern is the localized minus sign prefixed to the positive&lt;br /&gt;subpattern. That is, &lt;code&gt;"0.00"&lt;/code&gt; alone is equivalent to&lt;br /&gt;&lt;code&gt;"0.00;-0.00"&lt;/code&gt;. If there is an explicit negative subpattern, it&lt;br /&gt;serves only to specify the negative prefix and suffix; the number of digits,&lt;br /&gt;minimal digits, and other characteristics are ignored in the negative&lt;br /&gt;subpattern. That means that &lt;code&gt;"#,##0.0#;(#)"&lt;/code&gt; has precisely the&lt;br /&gt;same result as &lt;code&gt;"#,##0.0#;(#,##0.0#)"&lt;/code&gt;. &lt;/p&gt;&lt;p&gt;The prefixes, suffixes, and various symbols used for infinity, digits,&lt;br /&gt;thousands separators, decimal separators, etc. may be set to arbitrary&lt;br /&gt;values, and they will appear properly during formatting. However, care must&lt;br /&gt;be taken that the symbols and strings do not conflict, or parsing will be&lt;br /&gt;unreliable. For example, the decimal separator and thousands separator should&lt;br /&gt;be distinct characters, or parsing will be impossible. &lt;/p&gt;&lt;p&gt;The grouping separator is a character that separates clusters of integer&lt;br /&gt;digits to make large numbers more legible. It commonly used for thousands,&lt;br /&gt;but in some locales it separates ten-thousands. The grouping size is the&lt;br /&gt;number of digits between the grouping separators, such as 3 for "100,000,000"&lt;br /&gt;or 4 for "1 0000 0000". &lt;/p&gt;&lt;h3&gt;Pattern Grammar (BNF)&lt;/h3&gt;&lt;p&gt;The pattern itself uses the following grammar:&lt;br /&gt;&lt;br /&gt;pattern:=subpattern (';' subpattern)?&lt;br /&gt;subpattern:=prefix? number exponent? suffix?&lt;br /&gt;number:=(integer ('.' fraction)?) sigDigits&lt;br /&gt;prefix:='\u0000'..'\uFFFD' - specialCharacters&lt;br /&gt;suffix:='\u0000'..'\uFFFD' - specialCharacters&lt;br /&gt;integer:='#'* '0'*'0'&lt;br /&gt;fraction:='0'* '#'*&lt;br /&gt;sigDigits:='#'* '@''@'* '#'*&lt;br /&gt;exponent:='E' '+'? '0'* '0'&lt;br /&gt;padSpec:='*' padChar&lt;br /&gt;padChar:='\u0000'..'\uFFFD' - quote&lt;/p&gt;&lt;p&gt;Notation: &lt;/p&gt;&lt;p&gt;X* 0 or more instances of X&lt;br /&gt;X? 0 or 1 instances of X&lt;br /&gt;XY either X or Y&lt;br /&gt;C..D any character from C up to D, inclusive&lt;br /&gt;S-T characters in S, except those in T&lt;/p&gt;&lt;p&gt;&lt;br /&gt;The first subpattern is for positive numbers. The second (optional) subpattern is for negative numbers. &lt;/p&gt;&lt;h3&gt;&lt;span style="color:#33ff33;"&gt;Example&lt;/span&gt;&lt;/h3&gt;&lt;blockquote&gt;&lt;pre&gt;public class NumberFormatExample implements EntryPoint {&lt;br /&gt;&lt;br /&gt;  public void onModuleLoad() {&lt;br /&gt;    NumberFormat fmt = &lt;span style="color:#33ff33;"&gt;NumberFormat.getDecimalFormat();&lt;/span&gt;&lt;br /&gt;    double value = 12345.6789;&lt;br /&gt;    String formatted = fmt.format(value);&lt;br /&gt;    // Prints 1,2345.6789 in the default locale&lt;br /&gt;    GWT.log("Formatted string is" + formatted, null);&lt;br /&gt;&lt;br /&gt;    // Turn a string back into a double&lt;br /&gt;    value = NumberFormat.getDecimalFormat().parse("12345.6789");&lt;br /&gt;    GWT.log("Parsed value is" + value, null);&lt;br /&gt;&lt;br /&gt;    // Scientific notation&lt;br /&gt;    value = 12345.6789;&lt;br /&gt;    formatted = NumberFormat.getScientificFormat().format(value);&lt;br /&gt;    // prints 1.2345E4 in the default locale&lt;br /&gt;    GWT.log("Formatted string is" + formatted, null);&lt;br /&gt;&lt;br /&gt;    // Currency&lt;br /&gt;    fmt = NumberFormat.getCurrencyFormat();&lt;br /&gt;    formatted = fmt.format(123456.7899);&lt;br /&gt;    // prints $123,456.79 in the default locale&lt;br /&gt;    GWT.log("Formatted currency is" + formatted, null);&lt;br /&gt;&lt;br /&gt;    // Custom format&lt;br /&gt;    value = 12345.6789;&lt;br /&gt;    formatted = NumberFormat.getFormat("000000.000000").format(value);&lt;br /&gt;    // prints 012345.678900 in the default locale&lt;br /&gt;    GWT.log("Formatted string is" + formatted, null);&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;&lt;pre&gt;&lt;strong&gt;&lt;span style="font-size:130%;color:#33ff33;"&gt;Constructor Detail&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;a name="NumberFormat(com.google.gwt.i18n.client.constants.NumberConstants, java.lang.String, com.google.gwt.i18n.client.impl.CurrencyData, boolean)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;h3&gt;&lt;br /&gt;NumberFormat&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;protected &lt;b&gt;NumberFormat&lt;/b&gt;(com.google.gwt.i18n.client.constants.NumberConstants numberConstants,&lt;br /&gt;                       java.lang.String pattern,&lt;br /&gt;                       com.google.gwt.i18n.client.impl.CurrencyData cdata,&lt;br /&gt;                       boolean userSuppliedPattern)&lt;br /&gt;&lt;/pre&gt;&lt;dl&gt;&lt;dd&gt;Constructs a format object based on the specified settings.&lt;br /&gt;&lt;/dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt; &lt;dd&gt;&lt;code&gt;numberConstants&lt;/code&gt; - the locale-specific number constants to use for this&lt;br /&gt;format &lt;dd&gt;&lt;code&gt;pattern&lt;/code&gt; - pattern that specify how number should be formatted &lt;dd&gt;&lt;code&gt;cdata&lt;/code&gt; - currency data that should be used &lt;dd&gt;&lt;code&gt;userSuppliedPattern&lt;/code&gt; - true if the pattern was supplied by the user&lt;br /&gt;&lt;hr /&gt;&lt;!-- --&gt;&lt;/dd&gt;&lt;/dl&gt;&lt;/dl&gt;&lt;h3&gt;&lt;br /&gt;NumberFormat&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;protected &lt;b&gt;NumberFormat&lt;/b&gt;(java.lang.String pattern,&lt;br /&gt;                       com.google.gwt.i18n.client.impl.CurrencyData cdata,&lt;br /&gt;                       boolean userSuppliedPattern)&lt;/pre&gt;&lt;dl&gt;&lt;dd&gt;Constructs a format object for the default locale based on the specified&lt;br /&gt;settings.&lt;br /&gt;&lt;/dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt; &lt;dd&gt;&lt;code&gt;pattern&lt;/code&gt; - pattern that specify how number should be formatted &lt;dd&gt;&lt;code&gt;cdata&lt;/code&gt; - currency data that should be used &lt;dd&gt;&lt;code&gt;userSuppliedPattern&lt;/code&gt; - true if the pattern was supplied by the user&lt;/dd&gt;&lt;/dl&gt;&lt;/dl&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;Method Detail&lt;/span&gt;&lt;/strong&gt;&lt;a name="getCurrencyFormat()"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;&lt;br /&gt;getCurrencyFormat&lt;/h3&gt;&lt;pre&gt;&lt;br /&gt;public static &lt;b&gt;NumberFormat&lt;/b&gt; &lt;b&gt;getCurrencyFormat&lt;/b&gt;()&lt;br /&gt;&lt;/pre&gt;&lt;dl&gt;&lt;dd&gt;Provides the standard currency format for the default locale. &lt;/dd&gt;&lt;dl&gt;&lt;br /&gt;&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;dd&gt;a &lt;code&gt;NumberFormat&lt;/code&gt; capable of producing and consuming&lt;br /&gt;currency format for the default locale&lt;/dd&gt;&lt;/dl&gt;&lt;br /&gt;&lt;/dl&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;strong&gt;getCurrencyFormat&lt;/strong&gt;&lt;br /&gt;public static &lt;b&gt;NumberFormat&lt;/b&gt; &lt;b&gt;getCurrencyFormat&lt;/b&gt;(java.lang.String currencyCode)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;dl&gt;&lt;br /&gt;&lt;dd&gt;Provides the standard currency format for the default locale using a&lt;br /&gt;specified currency.&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;/dd&gt;&lt;dl&gt;&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt; &lt;dd&gt;&lt;code&gt;currencyCode&lt;/code&gt; - valid currency code, as defined in&lt;br /&gt;com.google.gwt.i18n.client.constants.CurrencyCodeMapConstants.properties&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;dd&gt;a &lt;code&gt;NumberFormat&lt;/code&gt; capable of producing and consuming&lt;br /&gt;currency format for the default locale&lt;/dd&gt;&lt;/dl&gt;&lt;br /&gt;&lt;/dl&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;strong&gt;getDecimalFormat&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static &lt;b&gt;NumberFormat&lt;/b&gt; &lt;b&gt;getDecimalFormat&lt;/b&gt;()&lt;/pre&gt;&lt;dl&gt;&lt;br /&gt;&lt;dd&gt;Provides the standard decimal format for the default locale. &lt;p&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;/p&gt;&lt;dd&gt;&lt;dl&gt;&lt;dd&gt;a &lt;code&gt;NumberFormat&lt;/code&gt; capable of producing and consuming&lt;br /&gt;decimal format for the default locale&lt;/dd&gt;&lt;/dl&gt;&lt;br /&gt;&lt;/dd&gt;&lt;br /&gt;&lt;/dl&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;strong&gt;getFormat&lt;/strong&gt;&lt;br /&gt;public static &lt;b&gt;NumberFormat&lt;/b&gt; &lt;b&gt;getFormat&lt;/b&gt;(java.lang.String pattern)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;dl&gt;&lt;br /&gt;&lt;dd&gt;Gets a &lt;code&gt;NumberFormat&lt;/code&gt; instance for the default locale using&lt;br /&gt;the specified pattern and the default currencyCode.&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;dd&gt;&lt;dl&gt;&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt; &lt;dd&gt;&lt;code&gt;pattern&lt;/code&gt; - pattern for this formatter&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;dd&gt;a NumberFormat instance&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Throws:&lt;/b&gt;&lt;br /&gt;&lt;dd&gt;&lt;code&gt;java.lang.IllegalArgumentException&lt;/code&gt; - if the specified pattern is invalid&lt;/dd&gt;&lt;/dl&gt;&lt;br /&gt;&lt;/dd&gt;&lt;br /&gt;&lt;/dl&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="getFormat(java.lang.String, java.lang.String)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt;&lt;br /&gt;getFormat&lt;br /&gt;&lt;/h3&gt;&lt;pre&gt;public static &lt;b&gt;NumberFormat&lt;/b&gt; &lt;b&gt;getFormat&lt;/b&gt;(java.lang.String pattern,&lt;br /&gt;                                     java.lang.String currencyCode)&lt;/pre&gt;&lt;dl&gt;&lt;br /&gt;&lt;dd&gt;Gets a custom &lt;code&gt;NumberFormat&lt;/code&gt; instance for the default locale&lt;br /&gt;using the specified pattern and currency code. &lt;/dd&gt;&lt;dl&gt;&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt; &lt;dd&gt;&lt;code&gt;pattern&lt;/code&gt; - pattern for this formatter &lt;dd&gt;&lt;code&gt;currencyCode&lt;/code&gt; - international currency code&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;dd&gt;a NumberFormat instance&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Throws:&lt;/b&gt;&lt;br /&gt;&lt;dd&gt;&lt;code&gt;java.lang.IllegalArgumentException&lt;/code&gt; - if the specified pattern is invalid&lt;/dd&gt;&lt;/dl&gt;&lt;br /&gt;&lt;/dl&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;strong&gt;getPercentFormat&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static &lt;b&gt;NumberFormat&lt;/b&gt; &lt;b&gt;getPercentFormat&lt;/b&gt;()&lt;/pre&gt;&lt;dl&gt;&lt;br /&gt;&lt;dd&gt;Provides the standard percent format for the default locale. &lt;p&gt;&lt;br /&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dl&gt;&lt;dd&gt;a &lt;code&gt;NumberFormat&lt;/code&gt; capable of producing and consuming&lt;br /&gt;percent format for the default locale&lt;/dd&gt;&lt;/dl&gt;&lt;br /&gt;&lt;/dl&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="getScientificFormat()"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt;getScientificFormat&lt;/h3&gt;&lt;pre&gt;&lt;br /&gt;public static &lt;b&gt;NumberFormat&lt;/b&gt; &lt;b&gt;getScientificFormat&lt;/b&gt;()&lt;/pre&gt;&lt;dl&gt;&lt;dd&gt;Provides the standard scientific format for the default locale. &lt;p&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dl&gt;&lt;dd&gt;a &lt;code&gt;NumberFormat&lt;/code&gt; capable of producing and consuming&lt;br /&gt;scientific format for the default locale&lt;/dd&gt;&lt;/dl&gt;&lt;br /&gt;&lt;/dl&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;format&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public java.lang.String &lt;b&gt;format&lt;/b&gt;(double number)&lt;/pre&gt;&lt;dl&gt;&lt;dd&gt;This method formats a double to produce a string. &lt;p&gt;&lt;b&gt;Parameters:&lt;/b&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dl&gt;&lt;dd&gt;&lt;code&gt;number&lt;/code&gt; - The double to format&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;dd&gt;the formatted number string&lt;/dd&gt;&lt;/dl&gt;&lt;/dl&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;getPattern&lt;/strong&gt;&lt;br /&gt;public java.lang.String &lt;b&gt;getPattern&lt;/b&gt;()&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;dl&gt;&lt;br /&gt;&lt;dd&gt;Returns the pattern used by this number format. &lt;hr /&gt;&lt;/dd&gt;&lt;/dl&gt;&lt;strong&gt;parse&lt;/strong&gt;&lt;br /&gt;public double &lt;b&gt;parse&lt;/b&gt;(java.lang.String text)&lt;br /&gt;&lt;br /&gt;throws java.lang.NumberFormatException&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;dl&gt;&lt;br /&gt;&lt;dd&gt;Parses text to produce a numeric value. A &lt;code&gt;NumberFormatException&lt;/code&gt; is&lt;br /&gt;thrown if either the text is empty or if the parse does not consume all&lt;br /&gt;characters of the text.&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;/dd&gt;&lt;dl&gt;&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt; &lt;dd&gt;&lt;code&gt;text&lt;/code&gt; - the string being parsed&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;dd&gt;a parsed number value&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Throws:&lt;/b&gt;&lt;br /&gt;&lt;dd&gt;&lt;code&gt;java.lang.NumberFormatException&lt;/code&gt; - if the entire text could not be converted&lt;br /&gt;into a number&lt;/dd&gt;&lt;/dl&gt;&lt;/dl&gt;&lt;hr /&gt;&lt;br /&gt;&lt;strong&gt;parse&lt;/strong&gt;&lt;br /&gt;public double &lt;b&gt;parse&lt;/b&gt;(java.lang.String text,&lt;br /&gt;&lt;br /&gt;int[] inOutPos)&lt;br /&gt;&lt;br /&gt;throws java.lang.NumberFormatException&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;dl&gt;&lt;br /&gt;&lt;dd&gt;Parses text to produce a numeric value.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;The method attempts to parse text starting at the index given by pos. If&lt;br /&gt;parsing succeeds, then the index of &lt;code&gt;pos&lt;/code&gt; is updated to the&lt;br /&gt;index after the last character used (parsing does not necessarily use all&lt;br /&gt;characters up to the end of the string), and the parsed number is returned.&lt;br /&gt;The updated &lt;code&gt;pos&lt;/code&gt; can be used to indicate the starting point&lt;br /&gt;for the next call to this method. If an error occurs, then the index of&lt;br /&gt;&lt;code&gt;pos&lt;/code&gt; is not changed. &lt;/p&gt;&lt;/dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt; &lt;dd&gt;&lt;code&gt;text&lt;/code&gt; - the string to be parsed &lt;dd&gt;&lt;code&gt;inOutPos&lt;/code&gt; - position to pass in and get back&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;dd&gt;a double value representing the parsed number, or &lt;code&gt;0.0&lt;/code&gt;&lt;br /&gt;if the parse fails&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Throws:&lt;/b&gt;&lt;br /&gt;&lt;dd&gt;&lt;code&gt;java.lang.NumberFormatException&lt;/code&gt; - if the text segment could not be converted into a number&lt;/dd&gt;&lt;/dl&gt;&lt;/dl&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-8008453530696350672?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/8008453530696350672/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/gwt-numberformat-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/8008453530696350672'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/8008453530696350672'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/gwt-numberformat-example.html' title='GWT NumberFormat Example'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-6363989110096100877</id><published>2009-06-23T19:18:00.001-07:00</published><updated>2009-06-24T14:04:02.756-07:00</updated><title type='text'>GWT File UPLOAD</title><content type='html'>Client:&lt;br /&gt;&lt;br /&gt;    public void onModuleLoad() {&lt;br /&gt;        final FormPanel form = new FormPanel();&lt;br /&gt;        form.setAction(GWT.getModuleBaseURL() + "/myFormHandler");&lt;br /&gt;        &lt;br /&gt;        // Because we're going to add a FileUpload widget, we'll need to set the&lt;br /&gt;        // form to use the POST method, and multipart MIME encoding.&lt;br /&gt;        form.setEncoding(FormPanel.ENCODING_MULTIPART);&lt;br /&gt;        form.setMethod(FormPanel.METHOD_POST);&lt;br /&gt;        &lt;br /&gt;        VerticalPanel panel = new VerticalPanel();&lt;br /&gt;        form.setWidget(panel);&lt;br /&gt;        &lt;br /&gt;        // Create a FileUpload widget.&lt;br /&gt;        FileUpload upload = new FileUpload();&lt;br /&gt;        upload.setName("uploadFormElement");&lt;br /&gt;        &lt;br /&gt;        panel.add(upload);&lt;br /&gt;        &lt;br /&gt;        Button button2 = new Button("Submit", new ClickListener() {&lt;br /&gt;            public void onClick(Widget sender) {&lt;br /&gt;                form.submit();&lt;br /&gt;            }&lt;br /&gt;        });&lt;br /&gt;        &lt;br /&gt;        // Add a 'submit' button.&lt;br /&gt;        panel.add(button2);&lt;br /&gt;        &lt;br /&gt;        // Add an event handler to the form.&lt;br /&gt;        form.addFormHandler(new FormHandler() {&lt;br /&gt;&lt;br /&gt;            public void onSubmitComplete(FormSubmitCompleteEvent event) {&lt;br /&gt;                // When the form submission is successfully completed, this&lt;br /&gt;                // event is&lt;br /&gt;                // fired. Assuming the service returned a response of type&lt;br /&gt;                // text/html,&lt;br /&gt;                // we can get the result text here (see the FormPanel&lt;br /&gt;                // documentation for&lt;br /&gt;                // further explanation).&lt;br /&gt;                Window.alert(event.getResults());&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            public void onSubmit(FormSubmitEvent event) {&lt;br /&gt;                // TODO Auto-generated method stub&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;        });&lt;br /&gt;        &lt;br /&gt;        RootPanel.get().add(form);&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;module&gt;.gwt.xml&lt;br /&gt;add this line:&lt;br /&gt;&lt;br /&gt;&lt;servlet path="/myFormHandler" class="com.posta.samples.server.MyFormHandler"/&gt;&lt;br /&gt;Server &lt;br /&gt;&lt;br /&gt;public class MyFormHandler extends HttpServlet {&lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    public void doPost(HttpServletRequest req, HttpServletResponse resp)&lt;br /&gt;            throws ServletException, IOException {&lt;br /&gt;        &lt;br /&gt;        resp.setContentType("text/html");&lt;br /&gt;        &lt;br /&gt;        FileItem uploadItem = getFileItem(req);&lt;br /&gt;        if(uploadItem == null) {&lt;br /&gt;            resp.getWriter().write("NO-SCRIPT-DATA");&lt;br /&gt;            return;&lt;br /&gt;        }&lt;br /&gt;        &lt;br /&gt;        resp.getWriter().write(new String(uploadItem.get()));&lt;br /&gt;        &lt;br /&gt;        &lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private FileItem getFileItem(HttpServletRequest req) {&lt;br /&gt;        FileItemFactory factory = new DiskFileItemFactory();&lt;br /&gt;        ServletFileUpload upload = new ServletFileUpload(factory);&lt;br /&gt;        &lt;br /&gt;        try {&lt;br /&gt;            List items = upload.parseRequest(req);&lt;br /&gt;            Iterator it = items.iterator();&lt;br /&gt;            &lt;br /&gt;            while(it.hasNext()) {&lt;br /&gt;                FileItem item = (FileItem) it.next();&lt;br /&gt;                if(!item.isFormField() &amp;&amp; "uploadFormElement".equals(item.getFieldName())) {&lt;br /&gt;                    return item;&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        catch(FileUploadException e){&lt;br /&gt;            return null;&lt;br /&gt;        }&lt;br /&gt;        &lt;br /&gt;        return null;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-6363989110096100877?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/6363989110096100877/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/gwt-file-upload.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/6363989110096100877'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/6363989110096100877'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/gwt-file-upload.html' title='GWT File UPLOAD'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-7604420522872691083</id><published>2009-06-23T19:16:00.000-07:00</published><updated>2009-06-24T14:04:02.759-07:00</updated><title type='text'>GWT File DownLoad</title><content type='html'>Per some requests for the File Download opposite of File Upload.&lt;br /&gt;&lt;br /&gt;On the server side I implemented the doGet method of the HttpServlet class. I grab the raw data from the database and set it into the response (with the appropriate response type):&lt;br /&gt;&lt;br /&gt;                BufferedOutputStream output = null;&lt;br /&gt;                try {&lt;br /&gt;                    RawAttachmentItem attachment = attachmentFileDao.retrieveContents(fileid);&lt;br /&gt;                    ByteArrayInputStream input = new ByteArrayInputStream(attachment.getContents());&lt;br /&gt;                    int contentLength = input.available();&lt;br /&gt;                    &lt;br /&gt;                    resp.reset();&lt;br /&gt;                    resp.setContentType("application/octet-stream");&lt;br /&gt;                    resp.setContentLength(contentLength);&lt;br /&gt;                    resp.setHeader("Content-disposition", "attachment; filename=\"" + attachment.getFilename()&lt;br /&gt;                        + "\"");&lt;br /&gt;                    output = new BufferedOutputStream(resp.getOutputStream());&lt;br /&gt;                    for(int data; (data=input.read()) != -1;) {&lt;br /&gt;                        output.write(data);&lt;br /&gt;                    }&lt;br /&gt;                    output.flush();&lt;br /&gt;                }&lt;br /&gt;                catch (IOException e) {&lt;br /&gt;                    &lt;br /&gt;                    e.printStackTrace();&lt;br /&gt;                }&lt;br /&gt;                finally {&lt;br /&gt;                    close(output);&lt;br /&gt;                }&lt;br /&gt;On the client side, you simple create a new iFrame with its 'src' attribute set to the servlet url for downloading the file:&lt;br /&gt;&lt;br /&gt;        boolean frameExists = (RootPanel.get("downloadiframe") != null);&lt;br /&gt;        if(frameExists) {&lt;br /&gt;            Widget widgetFrame = (Widget)RootPanel.get("downloadiframe");&lt;br /&gt;            widgetFrame.removeFromParent();&lt;br /&gt;        }&lt;br /&gt;        &lt;br /&gt;        NamedFrame frame = new NamedFrame("downloadiframe");&lt;br /&gt;        frame.setUrl(GWT.getModuleBaseURL() &lt;br /&gt;            + "/attachmentHandler?action=dl&amp;fileid="&lt;br /&gt;            + model.getFileId());&lt;br /&gt;        frame.setVisible(false);&lt;br /&gt;        &lt;br /&gt;        RootPanel.get().add(frame);&lt;br /&gt;When the file gets sent back to the iFrame, the browser will treat it as a file download and prompt you to do something with it (open, save, cancel, etc).&lt;br /&gt;&lt;br /&gt;If anyone has questions or requires more detail, please do not hesitate to ask!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-7604420522872691083?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/7604420522872691083/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/gwt-file-download.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/7604420522872691083'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/7604420522872691083'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/gwt-file-download.html' title='GWT File DownLoad'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-318228580368198809</id><published>2009-06-23T17:27:00.000-07:00</published><updated>2009-06-24T14:02:35.064-07:00</updated><title type='text'>Vector Example</title><content type='html'>In this example we are going to show the use of java.util.Vector class. We will be creating an object of Vector class and performs various operation like adding, removing etc. Vector class extends AbstractList and implements List, RandomAccess, Cloneable, Serializable. The size of a vector increase and decrease according to the program. Vector is synchronized.&lt;br /&gt;&lt;br /&gt;In this example we are using seven methods of a Vector class.&lt;br /&gt;&lt;br /&gt;add(Object o): It adds the element in the end of the Vector&lt;br /&gt;&lt;br /&gt;size(): It gives the number of element in the vector.&lt;br /&gt;&lt;br /&gt;elementAt(int index): It returns the element at the specified index.&lt;br /&gt;&lt;br /&gt;firstElement(): It returns the first element of the vector.&lt;br /&gt;&lt;br /&gt;lastElement(): It returns  last element.&lt;br /&gt;&lt;br /&gt;removeElementAt(int index): It deletes the element from the given index.&lt;br /&gt;&lt;br /&gt;elements(): It returns an enumeration of the element&lt;br /&gt;&lt;br /&gt;In this example we have also used Enumeration interface to retrieve the value of a vector. Enumeration interface has two methods.&lt;br /&gt;&lt;br /&gt;hasMoreElements(): It checks if this enumeration contains more elements or not.&lt;br /&gt;&lt;br /&gt;nextElement(): It checks the next element of the enumeration.&lt;br /&gt;&lt;br /&gt;Code of this program is given below: &lt;br /&gt;&lt;br /&gt;//java.util.Vector and java.util.Enumeration;&lt;br /&gt;&lt;br /&gt;import java.util.*;&lt;br /&gt;public class VectorDemo{&lt;br /&gt;  public static void main(String[] args){&lt;br /&gt;    Vector&lt;Object&gt; vector = new Vector&lt;Object&gt;();&lt;br /&gt;    int primitiveType = 10;&lt;br /&gt;    Integer wrapperType = new Integer(20);&lt;br /&gt;    String str = "animal";&lt;br /&gt;    vector.add(primitiveType);&lt;br /&gt;    vector.add(wrapperType);&lt;br /&gt;    vector.add(str);&lt;br /&gt;    vector.add(2, new Integer(30));&lt;br /&gt;    System.out.println("the elements of vector: " + vector);&lt;br /&gt;    System.out.println("The size of vector are: " + vector.size());&lt;br /&gt;    System.out.println("The elements at position 2 is: " + vector.elementAt(2));&lt;br /&gt;    System.out.println("The first element of vector is: " + vector.firstElement());&lt;br /&gt;    System.out.println("The last element of vector is: " + vector.lastElement());&lt;br /&gt;    vector.removeElementAt(2);&lt;br /&gt;    Enumeration e=vector.elements();&lt;br /&gt;    System.out.println("The elements of vector: " + vector);&lt;br /&gt;    while(e.hasMoreElements()){&lt;br /&gt;      System.out.println("The elements are: " + e.nextElement());&lt;br /&gt;    }  &lt;br /&gt;  }&lt;br /&gt;}  &lt;br /&gt;&lt;br /&gt;Output of this example is given below:&lt;br /&gt;&lt;br /&gt;the elements of vector: [10, 20, 30, animal]&lt;br /&gt;The size of vector are: 4&lt;br /&gt;The elements at position 2 is: 30&lt;br /&gt;The first element of vector is: 10&lt;br /&gt;The last element of vector is: animal&lt;br /&gt;The elements of vector: [10, 20, animal]&lt;br /&gt;The elements are: 10&lt;br /&gt;The elements are: 20&lt;br /&gt;The elements are: animal&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-318228580368198809?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/318228580368198809/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/vector-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/318228580368198809'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/318228580368198809'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/vector-example.html' title='Vector Example'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-2244241706627718387</id><published>2009-06-23T17:24:00.001-07:00</published><updated>2009-06-24T14:02:35.067-07:00</updated><title type='text'>ArrayList Example</title><content type='html'>In this example we are going to show the use of java.util.ArrayList. We will be creatiing an object of ArrayList class and performs various operations like adding removing the objects.&lt;br /&gt;&lt;br /&gt;Arraylist provides methods to manipulate the size of the array that is used internally to store the list. ArrayList extends AbstractList and implements List, Cloneable, Serializable.  ArrayList capacity .grows automatically. The ArrayList is not synchronized. It permits all elements including null.&lt;br /&gt;&lt;br /&gt;In this program we are inserting a value. We are using three methods of ArrayList class.&lt;br /&gt;&lt;br /&gt;add(Object o): Appends the specified element to the end of this list. It returns a boolean value.&lt;br /&gt;&lt;br /&gt;size():  Returns the number of elements in this list.&lt;br /&gt;&lt;br /&gt;remove(int index): Removes the element at the specified position in this list. It returns the element that was removed from the list. It throws IndexOutOfBoundsException : if index is out of range. &lt;br /&gt;&lt;br /&gt;Code of a program is given below:&lt;br /&gt;&lt;br /&gt;import java.util.*;&lt;br /&gt;&lt;br /&gt;public class ArrayListDemo{&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    ArrayList&lt;Object&gt; arl=new ArrayList&lt;Object&gt;();&lt;br /&gt;    Integer i1=new Integer(10);&lt;br /&gt;    Integer i2=new Integer(20);&lt;br /&gt;    Integer i3=new Integer(30);&lt;br /&gt;    Integer i4=new Integer(40);&lt;br /&gt;    String s1="animal";&lt;br /&gt;    System.out.println("The content of arraylist is: " + arl);&lt;br /&gt;    System.out.println("The size of an arraylist is: " + arl.size());&lt;br /&gt;    arl.add(i1);&lt;br /&gt;    arl.add(i2);&lt;br /&gt;    arl.add(s1);&lt;br /&gt;    System.out.println("The content of arraylist is: " + arl);&lt;br /&gt;    System.out.println("The size of an arraylist is: " + arl.size());&lt;br /&gt;    arl.add(i1);&lt;br /&gt;    arl.add(i2);&lt;br /&gt;    arl.add(i3);&lt;br /&gt;    arl.add(i4);&lt;br /&gt;    Integer i5=new Integer(50);&lt;br /&gt;    arl.add(i5);&lt;br /&gt;    System.out.println("The content of arraylist is: " + arl);&lt;br /&gt;    System.out.println("The size of an arraylist is: " + arl.size());&lt;br /&gt;    arl.remove(3);&lt;br /&gt;    Object a=arl.clone();&lt;br /&gt;    System.out.println("The clone is: " + a); &lt;br /&gt;    System.out.println("The content of arraylist is: " + arl);&lt;br /&gt;    System.out.println("The size of an arraylist is: " + arl.size());&lt;br /&gt;  }&lt;br /&gt;}  &lt;br /&gt;&lt;br /&gt;The output of program will be like this:&lt;br /&gt;&lt;br /&gt;The content of arraylist is: []&lt;br /&gt;The size of an arraylist is: 0&lt;br /&gt;The content of arraylist is: [10, 20, animal]&lt;br /&gt;The size of an arraylist is: 3&lt;br /&gt;The content of arraylist is: [10, 20, animal, 10, 20, 30, 40, 50]&lt;br /&gt;The size of an arraylist is: 8&lt;br /&gt;The clone is: [10, 20, animal, 20, 30, 40, 50]&lt;br /&gt;The content of arraylist is: [10, 20, animal, 20, 30, 40, 50]&lt;br /&gt;The size of an arraylist is: 7&lt;br /&gt; &lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-2244241706627718387?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/2244241706627718387/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/arraylist-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/2244241706627718387'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/2244241706627718387'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/arraylist-example.html' title='ArrayList Example'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-8526976181161005597</id><published>2009-06-23T17:13:00.000-07:00</published><updated>2009-06-24T14:02:35.070-07:00</updated><title type='text'>Abstract Methods and Classes</title><content type='html'>&lt;br /&gt;An abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed. &lt;br /&gt;An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon), like this: &lt;br /&gt;&lt;br /&gt;abstract void moveTo(double deltaX, double deltaY);&lt;br /&gt;&lt;br /&gt;If a class includes abstract methods, the class itself must be declared abstract, as in: &lt;br /&gt;&lt;br /&gt;public abstract class GraphicObject {&lt;br /&gt;   // declare fields&lt;br /&gt;   // declare non-abstract methods&lt;br /&gt;   abstract void draw();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, the subclass must also be declared abstract. &lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;Note: All of the methods in an interface  are implicitly abstract, so the abstract modifier is not used with interface methods (it could be—it's just not necessary). &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;An Abstract Class Example&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;First, you declare an abstract class, GraphicObject, to provide member variables and methods that are wholly shared by all subclasses, such as the current position and the moveTo method. GraphicObject also declares abstract methods for methods, such as draw or resize, that need to be implemented by all subclasses but must be implemented in different ways. The GraphicObject class can look something like this: &lt;br /&gt;&lt;br /&gt;abstract class GraphicObject {&lt;br /&gt;    int x, y;&lt;br /&gt;    ...&lt;br /&gt;    void moveTo(int newX, int newY) {&lt;br /&gt;        ...&lt;br /&gt;    }&lt;br /&gt;    abstract void draw();&lt;br /&gt;    abstract void resize();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Each non-abstract subclass of GraphicObject, such as Circle and Rectangle, must provide implementations for the draw and resize methods: &lt;br /&gt;class Circle extends GraphicObject {&lt;br /&gt;    void draw() {&lt;br /&gt;        ...&lt;br /&gt;    }&lt;br /&gt;    void resize() {&lt;br /&gt;        ...&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;class Rectangle extends GraphicObject {&lt;br /&gt;    void draw() {&lt;br /&gt;        ...&lt;br /&gt;    }&lt;br /&gt;    void resize() {&lt;br /&gt;        ...&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Abstract Classes versus Interfaces&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Unlike interfaces, abstract classes can contain fields that are not static and final, and they can contain implemented methods. Such abstract classes are similar to interfaces, except that they provide a partial implementation, leaving it to subclasses to complete the implementation. If an abstract class contains only abstract method declarations, it should be declared as an interface instead. &lt;br /&gt;&lt;br /&gt;Multiple interfaces can be implemented by classes anywhere in the class hierarchy, whether or not they are related to one another in any way. Think of Comparable or Cloneable, for example. &lt;br /&gt;&lt;br /&gt;By comparison, abstract classes are most commonly subclassed to share pieces of implementation. A single abstract class is subclassed by similar classes that have a lot in common (the implemented parts of the abstract class), but also have some differences (the abstract methods). &lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-8526976181161005597?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/8526976181161005597/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/abstract-methods-and-classes.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/8526976181161005597'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/8526976181161005597'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/abstract-methods-and-classes.html' title='Abstract Methods and Classes'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-7279143851317761903</id><published>2009-06-23T17:09:00.001-07:00</published><updated>2009-06-24T14:02:35.072-07:00</updated><title type='text'>Interface Example</title><content type='html'>In its most common form, an interface is a group of related methods with empty bodies. A bicycle's behavior, if specified as an interface, might appear as follows: &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;interface &lt;/strong&gt;Bicycle {&lt;br /&gt;&lt;br /&gt;       void changeCadence(int newValue);&lt;br /&gt;&lt;br /&gt;       void changeGear(int newValue);&lt;br /&gt;&lt;br /&gt;       void speedUp(int increment);&lt;br /&gt;&lt;br /&gt;       void applyBrakes(int decrement);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;To implement this interface, the name of your class would change (to ACMEBicycle, for example), and you'd use the implements keyword in the class declaration: &lt;br /&gt;&lt;br /&gt;class ACMEBicycle &lt;strong&gt;implements &lt;/strong&gt;Bicycle {&lt;br /&gt;&lt;br /&gt;   // remainder of this class implemented as before&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Implementing an interface allows a class to become more formal about the behavior it promises to provide. Interfaces form a contract between the class and the outside world, and this contract is enforced at build time by the compiler. If your class claims to implement an interface, all methods defined by that interface must appear in its source code before the class will successfully compile. &lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-7279143851317761903?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/7279143851317761903/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/interface-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/7279143851317761903'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/7279143851317761903'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/interface-example.html' title='Interface Example'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-8762693614584993616</id><published>2009-06-23T17:05:00.000-07:00</published><updated>2009-06-24T14:02:35.076-07:00</updated><title type='text'>Inheritance Example</title><content type='html'>Inheritance in Java&lt;br /&gt;Inheritance is a compile-time mechanism in Java that allows you to extend a class (called the base class or superclass) with another class (called the derived class or subclass). &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;class inheritance &lt;/strong&gt;- create a new class as an extension of another class, primarily for the purpose of code reuse. That is, the derived class inherits the public methods and public data of the base class. Java only allows a class to have one immediate base class, i.e., single class inheritance.&lt;br /&gt;&lt;br /&gt;For class inheritance, Java uses the keyword &lt;strong&gt;extends &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;public class derived-class-name &lt;strong&gt;extends &lt;/strong&gt; base-class-name {&lt;br /&gt;// derived class methods extend and possibly override&lt;br /&gt;// those of the base class&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-8762693614584993616?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/8762693614584993616/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/inheritance-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/8762693614584993616'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/8762693614584993616'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/inheritance-example.html' title='Inheritance Example'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-5142014808616129603</id><published>2009-06-23T16:57:00.001-07:00</published><updated>2009-06-24T14:02:35.079-07:00</updated><title type='text'>Method overriding</title><content type='html'>In a class hierarchy, when a method in a subclass has the same name and type signature as a method in its superclass, then the method in the subclass is said to override the method in the superclass. When an overridden method is called from within a subclass, it will always refer to the version of that method defined by the subclass. The version of the method defined by the superclass will be hidden. Consider the following: &lt;br /&gt;// Method overriding. &lt;br /&gt;class A { &lt;br /&gt;int i, j; &lt;br /&gt;A(int a, int b) { &lt;br /&gt;i = a; &lt;br /&gt;j = b; &lt;br /&gt;} &lt;br /&gt;// display i and j &lt;br /&gt;void show() { &lt;br /&gt;System.out.println("i and j: " + i + " " + j); &lt;br /&gt;} &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class B extends A { &lt;br /&gt;int k; &lt;br /&gt;B(int a, int b, int c) { &lt;br /&gt;super(a, b); &lt;br /&gt;k = c; &lt;br /&gt;} &lt;br /&gt;// display k – this overrides show() in A &lt;br /&gt;void show() { &lt;br /&gt;System.out.println("k: " + k); &lt;br /&gt;} &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Override { &lt;br /&gt;public static void main(String args[]) { &lt;br /&gt;B subOb = new B(1, 2, 3); &lt;br /&gt;subOb.show(); // this calls show() in B &lt;br /&gt;} &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The output produced by this program is shown here:&lt;br /&gt;&lt;br /&gt;k: 3&lt;br /&gt;&lt;br /&gt;When show( ) is invoked on an object of type B, the version of show( ) defined within B is used. That is, the versio n of show( ) inside B overrides the version declared in A. If you wish to access the superclass version of an overridden function, you can do so by using super. For example, in this version of B, the superclass version of show( ) is invoked within the subclass' version. This allows all instance variables to be displayed.&lt;br /&gt;&lt;br /&gt;class B extends A { &lt;br /&gt;int k; &lt;br /&gt;B(int a, int b, int c) { &lt;br /&gt;super(a, b); &lt;br /&gt;k = c; &lt;br /&gt;} &lt;br /&gt;void show() { &lt;br /&gt;super.show(); // this calls A's show() &lt;br /&gt;System.out.println("k: " + k); &lt;br /&gt;} &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;If you substitute this version of A into the previous program, you will see the following output:&lt;br /&gt;&lt;br /&gt;i and j: 1 2 &lt;br /&gt;k: 3&lt;br /&gt;&lt;br /&gt;Here, super.show( ) calls the superclass version of show( ). Method overriding occurs only when the names and the type signatures of the two methods are identical. &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-5142014808616129603?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/5142014808616129603/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/method-overriding.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/5142014808616129603'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/5142014808616129603'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/method-overriding.html' title='Method overriding'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-3132936416267594330</id><published>2009-06-23T16:48:00.000-07:00</published><updated>2009-06-24T14:02:35.083-07:00</updated><title type='text'>Method overloading</title><content type='html'>In Java it is possible to define two or more methods within the same class that share the same name, as long as their parameter declarations are different. When this is the case, the methods are said to be overloaded, and the process is referred to as method overloading. Method overloading is one of the ways that Java implements polymorphism. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When an overloaded method is invoked, Java uses the type and/or number of arguments as its guide to determine which version of the overloaded method to actually call. Thus, &lt;br /&gt;overloaded methods must differ in the type and/or number of their parameters. While overloaded methods may have different return types, the return type alone is insufficient to distinguish two versions of a method. When Java encounters a call to an overloaded method, it simply executes the version of the method whose parameters match the arguments used in the call. Here is a simple example that illustrates method overloading&lt;br /&gt;&lt;br /&gt;// Demonstrate method overloading. &lt;br /&gt;class OverloadDemo { &lt;br /&gt;void test() { &lt;br /&gt;System.out.println("No parameters"); &lt;br /&gt;} &lt;br /&gt;// Overload test for one integer parameter. &lt;br /&gt;void test(int a) { &lt;br /&gt;System.out.println("a: " + a); &lt;br /&gt;} &lt;br /&gt;// Overload test for two integer parameters. &lt;br /&gt;void test(int a, int b) { &lt;br /&gt;System.out.println("a and b: " + a + " " + b); &lt;br /&gt;} &lt;br /&gt;// overload test for a double parameter &lt;br /&gt;double test(double a) { &lt;br /&gt;System.out.println("double a: " + a); &lt;br /&gt;return a*a; &lt;br /&gt;} &lt;br /&gt;} &lt;br /&gt;class Overload { &lt;br /&gt;public static void main(String args[]) { &lt;br /&gt;OverloadDemo ob = new OverloadDemo(); &lt;br /&gt;double result; &lt;br /&gt;// call all versions of test() &lt;br /&gt;ob.test(); &lt;br /&gt;ob.test(10); &lt;br /&gt;ob.test(10, 20); &lt;br /&gt;result = ob.test(123.2); &lt;br /&gt;System.out.println("Result of ob.test(123.2): " + result); &lt;br /&gt;} &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;This program generates the following output:&lt;br /&gt;&lt;br /&gt;No parameters &lt;br /&gt;a: 10 &lt;br /&gt;a and b: 10 20 &lt;br /&gt;double a: 123.2 &lt;br /&gt;Result of ob.test(123.2): 15178.24&lt;br /&gt;&lt;br /&gt;As you can see, test( ) is overloaded four times. The first version takes no parameters, the second takes one integer parameter, the third takes two integer parameters, and the fourth takes one double parameter. The fact that the fourth version of test( ) also returns a value is of no consequence relative to overloading, since return types do not play a role in overload resolution.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-3132936416267594330?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/3132936416267594330/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/method-overloading.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/3132936416267594330'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/3132936416267594330'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/method-overloading.html' title='Method overloading'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-8637721021568902039</id><published>2009-06-13T19:47:00.000-07:00</published><updated>2009-06-13T19:48:57.912-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Xml'/><title type='text'>Xml Interview Questions</title><content type='html'>&lt;strong&gt;Q)What is XML ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;XML stands for EXtensible Markup Language.&lt;br /&gt;&lt;br /&gt;XML was designed to transport and store data.&lt;br /&gt;&lt;br /&gt;XML documents are universally accepted as a standard way of representing information in platform and language independent manner. &lt;br /&gt;&lt;br /&gt;XML is universal standard for information interchange. &lt;br /&gt;&lt;br /&gt;XML documents can be created in any language and can be used in any language&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q) What is the difference between Schema and DTD?&lt;/strong&gt;&lt;br /&gt;Schema might outphase DTD. XML shemas are in XML. XML Schema has a lot of built-in data types including xs:string,xs:decimal,xs:integer,xs:boolean,xs:date,xs:time. XML schemas can be edited with Schema files, parsed with XML parser, manipulated with XML DOM, and transformed with XSLT.&lt;br /&gt;The building blocks of DTD include elements, attributes, entities, PCDATA, and CDATA.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q) How do you parse/validate the XML document?&lt;/strong&gt;&lt;br /&gt;By using a SAXParser, DOMParser, or XSDValidator.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q) What is XML Namespace?&lt;/strong&gt;&lt;br /&gt;Namespaces are a simple and straightforward way to distinguish names used in XML documents and namespace to avoid confusion involves using a prefix and adding an xmlns attribute to the tag to give the prefix a qualified name associated with the namespace. All child elements with the same prefix are associated with the namespace defined in the start tag of an element.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is a well-formed XML document?&lt;/strong&gt; &lt;br /&gt;If a document is syntactically correct it can be called as well-formed XML documents. A well-formed document conforms to XML's basic rules of syntax: &lt;br /&gt;&lt;br /&gt;Every open tag must be closed. &lt;br /&gt;The open tag must exactly match the closing tag: XML is case-sensitive. &lt;br /&gt;All elements must be embedded within a single root element. &lt;br /&gt;Child tags must be closed before parent tags. &lt;br /&gt;A well-formed document has correct XML tag syntax, but the elements might be invalid for the specified document type. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is a valid XML document?&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;If a document is structurally correct then it can be called as valid XML documents. A valid document conforms to the predefined rules of a specific type of document: &lt;br /&gt;&lt;br /&gt;These rules can be written by the author of the XML document or by someone else. &lt;br /&gt;The rules determine the type of data that each part of a document can contain. &lt;br /&gt;Note:Valid XML document is implicitly well-formed, but well-formed may not be valid&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is a CDATA section in XML?&lt;/strong&gt;&lt;br /&gt;The CDATA section of XML is used to describe the text that should not be parsed by the XML parser.&lt;br /&gt;&lt;br /&gt;Any text that is included in CDATA section is ignored by the parser.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is the difference between SAX parser and DOM parser? &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;DOM&lt;/strong&gt;&lt;br /&gt;DOM spec defines an object-oriented hieararchy.&lt;br /&gt;The DOM parser creates an internal tree based on the hierarchy of the XML data.&lt;br /&gt;Tree stays in memory until released. The DOM parser is more memory intensive. DOM Parser’s advantage is that it is simple. Pairs nicely with XSLT.&lt;br /&gt;-Nice for smaller XML files, but because of the whole XML file&lt;br /&gt;representation is in memory, it is possible not useful for&lt;br /&gt;very large documents&lt;br /&gt;-good for representation of an XML document.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;SAX:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;SAX spec defines an event based approach, calling handler functions whenever certain text nodes or processing instructions are found.&lt;br /&gt;These events include the start and end of the document, finding a text node, finding child elements, and hitting a malformed element. SAX development is more challenging. SAX can parse gigabytes worth of XML without hitting resource barriers. &lt;br /&gt;It’s also faster and more complex. Better for huge XML docs. Best suited for sequential-scan applications.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What's XLink?&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;This specification defines the XML Linking Language (XLink), which allows elements to be inserted into XML documents in order to create and describe links between resources. It uses XML syntax to create structures that can describe links similar to the simple unidirectional hyperlinks of today's HTML, as well as more sophisticated links. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is Xpath?&lt;/strong&gt;&lt;br /&gt;XPath is a language for addressing parts of an XML document, designed to be used by both XSLT and XPointer.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q) What is XSL?&lt;/strong&gt;&lt;br /&gt;In addition to XSLT, XSL includes an XML vocabulary for specifying formatting. XSL specifies the styling of an XML document by using XSLT to describe how the document is transformed into another XML document that uses the formatting vocabulary.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q) What is XSLT?&lt;/strong&gt;&lt;br /&gt;A language for transforming XML documents into other XML documents. XSLT is designed for use as part of XSL, which is a stylesheet language for XML.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is JAXP ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The Java API for XML Processing (JAXP) is for processing XML data using applications written in the Java programming language. JAXP leverages the parser standards Simple API for XML Parsing (SAX) and Document Object Model (DOM) so that you can choose to parse your data as a stream of events or to build an object representation of it. JAXP also supports the Extensible Stylesheet Language Transformations (XSLT) standard, giving you control over the presentation of the data and enabling you to convert the data to other XML documents or to other formats, such as HTML. JAXP also provides namespace support, allowing you to work with DTDs that might otherwise have naming conflicts.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-8637721021568902039?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/8637721021568902039/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/xml-interview-questions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/8637721021568902039'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/8637721021568902039'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/xml-interview-questions.html' title='Xml Interview Questions'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-1211809056757103398</id><published>2009-06-13T19:32:00.001-07:00</published><updated>2009-06-13T19:37:13.086-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JMS'/><title type='text'>JMS</title><content type='html'>&lt;strong&gt;Q: What is JMS?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A: Java Message Service: An interface implemented by most J2EE containers to provide point-to-point queueing and topic (publish/subscribe) behavior. JMS is frequently used by EJB's that need to start another process asynchronously.&lt;br /&gt;&lt;br /&gt;For example, instead of sending an email directly from an Enterprise&lt;br /&gt;JavaBean, the bean may choose to put the message onto a JMS queue to be handled by a Message-Driven Bean (another type of EJB) or another&lt;br /&gt;system in the enterprise. This technique allows the EJB to return to&lt;br /&gt;handling requests immediately instead of waiting for a potentially&lt;br /&gt;lengthy process to complete.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What are major JMS products available in the market? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A: IBM's MQ Series, SonicMQ, iBus etc.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q:What are the advantages of JMS?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A: You can use it in the context of mutithreading but it means JMS is not meant for Multithreading. Its basically meant for object communication. &lt;br /&gt;&lt;br /&gt;It will be useful when you are writing some event based applications&lt;br /&gt;like Chat Server which needs a publish kind of event mechanism to send&lt;br /&gt;messages between the server to the clients who got connected with the server. Moreover JMS gives Loosely-coupled kind of mechanism when compared with&lt;br /&gt;RMI which is tightly-coupled. In JMS there is no need for the destination object to be available online while sending a message from&lt;br /&gt;the client to the server. But in RMI it is necessary. So we can use JMS&lt;br /&gt;in place of RMI where we need to have loosely-coupled mechanism.  &lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What are the different types of messages available in the JMS API? &lt;/strong&gt;&lt;br /&gt; &lt;br /&gt;A: Message, TextMessage, BytesMessage, StreamMessage, ObjectMessage, MapMessage are the different messages available in the JMS API.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What are the different messaging paradigms JMS supports?&lt;/strong&gt;&lt;br /&gt; &lt;br /&gt;A: Publish and Subscribe i.e. pub/suc and Point to Point i.e. p2p. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What are the various message types supported by JMS? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A: Stream Messages -- Group of Java Primitives&lt;br /&gt;Map Messages -- Name Value Pairs. Name being a string&amp;amp; Value being a java primitive &lt;br /&gt;Text Messages -- String messages (since being widely used a separate&lt;br /&gt;messaging Type has been supported) &lt;br /&gt;Object Messages -- Group of serialize able java object &lt;br /&gt;Bytes Message -- Stream of uninterrupted bytes&amp;nbsp; &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What are the types of messaging? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A: There are two kinds of Messaging.&lt;br /&gt;&lt;strong&gt;Synchronous Messaging:&lt;/strong&gt; Synchronous messaging involves a client that&lt;br /&gt;waits for the server to respond to a message.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Asynchronous Messaging: &lt;/strong&gt;Asynchronous messaging involves a client that does not wait for a message from the server. An event is used to trigger a message from a server.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What are the three components of a Message ? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A: A JMS message consists of three parts:&lt;br /&gt;&lt;strong&gt;Message header&lt;/strong&gt; &lt;br /&gt;For message identification. For example, the header is used to&lt;br /&gt;determine if a given message is appropriate for a "subscriber" &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Properties&lt;/strong&gt; &lt;br /&gt;For application-specific, provider-specific, and optional header fields&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Body &lt;/strong&gt;&lt;br /&gt;Holds the content of the message. Several formats are supported,&lt;br /&gt;including TextMessage, which wrap a simple String, that wrap arbitrary&lt;br /&gt;Java objects (which must be serializable). Other formats are supported&lt;br /&gt;as well. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What kind of information found in the header of a Message ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A: The header of a message contains message identification and routing information. This includes , but is not limited to :&lt;br /&gt;&lt;br /&gt;JMSDestination&lt;br /&gt;JMSDeliveryMode&lt;br /&gt;JMSMessageID&lt;br /&gt;JMSTimeStamp&lt;br /&gt;JMSExpiration&lt;br /&gt;JMSReplyTO&lt;br /&gt;JMSCorrelationID&lt;br /&gt;JMSType&lt;br /&gt;JMSRedelivered &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What is the basic difference between Publish Subscribe model and P2P model?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A: Publish Subscribe model is typically used in one-to-many situation. It is unreliable but very fast. P2P model is used in one-to-one situation. It is highly reliable.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What is the difference between BytesMessage and StreamMessage?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A: BytesMessage stores the primitive data types by converting them to their byte representation.&lt;br /&gt;Thus the message is one contiguous stream of bytes. While the&lt;br /&gt;StreamMessage maintains a boundary between the different data types&lt;br /&gt;stored because it also stores the type information along with the value&lt;br /&gt;of the primitive being stored. BytesMessage allows data to be read&lt;br /&gt;using any type. Thus even if your payload contains a long value, you&lt;br /&gt;can invoke a method to read a short and it will return you something.&lt;br /&gt;It will not give you a semantically correct data but the call will&lt;br /&gt;succeed in reading the first two bytes of data. This is strictly&lt;br /&gt;prohibited in the StreamMessage. It maintains the type information of&lt;br /&gt;the data being stored and enforces strict conversion rules on the data&lt;br /&gt;being read. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What is point-to-point messaging?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A: What are the core JMS-related objects required for each JMS-enabled&lt;br /&gt;application? &lt;br /&gt;&lt;br /&gt;Each JMS-enabled client must&lt;br /&gt;establish the following:&lt;br /&gt;• A connection object provided by the JMS server (the message broker) &lt;br /&gt;• Within a connection, one or more sessions, which provide a context&lt;br /&gt;for message sending and receiving &lt;br /&gt;• Within a session, either a queue or ic object representing the&lt;br /&gt;destination (the message staging area) within the message broker &lt;br /&gt;• Within a session, the appropriate sender or publisher or receiver or&lt;br /&gt;subscriber object (depending on whether the client is a message&lt;br /&gt;producer or consumer and uses a point-to-point or publish/subscribe&lt;br /&gt;strategy, respectively) &lt;br /&gt;Within a session, a message object (to send or to receive) &lt;br /&gt;     &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What is the difference between ic and queue?&lt;/strong&gt;&lt;br /&gt; &lt;br /&gt;A: A ic is typically used for one to many messaging i.e. it supports publish subscribe model of messaging. While queue is used for one-to-one messaging i.e. it supports Point to Point Messaging. &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Q)What are the core JMS-related objects required for each JMS-enabled application? &lt;/strong&gt;&lt;br /&gt; &lt;br /&gt;A: : Each JMS-enabled client must establish the following:&lt;br /&gt;• A connection object provided by the JMS server (the message broker) &lt;br /&gt;• Within a connection, one or more sessions, which provide a context for message sending and receiving &lt;br /&gt;• Within a session, either a queue or topic object representing the destination (the message staging area) within the message broker &lt;br /&gt;• Within a session, the appropriate sender or publisher or receiver or subscriber object (depending on whether the client is a message producer or consumer and uses a point-to-point or publish/subscribe strategy, respectively) &lt;br /&gt;Within a session, a message object (to send or to receive)  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q : What is the use of Message object?&lt;/strong&gt;&lt;br /&gt; &lt;br /&gt;A: Message is a light weight message having only header and properties and no payload. Thus if theIf the receivers are to be notified abt an event, and no data needs to be exchanged then using Message can be very efficient. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What is the use of BytesMessage?&lt;/strong&gt;&lt;br /&gt; &lt;br /&gt;A: BytesMessage contains an array of primitive bytes in it's payload. Thus it can be used for transfer of data between two applications in their native format which may not be compatible with other Message types. It is also useful where JMS is used purely as a transport between two systems and the message payload is opaque to the JMS client. Whenever you store any primitive type, it is converted into it's byte representation and then stored in the payload. There is no boundary line between the different data types stored. Thus you can even read a long as short. This would result in erroneous data and hence it is advisable that the payload be read in the same order and using the same type in which it was created by the sender.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What is the use of StreamMessage?&lt;/strong&gt;&lt;br /&gt; &lt;br /&gt;A: StreamMessage carries a stream of Java primitive types as it's payload. It contains some conveient methods for reading the data stored in the payload. However StreamMessage prevents reading a long value as short, something that is allwed in case of BytesMessage. This is so because the StreamMessage also writes the type information alonwgith the value of the primitive type and enforces a set of strict conversion rules which actually prevents reading of one primitive type as another. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What is the use of TextMessage?&lt;/strong&gt;&lt;br /&gt; &lt;br /&gt;A: TextMessage contains instance of java.lang.String as it's payload. Thus it is very useful for exchanging textual data. It can also be used for exchanging complex character data such as an XML document. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What is the use of ObjectMessage?&lt;/strong&gt;&lt;br /&gt; &lt;br /&gt;A: ObjectMessage contains a Serializable java object as it's payload. Thus it allows exchange of Java objects between applications. This in itself mandates that both the applications be Java applications. The consumer of the message must typecast the object received to it's appropriate type. Thus the consumer should before hand know the actual type of the object sent by the sender. Wrong type casting would result in ClassCastException. Moreover the class definition of the object set in the payload should be available on both the machine, the sender as well as the consumer. If the class definition is not available in the consumer machine, an attempt to type cast would result in ClassNotFoundException. Some of the MOMs might support dynamic loading of the desired class over the network, but the JMS specification does not mandate this behavior and would be a value added service if provided by your vendor. And relying on any such vendor specific functionality would hamper the portability of your application. Most of the time the class need to be put in the classpath of both, the sender and the consumer, manually by the developer.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What is the use of MapMessage?&lt;/strong&gt;&lt;br /&gt; &lt;br /&gt;A: A MapMessage carries name-value pair as it's payload. Thus it's payload is similar to the java.util.Properties object of Java. The values can be Java primitives or their wrappers. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What is MDB and What is the special feature of that? &lt;/strong&gt;&lt;br /&gt; &lt;br /&gt;A: MDB is Message driven bean, which very much resembles the Stateless session bean. The incoming and out going messages can be handled by the Message driven bean. The ability to communicate asynchronously is the special feature about the Message driven bean.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-1211809056757103398?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/1211809056757103398/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/jms.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/1211809056757103398'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/1211809056757103398'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/jms.html' title='JMS'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-209000822461052233</id><published>2009-06-13T17:39:00.001-07:00</published><updated>2009-06-13T19:27:37.320-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JUnit'/><title type='text'>JUnit</title><content type='html'>&lt;strong&gt;1)What is JUnit? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;JUnit is a simple, open source framework to write and run repeatable tests. It is an instance of the xUnit architecture for unit testing frameworks. JUnit features include: &lt;br /&gt;&lt;br /&gt;Assertions for testing expected results &lt;br /&gt;Test fixtures for sharing common test data &lt;br /&gt;Test runners for running tests &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;2)How do I write and run a simple test?&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;Create a class: &lt;br /&gt;       &lt;br /&gt;  package junitfaq;&lt;br /&gt;       &lt;br /&gt;  import org.junit.*;&lt;br /&gt;  import static org.junit.Assert.*;&lt;br /&gt;&lt;br /&gt;  import java.util.*;&lt;br /&gt;  &lt;br /&gt;  public class SimpleTest {&lt;br /&gt;Write a test method (annotated with @Test) that asserts expected results on the object under test: &lt;br /&gt;&lt;br /&gt;    @Test&lt;br /&gt;    public void testEmptyCollection() {&lt;br /&gt;        Collection collection = new ArrayList();&lt;br /&gt;        assertTrue(collection.isEmpty());&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;If you are running your JUnit 4 tests with a JUnit 3.x runner, write a suite() method that uses the JUnit4TestAdapter class to create a suite containing all of your test methods: &lt;br /&gt;&lt;br /&gt;    public static junit.framework.Test suite() {&lt;br /&gt;        return new junit.framework.JUnit4TestAdapter(SimpleTest.class);&lt;br /&gt;    }&lt;br /&gt;   Although writing a main() method to run the test is much less important with the advent of IDE runners, it's still possible:&lt;br /&gt;&lt;br /&gt;    public static void main(String args[]) {&lt;br /&gt;      org.junit.runner.JUnitCore.main("junitfaq.SimpleTest");&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;   Run the test: &lt;br /&gt;&lt;br /&gt;To run the test from the console, type: &lt;br /&gt;&lt;br /&gt;java org.junit.runner.JUnitCore junitfaq.SimpleTest &lt;br /&gt;To run the test with the test runner used in main(), type: &lt;br /&gt;&lt;br /&gt;java junitfaq.SimpleTest &lt;br /&gt;The passing test results in the following textual output: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  .&lt;br /&gt;Time: 0&lt;br /&gt;&lt;br /&gt;OK (1 tests)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;3)What CLASSPATH settings are needed to run JUnit? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;(Submitted by: Eric Armstrong) &lt;br /&gt;&lt;br /&gt;To run your JUnit tests, you'll need the following elemements in your CLASSPATH: &lt;br /&gt;&lt;br /&gt;JUnit class files &lt;br /&gt;Your class files, including your JUnit test classes &lt;br /&gt;Libraries your class files depend on &lt;br /&gt;If attempting to run your tests results in a NoClassDefFoundError, then something is missing from your CLASSPATH. &lt;br /&gt;&lt;br /&gt;Windows Example: &lt;br /&gt;&lt;br /&gt;set CLASSPATH=%JUNIT_HOME%\junit.jar;c:\myproject\classes;c:\myproject\lib\something.jar &lt;br /&gt;&lt;br /&gt;Unix (bash) Example: &lt;br /&gt;&lt;br /&gt;export CLASSPATH=$JUNIT_HOME/junit.jar:/myproject/classes:/myproject/lib/something.jar &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;4)Why not just use System.out.println()? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Inserting debug statements into code is a low-tech method for debugging it. It usually requires that output be scanned manually every time the program is run to ensure that the code is doing what's expected. &lt;br /&gt;&lt;br /&gt;It generally takes less time in the long run to codify expectations in the form of an automated JUnit test that retains its value over time. If it's difficult to write a test to assert expectations, the tests may be telling you that shorter and more cohesive methods would improve your design. &lt;br /&gt;&lt;br /&gt;        &lt;br /&gt;&lt;strong&gt;5)How do I test a method that doesn't return anything? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Often if a method doesn't return a value, it will have some side effect. Actually, if it doesn't return a value AND doesn't have a side effect, it isn't doing anything. &lt;br /&gt;&lt;br /&gt;There may be a way to verify that the side effect actually occurred as expected. For example, consider the add() method in the Collection classes. There are ways of verifying that the side effect happened (i.e. the object was added). You can check the size and assert that it is what is expected: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    @Test&lt;br /&gt;    public void testCollectionAdd() {&lt;br /&gt;        Collection collection = new ArrayList();&lt;br /&gt;        assertEquals(0, collection.size());&lt;br /&gt;        collection.add("itemA");&lt;br /&gt;        assertEquals(1, collection.size());&lt;br /&gt;        collection.add("itemB");&lt;br /&gt;        assertEquals(2, collection.size());&lt;br /&gt;    }&lt;br /&gt;      Another approach is to make use of MockObjects. &lt;br /&gt;&lt;br /&gt;A related issue is to design for testing. For example, if you have a method that is meant to output to a file, don't pass in a filename, or even a FileWriter. Instead, pass in a Writer. That way you can pass in a StringWriter to capture the output for testing purposes. Then you can add a method (e.g. writeToFileNamed(String filename)) to encapsulate the FileWriter creation.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt; 6)How do I test protected methods? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Place your tests in the same package as the classes under test.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;7)How do I test private methods? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Testing private methods may be an indication that those methods should be moved into another class to promote reusability. &lt;br /&gt;&lt;br /&gt;But if you must... &lt;br /&gt;&lt;br /&gt;If you are using JDK 1.3 or higher, you can use reflection to subvert the access control mechanism with the aid of the PrivilegedAccessor.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;8) Under what conditions should I test get() and set() methods? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Unit tests are intended to alleviate fear that something might break. If you think a get() or set() method could reasonably break, or has in fact contributed to a defect, then by all means write a test. &lt;br /&gt;&lt;br /&gt;In short, test until you're confident. What you choose to test is subjective, based on your experiences and confidence level. Remember to be practical and maximize your testing investment. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;9)Under what conditions should I not test get() and set() methods? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Most of the time, get/set methods just can't break, and if they can't break, then why test them? While it is usually better to test more, there is a definite curve of diminishing returns on test effort versus "code coverage". Remember the maxim: "Test until fear turns to boredom." &lt;br /&gt;&lt;br /&gt;Assume that the getX() method only does "return x;" and that the setX() method only does "this.x = x;". If you write this test: &lt;br /&gt;&lt;br /&gt;@Test&lt;br /&gt;public void testGetSetX() {&lt;br /&gt;    setX(23);&lt;br /&gt;    assertEquals(23, getX());&lt;br /&gt;}&lt;br /&gt;      then you are testing the equivalent of the following: &lt;br /&gt;&lt;br /&gt;@Test&lt;br /&gt;public void testGetSetX() {&lt;br /&gt;    x = 23;&lt;br /&gt;    assertEquals(23, x);&lt;br /&gt;}&lt;br /&gt;or, if you prefer, &lt;br /&gt;&lt;br /&gt;@Test&lt;br /&gt;public void testGetSetX() {&lt;br /&gt;    assertEquals(23, 23);&lt;br /&gt;}&lt;br /&gt;At this point, you are testing the Java compiler, or possibly the interpreter, and not your component or application. There is generally no need for you to do Java's testing for them. &lt;br /&gt;&lt;br /&gt;If you are concerned about whether a property has already been set at the point you wish to call getX(), then you want to test the constructor, and not the getX() method. This kind of test is especially useful if you have multiple constructors: &lt;br /&gt;&lt;br /&gt;@Test&lt;br /&gt;public void testCreate() {&lt;br /&gt;    assertEquals(23, new MyClass(23).getX());&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;10)How do I write a test that passes when an expected exception is thrown? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Add the optional expected attribute to the @Test annotation. The following is an example test that passes when the expected IndexOutOfBoundsException is raised: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    @Test(expected=IndexOutOfBoundsException.class)&lt;br /&gt;    public void testIndexOutOfBoundsException() {&lt;br /&gt;        ArrayList emptyList = new ArrayList();&lt;br /&gt; Object o = emptyList.get(0);&lt;br /&gt;    }&lt;br /&gt;     &lt;br /&gt;&lt;strong&gt;11) How do I write a test that fails when an unexpected exception is thrown? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Declare the exception in the throws clause of the test method and don't catch the exception within the test method. Uncaught exceptions will cause the test to fail with an error. &lt;br /&gt;&lt;br /&gt;The following is an example test that fails when the IndexOutOfBoundsException is raised: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    @Test&lt;br /&gt;    public void testIndexOutOfBoundsExceptionNotRaised() &lt;br /&gt;        throws IndexOutOfBoundsException {&lt;br /&gt;    &lt;br /&gt;        ArrayList emptyList = new ArrayList();&lt;br /&gt;        Object o = emptyList.get(0);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;12)Why does JUnit only report the first failure in a single test? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Reporting multiple failures in a single test is generally a sign that the test does too much, compared to what a unit test ought to do. Usually this means either that the test is really a functional/acceptance/customer test or, if it is a unit test, then it is too big a unit test. &lt;br /&gt;&lt;br /&gt;JUnit is designed to work best with a number of small tests. It executes each test within a separate instance of the test class. It reports failure on each test. Shared setup code is most natural when sharing between tests. This is a design decision that permeates JUnit, and when you decide to report multiple failures per test, you begin to fight against JUnit. This is not recommended. &lt;br /&gt;&lt;br /&gt;Long tests are a design smell and indicate the likelihood of a design problem. Kent Beck is fond of saying in this case that "there is an opportunity to learn something about your design." We would like to see a pattern language develop around these problems, but it has not yet been written down. &lt;br /&gt;&lt;br /&gt;Finally, note that a single test with multiple assertions is isomorphic to a test case with multiple tests: &lt;br /&gt;&lt;br /&gt;One test method, three assertions: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class MyTestCase {&lt;br /&gt;    @Test&lt;br /&gt;    public void testSomething() {&lt;br /&gt;        // Set up for the test, manipulating local variables&lt;br /&gt;        assertTrue(condition1);&lt;br /&gt;        assertTrue(condition2);&lt;br /&gt;        assertTrue(condition3);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;      Three test methods, one assertion each: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class MyTestCase {&lt;br /&gt;    // Local variables become instance variables&lt;br /&gt;&lt;br /&gt;    @Before&lt;br /&gt;    public void setUp() {&lt;br /&gt;        // Set up for the test, manipulating instance variables&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    @Test&lt;br /&gt;    public void testCondition1() {&lt;br /&gt;        assertTrue(condition1);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    @Test&lt;br /&gt;    public void testCondition2() {&lt;br /&gt;        assertTrue(condition2);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    @Test&lt;br /&gt;    public void testCondition3() {&lt;br /&gt;        assertTrue(condition3);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;      The resulting tests use JUnit's natural execution and reporting mechanism and, failure in one test does not affect the execution of the other tests. You generally want exactly one test to fail for any given bug, if you can manage it. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;13) Do I need to write a test class for every class I need to test? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;No. It is a convention to start with one test class per class under test, but it is not necessary. &lt;br /&gt;&lt;br /&gt;Test classes only provide a way to organize tests, nothing more. Generally you will start with one test class per class under test, but then you may find that a small group of tests belong together with their own common test fixture.[1] In this case, you may move those tests to a new test class. This is a simple object-oriented refactoring: separating responsibilities of an object that does too much. &lt;br /&gt;&lt;br /&gt;Another point to consider is that the TestSuite is the smallest execution unit in JUnit: you cannot execute anything smaller than a TestSuite at one time without changing source code. In this case, you probably do not want to put tests in the same test class unless they somehow "belong together". If you have two groups of tests that you think you'd like to execute separately from one another, it is wise to place them in separate test classes. &lt;br /&gt;&lt;br /&gt;[1] A test fixture is a common set of test data and collaborating objects shared by many tests. Generally they are implemented as instance variables in the test class. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;14) In Java 1.4, assert is a keyword. Won't this conflict with JUnit's assert() method? &lt;/strong&gt;&lt;br /&gt;JUnit 3.7 deprecated assert() and replaced it with assertTrue(), which works exactly the same way. &lt;br /&gt;&lt;br /&gt;JUnit 4 is compatible with the assert keyword. If you run with the -ea JVM switch, assertions that fail will be reported by JUnit. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;15) How do I test things that must be run in a J2EE container (e.g. servlets, EJBs)? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Refactoring J2EE components to delegate functionality to other objects that don't have to be run in a J2EE container will improve the design and testability of the software. &lt;br /&gt;&lt;br /&gt;Cactus is an open source JUnit extension that can be used to test J2EE components in their natural environment. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;16)Is there a basic template I can use to create a test? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The following templates are a good starting point. Copy/paste and edit these templates to suit your coding style. &lt;br /&gt;&lt;br /&gt;SampleTest is a basic test template: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import org.junit.*;&lt;br /&gt;import static org.junit.Assert.*;&lt;br /&gt;&lt;br /&gt;public class SampleTest {&lt;br /&gt;&lt;br /&gt;    private java.util.List emptyList;&lt;br /&gt;&lt;br /&gt;    /**&lt;br /&gt;     * Sets up the test fixture. &lt;br /&gt;     * (Called before every test case method.)&lt;br /&gt;     */&lt;br /&gt;    @Before&lt;br /&gt;    public void setUp() {&lt;br /&gt;        emptyList = new java.util.ArrayList();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /**&lt;br /&gt;     * Tears down the test fixture. &lt;br /&gt;     * (Called after every test case method.)&lt;br /&gt;     */&lt;br /&gt;    @After&lt;br /&gt;    public void tearDown() {&lt;br /&gt;        emptyList = null;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    @Test&lt;br /&gt;    public void testSomeBehavior() {&lt;br /&gt;        assertEquals("Empty list should have 0 elements", 0, emptyList.size());&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    @Test(expected=IndexOutOfBoundsException.class)&lt;br /&gt;    public void testForException() {&lt;br /&gt;        Object o = emptyList.get(0);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;17)How do I write a test for an abstract class? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Refer to http://c2.com/cgi/wiki?AbstractTestCases. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;18)When are tests garbage collected? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;By design, the tree of Test instances is built in one pass, then the tests are executed in a second pass. The test runner holds strong references to all Test instances for the duration of the test execution. This means that for a very long test run with many Test instances, none of the tests may be garbage collected until the end of the entire test run. &lt;br /&gt;&lt;br /&gt;Therefore, if you allocate external or limited resources in a test, you are responsible for freeing those resources. Explicitly setting an object to null in the tearDown() method, for example, allows it to be garbage collected before the end of the entire test run. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;19)How can I run setUp() and tearDown() code once for all of my tests? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The desire to do this is usually a symptom of excessive coupling in your design. If two or more tests must share the same test fixture state, then the tests may be trying to tell you that the classes under test have some undesirable dependencies. &lt;br /&gt;&lt;br /&gt;Refactoring the design to further decouple the classes under test and eliminate code duplication is usually a better investment than setting up a shared test fixture. &lt;br /&gt;&lt;br /&gt;But if you must... &lt;br /&gt;&lt;br /&gt;You can add a @BeforeClass annotation to a method to be run before all the tests in a class, and a @AfterClass annotation to a method to be run after all the tests in a class. Here's an example: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    package junitfaq;&lt;br /&gt;&lt;br /&gt;    import org.junit.*;&lt;br /&gt;    import static org.junit.Assert.*;&lt;br /&gt;    import java.util.*;&lt;br /&gt;    &lt;br /&gt;    public class SimpleTest {&lt;br /&gt;    &lt;br /&gt;        private Collection collection;&lt;br /&gt; &lt;br /&gt;        @BeforeClass&lt;br /&gt;        public static void oneTimeSetUp() {&lt;br /&gt;            // one-time initialization code        &lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        @AfterClass&lt;br /&gt;        public static void oneTimeTearDown() {&lt;br /&gt;            // one-time cleanup code&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        @Before&lt;br /&gt;        public void setUp() {&lt;br /&gt;            collection = new ArrayList();&lt;br /&gt;        }&lt;br /&gt; &lt;br /&gt;        @After&lt;br /&gt;        public void tearDown() {&lt;br /&gt;            collection.clear();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        @Test&lt;br /&gt;        public void testEmptyCollection() {&lt;br /&gt;            assertTrue(collection.isEmpty());&lt;br /&gt;        }&lt;br /&gt; &lt;br /&gt;        @Test&lt;br /&gt;        public void testOneItemCollection() {&lt;br /&gt;            collection.add("itemA");&lt;br /&gt;            assertEquals(1, collection.size());&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;      Given this test, the methods will execute in the following order: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;oneTimeSetUp()&lt;br /&gt;setUp()&lt;br /&gt;testEmptyCollection()&lt;br /&gt;tearDown()&lt;br /&gt;setUp()&lt;br /&gt;testOneItemCollection()&lt;br /&gt;tearDown()&lt;br /&gt;oneTimeTearDown()&lt;br /&gt; Running Tests &lt;br /&gt;&lt;strong&gt;20)What CLASSPATH settings are needed to run JUnit? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;To run your JUnit tests, you'll need the following elemements in your CLASSPATH: &lt;br /&gt;&lt;br /&gt;JUnit class files &lt;br /&gt;Your class files, including your JUnit test classes &lt;br /&gt;Libraries your class files depend on &lt;br /&gt;If attempting to run your tests results in a NoClassDefFoundError, then something is missing from your CLASSPATH. &lt;br /&gt;&lt;br /&gt;Windows Example: &lt;br /&gt;&lt;br /&gt;set CLASSPATH=%JUNIT_HOME%\junit.jar;c:\myproject\classes;c:\myproject\lib\something.jar &lt;br /&gt;&lt;br /&gt;Unix (bash) Example: &lt;br /&gt;&lt;br /&gt;export CLASSPATH=$JUNIT_HOME/junit.jar:/myproject/classes:/myproject/lib/something.jar &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;21)How do I run JUnit from my command window? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Set your CLASSPATH &lt;br /&gt;&lt;br /&gt;Invoke the runner: &lt;br /&gt;&lt;br /&gt;java org.junit.runner.JUnitCore (test class name)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;22)How do I pass command-line arguments to a test execution? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Use the -D JVM command-line options, as in: &lt;br /&gt;&lt;br /&gt;-DparameterName=parameterValue &lt;br /&gt;If the number of parameters on the command line gets unweildy, pass in the location of a property file that defines a set of parameters. Alternatively, the JUnit-addons package contains the XMLPropertyManager and PropertyManager classes that allow you to define a property file (or XML file) containing test parameters. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;23)Why do I get the warning "AssertionFailedError: No tests found in XXX" when I run my test? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Make sure you have more or more method annotated with @Test. &lt;br /&gt;&lt;br /&gt;For example: &lt;br /&gt;&lt;br /&gt;@Test&lt;br /&gt;public void testSomething() {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;24)Why do I get a NoClassDefFoundError when trying to test JUnit or run the samples? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Most likely your CLASSPATH doesn't include the JUnit installation directory. &lt;br /&gt;&lt;br /&gt;Refer to "What CLASSPATH settings are needed to run JUnit?" for more guidance. &lt;br /&gt;&lt;br /&gt;Also consider running WhichJunit to print the absolute location of the JUnit class files required to run and test JUnit and its samples.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-209000822461052233?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/209000822461052233/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/junit_13.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/209000822461052233'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/209000822461052233'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/06/junit_13.html' title='JUnit'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-7778358583702321770</id><published>2009-01-18T09:53:00.001-08:00</published><updated>2009-06-13T19:39:12.829-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Unix Commands'/><title type='text'>Unix Commands</title><content type='html'>mkdir .............. make a directory&lt;br /&gt;rmdir .............. remove directory (rm -r to delete folders with files)&lt;br /&gt;rm ................. remove files&lt;br /&gt;cd ................. change current directory&lt;br /&gt;ls ................. show directory, in alphabetical order&lt;br /&gt;logout ............. logs off system&lt;br /&gt;talk (user) ........ pages user for chat - (user) is a email address&lt;br /&gt;write (user) ....... write a user on the local system (control-c to end)&lt;br /&gt;man (command) ...... shows help on a specific command&lt;br /&gt;&lt;br /&gt;pico (filename) .... easy to use text editor to edit files&lt;br /&gt;pine ............... easy to use mailer&lt;br /&gt;more (file) ........ views a file, pausing every screenful&lt;br /&gt;&lt;br /&gt;grep ............... search for a string in a file&lt;br /&gt;tail ............... show the last few lines of a file&lt;br /&gt;who ................ shows who is logged into the local system&lt;br /&gt;w .................. shows who is logged on and what they're doing&lt;br /&gt;finger (emailaddr).. shows more information about a user&lt;br /&gt;df ................. shows disk space available on the system&lt;br /&gt;du ................. shows how much disk space is being used up by folders&lt;br /&gt;chmod .............. changes permissions on a file&lt;br /&gt;bc ................. a simple calculator&lt;br /&gt;&lt;br /&gt;passwd ............. change your password&lt;br /&gt;chfn ............... change your "Real Name" as seen on finger&lt;br /&gt;chsh ............... change the shell you log into&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;sz ................. send a file (to you) using zmodem&lt;br /&gt;rz ................. recieve a file (to the unix system) using zmodem&lt;br /&gt;&lt;br /&gt;ftp (host) ......... connects to a FTP site&lt;br /&gt;telnet (host) ...... connect to another Internet site&lt;br /&gt;archie (filename) .. search the Archie database for a file on a FTP site&lt;br /&gt;irc ................ connect to Internet Relay Chat&lt;br /&gt;lynx ............... a textual World Wide Web browser&lt;br /&gt;gopher ............. a Gopher database browser&lt;br /&gt;tin, trn ........... read Usenet newsgroups&lt;br /&gt;&lt;br /&gt;gzip ............... best compression for UNIX files&lt;br /&gt;zip ................ zip for IBM files&lt;br /&gt;tar ................ combines multiple files into one or vice-versa&lt;br /&gt;lharc, lzh, lha .... un-arc'ers, may not be on your system&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;make ............... compiles source code&lt;br /&gt;gcc (file.c) ....... compiles C source into a file named 'a.out'&lt;br /&gt;&lt;br /&gt;unix2dos (file) (new) - adds CR's to unix text files&lt;br /&gt;dos2unix (file) (new) - strips CR's out of dos text files&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-7778358583702321770?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/7778358583702321770/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/01/unix-commands.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/7778358583702321770'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/7778358583702321770'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/01/unix-commands.html' title='Unix Commands'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-2340117983142907949</id><published>2009-01-17T16:11:00.001-08:00</published><updated>2009-01-17T19:34:59.654-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Jdbc'/><title type='text'>Jdbc Interview Questions</title><content type='html'>&lt;strong&gt;Q.What is the Java Database Connectivity (JDBC) ? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Java Database Connectivity (JDBC) is a standard Java API to interact with relational databases form Java. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What are types of JDBC drivers?&lt;/strong&gt;&lt;br /&gt; &lt;br /&gt;There are four types of drivers defined by JDBC as follows: &lt;br /&gt;&lt;br /&gt;Type 1: JDBC/ODBC—These require an ODBC (Open Database Connectivity) driver for the database to be installed. This type of driver works by translating the submitted queries into equivalent ODBC queries and forwards them via native API calls directly to the ODBC driver. It provides no host redirection capability.&lt;br /&gt;&lt;br /&gt;Type2: Native API (partly-Java driver)—This type of driver uses a vendor-specific driver or database API to interact with the database. An example of such an API is Oracle OCI (Oracle Call Interface). It also provides no host redirection.&lt;br /&gt;&lt;br /&gt;Type 3: Open Protocol-Net—This is not vendor specific and works by forwarding database requests to a remote database source using a net server component. How the net server component accesses the database is transparent to the client. The client driver communicates with the net server using a database-independent protocol and the net server translates this protocol into database calls. This type of driver can access any database.&lt;br /&gt;&lt;br /&gt;Type 4: Proprietary Protocol-Net(pure Java driver)—This has a same configuration as a type 3 driver but uses a wire protocol specific to a particular vendor and hence can access only that vendor's database. Again this is all transparent to the client. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)Which type of JDBC driver is the fastest one?&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;JDBC Net pure Java driver(Type IV) is the fastest driver because it converts the JDBC calls into vendor specific protocol calls and it directly interacts with the database.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)Explain Basic Steps in a JDBC Programming? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Load the RDBMS specific JDBC driver because this driver actually communicates with the database (Incase of JDBC 4.0 this is automatically loaded). &lt;br /&gt;Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");&lt;br /&gt;&lt;br /&gt;Open the connection to database which is then used to send SQL statements and get results back. &lt;br /&gt;Connection con = DriverManager.getConnection( "jdbc:odbc:SSPer","Tiger","tictac");&lt;br /&gt;&lt;br /&gt;Create JDBC Statement object. This object contains SQL query.&lt;br /&gt;&lt;br /&gt;PreparedStatement ps = conn.prepareStatement(&lt;br /&gt;      "select * from Dept where deptid=? and dept=?");&lt;br /&gt;    ps.setString(1,deptid);&lt;br /&gt;    ps.setString(2,dept); &lt;br /&gt;&lt;br /&gt;Execute PreparedStatement which returns resultset(s). ResultSet contains the tuples of database table as a result of SQL query. &lt;br /&gt;&lt;br /&gt;ResultSet rs =  ps.executeQuery();&lt;br /&gt;&lt;br /&gt;Process the result set. &lt;br /&gt;while (rs.next()) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//Close the connection. &lt;br /&gt;con.close();&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What will Class.forName do while loading drivers? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;It is used to create an instance of a driver and register it with the&lt;br /&gt;DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is PreparedStatement? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A prepared statement is an SQL statement that is precompiled by the database. Through precompilation, prepared statements improve the performance of SQL commands that are executed multiple times (given that the database supports prepared statements). Once compiled, prepared statements can be customized prior to each execution by altering predefined SQL parameters. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PreparedStatement pstmt = conn.prepareStatement("select * from EMPLOYEES where SALARY = ? and  ID = ?");&lt;br /&gt;  pstmt.setBigDecimal(1, 2333.00);&lt;br /&gt;  pstmt.setInt(2, 4333);&lt;br /&gt; ResultSet rs =  pstmt.executeQuery();&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is the difference between a Statement and a PreparedStatement? &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Statement&lt;/strong&gt;  &lt;br /&gt;Statement has to verify its metadata against the database every time. &lt;br /&gt;If you want to execute the SQL statement once go for STATEMENT &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;PreparedStatement&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A PreparedStatement is a precompiled  statement. This means that when the PreparedStatement is executed, the RDBMS can just run the PreparedStatement SQL statement without having to compile it first. &lt;br /&gt;Prepared statement has to verify its metadata against the database only once.  &lt;br /&gt;If you want to execute a single SQL statement multiple number of times, then go for PREPAREDSTATEMENT. PreparedStatement objects can be reused with passing different values to the queries  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What does setAutoCommit do?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;When a connection is created, it is in auto-commit mode. This means that each individual SQL statement is treated as a transaction and will be automatically committed right after it is executed. The way to allow two or more statements to be grouped into a transaction is to disable auto-commit mode:&lt;br /&gt;&lt;br /&gt;con.setAutoCommit(false); &lt;br /&gt;&lt;br /&gt;Once auto-commit mode is disabled, no SQL statements will be committed until you call the method commit explicitly. &lt;br /&gt;&lt;br /&gt;con.setAutoCommit(false);&lt;br /&gt;PreparedStatement updateSales =&lt;br /&gt; con.prepareStatement( "UPDATE ICECREAMS SET SALES = ? WHERE ICECREAM_NAME LIKE ?");&lt;br /&gt;updateSales.setInt(1, 50); &lt;br /&gt;updateSales.setString(2, "chocolate");&lt;br /&gt;updateSales.executeUpdate();&lt;br /&gt;PreparedStatement updateTotal =&lt;br /&gt; con.prepareStatement("UPDATE ICECREAMS SET TOTAL = TOTAL + ? WHERE ICECREAM_NAME LIKE ?");&lt;br /&gt;updateTotal.setInt(1, 50);&lt;br /&gt;updateTotal.setString(2, "chocolate");&lt;br /&gt;updateTotal.executeUpdate();&lt;br /&gt;con.commit();&lt;br /&gt;con.setAutoCommit(true);&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What are callable statements ? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Callable statements are used from JDBC application to invoke stored procedures and functions.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)How to call a stored procedure from JDBC ?&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;PL/SQL stored procedures are called from within JDBC programs by means of the prepareCall() method of the Connection object created. A call to this method takes variable bind parameters as input parameters as well as output variables and creates an object instance of the CallableStatement class.&lt;br /&gt;&lt;br /&gt;The following line of code illustrates this:&lt;br /&gt;&lt;br /&gt;   CallableStatement stproc_stmt = conn.prepareCall("{call procname(?,?,?)}");&lt;br /&gt;Here conn is an instance of the Connection class.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)How do I retrieve warnings?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;SQLWarning objects are a subclass of SQLException that deal with database access warnings. Warnings do not stop the execution of an&lt;br /&gt;application, as exceptions do; they simply alert the user that something did not happen as planned. A warning can be reported on a&lt;br /&gt;Connection object, a Statement object (including PreparedStatement and CallableStatement objects), or a ResultSet object. Each of these&lt;br /&gt;classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling object:&lt;br /&gt;&lt;br /&gt;SQLWarning warning = stmt.getWarnings();&lt;br /&gt;if (warning != null)&lt;br /&gt;{&lt;br /&gt; System.out.println("n---Warning---n");&lt;br /&gt; while (warning != null)&lt;br /&gt; {&lt;br /&gt;  System.out.println("Message: " + warning.getMessage());&lt;br /&gt;  System.out.println("SQLState: " + warning.getSQLState());&lt;br /&gt;  System.out.print("Vendor error code: ");&lt;br /&gt;  System.out.println(warning.getErrorCode());&lt;br /&gt;  System.out.println("");&lt;br /&gt;  warning = warning.getNextWarning();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection?&lt;/strong&gt; &lt;br /&gt;No. You can open only one Statement object per connection when you are using the JDBC-ODBC Bridge.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)Which is the right type of driver to use and when?&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;Type I driver is handy for prototyping &lt;br /&gt;Type III driver adds security, caching, and connection control &lt;br /&gt;Type III and Type IV drivers need no pre-installation &lt;br /&gt;Note: Preferred by 9 out of 10 Java developers: Type IV. Click here to learn more about JDBC drivers. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What are the standard isolation levels defined by JDBC?&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;The values are defined in the class java.sql.Connection and are:&lt;br /&gt;&lt;br /&gt;TRANSACTION_NONE &lt;br /&gt;TRANSACTION_READ_COMMITTED &lt;br /&gt;TRANSACTION_READ_UNCOMMITTED &lt;br /&gt;TRANSACTION_REPEATABLE_READ &lt;br /&gt;TRANSACTION_SERIALIZABLE &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What are the types of resultsets?&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;The values are defined in the class java.sql.Connection and are:&lt;br /&gt;&lt;br /&gt;TYPE_FORWARD_ONLY specifies that a resultset is not scrollable, that is, rows within it can be advanced only in the forward direction. &lt;br /&gt;TYPE_SCROLL_INSENSITIVE specifies that a resultset is scrollable in either direction but is insensitive to changes committed by other transactions or other statements in the same transaction. &lt;br /&gt;TYPE_SCROLL_SENSITIVE specifies that a resultset is scrollable in either direction and is affected by changes committed by other transactions or statements within the same transaction. &lt;br /&gt;Note: A TYPE_FORWARD_ONLY resultset is always insensitive.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What’s the difference between TYPE_SCROLL_INSENSITIVE , and TYPE_SCROLL_SENSITIVE?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;You will get a scrollable ResultSet object if you specify one of these ResultSet constants.The difference between the two has to do with whether a result set reflects changes that are made to it while it is open and whether certain methods can be called to detect these changes. Generally speaking, a result set that is TYPE_SCROLL_INSENSITIVE does not reflect changes made while it is still open and one that is TYPE_SCROLL_SENSITIVE does. All three types of result sets will make changes visible if they are closed and then reopened:&lt;br /&gt;&lt;br /&gt;Statement stmt =&lt;br /&gt; con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);&lt;br /&gt;ResultSet srs =&lt;br /&gt; stmt.executeQuery("SELECT COF_NAME, PRICE FROM COFFEES");&lt;br /&gt;srs.afterLast();&lt;br /&gt;while (srs.previous())&lt;br /&gt;{&lt;br /&gt; String name = srs.getString("COF_NAME");&lt;br /&gt; float price = srs.getFloat("PRICE");&lt;br /&gt; System.out.println(name + " " + price);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)How to Make Updates to Updatable Result Sets?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Another new feature in the JDBC 2.0 API is the ability to update rows in a result set using methods in the Java programming language rather than having to send an SQL command. But before you can take advantage of this capability, you need to create a ResultSet object that is updatable. In order to do this, you supply the ResultSet constant CONCUR_UPDATABLE to the createStatement method.&lt;br /&gt;&lt;br /&gt;Connection con =&lt;br /&gt; DriverManager.getConnection("jdbc:mySubprotocol:mySubName");&lt;br /&gt;Statement stmt =&lt;br /&gt; con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);&lt;br /&gt;ResultSet uprs =&lt;br /&gt; stmt.executeQuery("SELECT COF_NAME, PRICE FROM COFFEES");&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is a DataSource?&lt;/strong&gt; &lt;br /&gt;A DataSource object is the representation of a data source in the Java programming language. In basic terms, &lt;br /&gt;&lt;br /&gt;A DataSource is a facility for storing data. &lt;br /&gt;DataSource can be referenced by JNDI. &lt;br /&gt;Data Source may point to RDBMS, file System , any DBMS etc..&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Q)What are the advantages of DataSource?&lt;/strong&gt; &lt;br /&gt;The few advantages of data source are : &lt;br /&gt;&lt;br /&gt;An application does not need to hardcode driver information, as it does with the DriverManager. &lt;br /&gt;The DataDource implementations can easily change the properties of data sources. For example: There is no need to modify the application code when making changes to the database details. &lt;br /&gt;The DataSource facility allows developers to implement a DataSource class to take advantage of features like connection pooling and distributed transactions. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is connection pooling? what is the main advantage of using connection pooling?&lt;/strong&gt; &lt;br /&gt;A connection pool is a mechanism to reuse connections created. Connection pooling can increase performance dramatically by reusing connections rather than creating a new physical connection each time a connection is requested..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-2340117983142907949?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/2340117983142907949/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/01/jdbc-interview-questions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/2340117983142907949'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/2340117983142907949'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/01/jdbc-interview-questions.html' title='Jdbc Interview Questions'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-9180134406305585821</id><published>2009-01-16T18:52:00.000-08:00</published><updated>2009-06-18T15:32:00.865-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ejb'/><title type='text'>Ejb Interview Questions</title><content type='html'>&lt;strong&gt;Q)What are the different kinds of enterprise beans? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Stateless session bean- An instance of these non-persistent EJBs provides a service without storing an interaction or conversation state between methods. Any instance can be used for any client. &lt;br /&gt;&lt;br /&gt;Stateful session bean- An instance of these non-persistent EJBs maintains state across methods and transactions. Each instance is associated with a particular client. &lt;br /&gt;&lt;br /&gt;Entity bean- An instance of these persistent EJBs represents an object view of the data, usually rows in a database. They have a primary key as a unique identifier. Entity bean persistence can be either container-managed or bean-managed. &lt;br /&gt;&lt;br /&gt; Message-driven bean- An instance of these EJBs is integrated with the Java Message Service (JMS) to provide the ability for message-driven beans to act as a standard JMS message consumer and perform asynchronous processing between the server and the JMS message producer&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is session bean ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;There are two types of session beans: stateful and stateless.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Stateful Session Beans&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;The state of an object consists of the values of its instance variables. In a stateful session bean, the instance variables represent the state of a unique client-bean session. Because the client interacts ("talks") with its bean, this state is often called the conversational state. &lt;br /&gt;&lt;br /&gt;The state is retained for the duration of the client-bean session. If the client removes the bean or terminates, the session ends and the state disappears. This transient nature of the state is not a problem, however, because when the conversation between the client and the bean ends there is no need to retain the state. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Stateless Session Beans &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A stateless session bean does not maintain a conversational state for a particular client. When a client invokes the method of a stateless bean, the bean's instance variables may contain a state, but only for the duration of the invocation. When the method is finished, the state is no longer retained. Except during method invocation, all instances of a stateless bean are equivalent, allowing the EJB container to assign an instance to any client. &lt;br /&gt;&lt;br /&gt;Because stateless session beans can support multiple clients, they can offer better scalability for applications that require large numbers of clients. Typically, an application requires fewer stateless session beans than stateful session beans to support the same number of clients. &lt;br /&gt;&lt;br /&gt;At times, the EJB container may write a stateful session bean to secondary storage. However, stateless session beans are never written to secondary storage. Therefore, stateless beans may offer better performance than stateful beans.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is Entity Bean? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The entity bean is used to represent data in the database. It provides an object-oriented interface to data that would normally be accessed by the JDBC or some other back-end API. More than that, entity beans provide a component model that allows bean developers to focus their attention on the business logic of the bean, while the container takes care of managing persistence,transactions, and access control. &lt;br /&gt;&lt;br /&gt;There are two basic kinds of entity beans: container-managed ersistence (CMP) andbean-managed persistence (BMP). &lt;br /&gt;&lt;br /&gt;Container-managed persistence beans are the simplest for the bean developer to create and the most difficult for the EJB server to support. This is because all the logic for synchronizing the bean's state with the database is handled automatically by the container. This means that the bean developer doesn't need to write any data access logic, while the EJB server is &lt;br /&gt;supposed to take care of all the persistence needs automatically. With CMP, the container manages the persistence of the entity bean. Vendor tools are used to map the entity fields to the database and absolutely no database access code is written in the bean class. &lt;br /&gt;&lt;br /&gt;The bean-managed persistence (BMP) enterprise bean manages synchronizing its state with the database as directed by the container. The bean uses a database API to read and write its fields to the database, but the container tells it when to do each synchronization operation and manages the transactions for the bean automatically. Bean-managed persistence gives the bean developer the flexibility to perform persistence operations that are too complicated for the container or to use a data source that is not supported by the container. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)what are Container-Managed Transactional attributes ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;NotSupported &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The bean is not involved in a transaction. If the bean invoker calls the bean while involved in a transaction, the invoker's transaction is suspended, the bean executes, and when the bean returns, the invoker's transaction is resumed. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Required &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The bean must be involved in a transaction. If the invoker is involved in a transaction, the bean uses the invoker's transaction. If the invoker is not involved in a transaction, the container starts a new transaction for the bean. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Supports &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Whatever transactional state that the invoker is involved in is used for the bean. If the invoker has begun a transaction, the invoker's transaction context is used by the bean. If the invoker is not involved in a transaction, neither is the bean. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;RequiresNew &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Whether or not the invoker is involved in a transaction, this bean starts a new transaction that exists only for itself. If the invoker calls while involved in a transaction, the invoker's transaction is suspended until the bean completes. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Mandatory &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The invoker must be involved in a transaction before invoking this bean. The bean uses the invoker's transaction context. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Never&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;The bean is not involved in a transaction. Furthermore, the invoker cannot be involved in a transaction when calling the bean. If the invoker is involved in a transaction, a RemoteException is thrown. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What's difference between httpsession and EJB session bean ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A session in a Servlet, is maintained by the Servlet Container through the HttpSession object, that is acquired through the request object. You cannot really instantiate a new HttpSession object, and it doesn't contains any business logic, but is more of a place where to store objects. &lt;br /&gt;&lt;br /&gt;A session in EJB is maintained using the SessionBeans. You design beans that can contain business logic, and that can be used by the clients. You have two different session beans: Stateful and Stateless. The first one is somehow connected with a single client. It maintains the state for that client, can be used only by that client and when the client "dies" then the session bean is "lost". &lt;br /&gt;&lt;br /&gt;A Stateless Session Bean doesn't maintain any state and there is no guarantee that the same client will use the same stateless bean, even for two calls one after the other. The lifecycle of a Stateless Session EJB is slightly different from the one of a Stateful Session EJB. Is EJB Container's responsability to take care of knowing exactly how to track each session and redirect the request from a client to the correct instance of a Session Bean. The way this is done is vendor dependant, and is part of the contract. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is the default transaction attribute for an EJB?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;There is no default transaction attribute for an EJB. &lt;br /&gt;Deployer must specify a value for the transaction attribute for those methods having container managed transaction. &lt;br /&gt;In WebLogic, the default transaction attribute for EJB is SUPPORTS. &lt;br /&gt;WAS6.0 its "Required". &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q) What is the need of Remote and Home interface. Why cant it be in one?  &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The main reason is because there is a clear division of roles and responsabilities between the two interfaces. The home interface is your way to communicate with the container, that is who is responsable of creating, locating even removing one or more beans. The remote interface is your link to the bean, that will allow you to remotely access to all its methods and members. As you can see there are two distinct elements (the container and the beans) and you need two different interfaces for accessing to both of them.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q) What is the diffrence between Bean Managed Persistance and  Container Managed Persistance? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;CMP means Container Managed Persistence. When we write CMP bean , we dont need to write any JDBC code to connect to Database. The container will take care of connection our enitty beans fields with database. The Container manages the persistence of the bean. Absolutely no database access code is written inside the bean class.  &lt;br /&gt;&lt;br /&gt;BMP means Bean Managed Persistence. When we write BMP bean, it is programmer responsiblity to write JDBC code to connect to Database. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)Why is ejbFindByPrimaryKey mandatory?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;An Entity Bean represents persistent data that is stored outside of the EJB Container/Server. The ejbFindByPrimaryKey is a method used to locate and load an Entity Bean into the container, similar to a SELECT statement in SQL. By making this method mandatory, the client programmer can be assured that if they have the primary key of the Entity Bean, then they can retrieve the bean without having to create a new bean each time &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What are the Differences between EJB 3.0 and EJB 2.1? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;1)EJB 3.0 allows developers to program EJB components as ordinary Java objects with ordinary Java business interfaces rather than as heavy weight components like EJB 2 (home,remote). &lt;br /&gt;&lt;br /&gt;2)In EJB 3.0 you can use annotaion or deployment descriptors  but in &lt;br /&gt;EJB 2 you have to use deployment descriptors. &lt;br /&gt;&lt;br /&gt;3) EJB 3 introduced persistence API for database access. In EJB 2 you can use Entity bean. &lt;br /&gt;&lt;br /&gt;4) EJB 3.0 is much faster the EJB 2.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-9180134406305585821?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/9180134406305585821/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/01/ejb-interview-questions_16.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/9180134406305585821'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/9180134406305585821'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/01/ejb-interview-questions_16.html' title='Ejb Interview Questions'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-3759803149107731559</id><published>2009-01-11T09:09:00.002-08:00</published><updated>2009-01-24T20:04:35.991-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ajax'/><title type='text'>Ajax Interview Questions</title><content type='html'>&lt;strong&gt;1) What is AJAX?  &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;AJAX stands for Asynchronous JavaScript And XML.&lt;br /&gt;&lt;br /&gt;With AJAX you can create better, faster, and more user-friendly web applications.&lt;br /&gt;&lt;br /&gt;AJAX is based on JavaScript and HTTP requests.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;2)What is XMLHttpRequest Object ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Your JavaScript communicates directly with the server, through the JavaScript XMLHttpRequest object&lt;br /&gt;&lt;br /&gt;By using the XMLHttpRequest object, a web developer can update a page with data from the server after the page has loaded!&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;3)Can Ajax be implemented in browsers that do not support the XmlHttpRequest object?  &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Yes. This is possible using remote scripts. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;4)How to we create an XmlHttpRequest object for Internet Explorer? How is this different for other browsers?&lt;/strong&gt;  &lt;br /&gt;&lt;br /&gt;For Internet Explorer, an ActiveXObject is used for declaring an XmlHttpRequest object in Javascript. &lt;br /&gt;//Code as below for IE: &lt;br /&gt;xmlHttpObject = new ActiveXObject("Msxml2.XMLHTTP"); &lt;br /&gt;//For Other browsers, code as below: &lt;br /&gt;xmlHttpObject = new XMLHttpRequest(); &lt;br /&gt;Note that XmlHttpObject used above is simply a variable for the respective browsers. &lt;br /&gt; &lt;br /&gt;&lt;strong&gt;5)What are the properties of the XmlHttpRequest object? What are the different types of readyStates in Ajax? &lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;i) onreadyStateChange - This function is used to process the reply from the web server.&lt;br /&gt;ii) readyState - This property holds the response status of the web server. There are 5 states:&lt;br /&gt;1 - request not yet initialized&lt;br /&gt;2 - request now set&lt;br /&gt;3 - request sent &lt;br /&gt;4 - request processing&lt;br /&gt;5 - request completes&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)Which request is better with AJAX, Get or Post?  &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;AJAX requests should use an HTTP GET request while retrieving data where the data does not change for a given URL requested. An HTTP POST should be used when state is updated on the server. This is in line with HTTP idempotency recommendations and is highly recommended for a consistent web application architecture.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)When do I use a synchronous versus a asynchronous request?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;They don't call it AJAX for nothing! A synchronous request would block in page event processing and I don't see many use cases where a synchronous request is preferable&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)Explain limitations of Ajax.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Back functionality cannot work because the dynamic pages don’t register themselves to the browsers history engine.......... &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)List out differences between AJAX and JavaScript.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Ajax is Asynchronous Java Script and XML. Here on Ajax sending request to the server, one needn’t wait for the.......&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)When should AJAX NOT be used?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;If the page is expected to be shown in a search engine like Google. Since Web crawlers don’t execute...............&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)Are there any security issues with AJAX?  &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;JavaScript is in plain view to the user with by selecting view source of the page. JavaScript can not access the local filesystem without the user's permission. An AJAX interaction can only be made with the servers-side component from which the page was loaded. A proxy pattern could be used for AJAX interactions with external services. You need to be careful not to expose your application model in such as way that your server-side components are at risk if a nefarious user to reverse engineer your application. As with any other web application, consider using HTTPS to secure the connection when confidential information is being exchanged.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-3759803149107731559?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/3759803149107731559/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/01/ajax-interview-questions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/3759803149107731559'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/3759803149107731559'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/01/ajax-interview-questions.html' title='Ajax Interview Questions'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-3485248748947852582</id><published>2009-01-11T09:09:00.001-08:00</published><updated>2009-01-17T11:18:44.316-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>Hibernate Interview Questions</title><content type='html'>&lt;strong&gt;Q. What is ORM?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;ORM stands for Object/Relational mapping. It is the programmed and translucent&lt;br /&gt;perseverance of objects in a Java application in to the tables of a relational database using&lt;br /&gt;the metadata that describes the mapping between the objects and the database. It works&lt;br /&gt;by transforming the data from one representation to another.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q). What is Hibernate?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Hibernate is a powerful, high performance object/relational persistence and query service.&lt;br /&gt;This lets the users to develop persistent classes following object-oriented principles such&lt;br /&gt;as association, inheritance, polymorphism, composition, and collections.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What  object states Hibernate defines and supports ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Transient - an object is transient if it has just been instantiated using the new operator, and it is not associated with a Hibernate Session. It has no persistent representation in the database and no identifier value has been assigned. Transient instances will be destroyed by the garbage collector if the application doesn't hold a reference anymore.&lt;br /&gt;&lt;br /&gt;Persistent - a persistent instance has a representation in the database and an identifier value. It might just have been saved or loaded, however, it is by definition in the scope of a Session. Hibernate will detect any changes made to an object in persistent state and synchronize the state with the database when the unit of work completes.&lt;br /&gt;&lt;br /&gt;Detached - a detached instance is an object that has been persistent, but its Session has been closed. The reference to the object is still valid, of course, and the detached instance might even be modified in this state. A detached instance can be reattached to a new Session at a later point in time, making it (and all the modifications) persistent again. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is lazy fetching in Hibernate? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Lazy fetching decides whether to load child objects while loading the Parent Object. &lt;br /&gt;&lt;br /&gt;You need to do this setting respective hibernate mapping file of the parent class. &lt;br /&gt;Lazy = true (means not to load child) &lt;br /&gt;By default the lazy loading of the child objects is true. &lt;br /&gt;This make sure that the child objects are not loaded unless they are explicitly invoked in the application by calling getChild() method on parent.In this case hibernate issues a fresh database call to load the child when getChild() is actully called on the Parent object &lt;br /&gt;.But in some cases you do need to load the child objects when parent is loaded. &lt;br /&gt;Just make the lazy=false and hibernate will load the child when parent is loaded from the database.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)how to create primary key using hibernate?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;generator class="increment"&lt;br /&gt;&lt;br /&gt;increment :: It generates identifiers of type long, short or int that are unique only when no other process is inserting data into the same table. It should not the used in the clustered environment. &lt;br /&gt;identity :: It supports identity columns in DB2, MySQL, MS SQL Server, Sybase and HypersonicSQL. The returned identifier is of type long, short or int. &lt;br /&gt;sequence :: The sequence generator uses a sequence in DB2, PostgreSQL, Oracle, SAP DB, McKoi or a generator in Interbase. The returned identifier is of type long, short or int &lt;br /&gt;native :: It picks identity, sequence or hilo depending upon the capabilities of the underlying database. &lt;br /&gt;assigned :: lets the application to assign an identifier to the object before save() is called. This is the default strategy if no generator element is specified. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q. How will you configure Hibernate? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The configuration files hibernate.cfg.xml (or hibernate.properties) and mapping files *.hbm.xml are used by the Configuration class to create (i.e. configure and bootstrap hibernate) the SessionFactory, which in turn creates the Session instances. Session instances are the primary interface for the persistence service. &lt;br /&gt;&lt;br /&gt;• hibernate.cfg.xml (alternatively can use hibernate.properties): These two files are used to configure the hibernate sevice (connection driver class, connection URL, connection username, connection password, dialect etc). If both files are present in the classpath then hibernate.cfg.xml file overrides the settings found in the hibernate.properties file. &lt;br /&gt;&lt;br /&gt;• Mapping files (*.hbm.xml): These files are used to map persistent objects to a relational database. It is the best practice to store each object in an individual mapping file (i.e mapping file per class) because storing large number of persistent classes into one mapping file can be difficult to manage and maintain. The naming convention is to use the same name as the persistent (POJO) class name. For example Account.class will have a mapping file named Account.hbm.xml. Alternatively hibernate annotations can be used as part of your persistent class code instead of the *.hbm.xml files. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q. What is a SessionFactory? Is it a thread-safe object? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;SessionFactory is Hibernate’s concept of a single datastore and is threadsafe so that many threads can access it concurrently and request for sessions and immutable cache of compiled mappings for a single database. A SessionFactory is usually only built once at startup. SessionFactory should be wrapped in some kind of singleton so that it can be easily accessed in an application code. &lt;br /&gt;&lt;br /&gt;SessionFactory sessionFactory = new Configuration().configure().buildSessionfactory(); &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;Q)What is the difference between session.save() , session.saveOrUpdate() and session.persist()? &lt;/strong&gt;&lt;br /&gt;session.save() : Save does an insert and will fail if the primary key is already persistent. &lt;br /&gt;&lt;br /&gt;session.saveOrUpdate() : saveOrUpdate does a select first to determine if it needs to do an insert or an update. &lt;br /&gt;Insert data if primary key not exist otherwise update data. &lt;br /&gt;&lt;br /&gt;session.persist() : Does the same like session.save(). &lt;br /&gt;But session.save() return Serializable object but session.persist() return void. &lt;br /&gt;         session.save() returns the generated identifier (Serializable object) and session.persist() doesn't. &lt;br /&gt;Example :         &lt;br /&gt; &lt;br /&gt; System.out.println(session.save(question)); &lt;br /&gt; This will print the generated primary key.          &lt;br /&gt; System.out.println(session.persist(question)); &lt;br /&gt; Compile time error because session.persist() return void. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q. What are the benefits of detached objects? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Detached objects can be passed across layers all the way up to the presentation layer without having to use any DTOs (Data Transfer Objects). You can later on re-attach the detached objects to another session. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q. What are the Advantages  and DisAdvantages of detached objects? &lt;/strong&gt;&lt;br /&gt;Advantages: &lt;br /&gt;&lt;br /&gt;• When long transactions are required due to user think-time, it is the best practice to break the long transaction up into two or more transactions. You can use detached objects from the first transaction to carry data all the way up to the presentation layer. These detached objects get modified outside a transaction and later on re-attached to a new transaction via another session. &lt;br /&gt;&lt;br /&gt;DisAdvantages &lt;br /&gt;&lt;br /&gt;• In general, working with detached objects is quite cumbersome, and better to not clutter up the session with them if possible. It is better to discard them and re-fetch them on subsequent requests. This approach is not only more portable but also more efficient because - the objects hang around in Hibernate's cache anyway. &lt;br /&gt;&lt;br /&gt;• Also from pure rich domain driven design perspective it is recommended to use DTOs (DataTransferObjects) and DOs (DomainObjects) to maintain the separation between Service and UI tiers. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q. What is the file extension you use for hibernate mapping file?&lt;/strong&gt;&lt;br /&gt;The name of the file should be like this : filename.hbm.xml&lt;br /&gt;The filename varies here. The extension of these files should be “.hbm.xml”.&lt;br /&gt;This is just a convention and it’s not mandatory. But this is the best practice to follow this&lt;br /&gt;extension.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q. How do you create a SessionFactory?&lt;/strong&gt;&lt;br /&gt;Configuration cfg = new Configuration();&lt;br /&gt;cfg.addResource("myinstance/MyConfig.hbm.xml");&lt;br /&gt;cfg.setProperties( System.getProperties() );&lt;br /&gt;SessionFactory sessions = cfg.buildSessionFactory();&lt;br /&gt;First, we need to create an instance of Configuration and use that instance to refer to the&lt;br /&gt;location of the configuration file. After configuring this instance is used to create the&lt;br /&gt;SessionFactory by calling the method buildSessionFactory().&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q. What is the difference between the session.get() method and the &lt;br /&gt;session.load() method? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Both the session.get(..) and session.load() methods create a persistent object by loading the required object from the database. But if there was not such object in the database then the method session.load(..) throws an exception whereas session.get(…) returns null. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q. What is the difference between the session.update() method and the &lt;br /&gt;session.lock() method? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Both of these methods and saveOrUpdate() method are intended for reattaching a detached object. The session.lock() method simply reattaches the object to the session without checking or updating the database on the assumption that the database in sync with the detached object. It is the best practice to use either session.update(..) or session.saveOrUpdate(). Use session.lock() only if you are absolutely sure that the detached object is in sync with your detached object or if it does not matter because you will be overwriting all the columns that would have changed later on within the same transaction. &lt;br /&gt;&lt;br /&gt;Note: When you reattach detached objects you need to make sure that the dependent objects are reatched as well. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q. How would you reatach detached objects to a session when the same object has already been loaded into the session? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;You can use the session.merge() method call. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q. What are the  best practices for defining your Hibernate persistent classes? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;1.You must have a default no-argument constructor for your persistent classes and there should be getXXX() (i.e accessor/getter) and setXXX( i.e. mutator/setter) methods for all your persistable instance variables. &lt;br /&gt;&lt;br /&gt;2.You should implement the equals() and hashCode() methods based on your business key and it is important not to use the id field in your equals() and hashCode() definition if the id field is a surrogate key (i.e. Hibernate managed identifier). This is because the Hibernate only generates and sets the field when saving the object. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3. It is recommended to implement the Serializable interface. This is potentially useful if you want to migrate around a multi-processor cluster. &lt;br /&gt;&lt;br /&gt;4.The persistent class should not be final because if it is final then lazy loading cannot be used by creating proxy objects. &lt;br /&gt;&lt;br /&gt;5.Use XDoclet tags for generating your *.hbm.xml files or Annotations (JDK 1.5 onwards), which are less verbose than *.hbm.xml files.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q. What are POJOs?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;POJO stands for plain old java objects. These are just basic JavaBeans that have defined&lt;br /&gt;setter and getter methods for all the properties that are there in that bean. Besides they&lt;br /&gt;can also have some business logic related to that property. Hibernate applications works&lt;br /&gt;efficiently with POJOs rather then simple java classes.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q. What is object/relational mapping metadata?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;ORM tools require a metadata format for the application to specify the mapping between&lt;br /&gt;classes and tables, properties and columns, associations and foreign keys, Java types and&lt;br /&gt;SQL types. This information is called the object/relational mapping metadata. It defines&lt;br /&gt;the transformation between the different data type systems and relationship&lt;br /&gt;representations.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q. What is HQL?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;HQL stands for Hibernate Query Language. Hibernate allows the user to express queries&lt;br /&gt;in its own portable SQL extension and this is called as HQL. It also allows the user to&lt;br /&gt;express in native SQL.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q. What are managed associations and hibernate associations?&lt;/strong&gt;&lt;br /&gt;Associations that are related to container management persistence are called managed&lt;br /&gt;associations. These are bi-directional associations. Coming to hibernate associations,&lt;br /&gt;these are unidirectional.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q. Where should SessionFactory be placed so that it can be easily accessed?&lt;/strong&gt;&lt;br /&gt;As far as it is compared to J2EE environment, if the SessionFactory is placed in JNDI&lt;br /&gt;then it can be easily accessed and shared between different threads and various&lt;br /&gt;components that are hibernate aware. You can set the SessionFactory to a JNDI by&lt;br /&gt;configuring a property hibernate.session_factory_name in the hibernate.properties file.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-3485248748947852582?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/3485248748947852582/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/01/hibernate-interview-questions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/3485248748947852582'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/3485248748947852582'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/01/hibernate-interview-questions.html' title='Hibernate Interview Questions'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-8461139099057348664</id><published>2009-01-01T17:41:00.001-08:00</published><updated>2009-06-14T16:16:04.338-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Spring'/><title type='text'>Spring Interview Questions</title><content type='html'>&lt;strong&gt;Q)What is Spring's MVC package?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt; This package provides a Model-View-Controller (MVC) implementation for web-applications. Spring's MVC framework is different from other implementations as it provides a clean separation between model code and web forms, and allows you to use all the other features of the Spring Framework.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What are the benifits of Spring framework?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt; The features of Spring are as follows: &lt;br /&gt;&lt;br /&gt;Spring has layered architecture. Use what you need and leave you don't need now. &lt;br /&gt;Spring Enables POJO Programming. and POJO programming enables continuous integration and testability. &lt;br /&gt;Dependency Injection and Inversion of Control Simplifies JDBC &lt;br /&gt;Open source and no vendor lock-in. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)Explain about Spring ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Lightweight - spring is lightweight when it comes to size&lt;br /&gt;and transparency. The basic version of spring framework is around 1MB.&lt;br /&gt;And the processing overhead is also very negligible.&lt;br /&gt;&lt;br /&gt;Inversion of control (IoC) - Loose coupling is achieved in&lt;br /&gt;spring using the technique Inversion of Control. The objects give their&lt;br /&gt;dependencies instead of creating or looking for dependent objects.&lt;br /&gt;&lt;br /&gt;Aspect oriented (AOP) - Spring supports Aspect oriented&lt;br /&gt;programming and enables cohesive development by separating application&lt;br /&gt;business logic from system services. &lt;br /&gt;&lt;br /&gt;Container - Spring contains and manages the life cycle and&lt;br /&gt;configuration of application objects. &lt;br /&gt;&lt;br /&gt;Framework - Spring provides most of the intra functionality&lt;br /&gt;leaving rest of the coding to the developer.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is Inversion of Control(or Dependency Injection)?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The basic concept of the Inversion of Control pattern (also known as dependency injection) is that you do not create your objects but describe how they should be created. You don't directly connect your components and services together in code but describe which services are needed by which components in a configuration file. A container (in the case of the Spring framework, the IOC container) is then responsible for hooking it all up.&lt;br /&gt;&lt;br /&gt;i.e., Applying IoC, objects are given their dependencies at creation time by some external entity that coordinates each object in the system. That is, dependencies are injected into objects. So, IoC means an inversion of responsibility with regard to how an object obtains references to collaborating objects. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What are the features of IOC (Dependency Injection)?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Benefits of IOC (Dependency Injection) are as follows:&lt;br /&gt;&lt;br /&gt;IOC containers support eager instantiation and lazy loading of services. Containers also provide support for instantiation of managed objects, cyclical dependencies, life cycles management, and dependency resolution between managed objects etc.&lt;br /&gt;&lt;br /&gt;Minimizes the amount of code in your application. With IOC containers you do not care about how services are created and how you get references to the ones you need. You can also easily add additional services by adding a new constructor or a setter method with little or no extra configuration.&lt;br /&gt;&lt;br /&gt;Loose coupling is promoted with minimal effort and least intrusive mechanism. The factory design pattern is more intrusive because components or services need to be requested explicitly whereas in IOC the dependency is injected into requesting piece of code. Also some containers promote the design to interfaces not to implementations design concept by encouraging managed objects to implement a well-defined service interface of your own.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What are the different types of Inversion of Control(dependency injection) ? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Constructor Injection:&lt;br /&gt;Constructor-based DI is realized by invoking a constructor with a number of arguments, each representing a collaborator.&lt;br /&gt;&lt;br /&gt;Setter Injection:&lt;br /&gt;Setter-based DI is realized by calling setter methods on your beans after invoking a no-argument constructor or no-argument static factory method to instantiate your bean. &lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Q)What are Bean Factory and Application Context?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Bean Factory&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A BeanFactory is like a factory class that contains a collection of beans. The BeanFactory holds Bean Definitions of multiple beans within itself and then instantiates the bean whenever asked for by clients.&lt;br /&gt;&lt;br /&gt;BeanFactory is able to create associations between collaborating objects as they are instantiated. This removes the burden of configuration from bean itself and the beans client. &lt;br /&gt;BeanFactory also takes part in the life cycle of a bean, making calls to custom initialization and destruction methods. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt; Application Context&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A bean factory is fine to simple applications, but to take advantage of the full power of the Spring framework, you may want to move up to Springs more advanced container, the application context. On the surface, an application context is same as a bean factory.Both load bean definitions, wire beans together, and dispense beans upon request. But it also provides: &lt;br /&gt;&lt;br /&gt;A means for resolving text messages, including support for internationalization. &lt;br /&gt;A generic way to load file resources. &lt;br /&gt;Events to beans that are registered as listeners. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q) What are the common implementations of the Application Context ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The three commonly used implementation of 'Application Context' are &lt;br /&gt;&lt;br /&gt;ClassPathXmlApplicationContext : It Loads context definition from an XML file located in the classpath, treating context definitions as classpath resources. The application context is loaded from the application's classpath by using the code .&lt;br /&gt;ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml"); &lt;br /&gt;FileSystemXmlApplicationContext : It loads context definition from an XML file in the filesystem. The application context is loaded from the file system by using the code . &lt;br /&gt;ApplicationContext context = new FileSystemXmlApplicationContext("bean.xml"); &lt;br /&gt;XmlWebApplicationContext : It loads context definition from an XML file contained within a web application. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)How many major modules are there in Spring? What are they?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The core container:&lt;/strong&gt;&lt;br /&gt;The core container provides the essential functionality of the Spring framework. A primary component of the core container is the BeanFactory, an implementation of the Factory pattern. The BeanFactory applies the Inversion of Control (IOC) pattern to separate an application's configuration and dependency specification from the actual application code.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Spring context:&lt;/strong&gt;&lt;br /&gt;The Spring context is a configuration file that provides context information to the Spring framework. The Spring context includes enterprise services such as JNDI, EJB, e-mail, internalization, validation, and scheduling functionality.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Spring AOP:&lt;/strong&gt;&lt;br /&gt;The Spring AOP module integrates aspect-oriented programming functionality directly into the Spring framework, through its configuration management feature. As a result you can easily AOP-enable any object managed by the Spring framework. The Spring AOP module provides transaction management services for objects in any Spring-based application. With Spring AOP you can incorporate declarative transaction management into your applications without relying on EJB components.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Spring DAO:&lt;/strong&gt;&lt;br /&gt;The Spring JDBC DAO abstraction layer offers a meaningful exception hierarchy for managing the exception handling and error messages thrown by different database vendors. The exception hierarchy simplifies error handling and greatly reduces the amount of exception code you need to write, such as opening and closing connections. Spring DAO's JDBC-oriented exceptions comply to its generic DAO exception hierarchy.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Spring ORM:&lt;/strong&gt;&lt;br /&gt;The Spring framework plugs into several ORM frameworks to provide its Object Relational tool, including JDO, Hibernate, and iBatis SQL Maps. All of these comply to Spring's generic transaction and DAO exception hierarchies.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Spring Web module:&lt;/strong&gt;&lt;br /&gt;The Web context module builds on top of the application context module, providing contexts for Web-based applications. As a result, the Spring framework supports integration with Jakarta Struts. The Web module also eases the tasks of handling multi-part requests and binding request parameters to domain objects.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Spring MVC framework:&lt;/strong&gt;&lt;br /&gt;The Model-View-Controller (MVC) framework is a full-featured MVC implementation for building Web applications. The MVC framework is highly configurable via strategy interfaces and accommodates numerous view technologies including JSP, Velocity, Tiles, iText, and POI.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is the difference between Bean Factory and Application Context ?  &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;An application context is same as a bean factory. But application context offers much more.. &lt;br /&gt;&lt;br /&gt;Application contexts provide a means for resolving text messages, including support for i18n of those messages. &lt;br /&gt;&lt;br /&gt;Application contexts provide a generic way to load file resources, such as images. &lt;br /&gt;&lt;br /&gt;Application contexts can publish events to beans that are registered as listeners. &lt;br /&gt;&lt;br /&gt;Certain operations on the container or beans in the container, which have to be handled in a programmatic fashion with a bean factory, can be handled declaratively in an application context. &lt;br /&gt;&lt;br /&gt;ResourceLoader support: Spring’s Resource interface us a flexible generic abstraction for handling low-level resources. An application context itself is a ResourceLoader, Hence provides an application with access to deployment-specific Resource instances. &lt;br /&gt;&lt;br /&gt;MessageSource support: The application context implements MessageSource, an interface used to obtain localized messages, with the actual implementation being pluggable &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)How is a typical spring implementation look like ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;For a typical Spring Application we need the following files:&lt;br /&gt;&lt;br /&gt;An interface that defines the functions.&lt;br /&gt;&lt;br /&gt;An Implementation that contains properties, its setter and getter methods, functions etc.,&lt;br /&gt;&lt;br /&gt;Spring AOP (Aspect Oriented Programming)&lt;br /&gt;&lt;br /&gt;A XML file called Spring configuration file.&lt;br /&gt;&lt;br /&gt;Client program that uses the function.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is the typical Bean life cycle in Spring Bean Factory Container ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Bean life cycle in Spring Bean Factory Container is as follows:&lt;br /&gt;&lt;br /&gt;The spring container finds the bean’s definition from the XML file and instantiates the bean. &lt;br /&gt;&lt;br /&gt;Using the dependency injection, spring populates all of the properties as specified in the bean definition&lt;br /&gt;&lt;br /&gt;If the bean implements the BeanNameAware interface, the factory calls setBeanName() passing the bean’s ID. &lt;br /&gt;&lt;br /&gt;If the bean implements the BeanFactoryAware interface, the factory calls setBeanFactory(), passing an instance of itself. &lt;br /&gt;&lt;br /&gt;If there are any BeanPostProcessors associated with the bean, their post- ProcessBeforeInitialization() methods will be called. &lt;br /&gt;&lt;br /&gt;If an init-method is specified for the bean, it will be called.&lt;br /&gt;&lt;br /&gt;Finally, if there are any BeanPostProcessors associated with the bean, their postProcessAfterInitialization() methods will be called. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What do you mean by Bean wiring ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The act of creating associations between application components (beans) within the Spring container is reffered to as Bean wiring.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What do you mean by Auto Wiring?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The Spring container is able to autowire relationships between collaborating beans. This means that it is possible to automatically let Spring resolve collaborators (other beans) for your bean by inspecting the contents of the BeanFactory. The autowiring functionality has five modes.&lt;br /&gt;&lt;br /&gt;no &lt;br /&gt;&lt;br /&gt;byName&lt;br /&gt;&lt;br /&gt;byType &lt;br /&gt;&lt;br /&gt;constructor &lt;br /&gt;&lt;br /&gt;autodirect &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is DelegatingVariableResolver?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Spring provides a custom JavaServer Faces VariableResolver implementation that extends the standard Java Server Faces managed beans mechanism which lets you use JSF and Spring together. This variable resolver is called as DelegatingVariableResolver&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)How to integrate  Java Server Faces (JSF) with Spring? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;JSF and Spring do share some of the same features, most noticeably in the area of IOC services. By declaring JSF managed-beans in the faces-config.xml configuration file, you allow the FacesServlet to instantiate that bean at startup. Your JSF pages have access to these beans and all of their properties.We can integrate JSF and Spring in two ways: &lt;br /&gt;&lt;br /&gt;DelegatingVariableResolver: Spring comes with a JSF variable resolver that lets you use JSF and Spring together. &lt;br /&gt;&lt;br /&gt;include org.springframework.web.jsf.DelegatingVariableResolver in variable-resolver of faces-config&lt;br /&gt;&lt;br /&gt;The DelegatingVariableResolver will first delegate value lookups to the default resolver of the underlying JSF implementation, and then to Spring's 'business context' WebApplicationContext. This allows one to easily inject dependencies into one's JSF-managed beans.&lt;br /&gt;&lt;br /&gt;FacesContextUtils:custom VariableResolver works well when mapping one's properties to beans in faces-config.xml, but at times one may need to grab a bean explicitly. The FacesContextUtils class makes this easy. It is similar to WebApplicationContextUtils, except that it takes a FacesContext parameter rather than a ServletContext parameter. &lt;br /&gt;&lt;br /&gt;ApplicationContext ctx = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What are the difference between Spring and  EJB  ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;have a look at the main important differences between the two:&lt;br /&gt;&lt;br /&gt;1) Distributed Computing – If components in your web-container need to access remote components, then EJB provides in-build support for remote method calls. The EJB container manages all RMI-IIOP connections. Spring provides support for proxying remote calls via RMI, JAX-RPC etc.&lt;br /&gt;2) Transaction Support – EJB by default uses the JTA manager provided by the EJB container and hence can support XA or distributed transactions. Spring does not have default support for distributed transactions, but it can plug in a JTA Transaction manager. Both EJB and Spring allows for declarative transaction demarcation. EJB uses deployment descriptor and Spring uses AOP.&lt;br /&gt;3) Persistance – Entity Beans provide CMP and BMP strategies, but my personal experience with these options has been devastating. Entity Beans are too slow!!!.&lt;br /&gt;Spring integrates with Hibernate, IBatis and also has good JDBC wrapper components (JdbcTemplate).&lt;br /&gt;4) Security – EJB provides support for declarative security through the deployment descriptor. But again, this incurs a heavy performance penalty and I have rarely seen projects using EJB-container managed security.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is  Java Server Faces (JSF) - Spring integration mechanism? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Spring provides a custom JavaServer Faces VariableResolver implementation that extends the standard JavaServer Faces managed beans mechanism. When asked to resolve a variable name, the following algorithm is performed:&lt;br /&gt;&lt;br /&gt;Does a bean with the specified name already exist in some scope (request, session, application)? If so, return it &lt;br /&gt;&lt;br /&gt;Is there a standard JavaServer Faces managed bean definition for this variable name? If so, invoke it in the usual way, and return the bean that was created. &lt;br /&gt;&lt;br /&gt;Is there configuration information for this variable name in the Spring WebApplicationContext for this application? If so, use it to create and configure an instance, and return that instance to the caller.&lt;br /&gt;&lt;br /&gt;If there is no managed bean or Spring definition for this variable name, return null instead.&lt;br /&gt;&lt;br /&gt;BeanFactory also takes part in the life cycle of a bean, making calls to custom initialization and destruction methods.&lt;br /&gt;&lt;br /&gt;As a result of this algorithm, you can transparently use either JavaServer Faces or Spring facilities to create beans on demand. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is Significance of JSF- Spring integration ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt; Spring - JSF integration is useful when an event handler wishes to explicitly invoke the bean factory to create beans on demand, such as a bean that encapsulates the business logic to be performed when a submit button is pressed. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)How to integrate your Struts application with Spring?  &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt; To integrate your Struts application with Spring, we have two options: &lt;br /&gt;&lt;br /&gt;Configure Spring to manage your Actions as beans, using the ContextLoaderPlugin, and set their dependencies in a Spring context file. &lt;br /&gt;&lt;br /&gt;Subclass Spring's ActionSupport classes and grab your Spring-managed beans explicitly using a getWebApplicationContext() method. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q) What are ORM’s Spring supports ? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Spring supports the following ORM’s : &lt;br /&gt;Hibernate &lt;br /&gt;iBatis &lt;br /&gt;JPA (Java Persistence API) &lt;br /&gt;TopLink &lt;br /&gt;JDO (Java Data Objects) &lt;br /&gt;OJB &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)How to integrate Spring and Hibernate ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Spring and Hibernate can integrate using Spring’s SessionFactory called LocalSessionFactory. The integration process is of 3 steps.&lt;br /&gt;&lt;br /&gt;Configure Hibernate mappings. &lt;br /&gt;Configure Hibernate properties. &lt;br /&gt;Wire dependant object to SessionFactory. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What are the ways to access Hibernate using Spring ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;There are two ways to access Hibernate from Spring:&lt;br /&gt;&lt;br /&gt;Through Hibernate Template. &lt;br /&gt;Subclassing HibernateDaoSupport &lt;br /&gt;Extending HibernateDaoSupport and Applying an AOP Interceptor &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;QWhat are Bean scopes in Spring Framework ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The Spring Framework supports exactly five scopes (of which three are available only if you are using a web-aware ApplicationContext). The scopes supported are listed below: &lt;br /&gt;&lt;br /&gt;Scope Description &lt;br /&gt;&lt;strong&gt;singleton&lt;/strong&gt;&lt;br /&gt; Scopes a single bean definition to a single object instance per Spring IoC container.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;prototype&lt;/strong&gt;&lt;br /&gt; Scopes a single bean definition to any number of object instances.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;request&lt;/strong&gt;&lt;br /&gt; Scopes a single bean definition to the lifecycle of a single HTTP request; that is each and every HTTP request will have its own instance of a bean created off the back of a single bean definition. Only valid in the context of a web-aware Spring ApplicationContext.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;session&lt;/strong&gt;&lt;br /&gt; Scopes a single bean definition to the lifecycle of a HTTP Session. Only valid in the context of a web-aware Spring ApplicationContext.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;global session&lt;/strong&gt;&lt;br /&gt; Scopes a single bean definition to the lifecycle of a global HTTP Session. Typically only valid when used in a portlet context. Only valid in the context of a web-aware Spring ApplicationContext.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Q)What is AOP?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Aspect-oriented programming, or AOP, is a programming technique that allows programmers to modularize crosscutting concerns, or behavior that cuts across the typical divisions of responsibility, such as logging and transaction management. The core construct of AOP is the aspect, which encapsulates behaviors affecting multiple classes into reusable modules. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)How the AOP used in Spring?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;AOP is used in the Spring Framework: To provide declarative enterprise services, especially as a replacement for EJB declarative services. The most important such service is declarative transaction management, which builds on the Spring Framework's transaction abstraction.To allow users to implement custom aspects, complementing their use of OOP with AOP. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What are the types of the transaction management Spring supports ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Spring Framework supports:&lt;br /&gt;&lt;br /&gt;Programmatic transaction management. &lt;br /&gt;Declarative transaction management. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What are the benefits of the Spring Framework transaction management ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The Spring Framework provides a consistent abstraction for transaction management that delivers the following benefits: &lt;br /&gt;&lt;br /&gt;Provides a consistent programming model across different transaction APIs such as JTA, JDBC, Hibernate, JPA, and JDO. &lt;br /&gt;Supports declarative transaction management. &lt;br /&gt;Provides a simpler API for programmatic transaction management than a number of complex transaction APIs such as JTA. &lt;br /&gt;Integrates very well with Spring's various data access abstractions. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)Why most users of the Spring Framework choose declarative transaction management ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Most users of the Spring Framework choose declarative transaction management because it is the option with the least impact on application code, and hence is most consistent with the ideals of a non-invasive lightweight container.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Q)When to use programmatic and declarative transaction management ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Programmatic transaction management is usually a good idea only if you have a small number of transactional operations. &lt;br /&gt;On the other hand, if your application has numerous transactional operations, declarative transaction management is usually worthwhile. It keeps transaction management out of business logic, and is not difficult to configure. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)Explain about the Spring DAO support ? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The Data Access Object (DAO) support in Spring is aimed at making it easy to work with data access technologies like JDBC, Hibernate or JDO in a consistent way. This allows one to switch between the persistence technologies fairly easily and it also allows one to code without worrying about catching exceptions that are specific to each technology.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What are the exceptions thrown by the Spring DAO classes ? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Spring DAO classes throw exceptions which are subclasses of DataAccessException(org.springframework.dao.DataAccessException).Spring provides a convenient translation from technology-specific exceptions like SQLException to its own exception class hierarchy with the DataAccessException as the root exception. These exceptions wrap the original exception.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is Spring's JdbcTemplate ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Spring's JdbcTemplate is central class to interact with a database through JDBC. JdbcTemplate provides many convenience methods for doing things such as converting database data into primitives or objects, executing prepared and callable statements, and providing custom database error handling. &lt;br /&gt;&lt;br /&gt;JdbcTemplate template = new JdbcTemplate(myDataSource);&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-8461139099057348664?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/8461139099057348664/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/01/spring-interview-questions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/8461139099057348664'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/8461139099057348664'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2009/01/spring-interview-questions.html' title='Spring Interview Questions'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-3604410011928139589</id><published>2008-12-31T14:30:00.000-08:00</published><updated>2009-01-17T11:25:46.599-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Struts'/><title type='text'>Struts Interview Questions</title><content type='html'>&lt;strong&gt;Q: What is  Struts Framework?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A: Struts is MVC architecture and The aim of MVC architecture is to separate the business logic and data of the application from the presentation of data to the user. Following is the small description of each of the components in MVC architecture:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Controller :&lt;/strong&gt; All the user requests to the application go through the controller. The controller intercepts the requests from view and passes it to the model for appropriate action. Based on the result of the action on data, the controller directs the user to the subsequent view&lt;br /&gt;Example :: Action Servlet&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Model :&lt;/strong&gt; The model represents the data of an application. Anything that an application will persist becomes a part of model. The model also defines the way of accessing this data ( the business logic of application) for manipulation. It knows nothing about the way the data will be displayed by the application. It just provides service to access the data and modify it.&lt;br /&gt;Example :: Java Bean,EJB&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;View :&lt;/strong&gt; The view represents the presentation of the application. The view queries the model for its content and renders it. The way the model will be rendered is defined by the view. The view is not dependent on data or application logic changes and remains same even if the business logic undergoes modification.&lt;br /&gt;Example :: Jsp,Html&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What is Action Class and Write code of any Action Class?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A: The class org.apache.struts.action.ActionServlet is the called the ActionServlet which plays the role of controller. All the requests to the server goes through the controller. Controller is responsible for handling all the requests.and the purpose of Action Class is to translate the HttpServletRequest to the business logic. To use the Action, we need to  Subclass and overwrite the execute()  method. &lt;br /&gt;&lt;br /&gt;Here is the code of Action Class that returns the ActionForward object.&lt;br /&gt;&lt;br /&gt;TestAction.java &lt;br /&gt;&lt;br /&gt;package struts.com.example;&lt;br /&gt;import javax.servlet.http.HttpServletRequest;&lt;br /&gt;import javax.servlet.http.HttpServletResponse;&lt;br /&gt;import org.apache.struts.action.Action;&lt;br /&gt;import org.apache.struts.action.ActionForm;&lt;br /&gt;import org.apache.struts.action.ActionForward;&lt;br /&gt;import org.apache.struts.action.ActionMapping;&lt;br /&gt;&lt;br /&gt;public class TestAction extends Action&lt;br /&gt;{&lt;br /&gt;  public ActionForward execute(&lt;br /&gt;    ActionMapping mapping,&lt;br /&gt;    ActionForm form,&lt;br /&gt;    HttpServletRequest request,&lt;br /&gt;    HttpServletResponse response) throws Exception{&lt;br /&gt;      return mapping.findForward("testAction");&lt;br /&gt;  }&lt;br /&gt;}  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: How you will make available any Message Resources Definitions file to the Struts Framework Environment?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A: Message Resources Definitions file are simple .properties files .&lt;br /&gt;   Message Resources Definitions files can be added to the struts-config.xml file through message-resources tag.&lt;br /&gt;Example:&lt;br /&gt;&lt;message-resources parameter="MessageResources" /&gt;&lt;br /&gt;      &lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Q: What is ActionForm?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A: An ActionForm is a JavaBean that extends org.apache.struts.action.ActionForm. ActionForm maintains the session state for web application and the ActionForm object is automatically populated on the server side with data entered from a form on the client side.&lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What is Struts Validator Framework and validation XML files ?&lt;/strong&gt;&lt;br /&gt;A: Struts Framework provides the functionality to validate the form data. It can be use to validate the data on the users browser as well as on the server side.    &lt;br /&gt;&lt;br /&gt;The Validator Framework uses two XML configuration files &lt;br /&gt;&lt;br /&gt;1) validator-rules.xml &lt;br /&gt;The validator-rules.xml defines the standard validation routines, these are reusable and used in validation.xml. to define the form specific validations. &lt;br /&gt;&lt;br /&gt;2)validation.xml&lt;br /&gt;The validation.xml file is used to declare sets of validations that should be applied to Form Beans. Each Form Bean you want to validate has its own definition in this file.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q. How you will display validation fail errors on jsp page?&lt;/strong&gt;&lt;br /&gt;A: Following tag displays all the errors:&lt;br /&gt;html:errors tag&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q.What are the various Struts tag libraries? &lt;/strong&gt;&lt;br /&gt;A)The various Struts tag libraries are:&lt;br /&gt;&lt;br /&gt;Bean Tags &lt;br /&gt;Logic Tags&lt;br /&gt;HTML Tags  &lt;br /&gt;Template Tags &lt;br /&gt;Nested Tags &lt;br /&gt;Tiles Tags &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)Can we have more than one struts-config.xml file for a single Struts application? &lt;/strong&gt;&lt;br /&gt;A)Yes, application can have more than one struts-config.xml for a single Struts application. They can be included in param-value of web.xml.&lt;br /&gt;Example :: /WEB-INF/struts-config.xml,/WEB-INF/struts-admin.xml,/WEB-INF/struts-config-forms.xml&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What is DynaActionForm and how do you create DynaActionForm?? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A specialized subclass of ActionForm that allows the creation of form beans with dynamic sets of properties (configured in configuration file), without requiring the developer to create a Java class for each type of form bean.&lt;br /&gt;&lt;br /&gt;Using a DynaActionForm instead of a custom subclass of ActionForm is relatively straightforward.&lt;br /&gt;&lt;br /&gt;In struts-config.xml: use your form-bean to be an org.apache.struts.action.DynaActionForm instead of some subclass of ActionForm&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-3604410011928139589?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/3604410011928139589/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2008/12/struts-interview-questions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/3604410011928139589'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/3604410011928139589'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2008/12/struts-interview-questions.html' title='Struts Interview Questions'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-9060958298982141440</id><published>2008-12-30T17:44:00.000-08:00</published><updated>2009-01-17T11:23:50.293-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sql'/><title type='text'>Sql Interview Questions</title><content type='html'>&lt;strong&gt;Q What is the diffrence between delete and truncate?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A •  1)The deletion of each row gets logged in the transaction log, which makes it slow.&lt;br /&gt;&lt;br /&gt;2)Truncate table  deletes all the rows in a table, but it won’t log the deletion of each row, instead it logs the de-allocation of the data pages of the table, which makes it faster. Of course, truncate table cannot be rolled back., but the table structure and its columns, constraints, indexes etc., remains as it is.&lt;br /&gt;&lt;br /&gt;3)Truncate table is functionally identical to delete statement with no “where clause” both remove all rows in the table. But truncate table is faster and uses fewer system and transaction log resources than delete.&lt;br /&gt;&lt;br /&gt;4)You cannot use truncate table on a table referenced by a foreign key constraint; instead, use delete statement without a where clause. Because truncate table is not logged, it cannot activate a trigger.&lt;br /&gt;&lt;br /&gt;5)Truncate table may not be used on tables participating in an indexed view.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q) What are basic SQL Optimization Tips ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;1)Use views and stored procedures instead of heavy-duty queries.&lt;br /&gt;2)Try to avoid using SQL Server cursors, whenever possible.&lt;br /&gt;3)Try to avoid using the DISTINCT clause, whenever possible.&lt;br /&gt;4)Try to restrict the queries result set by using the WHERE clause.&lt;br /&gt;5)Try to avoid the HAVING clause, whenever possible.&lt;br /&gt;6)Try to restrict the queries result set by returning only the particular columns from the table, not all table's columns.&lt;br /&gt;7)If you need to return the total table's row count, you can use alternative way instead of SELECT COUNT(*) statement.&lt;br /&gt;8)Try to use constraints instead of triggers, whenever possible.&lt;br /&gt;9)Use table variables instead of temporary tables.&lt;br /&gt;10)Use the select statements with TOP keyword or the SET ROWCOUNT statement, if you need to return only the first n rows.&lt;br /&gt;11)Use the FAST number_rows table hint if you need to quickly return 'number_rows' rows.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What are the advantages of Stored Procedures?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;1)Stored Procedures are stored in the database and  there is no need to transfer the code from the client to the database server,this results in much less network traffic and again improves scalability.&lt;br /&gt;&lt;br /&gt;2)Stored Procedures are pre-compiled and executes on the database server side which is likely to me more faster and powerful &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)How SQL Performance Tuning using Indexes?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A) Indexes directly improve the performance of database applications and  looks for a specific record or set of records with a join condition,where clause,group by and order by.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-9060958298982141440?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/9060958298982141440/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2008/12/sql-interview-questions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/9060958298982141440'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/9060958298982141440'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2008/12/sql-interview-questions.html' title='Sql Interview Questions'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-6733455634811328105</id><published>2008-12-30T12:24:00.000-08:00</published><updated>2009-01-24T20:23:37.640-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Servlet'/><title type='text'>Servlet Interview Questions</title><content type='html'>&lt;strong&gt;Q: Explain the life cycle methods of a Servlet.&lt;/strong&gt;&lt;br /&gt; &lt;br /&gt;A: The javax.servlet.Servlet interface defines the three methods known as life-cycle method.&lt;br /&gt;&lt;strong&gt;Initializing a Servlet:&lt;/strong&gt;public void init(ServletConfig config) throws ServletException&lt;br /&gt;&lt;strong&gt;Interacting with Clients:&lt;/strong&gt;public void service( ServletRequest req, ServletResponse res) throws ServletException, IOException&lt;br /&gt;&lt;strong&gt;Destroying a Servlet&lt;/strong&gt;&lt;br /&gt;public void destroy()&lt;br /&gt;First the servlet is constructed, then initialized wih the init() method.&lt;br /&gt;Any request from client are handled initially by the service() method before delegating to the doXxx() methods in the case of HttpServlet.&lt;br /&gt;&lt;br /&gt;The servlet is removed from service, destroyed with the destroy() methid, then garbaged collected and finalized. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What is the difference between HttpServlet and GenericServlet?&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;A: A GenericServlet has a service() method aimed to handle requests. HttpServlet extends GenericServlet and adds support for doGet(), doPost(), doHead() methods (HTTP 1.0) plus doPut(), doOptions(), doDelete(), doTrace() methods (HTTP 1.1). &lt;br /&gt;Both these classes are abstract. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: Explain ServletContext.&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;A: ServletContext interface is a window for a servlet to view it's environment. A servlet can use this interface to get information such as initialization parameters for the web applicationor servlet container's version. Every web application has one and only one ServletContext and is accessible to all active resource of that application. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What is the difference between Difference between doGet() and doPost()?&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;Answer: doGet is used when there is a requirement of sending data appended to a query string in the URL. The doGet models the GET method of Http and it is used to retrieve the info on the client from some server as a request to it. The doGet cannot be used to send too much info appended as a query stream. GET puts the form values into the URL string. GET is limited to about 256 characters (usually a browser limitation) and creates really ugly URLs.&lt;br /&gt;A request string for doGet() looks like the following: &lt;br /&gt;http://www.allapplabs.com/svt1?p1=v1&amp;p2=v2&amp;...&amp;pN=vN&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;POST allows you to have extremely dense forms and pass that to the server without clutter or limitation in size. e.g. you obviously can't send a file from the client to the server via GET. POST has no limit on the amount of data you can send and because the data does not show up on the URL you can send passwords. But this does not mean that POST is truly secure. For real security you have to look into encryption which is an entirely different topic&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What is the difference between ServletContext and ServletConfig?&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;A: ServletContext: Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file.The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized &lt;br /&gt;&lt;br /&gt;ServletConfig: The object created after a servlet is instantiated and its default constructor is read. It is created to pass initialization information to the servlet&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q :: Difference between forward and sendRedirect?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A :: When you invoke a forward request, the request is sent to another resource on the server, without the client being informed that a different resource is going to process the request. This process occurs completly with in the web container.&lt;br /&gt;&lt;br /&gt;When a sendRedirtect method is invoked, it causes the web container to return to the browser indicating that a new URL should be requested. Because the browser issues a completly new request any object that are stored as request attributes before the redirect occurs will be lost. This extra round trip a redirect is slower than forward.and you want to forward to is not in the same web application, use sendRedirect(). &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: What are the common mechanisms used for session tracking?&lt;/strong&gt; &lt;br /&gt;A: Cookies&lt;br /&gt;SSL sessions&lt;br /&gt;URL- rewriting &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q: Explain the directory structure of a web application.&lt;/strong&gt; &lt;br /&gt;A: The directory structure of a web application consists of two parts. &lt;br /&gt;1) private directory called WEB-INF&lt;br /&gt;2) public resource directory which contains public resource folder.&lt;br /&gt;&lt;br /&gt;WEB-INF folder consists of &lt;br /&gt;1. web.xml&lt;br /&gt;2. classes directory&lt;br /&gt;3. lib directory&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q.What is the difference between the getRequestDispatcher(String path) ServletRequest interface and ServletContext interface?  &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The getRequestDispatcher(String path) method of ServletRequest interface accepts parameter the path to the resource to be included or forwarded to, which can be relative to the request of the calling servlet. If the path begins with a "/" it is interpreted as relative to the current context root.&lt;br /&gt;&lt;br /&gt;The getRequestDispatcher(String path) method of ServletContext interface cannot accepts relative paths. All path must sart with a "/" and are interpreted as relative to curent context root. If the resource is not available, or if the server has not implemented a RequestDispatcher object for that type of resource, getRequestDispatcher will return null. Your servlet should be prepared to deal with this condition.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-6733455634811328105?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/6733455634811328105/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2008/12/servlet-interview-questions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/6733455634811328105'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/6733455634811328105'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2008/12/servlet-interview-questions.html' title='Servlet Interview Questions'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-4219365265491024593</id><published>2008-12-29T20:59:00.001-08:00</published><updated>2009-01-17T11:21:36.559-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Jsp'/><title type='text'>JSP Interview Questions</title><content type='html'>&lt;strong&gt;Q)What are Jsp Tags?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A)Directive tag &lt;br /&gt;Declaration tag &lt;br /&gt;Expression tag&lt;br /&gt;Scriptlet tag      &lt;br /&gt;&lt;strong&gt;Declarations&lt;/strong&gt;&lt;br /&gt;This tag is used for defining the functions and variables to be used in the JSP.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Scriplets&lt;/strong&gt;&lt;br /&gt;In this tag we can insert any amount of valid java code and these codes are placed in _jspService method by the JSP engine.&lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;Expressions&lt;/strong&gt;&lt;br /&gt;We can use this tag to output any data on the generated page. These data are automatically converted to string and printed on the output stream&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Directives&lt;/strong&gt;&lt;br /&gt;In the directives we can import packages, define error handling pages or the session information of the JSP page.&lt;br /&gt;&lt;br /&gt;language &lt;br /&gt;extends &lt;br /&gt;import &lt;br /&gt;session &lt;br /&gt;buffer &lt;br /&gt;autoFlush &lt;br /&gt;isThreadSafe &lt;br /&gt;info &lt;br /&gt;errorPage &lt;br /&gt;IsErrorPage &lt;br /&gt;contentType &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What are implicit objects?&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;A)Certain objects that are available for the use in JSP documents without being declared first. These objects are parsed by the JSP engine and inserted into the generated servlet. &lt;br /&gt;&lt;br /&gt;1)request&lt;br /&gt;2)response&lt;br /&gt;3)pageContext&lt;br /&gt;4)session&lt;br /&gt;5)application&lt;br /&gt;6)outconfig&lt;br /&gt;7)page&lt;br /&gt;8)exception&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)Difference between forward and sendRedirect?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A)When you invoke a forward request, the request is sent to another resource on the server, without the client being informed that a different resource is going to process the request. This process occurs completly with in the web container.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When a sendRedirtect method is invoked, it causes the web container to return to the browser indicating that a new URL should be requested. Because the browser issues a completly new request any object that are stored as request attributes before the redirect occurs will be lost. This extra round trip a redirect is slower than forward.and you want to forward to is not in the same web application, use sendRedirect(). &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)What are the different scope values for the Jsp Use Bean ?&lt;/strong&gt;&lt;br /&gt;A)&lt;br /&gt;1. page2. request3.session4.application&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)Explain the life-cycle mehtods in JSP?&lt;/strong&gt;&lt;br /&gt;A)&lt;br /&gt;&lt;strong&gt;JSP Page Translation :&lt;/strong&gt;&lt;br /&gt;java servlet file is generated from the JSP source file and the generated java servlet file is compiled into a java servlet class.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;jspInit( ):&lt;/strong&gt;&lt;br /&gt;This method is called when the instance is created and it is called only once during JSP life cycle. It is called for the servlet instance initialization. &lt;br /&gt;&lt;strong&gt;_jspService():&lt;/strong&gt;&lt;br /&gt;This method is called for every request of this JSP during its life cycle. It passes the request and the response objects. _jspService() cannot be overridden. &lt;br /&gt;&lt;strong&gt;jspDestroy():&lt;/strong&gt;&lt;br /&gt;This method is called when this JSP is destroyed and will not be available for future requests. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)How can I implement a thread-safe JSP page? What are the advantages and Disadvantages of using it?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A)You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive &lt;%@ page isThreadSafe="false" %&gt; within your JSP page. With this, instead of a single instance of the servlet generated for your JSP page loaded in memory, you will have N instances of the servlet loaded and initialized, with the service method of each instance effectively synchronized. You can typically control the number of instances (N) that are instantiated for all servlets implementing SingleThreadModel through the admin screen for your JSP engine. More importantly, avoid using the tag for variables. If you do use this tag, then you should set isThreadSafe to true, as mentioned above. Otherwise, all requests to that page will access those variables, causing a nasty race condition. SingleThreadModel is not recommended for normal use. There are many pitfalls, including the example above of not being able to use &lt;%! %&gt;. You should try really hard to make them thread-safe the old fashioned way: by making them thread-safe .&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q)How can I enable session tracking for JSP pages if the browser has disabled cookies?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A)The session tracking uses cookies by default to associate a session identifier with a unique user. If the browser does not support cookies, or if cookies are disabled, you can still enable session tracking using URL rewriting. URL rewriting essentially includes the session ID within the link itself as a name/value pair. However, for this to be effective, you need to append the session ID for each and every link that is part of your servlet response. Adding the session ID to a link is greatly simplified by means of of a couple of methods: response.encodeURL() associates a session ID with a given URL, and if you are using redirection, response.encodeRedirectURL() can be used by giving the redirected URL as input. Both encodeURL() and encodeRedirectedURL() first determine whether cookies are supported by the browser; if so, the input URL is returned unchanged since the session ID will be persisted as a cookie.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-4219365265491024593?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/4219365265491024593/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2008/12/jsp-interview-questions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/4219365265491024593'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/4219365265491024593'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2008/12/jsp-interview-questions.html' title='JSP Interview Questions'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-7390759207337188765</id><published>2008-12-29T16:54:00.000-08:00</published><updated>2009-01-17T11:20:59.887-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Multi Threading'/><title type='text'>multithreading interview questions</title><content type='html'>&lt;strong&gt;1)What is Thread ?&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;A thread is an independent path of execution in a system.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;2)What is the difference between the Thread and Runnable ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Thread Class ::&lt;/strong&gt; if you extend a Thread class , it does not allow to extend another class. A class extends the Thread class and overrides it's run() method.&lt;br /&gt;&lt;strong&gt;Runnable interface ::&lt;/strong&gt; if you implement Runnable interface ,you can extend another class. A class implements the Runnable interface, which has one method: run(). The class passes a reference to itself when it creates a thread. The thread then calls back to the run() method in the class.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;3)What is multithreading and what are the methods for inter-thread communication and what is the class in which these methods are defined? &lt;/strong&gt;-&lt;br /&gt;Multithreading is the mechanism in which more than one thread run independent of each other within the process. wait (), notify () and notifyAll() methods can be used for inter-thread communication and these methods are in Object class.wait() : When a thread executes a call to wait() method, it surrenders the object lock and enters into a waiting state.notify() or notifyAll() : To remove a thread from the waiting state, some other thread must make a call to notify() or notifyAll() method on the same object.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;4)What is the difference between sleep() and wait() in multithreading ?&lt;/strong&gt;&lt;br /&gt;the difference i think is that a wait() realeases the lock for the synchronized object butsleep() don't..so it may be interesting to implementthe behaviour of wait() and notify() and compare withsleep()....&lt;br /&gt;Never use sleep when you are using synchronization, it could cause deadlocks.Instead, use wait as wait will release all your locks and thus reduce the chance of deadlock.Remember that your thread may be holding locks that you are unaware of so it's best to wait (not sleep).&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;5)What is deadlock?&lt;/strong&gt;&lt;br /&gt;- When two threads are waiting each other and can’t precede the program is said to be deadlock.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;6)What is Demoniac Thread ?&lt;/strong&gt;&lt;br /&gt;A thread that exists/runs in the background.basically a low priority thread.garbage collector thread is an example for Deamon thread&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;strong&gt;7) What are the methods available in the Thread class? &lt;/strong&gt;&lt;br /&gt;1.isAlive() 2.join() 3.resume()4.suspend()5.stop()6.start()7.sleep()8.destroy()&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-7390759207337188765?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/7390759207337188765/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2008/12/multithreading-interview-questions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/7390759207337188765'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/7390759207337188765'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2008/12/multithreading-interview-questions.html' title='multithreading interview questions'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-74129442071215188</id><published>2008-12-28T17:05:00.000-08:00</published><updated>2009-01-24T18:01:00.820-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Core Java'/><title type='text'>Core Java Interview Questions</title><content type='html'>&lt;strong&gt;1)What are Encapsulation, Inheritance Polymorphism? &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;- &lt;strong&gt;Encapsulation&lt;/strong&gt; is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Inheritance&lt;/strong&gt; is the process by which one object acquires the properties of another object.&lt;br /&gt;&lt;br /&gt;1. class inheritance - create a new class as an extension of another class, primarily for the purposeof code reuse. That is, the derived class inherits the public methods and public data of thebase class. Java only allows a class to have one immediate base class, i.e., single classinheritance.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Polymorphism&lt;/strong&gt; is a term that describes a situation where one name may refer to different methods. In java there are two type of polymorphism: overloading type and overriding type.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;2)What are different types of access modifiers?&lt;/strong&gt;&lt;br /&gt;public: Any thing declared as public can be accessed from anywhere.&lt;br /&gt;private: Any thing declared as private can’t be seen outside of its class.&lt;br /&gt;protected: Any thing declared as protected can be accessed by classes in the same package and subclasses in the other packages.&lt;br /&gt;default modifier : Can be accessed only to classes in the same package.&lt;br /&gt;&lt;br /&gt;Modifier Class Package Subclass World&lt;br /&gt;public ------Y--Y-------- Y-------- Y&lt;br /&gt;protected---Y--Y-------- Y-------- N&lt;br /&gt;default------Y--Y-------- N-------- N&lt;br /&gt;private -----Y--N-------- N-------- N&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;3)What is the difference between Instance variable and Static Variables ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Instance variable :: &lt;/strong&gt;Copy belong to Particular class,and will be created with new key word&lt;br /&gt;&lt;strong&gt;Class Variables (Static Variables)&lt;/strong&gt; :: A class variable is any field declared with the static modifier; this tells the compiler that there is exactly one copy of this variable in existence, regardless of how many times the class has been instantiated. A field defining the number of gears for a particular kind of bicycle could be marked as static since conceptually the same number of gears will apply to all instances. The code static int numGears = 6; would create such a static field. Additionally, the keyword final could be added to indicate that the number of gears will never change.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;4)What is the difference between checked and unchecked exceptions?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Checked: You have to catch or declare it. It's stuff that your program can expect to go wrong and should be able to deal with.&lt;br /&gt;Unchecked: You don't have to catch (in fact, usually shouldn't) or declare it. It's stuff that you can't anticipate or can't really do anything about--like a bug in a method you're calling, or a problem in the VM.&lt;br /&gt;RuntimeException and its children are Exceptions that are for program bugs. Error and its children are for VM problems.&lt;br /&gt;You don’t need to declare unchecked Exceptions, those that derive from java.lang.Error and java.lang.RuntimeException, in your throws clauses. Checked Exceptions usually derive from java.lang.Exception.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;5)What is difference between overloading and overriding?&lt;/strong&gt;&lt;br /&gt;a) In overloading, there is a relationship between methods available in the same class whereas in overriding, there is relationship between a superclass method and subclass method.&lt;br /&gt;b) Overloading does not block inheritance from the superclass whereas overriding blocks inheritance from the superclass.&lt;br /&gt;c) In overloading, separate methods share the same name whereas in overriding, subclass method replaces the superclass.&lt;br /&gt;d) Overloading must have different method signatures whereas overriding must have same signature.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;6)What is the difference between this() and super()?&lt;/strong&gt;&lt;br /&gt;this() can be used to invoke a constructor of the same class whereas super() can be used to invoke a super class constructor.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;7)What is the difference between abstract class and interface? &lt;/strong&gt;&lt;br /&gt;a) All the methods declared inside an interface are abstract whereas abstract class must have at least one abstract method and others may be concrete or abstract. b) In abstract class, key word abstract must be used for the methods whereas interface we need not use that keyword for the methods. c) Abstract class must have subclasses whereas interface can’t have subclasses.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;8)What is the difference between String and String Buffer? &lt;/strong&gt;&lt;br /&gt;a) String objects are constants and immutable whereas StringBuffer objects are not. b) String class supports constant strings whereas StringBuffer class supports growable and modifiable strings.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;9)What is the difference between set and list?&lt;/strong&gt;&lt;br /&gt;- Set stores elements in an unordered way but does not contain duplicate elements, whereas list stores elements in an ordered way but may contain duplicate elements.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;10)What is final, finalize() and finally?&lt;/strong&gt;&lt;br /&gt;- final : final keyword can be used for class, method and variables. A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods. A final method can’t be overridden. A final variable can’t change from its initialized value.&lt;br /&gt;finalize() : finalize() method is used just before an object is destroyed and can be called just prior to garbage collection.&lt;br /&gt;finally : finally, a key word used in exception handling, creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. The finally block will execute whether or not an exception is thrown. For example, if a method opens a file upon exit, then you will not want the code that closes the file to be bypassed by the exception-handling mechanism. This finally keyword is designed to address this contingency.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;11)What is Garbage Collection and how to call it explicitly?&lt;/strong&gt;&lt;br /&gt;- When an object is no longer referred to by any variable, java automatically reclaims memory used by that object. This is known as garbage collection. System. gc() method may be used to call it explicitly.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;12)What are Transient and Volatile Modifiers? &lt;/strong&gt;&lt;br /&gt;Transient: The transient modifier applies to variables only and it is not stored as part of its object’s Persistent state. Transient variables are not serialized.&lt;br /&gt;Volatile: Volatile modifier applies to variables only and it tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;13)What are inner class and anonymous class?&lt;/strong&gt;&lt;br /&gt;Inner class : classes defined in other classes, including those defined in methods are called inner classes. An inner class can have any accessibility including private.&lt;br /&gt;Anonymous class : Anonymous class is a class defined inside a method without a name and is instantiated and declared in the same place and cannot have explicit constructors.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;14)Can you have an inner class inside a method and what variables can you access?&lt;/strong&gt;&lt;br /&gt;- Yes, we can have an inner class inside a method and final variables can be accessed.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;15)What is the difference between process andthread? &lt;/strong&gt;&lt;br /&gt;Process is a program in execution whereas thread is a separate path of execution in a program.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;16)What is multithreading and what are the methods for inter-thread communication and what is the class in which these methods are defined? &lt;/strong&gt;&lt;br /&gt;- Multithreading is the mechanism in which more than one thread run independent of each other within the process. wait (), notify () and notifyAll() methods can be used for inter-thread communication and these methods are in Object class.&lt;br /&gt;wait() : When a thread executes a call to wait() method, it surrenders the object lock and enters into a waiting state.&lt;br /&gt;notify() or notifyAll() : To remove a thread from the waiting state, some other thread must make a call to notify() or notifyAll() method on the same object.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;17)What is the class and interface in java to create thread and which is the most advantageous method? &lt;/strong&gt;&lt;br /&gt;- Thread class and Runnable interface can be used to create threads and using Runnable interface is the most advantageous method to create threads because we need not extend thread class here.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;18)What are the states associated in the thread? &lt;/strong&gt;&lt;br /&gt;- Thread contains ready, running, waiting and dead states.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;19)What is synchronization?&lt;/strong&gt;&lt;br /&gt;- Synchronization is the mechanism that ensures that only one thread is accessed the resources at a time.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;20)When you will synchronize a piece of your code?&lt;/strong&gt;&lt;br /&gt;- When you expect your code will be accessed by different threads and these threads may change a particular data causing data corruption.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;21)What is deadlock? &lt;/strong&gt;&lt;br /&gt;- When two threads are waiting each other and can’t precede the program is said to be deadlock.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;22)What is daemon thread and which method is used to create the daemon thread?&lt;/strong&gt;&lt;br /&gt;- Daemon thread is a low priority thread which runs intermittently in the back ground doing the garbage collection operation for the java runtime system. setDaemon method is used to create a daemon thread.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;23)What are Vector, Hashtable, LinkedList and Enumeration?&lt;/strong&gt;&lt;br /&gt;- Vector : The Vector class provides the capability to implement a growable array of objects. Hashtable : The Hashtable class implements a Hashtable data structure. A Hashtable indexes and stores objects in a dictionary using hash codes as the object’s keys. Hash codes are integer values that identify objects. LinkedList: Removing or inserting elements in the middle of an array can be done using LinkedList. A LinkedList stores each object in a separate link whereas an array stores object references in consecutive locations. Enumeration: An object that implements the Enumeration interface generates a series of elements, one at a time. It has two methods, namely hasMoreElements() and nextElement(). HasMoreElemnts() tests if this enumeration has more elements and nextElement method returns successive elements of the series.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;24)What is Singleton Class ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Singleton ensure that the user can create only one instance of this class and provides access to this object from all areas of the application&lt;br /&gt;&lt;br /&gt;public class ClassSingleton&lt;br /&gt;{&lt;br /&gt;private static ClassSingleton instance = null;&lt;br /&gt;protected ClassSingleton()&lt;br /&gt;{&lt;br /&gt;// Exists only to defeat instantiation.&lt;br /&gt;}&lt;br /&gt;public static ClassSingleton getInstance()&lt;br /&gt;{&lt;br /&gt;if(instance == null)&lt;br /&gt;{&lt;br /&gt;instance = new ClassSingleton();&lt;br /&gt;}&lt;br /&gt;return instance;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;25)What is the diffrence between Double vs BigDecimal ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Double ::The Double class wraps a value of the primitive type double in an object. An object of type Double contains a single field whose type is double. &lt;br /&gt;&lt;br /&gt;In addition, this class provides several methods for converting a double to a String and a String to a double, as well as other constants and methods useful when dealing with a double. &lt;br /&gt;&lt;br /&gt;BigDecimal :: BigDecimal extends Number implements Comparable&lt;br /&gt;&lt;br /&gt;It allows greater preceision than Double.&lt;br /&gt;&lt;br /&gt;The BigDecimal class gives its user complete control over rounding behavior.&lt;br /&gt;&lt;br /&gt;The BigDecimal class provides operations for arithmetic, scale manipulation, rounding, comparison, hashing, and format conversion. The toString() method provides a canonical representation of a BigDecimal. &lt;br /&gt;&lt;br /&gt;Immutable, arbitrary-precision signed decimal numbers. A BigDecimal consists of an arbitrary precision integer unscaled value and a 32-bit integer scale.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;26)What is the diffrence between Vector and ArrayList?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Vector and ArrayList both of these classes are implemented using dynamically resizable&lt;br /&gt;The Vector is synchronized and the ArrayList is not synchronized &lt;br /&gt;The Vector class is less efficient than the ArrayList class mainly because the Vector class is synchronized&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;27) Is it possible to override the main method? &lt;/strong&gt;&lt;br /&gt;NO, because main is a static method. A static method can't be overridden in Java.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;28)What are the diffrence between JDK, JRE and JVM ?&lt;/strong&gt;&lt;br /&gt;JDK: Java Developer Kit contains tools needed to develop the Java programs, and JRE to run the programs. The tools include compiler (javac.exe), Java application launcher (java.exe), Appletviewer, etc…&lt;br /&gt;&lt;br /&gt;Compiler converts java code into byte code. Java application launcher opens a JRE, loads the class, and invokes its main method.&lt;br /&gt;&lt;br /&gt;You need JDK, if at all you want to write your own programs, and to compile them. For running java programs, JRE is sufficient.&lt;br /&gt;&lt;br /&gt;JRE: Java Runtime Environment contains JVM, class libraries, and other supporting files. Actually JVM runs the program, and it uses the class libraries, and other supporting files provided in JRE. If you want to run any java program, you need to have JRE installed in the system.&lt;br /&gt;&lt;br /&gt;JVM: Java Virtual Machine interprets the bytecode into the machine code depending upon the underlying operating system and hardware combination. It is responsible for all the things like garbage collection, array bounds checking, etc… JVM is platform dependent.&lt;br /&gt;&lt;br /&gt;The JVM is called "virtual" because it provides a machine interface that does not depend on the underlying operating system and machine hardware architecture. This independence from hardware and operating system is a cornerstone of the write-once run-anywhere value of Java programs.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-74129442071215188?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/74129442071215188/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2008/12/core-java-interviewquestions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/74129442071215188'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/74129442071215188'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2008/12/core-java-interviewquestions.html' title='Core Java Interview Questions'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3690933364718152435.post-6392562798137098779</id><published>2008-12-24T20:53:00.000-08:00</published><updated>2009-07-25T13:41:47.600-07:00</updated><title type='text'>GWT DecimalFormat Example</title><content type='html'>&lt;dl&gt;&lt;dt&gt;&lt;pre&gt;public class &lt;b&gt;&lt;span style="color:#33cc00;"&gt;NumberFormat&lt;/span&gt;&lt;/b&gt;&lt;dt&gt;extends java.lang.Object &lt;/dt&gt;&lt;/pre&gt;&lt;/dt&gt;&lt;/dl&gt;&lt;p&gt;Formats and parses numbers using locale-sensitive patterns.&lt;br /&gt;&lt;br /&gt;This class provides comprehensive and flexible support for a wide variety of&lt;br /&gt;localized formats, including &lt;ul&gt;&lt;li&gt;&lt;b&gt;Locale-specific symbols&lt;/b&gt; such as decimal point, group separator,&lt;br /&gt;digit representation, currency symbol, percent, and permill&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;b&gt;Numeric variations&lt;/b&gt; including integers ("123"), fixed-point&lt;br /&gt;numbers ("123.4"), scientific notation ("1.23E4"), percentages ("12%"), and&lt;br /&gt;currency amounts ("$123")&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;b&gt;Predefined standard patterns&lt;/b&gt; that can be used both for parsing&lt;br /&gt;and formatting, including decimal,&lt;br /&gt;currency,&lt;br /&gt;percentages, and&lt;br /&gt;scientific&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;b&gt;Custom patterns&lt;/b&gt; and supporting features designed to make it&lt;br /&gt;possible to parse and format numbers in any locale, including support for&lt;br /&gt;Western, Arabic, and Indic digits&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;span style="color:#33ff33;"&gt;Patterns&lt;/span&gt;&lt;/h3&gt;&lt;p&gt;Formatting and parsing are based on customizable patterns that can include a&lt;br /&gt;combination of literal characters and special characters that act as&lt;br /&gt;placeholders and are replaced by their localized counterparts. Many&lt;br /&gt;characters in a pattern are taken literally; they are matched during parsing&lt;br /&gt;and output unchanged during formatting. Special characters, on the other&lt;br /&gt;hand, stand for other characters, strings, or classes of characters. For&lt;br /&gt;example, the '&lt;code&gt;#&lt;/code&gt;' character is replaced by a localized digit. &lt;/p&gt;&lt;p&gt;Often the replacement character is the same as the pattern character. In the&lt;br /&gt;U.S. locale, for example, the '&lt;code&gt;,&lt;/code&gt;' grouping character is&lt;br /&gt;replaced by the same character '&lt;code&gt;,&lt;/code&gt;'. However, the replacement&lt;br /&gt;is still actually happening, and in a different locale, the grouping&lt;br /&gt;character may change to a different character, such as '&lt;code&gt;.&lt;/code&gt;'.&lt;br /&gt;Some special characters affect the behavior of the formatter by their&lt;br /&gt;presence. For example, if the percent character is seen, then the value is&lt;br /&gt;multiplied by 100 before being displayed. &lt;/p&gt;&lt;p&gt;The characters listed below are used in patterns. Localized symbols use the&lt;br /&gt;corresponding characters taken from corresponding locale symbol collection,&lt;br /&gt;which can be found in the properties files residing in the&lt;br /&gt;&lt;code&gt;&lt;nobr&gt;com.google.gwt.i18n.client.constants&lt;/nobr&gt;&lt;/code&gt;. To insert&lt;br /&gt;a special character in a pattern as a literal (that is, without any special&lt;br /&gt;meaning) the character must be quoted. There are some exceptions to this&lt;br /&gt;which are noted below. &lt;/p&gt;&lt;p&gt;A &lt;code&gt;NumberFormat&lt;/code&gt; pattern contains a postive and negative&lt;br /&gt;subpattern separated by a semicolon, such as&lt;br /&gt;&lt;code&gt;"#,##0.00;(#,##0.00)"&lt;/code&gt;. Each subpattern has a prefix, a&lt;br /&gt;numeric part, and a suffix. If there is no explicit negative subpattern, the&lt;br /&gt;negative subpattern is the localized minus sign prefixed to the positive&lt;br /&gt;subpattern. That is, &lt;code&gt;"0.00"&lt;/code&gt; alone is equivalent to&lt;br /&gt;&lt;code&gt;"0.00;-0.00"&lt;/code&gt;. If there is an explicit negative subpattern, it&lt;br /&gt;serves only to specify the negative prefix and suffix; the number of digits,&lt;br /&gt;minimal digits, and other characteristics are ignored in the negative&lt;br /&gt;subpattern. That means that &lt;code&gt;"#,##0.0#;(#)"&lt;/code&gt; has precisely the&lt;br /&gt;same result as &lt;code&gt;"#,##0.0#;(#,##0.0#)"&lt;/code&gt;. &lt;/p&gt;&lt;p&gt;The prefixes, suffixes, and various symbols used for infinity, digits,&lt;br /&gt;thousands separators, decimal separators, etc. may be set to arbitrary&lt;br /&gt;values, and they will appear properly during formatting. However, care must&lt;br /&gt;be taken that the symbols and strings do not conflict, or parsing will be&lt;br /&gt;unreliable. For example, the decimal separator and thousands separator should&lt;br /&gt;be distinct characters, or parsing will be impossible. &lt;/p&gt;&lt;p&gt;The grouping separator is a character that separates clusters of integer&lt;br /&gt;digits to make large numbers more legible. It commonly used for thousands,&lt;br /&gt;but in some locales it separates ten-thousands. The grouping size is the&lt;br /&gt;number of digits between the grouping separators, such as 3 for "100,000,000"&lt;br /&gt;or 4 for "1 0000 0000". &lt;/p&gt;&lt;h3&gt;Pattern Grammar (BNF)&lt;/h3&gt;&lt;p&gt;The pattern itself uses the following grammar:&lt;br /&gt;&lt;br /&gt;pattern:=subpattern (';' subpattern)?&lt;br /&gt;subpattern:=prefix? number exponent? suffix?&lt;br /&gt;number:=(integer ('.' fraction)?) sigDigits&lt;br /&gt;prefix:='\u0000'..'\uFFFD' - specialCharacters&lt;br /&gt;suffix:='\u0000'..'\uFFFD' - specialCharacters&lt;br /&gt;integer:='#'* '0'*'0'&lt;br /&gt;fraction:='0'* '#'*&lt;br /&gt;sigDigits:='#'* '@''@'* '#'*&lt;br /&gt;exponent:='E' '+'? '0'* '0'&lt;br /&gt;padSpec:='*' padChar&lt;br /&gt;padChar:='\u0000'..'\uFFFD' - quote&lt;/p&gt;&lt;p&gt;Notation: &lt;/p&gt;&lt;p&gt;X* 0 or more instances of X&lt;br /&gt;X? 0 or 1 instances of X&lt;br /&gt;XY either X or Y&lt;br /&gt;C..D any character from C up to D, inclusive&lt;br /&gt;S-T characters in S, except those in T&lt;/p&gt;&lt;p&gt;&lt;br /&gt;The first subpattern is for positive numbers. The second (optional) subpattern is for negative numbers. &lt;/p&gt;&lt;h3&gt;&lt;span style="color:#33ff33;"&gt;Example&lt;/span&gt;&lt;/h3&gt;&lt;blockquote&gt;&lt;pre&gt;public class NumberFormatExample implements EntryPoint {&lt;br /&gt;&lt;br /&gt;  public void onModuleLoad() {&lt;br /&gt;    NumberFormat fmt = &lt;span style="color:#33ff33;"&gt;NumberFormat.getDecimalFormat();&lt;/span&gt;&lt;br /&gt;    double value = 12345.6789;&lt;br /&gt;    String formatted = fmt.format(value);&lt;br /&gt;    // Prints 1,2345.6789 in the default locale&lt;br /&gt;    GWT.log("Formatted string is" + formatted, null);&lt;br /&gt;&lt;br /&gt;    // Turn a string back into a double&lt;br /&gt;    value = NumberFormat.getDecimalFormat().parse("12345.6789");&lt;br /&gt;    GWT.log("Parsed value is" + value, null);&lt;br /&gt;&lt;br /&gt;    // Scientific notation&lt;br /&gt;    value = 12345.6789;&lt;br /&gt;    formatted = NumberFormat.getScientificFormat().format(value);&lt;br /&gt;    // prints 1.2345E4 in the default locale&lt;br /&gt;    GWT.log("Formatted string is" + formatted, null);&lt;br /&gt;&lt;br /&gt;    // Currency&lt;br /&gt;    fmt = NumberFormat.getCurrencyFormat();&lt;br /&gt;    formatted = fmt.format(123456.7899);&lt;br /&gt;    // prints $123,456.79 in the default locale&lt;br /&gt;    GWT.log("Formatted currency is" + formatted, null);&lt;br /&gt;&lt;br /&gt;    // Custom format&lt;br /&gt;    value = 12345.6789;&lt;br /&gt;    formatted = NumberFormat.getFormat("000000.000000").format(value);&lt;br /&gt;    // prints 012345.678900 in the default locale&lt;br /&gt;    GWT.log("Formatted string is" + formatted, null);&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;&lt;pre&gt;&lt;strong&gt;&lt;span style="font-size:130%;color:#33ff33;"&gt;Constructor Detail&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;a name="NumberFormat(com.google.gwt.i18n.client.constants.NumberConstants, java.lang.String, com.google.gwt.i18n.client.impl.CurrencyData, boolean)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;h3&gt;&lt;br /&gt;NumberFormat&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;protected &lt;b&gt;NumberFormat&lt;/b&gt;(com.google.gwt.i18n.client.constants.NumberConstants numberConstants,&lt;br /&gt;                       java.lang.String pattern,&lt;br /&gt;                       com.google.gwt.i18n.client.impl.CurrencyData cdata,&lt;br /&gt;                       boolean userSuppliedPattern)&lt;br /&gt;&lt;/pre&gt;&lt;dl&gt;&lt;dd&gt;Constructs a format object based on the specified settings.&lt;br /&gt;&lt;/dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt; &lt;dd&gt;&lt;code&gt;numberConstants&lt;/code&gt; - the locale-specific number constants to use for this&lt;br /&gt;format &lt;dd&gt;&lt;code&gt;pattern&lt;/code&gt; - pattern that specify how number should be formatted &lt;dd&gt;&lt;code&gt;cdata&lt;/code&gt; - currency data that should be used &lt;dd&gt;&lt;code&gt;userSuppliedPattern&lt;/code&gt; - true if the pattern was supplied by the user&lt;br /&gt;&lt;hr /&gt;&lt;!-- --&gt;&lt;/dd&gt;&lt;/dl&gt;&lt;/dl&gt;&lt;h3&gt;&lt;br /&gt;NumberFormat&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;protected &lt;b&gt;NumberFormat&lt;/b&gt;(java.lang.String pattern,&lt;br /&gt;                       com.google.gwt.i18n.client.impl.CurrencyData cdata,&lt;br /&gt;                       boolean userSuppliedPattern)&lt;/pre&gt;&lt;dl&gt;&lt;dd&gt;Constructs a format object for the default locale based on the specified&lt;br /&gt;settings.&lt;br /&gt;&lt;/dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt; &lt;dd&gt;&lt;code&gt;pattern&lt;/code&gt; - pattern that specify how number should be formatted &lt;dd&gt;&lt;code&gt;cdata&lt;/code&gt; - currency data that should be used &lt;dd&gt;&lt;code&gt;userSuppliedPattern&lt;/code&gt; - true if the pattern was supplied by the user&lt;/dd&gt;&lt;/dl&gt;&lt;/dl&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;Method Detail&lt;/span&gt;&lt;/strong&gt;&lt;a name="getCurrencyFormat()"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;&lt;br /&gt;getCurrencyFormat&lt;/h3&gt;&lt;pre&gt;&lt;br /&gt;public static &lt;b&gt;NumberFormat&lt;/b&gt; &lt;b&gt;getCurrencyFormat&lt;/b&gt;()&lt;br /&gt;&lt;/pre&gt;&lt;dl&gt;&lt;dd&gt;Provides the standard currency format for the default locale. &lt;/dd&gt;&lt;dl&gt;&lt;br /&gt;&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;dd&gt;a &lt;code&gt;NumberFormat&lt;/code&gt; capable of producing and consuming&lt;br /&gt;currency format for the default locale&lt;/dd&gt;&lt;/dl&gt;&lt;br /&gt;&lt;/dl&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;strong&gt;getCurrencyFormat&lt;/strong&gt;&lt;br /&gt;public static &lt;b&gt;NumberFormat&lt;/b&gt; &lt;b&gt;getCurrencyFormat&lt;/b&gt;(java.lang.String currencyCode)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;dl&gt;&lt;br /&gt;&lt;dd&gt;Provides the standard currency format for the default locale using a&lt;br /&gt;specified currency.&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;/dd&gt;&lt;dl&gt;&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt; &lt;dd&gt;&lt;code&gt;currencyCode&lt;/code&gt; - valid currency code, as defined in&lt;br /&gt;com.google.gwt.i18n.client.constants.CurrencyCodeMapConstants.properties&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;dd&gt;a &lt;code&gt;NumberFormat&lt;/code&gt; capable of producing and consuming&lt;br /&gt;currency format for the default locale&lt;/dd&gt;&lt;/dl&gt;&lt;br /&gt;&lt;/dl&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;strong&gt;getDecimalFormat&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static &lt;b&gt;NumberFormat&lt;/b&gt; &lt;b&gt;getDecimalFormat&lt;/b&gt;()&lt;/pre&gt;&lt;dl&gt;&lt;br /&gt;&lt;dd&gt;Provides the standard decimal format for the default locale. &lt;p&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;/p&gt;&lt;dd&gt;&lt;dl&gt;&lt;dd&gt;a &lt;code&gt;NumberFormat&lt;/code&gt; capable of producing and consuming&lt;br /&gt;decimal format for the default locale&lt;/dd&gt;&lt;/dl&gt;&lt;br /&gt;&lt;/dd&gt;&lt;br /&gt;&lt;/dl&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;strong&gt;getFormat&lt;/strong&gt;&lt;br /&gt;public static &lt;b&gt;NumberFormat&lt;/b&gt; &lt;b&gt;getFormat&lt;/b&gt;(java.lang.String pattern)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;dl&gt;&lt;br /&gt;&lt;dd&gt;Gets a &lt;code&gt;NumberFormat&lt;/code&gt; instance for the default locale using&lt;br /&gt;the specified pattern and the default currencyCode.&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;dd&gt;&lt;dl&gt;&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt; &lt;dd&gt;&lt;code&gt;pattern&lt;/code&gt; - pattern for this formatter&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;dd&gt;a NumberFormat instance&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Throws:&lt;/b&gt;&lt;br /&gt;&lt;dd&gt;&lt;code&gt;java.lang.IllegalArgumentException&lt;/code&gt; - if the specified pattern is invalid&lt;/dd&gt;&lt;/dl&gt;&lt;br /&gt;&lt;/dd&gt;&lt;br /&gt;&lt;/dl&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="getFormat(java.lang.String, java.lang.String)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt;&lt;br /&gt;getFormat&lt;br /&gt;&lt;/h3&gt;&lt;pre&gt;public static &lt;b&gt;NumberFormat&lt;/b&gt; &lt;b&gt;getFormat&lt;/b&gt;(java.lang.String pattern,&lt;br /&gt;                                     java.lang.String currencyCode)&lt;/pre&gt;&lt;dl&gt;&lt;br /&gt;&lt;dd&gt;Gets a custom &lt;code&gt;NumberFormat&lt;/code&gt; instance for the default locale&lt;br /&gt;using the specified pattern and currency code. &lt;/dd&gt;&lt;dl&gt;&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt; &lt;dd&gt;&lt;code&gt;pattern&lt;/code&gt; - pattern for this formatter &lt;dd&gt;&lt;code&gt;currencyCode&lt;/code&gt; - international currency code&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;dd&gt;a NumberFormat instance&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Throws:&lt;/b&gt;&lt;br /&gt;&lt;dd&gt;&lt;code&gt;java.lang.IllegalArgumentException&lt;/code&gt; - if the specified pattern is invalid&lt;/dd&gt;&lt;/dl&gt;&lt;br /&gt;&lt;/dl&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;strong&gt;getPercentFormat&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static &lt;b&gt;NumberFormat&lt;/b&gt; &lt;b&gt;getPercentFormat&lt;/b&gt;()&lt;/pre&gt;&lt;dl&gt;&lt;br /&gt;&lt;dd&gt;Provides the standard percent format for the default locale. &lt;p&gt;&lt;br /&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dl&gt;&lt;dd&gt;a &lt;code&gt;NumberFormat&lt;/code&gt; capable of producing and consuming&lt;br /&gt;percent format for the default locale&lt;/dd&gt;&lt;/dl&gt;&lt;br /&gt;&lt;/dl&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="getScientificFormat()"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt;getScientificFormat&lt;/h3&gt;&lt;pre&gt;&lt;br /&gt;public static &lt;b&gt;NumberFormat&lt;/b&gt; &lt;b&gt;getScientificFormat&lt;/b&gt;()&lt;/pre&gt;&lt;dl&gt;&lt;dd&gt;Provides the standard scientific format for the default locale. &lt;p&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dl&gt;&lt;dd&gt;a &lt;code&gt;NumberFormat&lt;/code&gt; capable of producing and consuming&lt;br /&gt;scientific format for the default locale&lt;/dd&gt;&lt;/dl&gt;&lt;br /&gt;&lt;/dl&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;format&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public java.lang.String &lt;b&gt;format&lt;/b&gt;(double number)&lt;/pre&gt;&lt;dl&gt;&lt;dd&gt;This method formats a double to produce a string. &lt;p&gt;&lt;b&gt;Parameters:&lt;/b&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dl&gt;&lt;dd&gt;&lt;code&gt;number&lt;/code&gt; - The double to format&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;dd&gt;the formatted number string&lt;/dd&gt;&lt;/dl&gt;&lt;/dl&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;getPattern&lt;/strong&gt;&lt;br /&gt;public java.lang.String &lt;b&gt;getPattern&lt;/b&gt;()&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;dl&gt;&lt;br /&gt;&lt;dd&gt;Returns the pattern used by this number format. &lt;hr /&gt;&lt;/dd&gt;&lt;/dl&gt;&lt;strong&gt;parse&lt;/strong&gt;&lt;br /&gt;public double &lt;b&gt;parse&lt;/b&gt;(java.lang.String text)&lt;br /&gt;&lt;br /&gt;throws java.lang.NumberFormatException&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;dl&gt;&lt;br /&gt;&lt;dd&gt;Parses text to produce a numeric value. A &lt;code&gt;NumberFormatException&lt;/code&gt; is&lt;br /&gt;thrown if either the text is empty or if the parse does not consume all&lt;br /&gt;characters of the text.&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;/dd&gt;&lt;dl&gt;&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt; &lt;dd&gt;&lt;code&gt;text&lt;/code&gt; - the string being parsed&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;dd&gt;a parsed number value&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Throws:&lt;/b&gt;&lt;br /&gt;&lt;dd&gt;&lt;code&gt;java.lang.NumberFormatException&lt;/code&gt; - if the entire text could not be converted&lt;br /&gt;into a number&lt;/dd&gt;&lt;/dl&gt;&lt;/dl&gt;&lt;hr /&gt;&lt;br /&gt;&lt;strong&gt;parse&lt;/strong&gt;&lt;br /&gt;public double &lt;b&gt;parse&lt;/b&gt;(java.lang.String text,&lt;br /&gt;&lt;br /&gt;int[] inOutPos)&lt;br /&gt;&lt;br /&gt;throws java.lang.NumberFormatException&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;dl&gt;&lt;br /&gt;&lt;dd&gt;Parses text to produce a numeric value.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;The method attempts to parse text starting at the index given by pos. If&lt;br /&gt;parsing succeeds, then the index of &lt;code&gt;pos&lt;/code&gt; is updated to the&lt;br /&gt;index after the last character used (parsing does not necessarily use all&lt;br /&gt;characters up to the end of the string), and the parsed number is returned.&lt;br /&gt;The updated &lt;code&gt;pos&lt;/code&gt; can be used to indicate the starting point&lt;br /&gt;for the next call to this method. If an error occurs, then the index of&lt;br /&gt;&lt;code&gt;pos&lt;/code&gt; is not changed. &lt;/p&gt;&lt;/dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt; &lt;dd&gt;&lt;code&gt;text&lt;/code&gt; - the string to be parsed &lt;dd&gt;&lt;code&gt;inOutPos&lt;/code&gt; - position to pass in and get back&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Returns:&lt;/b&gt; &lt;dd&gt;a double value representing the parsed number, or &lt;code&gt;0.0&lt;/code&gt;&lt;br /&gt;if the parse fails&lt;br /&gt;&lt;dt&gt;&lt;b&gt;Throws:&lt;/b&gt;&lt;br /&gt;&lt;dd&gt;&lt;code&gt;java.lang.NumberFormatException&lt;/code&gt; - if the text segment could not be converted into a number&lt;/dd&gt;&lt;/dl&gt;&lt;/dl&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3690933364718152435-6392562798137098779?l=java-j2ee-interview-questions-book.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-j2ee-interview-questions-book.blogspot.com/feeds/6392562798137098779/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2008/12/gwt-decimalformat-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/6392562798137098779'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3690933364718152435/posts/default/6392562798137098779'/><link rel='alternate' type='text/html' href='http://java-j2ee-interview-questions-book.blogspot.com/2008/12/gwt-decimalformat-example.html' title='GWT DecimalFormat Example'/><author><name>java-j2ee</name><uri>http://www.blogger.com/profile/06532132530961920018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
