<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2enclosuresfull.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0"><channel><title>Java  Examples</title><link>http://www.javaexamples4u.com/</link><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/JavaExamples" /><description>Sun certification level tutorial and examples Organized by topic.</description><language>en</language><managingEditor>noreply@blogger.com (LakshmiNarayana Gorantla)</managingEditor><lastBuildDate>Fri, 24 May 2013 04:51:19 PDT</lastBuildDate><generator>Blogger http://www.blogger.com</generator><openSearch:totalResults xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">362</openSearch:totalResults><openSearch:startIndex xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">1</openSearch:startIndex><openSearch:itemsPerPage xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">25</openSearch:itemsPerPage><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="javaexamples" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><itunes:owner><itunes:email>noreply@blogger.com</itunes:email></itunes:owner><itunes:explicit>no</itunes:explicit><itunes:subtitle>Sun certification level tutorial and examples Organized by topic.</itunes:subtitle><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">JavaExamples</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><item><title>Struts Interview Questions And Answers</title><link>http://www.javaexamples4u.com/2012/05/struts-interview-questions-and-answers.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Mon, 10 Sep 2012 21:37:18 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-9060819800732009076</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;code&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;b&gt;Q) What is MVC? &lt;/b&gt;&lt;br /&gt;Model-View-Controller (MVC) is a design pattern put together to help control change. MVC decouples interface from business logic and data. &lt;br /&gt;&lt;b&gt;Model : &lt;/b&gt;The model contains the core of the application's functionality. The model encapsulates the business logic of the application.It knows nothing about the view or controller.&lt;br /&gt;&lt;b&gt;View:&lt;/b&gt; The view provides the presentation to the user. It will show the view components to the user.&lt;br /&gt;&lt;b&gt;Controller:&lt;/b&gt;The controller reacts to the user input. It creates and sets the model. &lt;br /&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;b&gt;Q) What is a framework? &lt;/b&gt;&lt;br /&gt;A framework is made up of the set of classes and interfaces which allow us to use a library in a best possible way for a specific requirement.Framework provides facilities to do the common functionality in the application development. &lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;b&gt;Q) What is Struts framework? &lt;/b&gt;&lt;br /&gt;Struts framework is an open-source framework for developing the web applications in Java EE, based on MVC-2 architecture. It uses and extends the Java Servlet API. Struts is robust architecture and can be used for the development of application of any size. Struts framework makes it much easier to design scalable, reliable Web applications with Java.&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;b&gt;Q) What are the components of Struts?&lt;/b&gt; &lt;br /&gt;Struts components can be categorize into Model, View and Controller: &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;b&gt; Model:&lt;/b&gt; Components like business logic /business processes and data are the part of model. &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;b&gt;View: &lt;/b&gt;HTML, JSP are the view components. &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;b&gt;Controller:&lt;/b&gt; Action Servlet of Struts is part of Controller components which works as front controller to handle all the requests.&amp;nbsp;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;b&gt;Q) What are the core classes of the Struts Framework?&lt;/b&gt; &lt;br /&gt;Struts is a set of classes, servlets, and JSP tags that make up a reusable design. &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Java Beans components for managing application state and behavior. &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Event-driven development (via listeners as in traditional GUI development). &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Pages that represent MVC-style views; pages reference view roots via the JSF component tree.&amp;nbsp;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;b&gt;Q) What is ActionServlet class? &lt;/b&gt;&lt;br /&gt;ActionServlet is a simple servlet which is the backbone of all Struts applications. It is the main Controller component that handles client requests and determines which Action will process each received request. It serves as an Action factory – creating specific Action classes based on user’s request.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) What is role of ActionServlet class? &lt;/b&gt;&lt;br /&gt;ActionServlet performs the role of Controller:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Process user requests &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Determine what the user is trying to achieve according to the request &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Pull data from the model (if necessary) to be given to the appropriate view, &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Select the proper view to respond to the user &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Delegates most of this grunt work to Action classes &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Is responsible for initialization and clean-up of resources &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) What is the ActionForm class? &lt;/b&gt;&lt;br /&gt;Action Form is javabean which represents the form inputs containing the request parameters from the View referencing the Action bean.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) What are the important methods of ActionForm class?&lt;/b&gt; &lt;br /&gt;The important methods of ActionForm are : validate() &amp;amp; reset().&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q)Describe validate() and reset() methods in Action form class? &lt;/b&gt;&lt;br /&gt;&lt;b&gt;validate() :&lt;/b&gt; Used to validate properties after they have been populated; Called before FormBean is handed to Action. Returns a collection of ActionError as ActionErrors. Following is the method signature for the validate() method.&lt;br /&gt;&lt;br /&gt;public ActionErrors validate(ActionMapping mapping,HttpServletRequest request)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;reset():&lt;/b&gt; reset() method is called by Struts Framework with each request that uses the defined ActionForm. The purpose of this method is to reset all of the ActionForm's data members prior to the new request values being set. &lt;br /&gt;public void reset() {}&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q).What is ActionMapping in struts-config.xml file? &lt;/b&gt;&lt;br /&gt;Action mapping contains all the deployment information for a particular Action bean. This class is to determine where the results of the Action will be sent once its processing is complete.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) How is the Action Mapping specified ? &lt;/b&gt;&lt;br /&gt;We can specify the action mapping in the configuration file called struts-config.xml. Struts framework creates ActionMapping object from &lt;actionmapping&gt; configuration element of struts-config.xml file &lt;br /&gt;&lt;br /&gt;&amp;lt;action-mappings&amp;gt;&lt;br /&gt;&amp;nbsp;&lt;/actionmapping&gt;&lt;/code&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;code&gt;action path="/mySubmit"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; type="submit.MySubmitAction"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;name="MySubmitForm"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;input="/MySubmit.jsp"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;scope="request"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; validate="true"&amp;gt;&lt;br /&gt;&amp;nbsp; &lt;/code&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;code&gt;forward name="success" path="/success.jsp"/&amp;gt;&lt;br /&gt;&amp;nbsp; &lt;/code&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;code&gt;forward name="failure" path="/error.jsp"/&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) What is role of Action Class? &lt;/b&gt;&lt;br /&gt;An Action Class performs a role of an adapter between the contents of an incoming HTTP request and the corresponding business logic that should be executed to process this request. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) In which method of Action class the business logic is executed ? &lt;/b&gt;&lt;br /&gt;In the execute() method of Action class the business logic is executed.&lt;br /&gt;&lt;br /&gt;public ActionForward execute( &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ActionMapping mapping,&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; ActionForm form,&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;HttpServletRequest request,&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;HttpServletResponse response)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;throws Exception ;&lt;br /&gt;&lt;br /&gt;execute() method of Action class: &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Perform the processing required to deal with this request &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Update the server-side objects (Scope variables) that will be used to create the next page of the user interface &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return an appropriate ActionForward object &lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) Can we have more than one struts-config.xml file for a single Struts application? &lt;/b&gt;&lt;br /&gt;Yes, we can have more than one struts-config.xml for a single Struts application. They can be configured as follows:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;servlet&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;code&gt;&amp;lt;&lt;/code&gt;servlet-name&amp;gt;action &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;code&gt;&amp;lt;&lt;/code&gt;servlet-class&amp;gt;org.apache.struts.action.ActionServlet&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;code&gt;&amp;lt;&lt;/code&gt; /servlet-class&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;code&gt;&amp;lt;&lt;/code&gt; init-param&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;code&gt;&amp;lt;&lt;/code&gt; param-name&amp;gt;config&lt;code&gt;&amp;lt;&lt;/code&gt;/param-name&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;code&gt;&amp;lt;&lt;/code&gt;param-value&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /WEB-INF/struts-config.xml, &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /WEB-INF/struts-admin.xml,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /WEB-INF/struts-config-forms.xml &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;.....&lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;servlet&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) What is the directory structure of Struts application? &lt;/b&gt;&lt;br /&gt;The directory structure of Struts application :&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-AgAdHeupT4k/T7stPCS_QmI/AAAAAAAAALk/j6fPxat1vkU/s1600/Struts-Directory-Structure.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-AgAdHeupT4k/T7stPCS_QmI/AAAAAAAAALk/j6fPxat1vkU/s1600/Struts-Directory-Structure.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) What is the difference between session scope and request scope when saving formbean ? &lt;/b&gt;&lt;br /&gt;when the scope is request,the values of formbean would be available for the current request.&lt;br /&gt;when the scope is session,the values of formbean would be available throughout the session. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) What are the important tags of struts-config.xml ? &lt;/b&gt;&lt;br /&gt;The five important sections are:&lt;br /&gt;Form Bean Definition&amp;nbsp; &lt;br /&gt;Global Forward Definition&lt;br /&gt;Action Mapping Definition&lt;br /&gt;Controller Configuration&amp;nbsp; Definition&lt;br /&gt;Message Resource&amp;nbsp; Definition &lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-hovuxgWHUuA/T7stwiHkn_I/AAAAAAAAALs/15Q0ZaJgIIk/s1600/Struts-Config.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://4.bp.blogspot.com/-hovuxgWHUuA/T7stwiHkn_I/AAAAAAAAALs/15Q0ZaJgIIk/s400/Struts-Config.png" width="341" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Q) What are the different kinds of actions in Struts? &lt;/b&gt;&lt;br /&gt;The different kinds of actions in Struts are: &lt;br /&gt;DispatchAction &lt;br /&gt;LookupDispatchAction &lt;br /&gt;ForwardAction &lt;br /&gt;IncludeAction &lt;br /&gt;SwitchAction &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) What is DispatchAction? &lt;/b&gt;&lt;br /&gt;The DispatchAction class is used to group related actions into one class.Using the Dispatchaction we can reduce number of action class in the application . you can have a method for each logical action compared than a single execute method. The DispatchAction dispatches to one of the logical actions represented by the methods. It picks a method to invoke based on an incoming request parameter. The value of the incoming parameter is the name of the method that the DispatchAction will invoke.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) How to use DispatchAction? &lt;/b&gt;&lt;br /&gt;To use the DispatchAction, follow these steps :&lt;br /&gt;Create a class that extends DispatchAction (instead of Action) &lt;br /&gt;In a new class, add a method for every function you need to perform on the service – The method has the same signature as the execute() method of an Action class. &lt;br /&gt;Do not override execute() method – Because DispatchAction class itself provides execute() method. &lt;br /&gt;Add an entry to struts-config.xml &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;action input="/index.jsp" parameter="method" name="UserForm" path="/UserAction" scope="session" type="com.vaannila.UserAction"&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q).What is the use of ForwardAction? &lt;/b&gt;&lt;br /&gt;The ForwardAction class is useful when you’re trying to integrate Struts into an existing application that uses Servlets to perform business logic functions. You can use this class to take advantage of the Struts controller and its functionality, without having to rewrite the existing Servlets. Use ForwardAction to forward a request to another resource in your application, such as a Servlet that already does business logic processing or even another JSP page. By using this predefined action, you don’t have to write your own Action class. You just have to set up the struts-config file properly to use ForwardAction.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q)What is IncludeAction? &lt;/b&gt;&lt;br /&gt;The IncludeAction class is useful when you want to integrate Struts into an application that uses Servlets. Use the IncludeAction class to include another resource in the response to the request being processed. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) What is LookupDispatchAction? &lt;/b&gt;&lt;br /&gt;The LookupDispatchAction is a subclass of DispatchAction. It does a reverse lookup on the resource bundle to get the key and then gets the method whose name is associated with the key into the Resource Bundle.LookupDispatchAction is useful if the method name in the Action is not driven by its name in the front end, but by the Locale independent key into the resource bundle. Since the key is always the same, the LookupDispatchAction shields your application from the side effects of I18N.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) What is difference between LookupDispatchAction and DispatchAction? &lt;/b&gt;&lt;br /&gt;The difference between LookupDispatchAction and DispatchAction is that the actual method that gets called in LookupDispatchAction is based on a lookup of a key value instead of specifying the method name directly. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) What is SwitchAction? &lt;/b&gt;&lt;br /&gt;The SwitchAction class provides a means to switch from a resource in one module to another resource in a different module. SwitchAction is useful only if you have multiple modules in your Struts application. The SwitchAction class can be used as is, without extending.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) What is DynaActionForm? &lt;/b&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;&lt;b&gt;Q) What are the steps need to use DynaActionForm? &lt;/b&gt;&lt;br /&gt;Using a DynaActionForm instead of a custom subclass of ActionForm is relatively straightforward. You need to make changes in two places:&lt;br /&gt;&lt;br /&gt;In struts-config.xml: change your &lt;br /&gt;&lt;form -bean="-bean"&gt;to be an org.apache.struts.action.DynaActionForm instead of some subclass of ActionForm &lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;form-bean name="loginForm"type="org.apache.struts.action.DynaActionForm" &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/form&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;form-property name="userName" type="java.lang.String"/&amp;gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;form-property name="password" type="java.lang.String" /&amp;gt;&lt;br /&gt;&lt;code&gt;&amp;lt;/&lt;/code&gt;form-bean&amp;gt;&lt;br /&gt;&lt;br /&gt;In your Action subclass that uses your form bean: &lt;br /&gt;import org.apache.struts.action.DynaActionForm &lt;br /&gt;downcast the ActionForm parameter in execute() to a DynaActionForm &lt;br /&gt;access the form fields with get(field) rather than getField() &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) How to display validation errors on jsp page? &lt;/b&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;html:errors/&amp;gt; tag displays all the errors. &lt;code&gt;&amp;lt;&lt;/code&gt;html:errors/&amp;gt; iterates over ActionErrors request attribute. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) What are the various Struts tag libraries? &lt;/b&gt;&lt;br /&gt;The various Struts tag libraries are:&lt;br /&gt;&lt;br /&gt;HTML Tags &lt;br /&gt;Bean Tags &lt;br /&gt;Logic Tags &lt;br /&gt;Template Tags &lt;br /&gt;Nested Tags &lt;br /&gt;Tiles Tags &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) What is the use of&amp;nbsp; logic:iterate? &lt;/b&gt;&lt;br /&gt;logic:iterate&amp;gt; repeats the nested body content of this tag over a specified collection.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; table border=1&amp;gt; &lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; logic:iterate id="customer" name="customers"&amp;gt; &lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; tr&amp;gt; &lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; td&amp;gt;&lt;code&gt;&amp;lt;&lt;/code&gt; bean:write name="customer" property="firstName"/&amp;gt;&lt;code&gt;&amp;lt;&lt;/code&gt; /td&amp;gt; &lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; td&amp;gt;&lt;code&gt;&amp;lt;&lt;/code&gt; bean:write name="customer" property="lastName"/&amp;gt;&lt;code&gt;&amp;lt;&lt;/code&gt; /td&amp;gt; &lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; td&amp;gt;&lt;code&gt;&amp;lt;&lt;/code&gt; bean:write name="customer" property="address"/&amp;gt;&lt;code&gt;&amp;lt;&lt;/code&gt; /td&amp;gt; &lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; /tr&amp;gt; &lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; /logic:iterate&amp;gt; &lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; /table&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) What are differences between bean:message and bean:write &lt;/b&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; bean:message&amp;gt;: is used to retrive keyed values from resource bundle. It also supports the ability to include parameters that can be substituted for defined placeholders in the retrieved string.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; bean:message key="prompt.customer.firstname"/&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; bean:write&amp;gt;: is used to retrieve and print the value of the bean property. &lt;bean:write&gt; has no body.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; bean:write name="customer" property="firstName"/&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) How the exceptions are handled in struts? &lt;/b&gt;&lt;br /&gt;Exceptions in Struts are handled in two ways: &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Programmatic exception handling :&lt;/b&gt; Explicit try/catch blocks in any code that can throw exception. It works well when custom value (i.e., of variable) needed when error occurs. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Declarative exception handling :&lt;/b&gt;You can either define &lt;global -exceptions="-exceptions"&gt; handling tags in your struts-config.xml or define the exception handling tags within &lt;action&gt;&lt;/action&gt; tag. It works well when custom page needed when error occurs. This approach applies only to exceptions thrown by Actions. &lt;/global&gt;&lt;/bean:write&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) What is difference between ActionForm class and DynaActionForm class? &lt;/b&gt;&lt;br /&gt;An ActionForm represents an HTML form that the user interacts with over one or more pages. You will provide properties to hold the state of the form with getters and setters to access them. Whereas, using DynaActionForm there is no need of providing properties to hold the state. Instead these properties and their type are declared in the struts-config.xml&lt;br /&gt;&lt;br /&gt;The DynaActionForm bloats up the Struts config file with the xml based definition. This gets annoying as the Struts Config file grow larger.&lt;br /&gt;&lt;br /&gt;The DynaActionForm is not strongly typed as the ActionForm. This means there is no compile time checking for the form fields. Detecting them at runtime is painful and makes you go through redeployment.&lt;br /&gt;&lt;br /&gt;ActionForm can be cleanly organized in packages as against the flat organization in the Struts Config file.&lt;br /&gt;&lt;br /&gt;ActionForm were designed to act as a Firewall between HTTP and the Action classes, i.e. isolate and encapsulate the HTTP request parameters from direct use in Actions. With DynaActionForm, the property access is no different than using request.getParameter( .. ).&lt;br /&gt;&lt;br /&gt;DynaActionForm construction at runtime requires a lot of Java Reflection (Introspection) machinery that can be avoided.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) How can we make message resources definitions file available to the Struts framework environment? &lt;/b&gt;&lt;br /&gt;We can make message resources definitions file (properties file) available to Struts framework environment by adding this file to struts-config.xml.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; message-resources parameter="com.login.struts.ApplicationResources"/&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q) What is the life cycle of ActionForm? &lt;/b&gt;&lt;br /&gt;The lifecycle of ActionForm invoked by the RequestProcessor is as follows:&lt;br /&gt;&lt;br /&gt;Retrieve or Create Form Bean associated with Action &lt;br /&gt;"Store" FormBean in appropriate scope (request or session) &lt;br /&gt;Reset the properties of the FormBean &lt;br /&gt;Populate the properties of the FormBean &lt;br /&gt;Validate the properties of the FormBean &lt;br /&gt;Pass FormBean to Action &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;</description><media:thumbnail url="http://4.bp.blogspot.com/-AgAdHeupT4k/T7stPCS_QmI/AAAAAAAAALk/j6fPxat1vkU/s72-c/Struts-Directory-Structure.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>Servlet interview questions with answers</title><link>http://www.javaexamples4u.com/2011/11/servlet-interview-questions-with.html</link><category>Interview Questions On Servlet</category><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Tue, 01 Nov 2011 05:58:40 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-683640598950109555</guid><description>&lt;span style="font-weight: bold;"&gt;What is the servlet?&lt;/span&gt;&lt;br /&gt;Servlets  are modules that extend request/response-oriented servers, such as  Java-enabled web servers. For example, a servlet may be responsible for  taking data in an HTML order-entry form and applying the business logic  used to update a company's order database.&lt;br /&gt;-Servlets are used to enhance and extend the functionality of Webserver.&lt;br /&gt;Servlets handles Java and HTML separately.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What are the uses of Servlets?&lt;/span&gt;&lt;br /&gt;      A servlet can handle multiple requests concurrently, and can  synchronize requests. This allows servlets to support systems such as  on-line conferencing. Servlets can forward requests to other servers and  servlets. Thus servlets can be used to balance load among several  servers that mirror the same content, and to partition a single logical  service over several servers, according to task.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What are the characters of Servlet?&lt;/span&gt;&lt;br /&gt;  As Servlet are written in java, they can make use of extensive power  of the JAVA API,such as networking and URL  access,multithreading,databaseconnectivity,RMI object serialization.&lt;br /&gt;Efficient : The initilazation code for a servlet is executed only once, when the servlet is executed for the first time.&lt;br /&gt;Robest :  provide all the powerfull features of JAVA, such as Exception handling and garbage collection.&lt;br /&gt;Portable: This enables easy portability across Web Servers.&lt;br /&gt;Persistance : Increase the performance of the system by executing features data access.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is the difference between JSP and SERVLETS &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Servlets :&lt;/span&gt;  servlet tieup files to independitently handle the static presentation  logic and dynamic business logic , due to this a changes made to any  file requires recompilation of the servlet.&lt;br /&gt;- The servlet is Pre-Compile.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;JSP :&lt;/span&gt;  Facilities segregation of work profiles to Web-Developer and  Web-Designer , Automatically incorporates changes made to any file (PL  &amp;amp; BL) , no need to recompile.&lt;br /&gt;Web-Developer write the code for Bussiness logic whereas Web-Designer designs the layout for the WebPage by HTML &amp;amp; JSP.&lt;br /&gt;- The JSP is Post-Compile.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What are the advantages using servlets than using CGI?&lt;/span&gt;&lt;br /&gt;        Servlets provide a way to generate dynamic documents that is  both easier to write and faster to run. It is efficient, convenient,  powerful, portable, secure and inexpensive. Servlets also address the  problem of doing server-side programming with platform-specific APIs.  They are developed with Java Servlet API, a standard Java extension.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is the difference between servlets and applets?&lt;/span&gt;&lt;br /&gt;     Servlets are to servers. Applets are to browsers. Unlike applets, however, servlets have no graphical user interface.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is the difference between GenericServlet and HttpServlet?&lt;/span&gt;&lt;br /&gt;GenericServlet  is for servlets that might not use HTTP, like for instance FTP  service.As of only Http is implemented completely in HttpServlet. The  GenericServlet has a service() method that gets called when a client  request is made. This means that it gets called by both incoming  requests and the HTTP requests are given to the servlet as they are.&lt;br /&gt;GenericServlet belongs to javax.servlet package&lt;br /&gt;GenericServlet  is an abstract class which extends Object and implements Servlet,  ServletConfig and java.io.Serializable interfaces.&lt;br /&gt;The direct subclass to GenericServlet is HttpServlet.It is a protocol-independent servlet&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What are the differences between GET and POST service methods? &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Get Method &lt;/span&gt;: Uses Query String to send additional information to the server.&lt;br /&gt;-Query String is displayed on the client Browser.&lt;br /&gt;Query  String : The additional sequence of characters that are appended to the  URL ia called  Query String.  The length of the Query string is limited  to 255 characters.&lt;br /&gt;-The amount of information you can send back using a GET is restricted as URLs can only be 1024 characters.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;POST Method&lt;/span&gt;  :  The Post Method sends the Data as packets through a separate socket  connection. The complete transaction is invisible to the client.  The  post method is slower compared to the Get method because Data is sent to  the server as separate packates.&lt;br /&gt;--You can send much more  information to the server this way - and it's not restricted to textual  data either. It is possible to send files and even binary data such as  serialized Java objects!&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is the servlet life cycle?&lt;/span&gt;&lt;br /&gt;In Servlet life cycles are,&lt;br /&gt;init(),services(),destory().&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Init( ) : &lt;/span&gt;Is called by the Servlet container after the servlet has ben Instantiated.&lt;br /&gt;--Contains all information code for servlet and is invoked when the servlet is first loaded.&lt;br /&gt;-The init( ) does not require any argument , returns a void and throws Servlet Exception.&lt;br /&gt;-If init() executed at the time of servlet class loading.And init() executed only for first user.&lt;br /&gt;-You  can Override this method to write initialization code that needs to run  only once, such as loading a driver , initializing values and soon,  Inother case you can leave normally blank.&lt;br /&gt;Public void init(ServletConfig Config) throws ServletException&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Service( ) :&lt;/span&gt; is called by the Servlet container after the init method to allow the servlet to respond to a request.&lt;br /&gt;-Receives  the request from the client and identifies the type of request and  deligates them to doGet( ) or doPost( ) for processing.&lt;br /&gt;Public void service(ServletRequest request,ServletResponce response) throws ServletException,  IOException&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Destroy( ) : &lt;/span&gt;The Servlet Container calls the destroy( ) before removing a Servlet Instance from Sevice.&lt;br /&gt;-Excutes only once when the Servlet is removed from Server.&lt;br /&gt;Public void destroy( )&lt;br /&gt;&lt;br /&gt;If services() are both for get and post methods.&lt;br /&gt;-So if u want to use post method in html page,we use doPost() or services() in servlet class.&lt;br /&gt;-if want to use get methods in html page,we can use doGet() or services() in servlet calss.&lt;br /&gt;-Finally destory() is used to free the object.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is the difference between ServletContext and ServletConfig? &lt;/span&gt;&lt;br /&gt;Both are interfaces.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Servlet Config():&lt;/span&gt;The  servlet engine implements the ServletConfig interface in order to pass  configuration information to a servlet. The server passes an object that  implements the ServletConfig interface to the servlet's init() method.&lt;br /&gt;    A ServletConfig object passes configuration information from the  server to a servlet. ServletConfig also includes ServletContext object.&lt;br /&gt;getParameter( ) , getServletContext( ) , getServletConfig( ), GetServletName( )&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Servlet Context():&lt;/span&gt;  The ServletContext interface provides information to servlets regarding  the environment in which they are running. It also provides standard  way for servlets to write events to a log file.&lt;br /&gt;  ServletContext  defines methods that allow a servlet to interact with the host server.  This includes reading server-specific attributes, finding information  about particular files located on the server, and writing to the server  log files. I f there are several virtual servers running, each one may  return a different ServletContext.&lt;br /&gt;getMIMEType( ) , getResourse( ), getContext( ),getServerInfo( ),getServletContetName( )&lt;br /&gt;11.    Can I invoke a JSP error page from a servlet?&lt;br /&gt;     Yes, you can invoke the JSP error page and pass the exception  object to it from within a servlet. The trick is to create a request  dispatcher for the JSP error page, and pass the exception object as a  javax.servlet.jsp.jspException request attribute. However, note that you  can do this from only within controller servlets.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Can I just abort processing a JSP?&lt;/span&gt;&lt;br /&gt;Yes.Because your JSP is just a servlet method,you can just put (whereever necessary) a &amp;lt; % return; %&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is a better approach for enabling thread-safe servlets and JSPs? SingleThreadModel Interface or Synchronization?&lt;/span&gt;&lt;br /&gt;          Although the SingleThreadModel technique is easy to use, and  works well for low volume sites, it does not scale well. If you  anticipate your users to increase in the future, you may be better off  implementing explicit synchronization for your shared data. The key  however, is to effectively minimize the amount of code that is  synchronzied so that you take maximum advantage of multithreading.&lt;br /&gt;Also,  note that SingleThreadModel is pretty resource intensive from the  server's perspective. The most serious issue however is when the number  of concurrent requests exhaust the servlet instance pool. In that case,  all the unserviced requests are queued until something becomes free -  which results in poor performance. Since the usage is non-deterministic,  it may not help much even if you did add more memory and increased the  size of the instance pool.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;If you want a servlet to take the same action for both GET and POST request, what should you do?&lt;/span&gt;&lt;br /&gt;Simply have doGet call doPost, or vice versa.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Which code line must be set before any of the lines that use the PrintWriter?&lt;/span&gt;&lt;br /&gt;setContentType() method must be set before transmitting the actual document.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;How HTTP Servlet handles client requests?&lt;/span&gt;&lt;br /&gt;      An HTTP Servlet handles client requests through its service  method. The service method supports standard HTTP client requests by  dispatching each request to a method designed to handle that request.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is the Servlet Interface?&lt;/span&gt;&lt;br /&gt;       The central abstraction in the Servlet API is the Servlet  interface. All servlets implement this interface, either directly or,  more commonly, by extending a class that implements it such as  HttpServlet.&lt;br /&gt;Servlets--&amp;gt;Generic Servlet--&amp;gt;HttpServlet--&amp;gt;MyServlet.&lt;br /&gt;The  Servlet interface declares, but does not implement, methods that manage  the servlet and its communications with clients. Servlet writers  provide some or all of these methods when developing a servlet.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;When a servlet accepts a call from a client, it receives two objects. What are they?&lt;/span&gt;&lt;br /&gt;ServeltRequest: which encapsulates the communication from the client to the server.&lt;br /&gt;ServletResponse: which encapsulates the communication from the servlet back to the&lt;br /&gt;Client.&lt;br /&gt;ServletRequest and ServletResponse are interfaces defined by the javax.servlet package.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What information that the ServletRequest interface allows the servlet access to?&lt;/span&gt;&lt;br /&gt;      Information such as the names of the parameters passed in by the  client, the protocol (scheme) being used by the client, and the names of  the remote host that made the request and the server that received it.  The input stream, ServletInputStream.Servlets use the input stream to  get data&lt;br /&gt;from clients that use application protocols such as the HTTP POST and PUT methods.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What information that the ServletResponse interface gives the servlet methods for replying to the client?&lt;/span&gt;&lt;br /&gt;      It Allows the servlet to set the content length and MIME type of  the reply. Provides an output stream, ServletOutputStream and a Writer  through which the servlet can send the reply data.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Difference between single thread and multi thread model servlet&lt;/span&gt;&lt;br /&gt;       A servlet that implements SingleThreadModel means that for every  request, a single servlet instance is created. This is not a very  scalable solution as most web servers handle multitudes of requests. A  multi-threaded servlet means that one servlet is capable of handling  many requests which is the way most servlets should be implemented.&lt;br /&gt;a.    A single thread model for servlets is generally used to protect sensitive data ( bank account operations ).&lt;br /&gt;b.     Single thread model means instance of the servlet gets created for  each request recieved. Its not thread safe whereas in multi threaded  only single instance of the servlet exists for what ever # of requests  recieved. Its thread safe and is taken care by the servlet container.&lt;br /&gt;c.     A servlet that implements SingleThreadModel means that for every  request, a single servlet instance is created. This is not a very  scalable solution as most web servers handle multitudes of requests. A  multi-threaded servlet means that one servlet is capable of handling  many requests which is the way most servlets should be implemented.&lt;br /&gt;&lt;br /&gt;A single thread model for servlets is generally used to protect sensitive data ( bank account operations ).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is servlet context and what it takes actually as parameters?&lt;/span&gt;&lt;br /&gt;        Servlet context is an object which is created as soon as the  Servlet gets initialized.Servlet context object is contained in Servlet  Config. With the context object u can get access to specific&lt;br /&gt;resource (like file) in the server and pass it as a URL to be displayed as a next screen with the help of RequestDispatcher&lt;br /&gt;eg :-&lt;br /&gt;ServletContext app = getServletContext();&lt;br /&gt;RequestDispatcher disp;&lt;br /&gt;if(b==true)&lt;br /&gt;disp = app.getRequestDispatcher&lt;br /&gt;("jsp/login/updatepassword.jsp");&lt;br /&gt;else&lt;br /&gt;disp = app.getRequestDispatcher&lt;br /&gt;("jsp/login/error.jsp");&lt;br /&gt;this code will take user to the screen depending upon the value of b.&lt;br /&gt;in ServletContext u can also get or set some variables which u would&lt;br /&gt;like to retreive in next screen.&lt;br /&gt;eg&lt;br /&gt;context.setAttribute("supportAddress", "temp@temp.com");&lt;br /&gt;Better yet, you could use the web.xml context-param element to&lt;br /&gt;designate the address, then read it with the getInitParameter method&lt;br /&gt;of ServletContext.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Can we call destroy() method on servlets from service method?&lt;/span&gt;&lt;br /&gt;destroy()  is a servlet life-cycle method called by servlet container to kill the  instance of the servlet.   "Yes". You can call destroy() from within the  service(). It will do whatever logic you have in destroy() (cleanup,  remove attributes, etc.) but it won't "unload" the servlet instance  itself. That can only be done by the container&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is the use of ServletConfig and ServletContext..? &lt;/span&gt;&lt;br /&gt;        An interface that describes the configuration parameters for a  servlet. This is passed to the servlet when the web server calls its  init() method. Note that the servlet should save the reference to the  ServletConfig object, and define a getServletConfig() method to return  it when asked. This interface defines how to get the initialization  parameters for the servlet and the context under which the servlet is  running.&lt;br /&gt;    An interface that describes how a servlet can get  information about the server in which it is running. It can be retrieved  via the getServletContext() method of the ServletConfig object.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is difference between forward()  and sendRedirect().. ? Which one is faster then other and which works on server?  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Forward( ) :&lt;/span&gt;  javax.Servlet.RequestDispatcher interface.&lt;br /&gt;-RequestDispatcher.forward( ) works on the Server.&lt;br /&gt;-The forward( ) works inside the WebContainer.&lt;br /&gt;-The forward( ) restricts you to redirect only to a resource in the same web-Application.&lt;br /&gt;-After executing the forward( ), the control will return back to the same method from where the forward method was called.&lt;br /&gt;-the forward( ) will redirect in the application server itself, it does’n come back to the client.&lt;br /&gt;- The forward( ) is faster than Sendredirect( ) .&lt;br /&gt;To  use the forward( ) of the requestDispatcher interface, the first thing  to do is to obtain RequestDispatcher Object. The Servlet technology  provides in three ways.&lt;br /&gt;1. By using the getRequestDispatcher( ) of  the javax.Servlet.ServletContext interface , passing a String containing  the path of the other resources, path is relative to the root of the  ServletContext.&lt;br /&gt;&lt;br /&gt;RequestDispatcher rd=request.getRequestDispatcher(“secondServlet”);&lt;br /&gt;Rd.forward(request, response);&lt;br /&gt;&lt;br /&gt;2.   getRequestDispatcher( ) of the javax.Servlet.Request interface  , the path is relative to current HtpRequest.&lt;br /&gt;RequestDispatcher rd=getServletContext( ).getRequestDispatcher(“servlet/secondServlet”);&lt;br /&gt;Rd.forward(request, response);&lt;br /&gt;&lt;br /&gt;3. By using the getNameDispatcher( ) of the javax.Servlet.ServletContext interface.&lt;br /&gt;RequestDispatcher rd=getServletContext( ).getNameDispatcher(“secondServlet”);&lt;br /&gt;Rd.forward(request, response);&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sendredirect( ) :&lt;/span&gt; javax.Servlet.Http.HttpServletResponce interface&lt;br /&gt;-RequestDispatcher.SendRedirect( ) works on the browser.&lt;br /&gt;-The SendRedirect( ) allows you to redirect trip to the Client.&lt;br /&gt;-The SendRedirect( ) allows you to redirect to any URL.&lt;br /&gt;-After executing the SendRedirect( ) the control will not return back to same method.&lt;br /&gt;-The  Client receives the Http response code 302 indicating that temporarly  the client is being redirected to the specified location , if the  specified location is relative , this method converts it into an  absolute URL before redirecting.&lt;br /&gt;&lt;br /&gt;-The SendRedirect( ) will come to the Client and go back,.. ie URL appending will happen.&lt;br /&gt;Response. SendRedirect( “absolute path”);&lt;br /&gt;Absolutepath – other than application ,  relative path - same application.&lt;br /&gt;&lt;br /&gt;           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  completely with in the web container. 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  completely 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.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;do we have a constructor in servlet ? can we explictly provide a constructor in servlet programme as in java program ? &lt;/span&gt;&lt;br /&gt;We can have a constructor in servlet .&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Session :&lt;/span&gt; A session is a group of activities that are performed by a user while accesing a particular website.&lt;br /&gt;Session Tracking :The process of keeping track of settings across session is called session tracking.&lt;br /&gt;Hidden Form Fields : Used to keep track of users by placing hidden fields in the form.&lt;br /&gt;-The values that have been entered in these fields are sent to the server when the user submits the Form.&lt;br /&gt;URL-rewriting  : this is a technique by which the URL is modified to include the  session ID of a particular user and is sent back to the Client.&lt;br /&gt;-The session Id is used by the client for subsequent transactions with the server.&lt;br /&gt;Cookies : Cookies are small text files that are used by a webserver to keep track the Users.&lt;br /&gt;A  cookie is created by the server and send back to the client , the value  is in the form of Key-value pairs. Aclient can accept 20 cookies per  host and the size of each cookie can be maximum of 4 bytes each.&lt;br /&gt;HttpSession : Every user who logs on to the website is autometacally associated with an HttpSession Object.&lt;br /&gt;-The Servlet can use this Object to store information about the users Session.&lt;br /&gt;-HttpSession Object enables the user to maintain two types of Data.&lt;br /&gt;    ie State and Application.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;How to communicate between two servlets?&lt;/span&gt;&lt;br /&gt;Two ways:&lt;br /&gt;a.    Forward or redirect from one Servlet to another.&lt;br /&gt;b.    Load the Servlet from ServletContext and access methods.&lt;br /&gt;29.    How to get one Servlet's Context Information in another Servlet?&lt;br /&gt;Access or load the Servlet from the Servlet Context and access the Context Information</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>JDBC FAQS</title><link>http://www.javaexamples4u.com/2011/10/jdbc-faqs.html</link><category>Jdbc Interview Questions</category><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Tue, 18 Oct 2011 02:13:46 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-8054410368166879683</guid><description>&lt;span style="font-weight: bold;"&gt;What is JDBC?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ans&lt;/span&gt;: JDBC is a set of Java API for executing SQL statements. This API consists of a set of  classes and interfaces to Java Database applications. The database vendors like Oracle,MySql ,TeraData ….are provided the implementations for some of the classes in JDBC API.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What are drivers available?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ans: &lt;/span&gt; Type 1- JDBC-ODBC Bridge driver&lt;br /&gt;Type 2- Native API Partly-Java driver&lt;br /&gt; Type 3 -JDBC-Net Pure Java driver&lt;br /&gt;Type 4 -Native-Protocol Pure Java driver&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; What is the difference between JDBC and ODBC?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ans:&lt;/span&gt;  a)   ODBC(Open Data Base Connectivity)  is for Microsoft and JDBC is for Java applications.&lt;br /&gt;b)    ODBC can’t be directly used with Java because it uses a C interface.&lt;br /&gt;c)    ODBC  makes use of pointers which have been removed totally from Java.&lt;br /&gt;d)    ODBC mixes simple and advanced features together and has complex options for simple queries. But JDBC is designed to keep things simple while allowing advanced capabilities when required.&lt;br /&gt;e)    ODBC requires manual installation of the ODBC driver manager and driver on all client machines. JDBC drivers are written in Java and JDBC code is automatically installable, secure, and portable on all platforms.&lt;br /&gt;f)    JDBC API is a natural Java interface and is built on ODBC. JDBC retains some of the basic features of ODBC.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What are the types of JDBC Driver Models and explain them?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ans:&lt;/span&gt; There are two types of JDBC Driver Models and they are:&lt;br /&gt;a)    Two tier model and b) Three tier model&lt;br /&gt; Two tier model: In this model, Java applications interact directly with the database. A JDBC driver is required to communicate with the particular database management system that is being accessed. SQL statements are sent to the database and the results are given to user. This model is referred to as client/server configuration where user is the client and the machine that has the database is called as the server.&lt;br /&gt;Three tier model: A middle tier is introduced in this model. The functions of this model are:&lt;br /&gt;a)    Collection of SQL statements from the client and handing it over to the database,&lt;br /&gt;b)    Receiving results from database to the client and&lt;br /&gt;c)    Maintaining control over accessing and updation of the above.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What are the steps involved for making a connection with a database or how do you connect to a database? &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ans:&lt;/span&gt;&lt;br /&gt;a)    Loading the driver : To load the driver, Class.forName( ) method is used.&lt;br /&gt;                     Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);&lt;br /&gt;                When the driver is loaded, it registers itself with the java.sql.DriverManager class as an available database driver.&lt;br /&gt;b)    Making a connection with database : To open a connection to a given database,&lt;br /&gt;       DriverMnaager.getConnection( ) method is used.&lt;br /&gt;           Connection con = DriverManager.getConnection(“jdbc:odbc:somedb”, “user”,  ”password”);&lt;br /&gt;c)    Executing SQL statements : To execute a SQL query, java.sql.statements class is used.  &lt;br /&gt;       createStatement( ) method of Connection to obtain a new Statement object.&lt;br /&gt;            Statement stmt  = con.createStatement( );&lt;br /&gt;       A query that returns data can be executed using the executeQuery( ) method of  Statement. This method&lt;br /&gt;       executes the statement and returns a java.sql.ResultSet that encapsulates the retrieved data:&lt;br /&gt;            ResultSet rs = stmt.executeQuery(“SELECT * FROM some table”);&lt;br /&gt;d)    Process the results : ResultSet returns one row at a time. Next( ) method of ResultSet  object can be called to move to the next row.  The getString( ) and getObject( ) methods are used for retrieving  column values:&lt;br /&gt;                       while(rs.next( ) ) {&lt;br /&gt;                           String event = rs.getString(“event”);&lt;br /&gt;                           Object count = (Integer) rs.getObject(“count”);&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What type of driver did you use in project?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ans&lt;/span&gt;: JDBC-ODBC Bridge driver (is a driver that uses native(C language) libraries and makes calls to an existing ODBC driver to access a database engine).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What are the types of statements in JDBC?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ans&lt;/span&gt;: Statement    --  To be used createStatement( ) method for executing single SQL statement&lt;br /&gt;PreparedStatement  --  To be used preparStatement( ) method for executing same SQL  statement over and over.&lt;br /&gt;CallableStatement    --  To be used prepareCall( ) method for multiple SQL statements over and over&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is stored procedure?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ans&lt;/span&gt;: Stored procedure is a group of SQL statements that forms a logical unit and performs a particular task. Stored Procedures are used to encapsulate a set of operations or queries to execute on database. Stored procedures can be compiled and executed with different  parameters and results and may have any  combination of input/output parameters.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;How to create and call stored procedures?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ans&lt;/span&gt;:   To create stored procedures:&lt;br /&gt;          Create procedure procedure name (specify in, out and in out parameters)&lt;br /&gt;          BEGIN&lt;br /&gt;          Any multiple SQL statement;&lt;br /&gt;          END;&lt;br /&gt;&lt;br /&gt;         To call stored procedures:&lt;br /&gt;          CallableStatement  csmt  = con.prepareCall(“{call procedure name(?,?)}”);&lt;br /&gt;          csmt.registerOutParameter(column no., data type);&lt;br /&gt;          csmt.setInt(column no., column name)&lt;br /&gt;          csmt.execute( ); &lt;br /&gt;        &lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What are the differences between executeQuery(…), executeUpdate(…) and execute(…)     methods?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ans:                &lt;/span&gt;&lt;br /&gt;public  ResultSet executeQuery(String sqlquery)&lt;br /&gt;&lt;br /&gt;where executeQuery() can be used to execute selection group sql queries to fetch the data from database.When we use selection group sql query with executeQuery() then JVM will send that sql query to the database engine, database engine will execute it, by this database engine(DBE) will fetch the data from database and send back to the java application.&lt;br /&gt;           &lt;br /&gt;public int executeUpdate(String sqlquery)&lt;br /&gt;&lt;br /&gt;            where executeUpdate() can be used to execute updation group sql query to update the database. When we provide updation group sql query as a parameter to executeUpdate(), then JVM will send that sql query to DBE, here DBE will execute it and perform updations on the database, by this DBE will identify the number of records got updated value called as “records updated count” and return back to the java application.&lt;br /&gt;&lt;br /&gt;            public  boolean execute(String sqlquery)&lt;br /&gt;&lt;br /&gt;                        where execute() can be used to execute either selection group sql queries or updation group queries. But this method is renturn value is Boolean to get the ResultSet object to call the statement.get ResultSet() method . If we want to get Update count we have to use the statement.getUpdateCount() method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is a transaction ?&lt;/span&gt;&lt;br /&gt;transaction is collection of logical operation that perform a task&lt;br /&gt;Transaction should ACID properties.&lt;br /&gt;A for Automicity&lt;br /&gt;C for Consistency&lt;br /&gt;I for Isolation&lt;br /&gt;D for Durability.&lt;br /&gt;A transaction can be termed as any operation such as storing, retrieving, updating or deleting records in the table that hits the database.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is the purpose of setAutoCommit( ) &lt;/span&gt;&lt;br /&gt;It is set as  ConnectionObject.setAutoComit(boolean val);&lt;br /&gt;after any updates through the program cannot be effected to the database.We have to commit the transctions then only it reflect on Database .For this puprpose we can set AutoCommit flag to Connection Object.</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>Online Java Training</title><link>http://www.javaexamples4u.com/2011/09/online-java-training.html</link><category>online java course</category><category>java online</category><category>online training java</category><category>java online course</category><category>online java classes</category><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Tue, 25 Sep 2012 18:34:59 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-1103208413174531555</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:worddocument&gt;   &lt;w:view&gt;Normal&lt;/w:View&gt;   &lt;w:zoom&gt;0&lt;/w:Zoom&gt;   &lt;w:trackmoves/&gt;   &lt;w:trackformatting/&gt;   &lt;w:punctuationkerning/&gt;   &lt;w:validateagainstschemas/&gt;   &lt;w:saveifxmlinvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;   &lt;w:ignoremixedcontent&gt;false&lt;/w:IgnoreMixedContent&gt;   &lt;w:alwaysshowplaceholdertext&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;   &lt;w:donotpromoteqf/&gt;   &lt;w:lidthemeother&gt;EN-US&lt;/w:LidThemeOther&gt;   &lt;w:lidthemeasian&gt;X-NONE&lt;/w:LidThemeAsian&gt;   &lt;w:lidthemecomplexscript&gt;X-NONE&lt;/w:LidThemeComplexScript&gt;   &lt;w:compatibility&gt;    &lt;w:breakwrappedtables/&gt;    &lt;w:snaptogridincell/&gt;    &lt;w:wraptextwithpunct/&gt;    &lt;w:useasianbreakrules/&gt;    &lt;w:dontgrowautofit/&gt;    &lt;w:splitpgbreakandparamark/&gt;    &lt;w:dontvertaligncellwithsp/&gt;    &lt;w:dontbreakconstrainedforcedtables/&gt;    &lt;w:dontvertalignintxbx/&gt;    &lt;w:word11kerningpairs/&gt;    &lt;w:cachedcolbalance/&gt;   &lt;/w:Compatibility&gt;   &lt;w:browserlevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;   &lt;m:mathpr&gt;    &lt;m:mathfont val="Cambria Math"&gt;    &lt;m:brkbin val="before"&gt;    &lt;m:brkbinsub val="&amp;#45;-"&gt;    &lt;m:smallfrac val="off"&gt;    &lt;m:dispdef/&gt;    &lt;m:lmargin val="0"&gt;    &lt;m:rmargin val="0"&gt;    &lt;m:defjc val="centerGroup"&gt;    &lt;m:wrapindent val="1440"&gt;    &lt;m:intlim val="subSup"&gt;    &lt;m:narylim val="undOvr"&gt;   &lt;/m:mathPr&gt;&lt;/w:WordDocument&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:latentstyles deflockedstate="false" defunhidewhenused="true" defsemihidden="true" defqformat="false" defpriority="99" latentstylecount="267"&gt;   &lt;w:lsdexception locked="false" priority="0" semihidden="false" unhidewhenused="false" qformat="true" name="Normal"&gt;   &lt;w:lsdexception locked="false" priority="9" semihidden="false" unhidewhenused="false" qformat="true" name="heading 1"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 2"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 3"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 4"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 5"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 6"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 7"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 8"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 9"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 1"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 2"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 3"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 4"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 5"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 6"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 7"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 8"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 9"&gt;   &lt;w:lsdexception locked="false" priority="35" qformat="true" name="caption"&gt;   &lt;w:lsdexception locked="false" priority="10" semihidden="false" unhidewhenused="false" qformat="true" name="Title"&gt;   &lt;w:lsdexception locked="false" priority="1" name="Default Paragraph Font"&gt;   &lt;w:lsdexception locked="false" priority="11" semihidden="false" unhidewhenused="false" qformat="true" name="Subtitle"&gt;   &lt;w:lsdexception locked="false" priority="22" semihidden="false" unhidewhenused="false" qformat="true" name="Strong"&gt;   &lt;w:lsdexception locked="false" priority="20" semihidden="false" unhidewhenused="false" qformat="true" name="Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="59" semihidden="false" unhidewhenused="false" name="Table Grid"&gt;   &lt;w:lsdexception locked="false" unhidewhenused="false" name="Placeholder Text"&gt;   &lt;w:lsdexception locked="false" priority="1" semihidden="false" unhidewhenused="false" qformat="true" name="No Spacing"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" unhidewhenused="false" name="Revision"&gt;   &lt;w:lsdexception locked="false" priority="34" semihidden="false" unhidewhenused="false" qformat="true" name="List Paragraph"&gt;   &lt;w:lsdexception locked="false" priority="29" semihidden="false" unhidewhenused="false" qformat="true" name="Quote"&gt;   &lt;w:lsdexception locked="false" priority="30" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Quote"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="19" semihidden="false" unhidewhenused="false" qformat="true" name="Subtle Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="21" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="31" semihidden="false" unhidewhenused="false" qformat="true" name="Subtle Reference"&gt;   &lt;w:lsdexception locked="false" priority="32" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Reference"&gt;   &lt;w:lsdexception locked="false" priority="33" semihidden="false" unhidewhenused="false" qformat="true" name="Book Title"&gt;   &lt;w:lsdexception locked="false" priority="37" name="Bibliography"&gt;   &lt;w:lsdexception locked="false" priority="39" qformat="true" name="TOC Heading"&gt;  &lt;/w:LatentStyles&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 10]&gt; &lt;style&gt;  /* Style Definitions */  table.MsoNormalTable  {mso-style-name:"Table Normal";  mso-tstyle-rowband-size:0;  mso-tstyle-colband-size:0;  mso-style-noshow:yes;  mso-style-priority:99;  mso-style-qformat:yes;  mso-style-parent:"";  mso-padding-alt:0in 5.4pt 0in 5.4pt;  mso-para-margin-top:0in;  mso-para-margin-right:0in;  mso-para-margin-bottom:10.0pt;  mso-para-margin-left:0in;  line-height:115%;  mso-pagination:widow-orphan;  font-size:11.0pt;  font-family:"Calibri","sans-serif";  mso-ascii-font-family:Calibri;  mso-ascii-theme-font:minor-latin;  mso-fareast-font-family:"Times New Roman";  mso-fareast-theme-font:minor-fareast;  mso-hansi-font-family:Calibri;  mso-hansi-theme-font:minor-latin;} &lt;/style&gt; &lt;![endif]--&gt;  &lt;br /&gt;&lt;div class="MsoNormal"&gt;This is LakshmiNarayana Gorantla. I am sun certified java programmer.&lt;/div&gt;&lt;div class="MsoNormal"&gt;I am having 5 years of IT experience, Involved in developing the Software applications using &lt;/div&gt;&lt;div class="MsoNormal"&gt;Java, J2ee and related frameworks like Struts, Spring, Hibernate. Good experience in XML and&lt;/div&gt;&lt;div class="MsoNormal"&gt;Web Services.&lt;/div&gt;&lt;div class="MsoNormal"&gt;I am providing Certification level Online training courses on below technologies.&lt;/div&gt;&lt;div class="MsoNormal" style="color: #cc0000; font-weight: bold;"&gt;Core Java,&lt;/div&gt;&lt;div class="MsoNormal" style="color: #cc0000; font-weight: bold;"&gt;JDBC,&lt;/div&gt;&lt;div class="MsoNormal" style="color: #cc0000; font-weight: bold;"&gt;Servlets,&lt;/div&gt;&lt;div class="MsoNormal" style="color: #cc0000; font-weight: bold;"&gt;JSP,&lt;/div&gt;&lt;div class="MsoNormal" style="color: #cc0000; font-weight: bold;"&gt;RMI,&lt;/div&gt;&lt;div class="MsoNormal" style="color: #cc0000; font-weight: bold;"&gt;EJB&lt;/div&gt;&lt;div class="MsoNormal" style="color: #cc0000; font-weight: bold;"&gt;Struts,&lt;/div&gt;&lt;div class="MsoNormal" style="color: #cc0000; font-weight: bold;"&gt;Hibernate,&lt;/div&gt;&lt;div class="MsoNormal" style="color: #cc0000; font-weight: bold;"&gt;Spring,&lt;/div&gt;&lt;div class="MsoNormal" style="color: #cc0000; font-weight: bold;"&gt;XML,&lt;/div&gt;&lt;div class="MsoNormal" style="color: #cc0000; font-weight: bold;"&gt;Web Services.&lt;/div&gt;&lt;div class="MsoNormal"&gt;We will provide the certificate from our end at the end of the course.&lt;/div&gt;&lt;div class="MsoNormal"&gt;If anyone interested Please mail me &lt;span style="color: #3366ff; font-weight: bold;"&gt;laxman.scjp@gmail.com&lt;/span&gt; or call me on&lt;span style="color: #009900;"&gt; &lt;span style="color: #3366ff; font-weight: bold;"&gt;9885&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #00cccc; font-weight: bold;"&gt;&lt;span style="color: #3366ff;"&gt; 9883 11&lt;/span&gt;.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-weight: bold;"&gt;Thanks.....&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></item><item><title>My own ConnectionPool implementation</title><link>http://www.javaexamples4u.com/2010/07/my-own-connectionpool-implementation.html</link><category>connection pooling</category><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Fri, 09 Jul 2010 22:49:26 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-6008833576662527434</guid><description>By seeing this example we can get the two things&lt;br /&gt;&lt;br /&gt;1- how to implement our own connection&lt;br /&gt;2-why sun gives wait , notify methods in object class.&lt;br /&gt;&lt;br /&gt;import java.sql.Connection;&lt;br /&gt;import java.sql.DriverManager;&lt;br /&gt;import java.util.Vector;&lt;br /&gt;public class MyConnectionPool {&lt;br /&gt;Vector connections= null;&lt;br /&gt;static MyConnectionPool instance=null;&lt;br /&gt;public static final int MAX_CONNECTIONS=10;&lt;br /&gt;&lt;br /&gt;//removeAllConnections objects&lt;br /&gt;public synchronized void removeAllConnections() {&lt;br /&gt;if (connections==null) {&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;try {&lt;br /&gt;int sz= connections.size();&lt;br /&gt;for (int i=0; i &lt; sz/2; i++) {&lt;br /&gt;Connection c= (Connection) connections.elementAt(i);&lt;br /&gt;c= null;&lt;br /&gt;connections.remove(i);&lt;br /&gt;}&lt;br /&gt;if (connections!= null &amp;amp;&amp;amp; connections.size() &gt; 0) {&lt;br /&gt;connections.removeAllElements();&lt;br /&gt;}&lt;br /&gt;connections= null;&lt;br /&gt;}catch (Exception e) {&lt;br /&gt;System.out.println( "Error "+ e);&lt;br /&gt;}&lt;br /&gt;instance =null;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//getInstance...&lt;br /&gt;public static MyConnectionPool getInstance() {&lt;br /&gt;if (instance ==null)&lt;br /&gt;instance= new MyConnectionPool();&lt;br /&gt;return instance;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//initializing all connections upto max limit i.e upto 10 connections...&lt;br /&gt;public synchronized void initialize() {&lt;br /&gt;if (connections ==null) {&lt;br /&gt;try {&lt;br /&gt;Class.forName(" com.mysql.jdbc.Driver ");&lt;br /&gt;connections= new Vector();&lt;br /&gt;int count =0;&lt;br /&gt;while (count &lt; MAX_CONNECTIONS) {&lt;br /&gt;Connection connection=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","scott","tiger");&lt;br /&gt;connections.addElement(connection);&lt;br /&gt;count++;&lt;br /&gt;}&lt;br /&gt;System.out.println( "total connections created r:" + count);&lt;br /&gt;} catch (Exception e) {&lt;br /&gt;System.out.println( "initialise:Exception ");&lt;br /&gt;e.printStackTrace();&lt;br /&gt;instance.removeAllConnections();&lt;br /&gt;initialize();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;//getting connection....&lt;br /&gt;public synchronized Connection getConnection() {&lt;br /&gt;System.out.println( "getConnection ");&lt;br /&gt;Connection c =null;&lt;br /&gt;System.out.println("connections"+connections.size());&lt;br /&gt;if (connections== null)&lt;br /&gt;return null;&lt;br /&gt;if (connections.size() &gt; 0) {&lt;br /&gt;System.out.println("i am in if");&lt;br /&gt;c =(Connection) connections.elementAt(0);&lt;br /&gt;connections.removeElementAt(0);&lt;br /&gt;}else&lt;br /&gt;{&lt;br /&gt;System.out.println("i am in else");&lt;br /&gt;try {&lt;br /&gt;wait();&lt;br /&gt;c =(Connection) connections.elementAt(0);&lt;br /&gt;connections.removeElementAt(0);&lt;br /&gt;} catch (InterruptedException e) {&lt;br /&gt;e.printStackTrace();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;return c;&lt;br /&gt;}&lt;br /&gt;//put connection obj into vector.&lt;br /&gt;public synchronized void putConnection(Connection c) {&lt;br /&gt;if (c != null) {&lt;br /&gt;connections.addElement(c);&lt;br /&gt;notifyAll();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total></item><item><title>Java Tutorial  with Examples Home Page</title><link>http://www.javaexamples4u.com/2009/02/java-tutorial-with-examples-home-page.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Sat, 04 Jul 2009 02:56:08 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-8722822877164532848</guid><description>&lt;span style="color: rgb(153, 0, 0); font-weight: bold;"&gt;Fundamentals&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;-------------------------------------------------------------------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/02/java-datatypes-tutorial-datatypes.html"&gt;DataTypes&lt;/a&gt;  &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp     &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp    &lt;a href="http://www.javaexamples4u.com/2009/02/java-identifiers.html"&gt;Identifiers&lt;/a&gt; &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp       &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp      &lt;a href="http://www.javaexamples4u.com/2009/02/java-literals-tutorial-literals.html"&gt;Literals&lt;/a&gt;    &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp      &lt;a href="http://www.javaexamples4u.com/2009/02/java-keywords.html"&gt;JavaKeyords&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/02/java-variable-tutorial-variable.html"&gt;Variable&lt;/a&gt; &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp    &lt;a href="http://www.javaexamples4u.com/2009/02/java-arrays-tutorial-arrays-examples.html"&gt;Arrays &lt;/a&gt;   &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp      &lt;a href="http://www.javaexamples4u.com/2009/02/java-operators-tutorial-operators.html"&gt;Operators&lt;/a&gt;   &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp      &lt;a href="http://www.javaexamples4u.com/2009/02/java-type-casting-tutorial-type-casting.html"&gt;TypeCasting&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/02/java-control-flow-tutorial-control-flow.html"&gt;FlowControl&lt;/a&gt;        &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp    &lt;a href="http://www.javaexamples4u.com/2009/02/coding-standards.html"&gt;Coding Standards&lt;/a&gt;        &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp      &lt;a href="http://www.javaexamples4u.com/2009/02/java-staticimports-tutorial.html"&gt;imports,package&lt;/a&gt;    &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp      &lt;a href="http://www.javaexamples4u.com/2009/02/java-mainmethod-command-line-arguments.html"&gt;mainMethod,args&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/02/java-access-specifiers-tutorial-access.html"&gt;Access Modifiers&lt;/a&gt; &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp    &lt;a href="http://www.javaexamples4u.com/2009/02/java-var-arg-method-tutorial-var.html"&gt;var-argMethod&lt;/a&gt;    &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp      &lt;a href="http://www.javaexamples4u.com/2009/03/abstract-class.html"&gt;AbstructClass &lt;/a&gt;  &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp     &lt;a href="http://www.javaexamples4u.com/2009/02/java-garbage-collection-tutorial.html"&gt; GarbageCollection&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/02/java-inner-class-tutorial-inner-class.html"&gt;InnerClass&lt;/a&gt;  &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp    &lt;a href="http://www.javaexamples4u.com/2009/02/java-interface-tutorial-interface.html"&gt;Interface &lt;/a&gt;   &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp     &lt;a href="http://www.javaexamples4u.com/2009/02/java-assertions-tutorial-assertions.html"&gt;Assertions&lt;/a&gt;  &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp &lt;a href="http://www.javaexamples4u.com/2009/02/static-control-flow.html"&gt;java execution flow&lt;/a&gt;          &lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/03/java-super-java-this.html"&gt;super,this&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0); font-weight: bold;"&gt;java.lang&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;-------------------------------------------------------------------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/02/java-classobject-classes-tutorial.html"&gt;Class,Object Classes&lt;/a&gt;   &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp    &lt;a href="http://www.javaexamples4u.com/2009/02/enum-tutorial-enum-examples.html"&gt;Enum &lt;/a&gt;        &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp      &lt;a href="http://www.javaexamples4u.com/2009/02/java-string-class-tutorial-string.html"&gt;String &lt;/a&gt;    &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp      &lt;a href="http://www.javaexamples4u.com/2009/02/stringbufferstringbuilder-tutorial.html"&gt;StringBuffer,StringBuilder&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/02/cloneablecomparable-tutorial-examples.html"&gt;Cloneable,Comparable&lt;/a&gt; &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp  &lt;a href="http://www.javaexamples4u.com/2009/02/java-wrapper-classes-tutorial-wrapper.html"&gt;Wrapper Classes&lt;/a&gt;        &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp      &lt;a href="http://www.javaexamples4u.com/2009/03/math-class.html"&gt;Math class&lt;/a&gt;  &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp              &lt;a href="http://www.javaexamples4u.com/2009/02/java-autoboxingautounboxing-tutorial.html"&gt;Autoboxing,Autounboxing&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/03/system-class.html"&gt;System class&lt;/a&gt;       &lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0); font-weight: bold;"&gt;OOPS&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;-------------------------------------------------------------------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/02/class.html"&gt;class,object&lt;/a&gt;      &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp    &lt;a href="http://www.javaexamples4u.com/2009/02/encapsulation.html"&gt;Encapsulation&lt;/a&gt;        &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp      &lt;a href="http://www.javaexamples4u.com/2009/02/java-abstraction.html"&gt;Abstraction&lt;/a&gt;    &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp     &lt;a href="http://www.javaexamples4u.com/2009/02/inheritance-tutorial-inheritance.html"&gt;Inheritance&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/02/method-overloading-tutorial-method.html"&gt;Method Overloading&lt;/a&gt;  &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp    &lt;a href="http://www.javaexamples4u.com/2009/02/method-overriding-tutorial-method.html"&gt;Method Overriding&lt;/a&gt;    &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp     &lt;a href="http://www.javaexamples4u.com/2009/02/constructor-tutorial-constructor.html"&gt;Constructors&lt;/a&gt;    &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp      &lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0); font-weight: bold;"&gt;Collections&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;-------------------------------------------------------------------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/02/list-classes-tutorial-list-classes.html"&gt;All List Classes&lt;/a&gt;       &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp    &lt;a href="http://www.javaexamples4u.com/2009/02/set-classes-tutorial-set-classes.html"&gt;All Set Classes&lt;/a&gt;        &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp      &lt;a href="http://www.javaexamples4u.com/2009/02/map-interface-and-implemeted-classes.html"&gt;All Map Classes &lt;/a&gt;     &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp  &lt;a href="http://www.javaexamples4u.com/2009/02/collections-class-tutorial-examples.html"&gt;Collections Class&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/02/iteratorlistiteratorenumeration_02.html"&gt;Iterator,ListIterator&lt;/a&gt; &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp    &lt;a href="http://www.javaexamples4u.com/2009/02/source-code-comparator.html"&gt;Comparator&lt;/a&gt;   &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp      &lt;a href="http://www.javaexamples4u.com/2009/03/generics-tutorial-generics-example.html"&gt;Generics&lt;/a&gt;  &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp     Timer,TimerTask&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/02/stringtokenizer-tutorial.html"&gt;StringTokenizer&lt;/a&gt;&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp   &lt;a href="http://www.javaexamples4u.com/2009/03/locale-example-tutorial.html"&gt;Locale class&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0); font-weight: bold;"&gt;Exceptions&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;-------------------------------------------------------------------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/02/java-exception-handling-tutorial.html"&gt;DefaultException&lt;/a&gt;       &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp   &lt;a href="http://www.javaexamples4u.com/2009/02/checked-exceptionunchecked-exceptions.html"&gt;Checked,UnChecked&lt;/a&gt;        &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp      &lt;a href="http://www.javaexamples4u.com/2009/02/trycatchfinally-tutorial.html"&gt;try,catch,finally&lt;/a&gt;    &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp      &lt;a href="http://www.javaexamples4u.com/2009/02/throw-throws-tutorial-throw-throws.html"&gt;throw , throws&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/02/java-exception-handling-tutorial.html"&gt;Handler&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0); font-weight: bold;"&gt;Threads&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;-------------------------------------------------------------------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/02/thread-create-tutorial-thread-create.html"&gt;Thread Creation&lt;/a&gt; &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp            &lt;a href="http://www.javaexamples4u.com/2009/02/thread-sleepyieldjoininterupt-methods.html"&gt;Thread Class Methods&lt;/a&gt; &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp     &lt;a href="http://www.javaexamples4u.com/2009/02/thread-synchronization-tutorial-thread.html"&gt;Synchronization&lt;/a&gt;    &amp;nbsp&amp;nbsp&amp;nbsp     &lt;a href="http://www.javaexamples4u.com/2009/02/thread-communication-wait-notify.html"&gt;wait,notify,notifyAl&lt;/a&gt;l    &lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/02/daemon-threads-tutorial-examples.html"&gt;Daemon Threads&lt;/a&gt;  &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp  &lt;a href="http://www.javaexamples4u.com/2009/02/thread-groups-tutorial-examples.html"&gt;Thread group&lt;/a&gt;  &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp   &lt;a href="http://www.javaexamples4u.com/2009/02/thread-deadlock-tutorial-example.html"&gt;Thread Deadlock&lt;/a&gt;  &lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0); font-weight: bold;"&gt;java.io&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;-------------------------------------------------------------------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/02/java-files-tutorial-examples.html"&gt;File&lt;/a&gt;  &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp      &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp    &lt;a href="http://www.javaexamples4u.com/2009/02/all-reader-classes-tutorial-examples.html"&gt;All Reader Classes&lt;/a&gt;           &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp      &lt;a href="http://www.javaexamples4u.com/2009/02/all-writer-classes-tutorial-examples.html"&gt;All Writer Classes&lt;/a&gt;    &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp  &lt;a href="http://www.javaexamples4u.com/2009/03/stream-i-constant-flow-of-water-is.html"&gt;All Stream Classes &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.javaexamples4u.com/2009/02/serialization-tutorial-examples.html"&gt;Serialization&lt;/a&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>servlet-interface</title><link>http://www.javaexamples4u.com/2009/07/servlet-interface.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Wed, 08 Jul 2009 05:23:25 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-596099389587133197</guid><description>&lt;span style="font-weight: bold; color: rgb(153, 0, 0); font-family: verdana;"&gt;In javax.servlet.Servlet Interface contains the following methods:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;"&gt;public void init (Servletconfig config) throws  ServletException.&lt;/span&gt;&lt;br /&gt;&lt;ul style="font-family: verdana;"&gt;&lt;li&gt;This method called by servlet container to indicate to a servlet that the servlet is being placed into the service.&lt;/li&gt;&lt;li&gt;The init () method called by servlet container exactly once after instantiating the servlet.&lt;/li&gt;&lt;li&gt;We can override init () method if we have initialization code like getting database connection.&lt;/li&gt;&lt;li&gt;The servlet container can not place the servlet into service of the init () methods.&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family: verdana;"&gt;In the following situation the web container destroys that servlet object.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;If it throws a servlet exception&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;If it doesn't return with in a time period defined by the web server.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;"&gt;public void service (servlet Request req, Servlet Response res) throws ServletException, IOException  :&lt;/span&gt;&lt;br /&gt;&lt;ul style="font-family: verdana;"&gt;&lt;li&gt;Called by servlet container to allow to respond to the client request.&lt;/li&gt;&lt;li&gt; It should be called after the servlet’s init()method completion&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;"&gt;public void destroy()  :&lt;/span&gt;&lt;br /&gt;&lt;ul style="font-family: verdana;"&gt;&lt;li&gt;The servlet container call the destroy () method before removing a servlet instance from service.&lt;/li&gt;&lt;li&gt;This normally happens when the servlet container is shut down of the servlet container needs some free memory.&lt;/li&gt;&lt;li&gt;This method is only called once all the thread with in the servlet service () method have exited.&lt;/li&gt;&lt;li&gt;We can keep cleanup code inside destroy () method.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;"&gt;public servlet config getservletconfig()  :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;It  returns servlet config object which contain initialization and start of information of the servlet object.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;"&gt;public string getServletInfo()  :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;It returns a string containing information about the servlet such as author version and copy right.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;"&gt;&lt;br /&gt;Sample servlet program by implement Servlet interface :&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;import javax.servlet.*;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;import java.io.*;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;class BasicServlet implements Servlet&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt; public void init ()(Servlet config conf) throws ServletException&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;System.out.println (“input method”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;public void service (ServletRequest req, ServletResponse res) throws ServletException, IOException&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;System.out.println (“service method”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;} &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;public void destroy ()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;System.out.println (“destroy method”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;public ServletConfig getServletConfig ()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;return null;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;public String getServletInfo ()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;return null;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;public String getServletInfo ()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;return null;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;}&lt;/span&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>javax servlet package</title><link>http://www.javaexamples4u.com/2009/07/javax-servlet-package.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Wed, 01 Jul 2009 04:32:26 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-3562087804118998353</guid><description>&lt;ul  style="font-family:verdana;"&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Javax.servlet:&lt;/span&gt;   It defines several basic classes and interfaces to build servlets from the scratch irrespective of any protocol.&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Javax.servlet.http&lt;/span&gt;:  This package contain several more convenient classes and interfaces (which extends classes and interfaces of javax.servlet package) to build servlets specific to http. It also contain several extra utility classes and interfaces like cookies http session(interface for developing web applications efficiently.&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold; color: rgb(102, 0, 0);font-family:verdana;" &gt;JAVAX.SERVLET PACKAGE:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;This package contains the following important interfaces:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;1.Servlet  Interface&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;:  It defines several methods which must be implemented by every servlet in java either directly or indirectly.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;- this is the interface which define life cycle methods of interface.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;2.Servlet Request &lt;/span&gt;&lt;span style="font-family:verdana;"&gt;:  The servlet Request object contain client information which can be used by servlet to generate response.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;3.Servlet Response :&lt;/span&gt;&lt;span style="font-family:verdana;"&gt; servlet response object contain the response which can sent to the client .  ex:servlet uses servlet response object it send response to the client.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;4.Servlet config  :&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;  it contains the configuration or deployment information of start up information of the servlet.Web container creates a separate servlet and pass configuration information to the server by using this object.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;5.Servlet context  : &lt;/span&gt;&lt;span style="font-family:verdana;"&gt; Servlet context in the object which can be used by servlet to communicate with web server.For every web application one servlet context object will create by using the servlet context object servlet can get servlet context object.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;6. Request Dispatcher:&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;  This object can be used by servlet to redirect the requests for another web component (servlet/jsp). This interface contain forward and include methods.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;7. Single Thread Model:&lt;/span&gt;&lt;span style="font-family:verdana;"&gt; This interface can be implementing by servlet to generate that it can process only one request at a time.This is the deprecated interface and there is no replacement control 2.4. version.It does not contain any methods. So this is a MARKER INTERFACE.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;These packages contain the following important classes.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol  style="font-family:verdana;"&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;GenericServlet:&lt;/span&gt;  to implement Generic protocol independent servlets.&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;ServletInputStream:&lt;/span&gt;  provides an input stream for reading binary data from a client request.&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;ServletOutputStream:&lt;/span&gt; provides an output stream for reading binary data from a client request.This package defined the following Exception&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;ServletException: &lt;/span&gt;Defines a general Exception. A servlet can throw when it fare some difficulty whose processing client request.&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;UnavailableException:&lt;/span&gt;  Defines an Exception that a servlet throws to indicate that the servlet is unavailable permanently or temporally.&lt;/li&gt;&lt;/ol&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>Serialization Inheritence</title><link>http://www.javaexamples4u.com/2009/06/serialization-inheritence.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Thu, 04 Jun 2009 05:44:52 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-7514546014703109642</guid><description>&lt;span style="font-weight: bold; color: rgb(153, 0, 0); font-family: verdana;font-family:verdana;"&gt;Serialization in case of  Inheritence:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;class Animal implements Serializable&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;int i=10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;class Dog extends Animal&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;int j=20;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;When ever we are adding a child class object to a file ,parent class object will not save to the file .Because parent class objects are not part of  state of the child class object.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;If any variable is inherited from the perent that variable will also add to the file as a part of child class object.&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0); font-family: verdana;font-family:verdana;"&gt;example:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;class SerialDemo&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;public static void main(String arg[])&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;Dog d=new  Dog();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;System.out.println(d.i+”……..”+d.j);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;FileOutputStream fos=new FileOutputStream(“abc.txt”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;ObjectOutputStream oos=new ObjectOutputStream(fos);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;Oos.writeObject(d);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;FileInputStream fis=new FileInputStream(“abc.txt’);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;ObjectInputStream  ois=new ObjectInputStream(fis);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;Dog d1=9Dog)ois.readObject();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;System.out.println(d.i+”……..”+d.j);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;ul style="font-family: verdana;"&gt;&lt;li&gt;If the parent class is serializable  by default every child class is also serializable.&lt;/li&gt;&lt;li&gt;If we are writing any servlet by extending GenericServlet or HttpServlet it is always Serializable because GenericServlet already implements serializable interface&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;"&gt;Note:&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt; By just simply seeing a class we can’t tell whether it is serializable or not .We have to check any parent class of this class of this class is serializable  or not .If none of the parent class is not serializable then then only we can decode the given class is not serializable.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0); font-family: verdana;font-family:verdana;"&gt;Serialization in case of  Inheritence  example:&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;class Animal&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;int i=10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;class Dog extends Animal implements serializable&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;int j=20;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;class SerialDemo&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;public static void main(String arg[])throws Exception&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;Dog d=new  Dog();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;d.i=1000;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;d.j=2000;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;FileOutputStream fos=new FileOutputStream(“abc.txt”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;ObjectOutputStream oos=new ObjectOutputStream(fos);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;Oos.writeObject(d);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;FileInputStream fis=new FileInputStream(“abc.txt’);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;ObjectInputStream  ois=new ObjectInputStream(fis);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;Dog d1=9Dog)ois.readObject();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;System.out.println(d.i+”……..”+d.j);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;ul style="font-family: verdana;"&gt;&lt;li&gt;If the child class is serializable and the parent is non serializable still we are allowed to save the child class objects to the file.&lt;/li&gt;&lt;li&gt;If any variable is inherited from the non-serializable parent its value is not allowed to save to the file as its corresponding class is non- serializable.&lt;/li&gt;&lt;li&gt;Instead of original value ,default values will save to the file.&lt;/li&gt;&lt;li&gt;At the time of de serialization to perform initialization for instance variable which are inherited from non- serializable parents its objects will create .After creation of parent class object ,the values of inherited values will be assigned.&lt;/li&gt;&lt;li&gt;At the time of deserialization of an object if any variable is inherited from non- serializable parent then the JVM creates parent class object by calling default no argument constructor.&lt;/li&gt;&lt;li&gt;If the parent class doesn’t contain any no argument constructor we can get a RTE saying Java.io.invalidClassException Dog :novalid constructor.&lt;/li&gt;&lt;/ul&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></item><item><title>jdbc-data-types-tutorial</title><link>http://www.javaexamples4u.com/2009/05/jdbc-data-types-tutorial.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Wed, 20 May 2009 23:10:04 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-4350512526541140419</guid><description>&lt;span style="font-family:verdana;"&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Data Types and Conversions :&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;For the getXXX methods, the JDBC driver attempts to convert the underlying data to the specified Java type and then returns a suitable Java value. For example, if the getXXX method is getString, and the data type of the data in the underlying database is VARCHAR, the JDBC driver will convert VARCHAR to Java String. The return value of getString will be a Java String object. &lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;The following table shows which JDBC types a getXXX method is allowed to retrieve and which JDBC types (generic SQL types) are recommended for it to retrieve. A small x indicates a legal getXXX method for a particular data type; a large X indicates the recommended getXXX method for a data type. For example, any getXXX method except getBytes or getBinaryStream can be used to retrieve the value of a LONGVARCHAR, but getAsciiStream or getUnicodeStream are recommended, depending on which data type is being returned.&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="font-family:verdana;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 238px;" src="http://1.bp.blogspot.com/_Pc8VSCmbaAo/ShTvtAsyAtI/AAAAAAAAAKU/NOk7cEKrWa8/s400/java+type-jdbc+type.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5338155014901859026" /&gt;&lt;span style="font-family:verdana;"&gt;The method getObject will return any data type as a Java Object and is useful when the underlying data type is a database-specific abstract type or when a generic application needs to be able to accept any data type. &lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;Use of ResultSet.getXXX methods to retrieve common JDBC data types. &lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;An "x" indicates that the getXXX method may legally be used to retrieve the given JDBC type. &lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="font-family:verdana;"&gt;An "X" indicates that the getXXX method is recommended for retrieving the given JDBC type&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:verdana;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 382px;" src="http://2.bp.blogspot.com/_Pc8VSCmbaAo/ShTl-T3mDmI/AAAAAAAAAKM/vaom6Pzx_5s/s400/jdbc-data-types.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5338144316988984930" /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;&lt;span style="font-family:verdana;"&gt;Using Streams for Very Large Row Values :&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;ResultSet makes it possible to retrieve arbitrarily large LONGVARBINARY or LONGVARCHAR data. The methods getBytes and getString return data as one large chunk (up to the limits imposed by the return value of Statement.getMaxFieldSize). However, it may be more convenient to retrieve very large data in smaller, fixed-size chunks. This is done by having the ResultSet class return java.io.Input streams from which data can be read in chunks. Note that these streams must be accessed immediately because they will be closed automatically on the next getXXX call on ResultSet. (This behavior is imposed by underlying implementation constraints on large blob access.) &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;The JDBC API has three separate methods for getting streams, each with a different return value: &lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:verdana;"&gt;getBinaryStream returns a stream which simply provides the raw bytes from the database without any conversion. &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:verdana;"&gt; getAsciiStream returns a stream which provides one-byte ASCII characters. &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:verdana;"&gt; getUnicodeStream returns a stream which provides two-byte Unicode characters. &lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;Note that this differs from Java streams, which return untyped bytes and can (for  example) be used for both ASCII and Unicode characters. &lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style="font-family:verdana;"&gt;The following code gives an example of using getAsciiStream: &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:verdana;"&gt;    java.sql.Statement stmt = con.createStatement();&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;    ResultSet r = stmt.executeQuery("SELECT x FROM Table2");&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;    // Now retrieve the column 1 results in 4 K chunks:&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;    byte buff = new byte[4096];&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;    while (r.next()) { &lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;      Java.io.InputStream fin = r.getAsciiStream(1);&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;      for (;;) {&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;        int size = fin.read(buff);&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;        if (size == -1) { // at end of stream&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;              break;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;        }&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;        // Send the newly-filled buffer to some ASCII output stream:&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;        output.write(buff, 0, size);&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;      }&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;</description><media:thumbnail url="http://1.bp.blogspot.com/_Pc8VSCmbaAo/ShTvtAsyAtI/AAAAAAAAAKU/NOk7cEKrWa8/s72-c/java+type-jdbc+type.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>JDBC-Result-Set</title><link>http://www.javaexamples4u.com/2009/04/resultset.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Wed, 15 Apr 2009 18:30:44 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-8746842005796628838</guid><description>&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;" &gt;ResultSet&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt; :&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;A ResultSet contains all of the rows which satisfied the conditions in an SQL statement, and it provides access to the data in those rows through a set of get methods that allow access to the various columns of the current row. The ResultSet.next method is used to move to the next row of the ResultSet, making the next row become the current row. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The general form of a result set is a table with column headings and the corresponding values returned by a query. For example, if your query is SELECT a, b, c FROM Table1, your result set will have the following form: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The following code fragment is an example of executing an SQL statement that will return a collection of rows, with column 1 as an int, column 2 as a String, and column 3 as an array of bytes: &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    java.sql.Statement stmt = conn.createStatement();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    ResultSet r = stmt.executeQuery("SELECT a, b, c FROM Table1");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    while (r.next()) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      // print the values for the current row.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      int i = r.getInt("a");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      String s = r.getString("b");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      float f = r.getFloat("c");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      System.out.println("ROW = " + i + " " + s + " " + f);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;" &gt;Rows and Cursors&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;A ResultSet maintains a cursor which points to its current row of data. The cursor moves down one row each time the method next is called. Initially it is positioned before the first row, so that the first call to next puts the cursor on the first row, making it the current row. ResultSet rows are retrieved in sequence from the top row down as the cursor moves down one row with each successive call to next. &lt;/span&gt;&lt;span style="font-family:verdana;"&gt;A cursor remains valid until the ResultSet object or its parent Statement object is closed. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;In SQL, the cursor for a result table is named. If a database allows positioned updates or positioned deletes, the name of the cursor needs to be supplied as a parameter to the update or delete command. This cursor name can be obtained by calling the method getCursorName. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Note that not all DBMSs support positioned update and delete. The DatabaseMetaData.supportsPositionedDelete and supportsPositionedUpdate methods can be used to discover whether a particular connection supports these operations. When they are supported, the DBMS/driver must ensure that rows selected are properly locked so that positioned updates do not result in update anomalies or other concurrency problems. &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-size:130%;" &gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Columns :&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The getXXX methods provide the means for retrieving column values from the current row. Within each row, column values may be retrieved in any order, but for maximum portability, one should retrieve values from left to right and read column values only once. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Either the column name or the column number can be used to designate the column from which to retrieve data. For example, if the second column of a ResultSet object rs is named "title" and stores values as strings, either of the following will retrieve the value stored in that column: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    String s = rs.getString("title");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    String s = rs.getString(2);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Note that columns are numbered from left to right starting with column 1. Also, column names used as input to getXXX methods are case insensitive. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The option of using the column name was provided so that a user who specifies column names in a query can use those same names as the arguments to getXXX methods. If, on the other hand, the select statement does not specify column names (as in "select * from table1" or in cases where a column is derived), column numbers should be used. In such situations, there is no way for the user to know for sure what the column names are. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;In some cases, it is possible for a SQL query to return a result set that has more than one column with the same name. If a column name is used as the parameter to a getXXX method, getXXX will return the value of the first matching column name. Thus, if there are multi0ple columns with the same name, one needs to use a column index to be sure that the correct column value is retrieved. It may also be slightly more efficient to use column numbers. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Information about the columns in a ResultSet is available by calling the method ResultSet.getMetaData. The ResultSetMetaData object returned gives the number, types, and properties of its ResultSet object's columns. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;If the name of a column is known, but not its index, the method findColumn can be used to find the column number. &lt;/span&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>JDBC-CallableStatement</title><link>http://www.javaexamples4u.com/2009/04/callablestatement.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Tue, 14 Apr 2009 18:48:17 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-8829612336813018204</guid><description>&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;CallableStatement&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;&lt;span style="font-weight: bold;"&gt; :&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;A CallableStatement object provides a way to call stored procedures in a standard way for all DBMSs. A stored procedure is stored in a database; the call to the stored procedure is what a CallableStatement object contains. This call is written in an escape syntax that may take one of two forms: one form with a result parameter, and the other without one. A result parameter, a kind of OUT parameter, is the return value for the stored procedure. Both forms may have a variable number of parameters used for input (IN parameters), output (OUT parameters), or both (INOUT parameters). A question mark serves as a placeholder for a parameter. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The syntax for invoking a stored procedure in JDBC is shown below. Note that the square brackets indicate that what is between them is optional; they are not themselves part of the syntax. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    {call procedure_name[(?, ?, ...)]}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The syntax for a procedure that returns a result parameter is: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    {? = call procedure_name[(?, ?, ...)]}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The syntax for a stored procedure with no parameters would look like this: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    {call procedure_name}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Normally, anyone creating a CallableStatement object would already know that the DBMS being used supports stored procedures and what those procedures are. If one needed to check, however, various DatabaseMetaData methods will supply such information. For instance, the method supportsStoredProcedures will return true if the DBMS supports stored procedure calls, and the method getProcedures will return a description of the stored procedures available. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;CallableStatement inherits Statement methods, which deal with SQL statements in general, and it also inherits PreparedStatement methods, which deal with IN parameters. All of the methods defined in CallableStatement deal with OUT parameters or the output aspect of INOUT parameters: registering the JDBC types (generic SQL types) of the OUT parameters, retrieving values from them, or checking whether a returned value was JDBC NULL. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;" &gt;Creating a CallableStatement Object&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;CallableStatement objects are created with the Connection method prepareCall. The example below creates an instance of CallableStatement that contains a call to the stored procedure getTestData, which has two arguments and no result parameter: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    CallableStatement cstmt = con.prepareCall(&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                  "{call getTestData(?, ?)}");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Whether the ? placeholders are IN, OUT, or INOUT parameters depends on the stored procedure getTestData. &lt;/span&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>PreparedStatement</title><link>http://www.javaexamples4u.com/2009/04/preparedstatement.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Thu, 09 Apr 2009 08:34:43 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-2531358858872775816</guid><description>&lt;span style="font-family: verdana;font-family:verdana;font-size:130%;"  &gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;PreparedStatement&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;:&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;  The PreparedStatement interface inherits from Statement and differs from it in two ways: &lt;/span&gt;&lt;br /&gt;&lt;ul style="font-family: verdana;"&gt;&lt;li&gt;Instances of PreparedStatement contain an SQL statement that has already been compiled. This is what makes a statement "prepared." &lt;/li&gt;&lt;li&gt;The SQL statement contained in a PreparedStatement object may have one or more IN parameters. An IN parameter is a parameter whose value is not specified when the SQL statement is created. Instead the statement has a question mark ("?") as a placeholder for each IN parameter. A value for each question mark must be supplied by the appropriate setXXX method before the statement is executed. &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Because PreparedStatement objects are precompiled, their execution can be faster than that of Statement objects. Consequently, an SQL statement that is executed many times is often created as a PreparedStatement object to increase efficiency. Being a subclass of Statement, PreparedStatement inherits all the functionality of Statement. In addition, it adds a whole set of methods which are needed for setting the values to be sent to the database in place of the placeholders for IN parameters. Also, the three methods execute, executeQuery, and executeUpdate are modified so that they take no argument. The Statement forms of these methods (the forms that take an SQL statement parameter) should never be used with a PreparedStatement object. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0); font-family: verdana;font-family:verdana;" &gt;Creating PreparedStatement Objects&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt; &lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0); font-family: verdana;font-family:verdana;" &gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;The following code fragment, where con is a Connection object, creates a PreparedStatement object containing an SQL statement with two placeholders for IN parameters: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;    PreparedStatement pstmt = con.prepareStatement(&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;        "UPDATE table4 SET m = ? WHERE x = ?");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;The object pstmt now contains the statement "UPDATE table4 SET m = ? WHERE x = ?", which has already been sent to the DBMS and been prepared for execution. &lt;/span&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>jdbc</title><link>http://www.javaexamples4u.com/2009/04/jdbc.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Sat, 04 Jul 2009 02:55:11 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-5333087273044982499</guid><description>&lt;div  style="text-align: center;font-family:verdana;"&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;        &lt;span style="color: rgb(255, 102, 0);"&gt;JDBC TUTORIAL  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;                                                                    &lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style=";font-family:verdana;font-size:130%;"  &gt;&lt;a href="http://www.javaexamples4u.com/2009/03/what-is-jdbc.html"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;JDBC&lt;/span&gt;  Introduction?&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=";font-family:verdana;font-size:130%;"  &gt;&lt;a style="font-weight: bold;" href="http://www.javaexamples4u.com/2009/03/jdbc-odbc-tutorial.html"&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;JDBC - ODBC&lt;/span&gt; Introduction &lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a style="font-family: verdana;" href="http://www.javaexamples4u.com/2009/04/types-of-jdbc-drivers.html"&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;Types Of &lt;span style="color: rgb(153, 0, 0);"&gt;JDBC Drivers&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a style="font-family: verdana;" href="http://www.javaexamples4u.com/2009/04/jdbc-url.html"&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;JDBC - URL&lt;/span&gt; format tutorial&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a style="font-family: verdana;" href="http://www.javaexamples4u.com/2009/04/statement-jdbc-tutorial.html"&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;JDBC &lt;span style="color: rgb(153, 0, 0);"&gt;Statement&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a style="font-family: verdana;" href="http://www.javaexamples4u.com/2009/04/jdbc-execute-method.html"&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;JDBC &lt;span style="color: rgb(153, 0, 0);"&gt;execute Method&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://www.javaexamples4u.com/2009/04/preparedstatement.html"&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;JDBC&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;&lt;span style="color: rgb(102, 0, 0);"&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;a href="http://www.javaexamples4u.com/2009/04/preparedstatement.html"&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;Prepare Statement&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;&lt;a href="http://www.javaexamples4u.com/2009/04/callablestatement.html"&gt;JDBC &lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;&lt;a href="http://www.javaexamples4u.com/2009/04/callablestatement.html"&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;CallableStatement&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;&lt;a href="http://www.javaexamples4u.com/2009/04/resultset.html"&gt;JDBC  &lt;span style="color: rgb(153, 0, 0);"&gt;Result Set&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;&lt;a href="http://www.javaexamples4u.com/2009/05/jdbc-data-types-tutorial.html"&gt;JDBC  &lt;span style="color: rgb(153, 0, 0);"&gt;Data types&lt;/span&gt; &lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;&lt;a href="http://www.javaexamples4u.com/2009/05/odbc-jdbc-bridge-driver.html"&gt;&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;div  style="text-align: center;font-family:verdana;"&gt;&lt;span style="color: rgb(255, 102, 0);font-size:130%;" &gt;&lt;span style="font-weight: bold;"&gt;JDBC EXAMPLES&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;1. &lt;a href="http://www.javaexamples4u.com/2009/03/jdbc-connection-example.html"&gt;JDBC connection Example code&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;2&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;. &lt;/span&gt;&lt;a style="font-family: verdana;" href="http://www.javaexamples4u.com/2009/03/jdbc-code-create-table.html"&gt;&lt;span style="font-weight: bold;"&gt;JDBC code to create a table ?&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;3.&lt;/span&gt;&lt;span style="font-family:verdana;"&gt; &lt;/span&gt;&lt;a style="font-family: verdana;" href="http://www.javaexamples4u.com/2009/03/jdbc-example-insert-data-database.html"&gt;&lt;span style="font-weight: bold;"&gt;JDBC code ti insert data in DataBase?&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;4.&lt;/span&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>jdbc-execute-method</title><link>http://www.javaexamples4u.com/2009/04/jdbc-execute-method.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Tue, 07 Apr 2009 23:01:44 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-846529575939274033</guid><description>&lt;span style="font-family:verdana;"&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;execute method:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;The execute method should be used only when it is possible that a statement may return more than one ResultSet object, more than one update count, or a combination of ResultSet objects and update counts. These multiple possibilities for results, though rare, are possible when one is executing certain stored procedures or dynamically executing an unknown SQL string (that is, unknown to the application programmer at compile time). For example, a user might execute a stored procedure and that stored procedure could perform an update, then a select, then an update, then a select, and so on. Typically, someone using a stored procedure will know what it returns. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Because the method execute handles the cases that are out of the ordinary, it is no surprise that retrieving its results requires some special handling. For instance, suppose it is known that a procedure returns two result sets. After using the method execute to execute the procedure, one must call the method getResultSet to get the first result set and then the appropriate getXXX methods to retrieve values from it. To get the second result set, one needs to call getMoreResults and then getResultSet a second time. If it is known that a procedure returns two update counts, the method getUpdateCount is called first, followed by getMoreResults and a second call to getUpdateCount. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Those cases where one does not know what will be returned present a more complicated situation. The method execute returns true if the result is a ResultSet object and false if it is a Java int. If it returns an int, that means that the result is either an update count or that the statement executed was a DDL command. The first thing to do after calling the method execute, is to call either getResultSet or getUpdateCount. The method getResultSet is called to get what might be the first of two or more ResultSet objects; the method getUpdateCount is called to get what might be the first of two or more update counts. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;When the result of an SQL statement is not a result set, the method getResultSet will return null. This can mean that the result is an update count or that there are no more results. The only way to find out what the null really means in this case is to call the method getUpdateCount, which will return an integer. This integer will be the number of rows affected by the calling statement or -1 to indicate either that the result is a result set or that there are no results. If the method getResultSet has already returned null, which means that the result is not a ResultSet object, then a return value of -1 has to mean that there are no more results. In other words, there are no results (or no more results) when the following is true: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    &lt;span style="color: rgb(0, 102, 0); font-weight: bold;"&gt;((stmt.getResultSet() == null) &amp;amp;&amp;amp; (stmt.getUpdateCount() == -1))&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;If one has called the method getResultSet and processed the ResultSet object it returned, it is necessary to call the method getMoreResults to see if there is another result set or update count. If getMoreResults returns true, then one needs to again call getResultSet to actually retrieve the next result set. As already stated above, if getResultSet returns null, one has to call getUpdateCount to find out whether null means that the result is an update count or that there are no more results. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;When getMoreResults returns false, it means that the SQL statement returned an update count or that there are no more results. So one needs to call the method getUpdateCount to find out which is the case. In this situation, there are no more results when the following is true: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    &lt;span style="font-weight: bold; color: rgb(0, 102, 0);"&gt;((stmt.getMoreResults() == false) &amp;amp;&amp;amp; (stmt.getUpdateCount() == -1))&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The code below demonstrates one way to be sure that one has accessed all the result sets and update counts generated by a call to the method execute: &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    stmt.execute(queryStringWithUnknownResults);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    while (true)  {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      int rowCount = stmt.getUpdateCount();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      if (rowCount &gt; 0) {   &lt;span style="color: rgb(0, 102, 0);"&gt; //  this is an update count&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;        System.out.println("Rows changed = " + count);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;        stmt.getMoreResults();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;        continue;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      if (rowCount == 0) {    &lt;span style="color: rgb(0, 102, 0);"&gt;// DDL command or 0 updates&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;        System.out.println(" No rows changed or statement was DDL&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                                    command");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;        stmt.getMoreResults();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;        continue;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    &lt;span style="color: rgb(0, 102, 0);"&gt;// if we have gotten this far, we have either a result set &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);font-family:verdana;" &gt;    // or no more results&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      ResultSet rs = stmt.getResultSet; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      if (rs != null) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;        . . .  // use metadata to get info about result set columns&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;        while (rs.next())  {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;        . . .  // process results&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;        stmt.getMoreResults();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;        continue;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      break;      &lt;span style="color: rgb(0, 102, 0);"&gt;// there are no more results&lt;/span&gt;&lt;/span&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></item><item><title>jdbc-statement-tutorial</title><link>http://www.javaexamples4u.com/2009/04/statement-jdbc-tutorial.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Mon, 06 Apr 2009 23:07:13 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-7218876986764154041</guid><description>&lt;span style="color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;&lt;span style="font-weight: bold;"&gt;Statement&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;&lt;span style="font-weight: bold;"&gt;:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;A Statement object is used to send SQL statements to a database. There are actually three kinds of Statement objects, all of which act as containers for executing SQL statements on a given connection: Statement, PreparedStatement, which inherits from Statement, and CallableStatement, which inherits from PreparedStatement. They are specialized for sending particular types of SQL statements: a Statement object is used to execute a simple SQL statement with no parameters; a PreparedStatement object is used to execute a precompiled SQL statement with or without IN parameters; and a CallableStatement object is used to execute a call to a database stored procedure. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The Statement interface provides basic methods for executing statements and retrieving results. The PreparedStatement interface adds methods for dealing with IN parameters; CallableStatement adds methods for dealing with OUT parameters. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;&lt;span style="font-weight: bold;"&gt;Creating Statement Objects&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Once a connection to a particular database is established, that connection can be used to send SQL statements. A Statement object is created with the Connection method createStatement, as in the following code fragment: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    Connection con = DriverManager.getConnection(url, "sunny", "");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    Statement stmt = con.createStatement();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The SQL statement that will be sent to the database is supplied as the argument to one of the methods for executing a Statement object: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table2);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;" &gt;Executing Statements Using Statement objects&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The Statement interface provides three different methods for executing SQL statements, executeQuery, executeUpdate, and execute. The one to use is determined by what the SQL statement produces. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The method executeQuery is designed for statements that produce a single result set, such as SELECT statements. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The method executeUpdate is used to execute INSERT, UPDATE, or DELETE statements and also SQL DDL (Data Definition Language) statements like CREATE TABLE and DROP TABLE. The effect of an INSERT, UPDATE, or DELETE statement is a modification of one or more columns in zero or more rows in a table. The return value of executeUpdate is an integer indicating the number of rows that were affected (referred to as the update count). For statements such as CREATE TABLE or DROP TABLE, which do not operate on rows, the return value of executeUpdate is always zero. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The method execute is used to execute statements that return more than one result set, more than one update count, or a combination of the two. Because it is an advanced feature that most programmers will never need, it is explained in its own section later in this overview. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;All of the methods for executing statements close the calling Statement object's current result set if there is one open. This means that one needs to complete any processing of the current ResultSet object before re-executing a Statement object. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;It should be noted that the PreparedStatement interface, which inherits all of the methods in the Statement interface, has its own versions of the methods executeQuery, executeUpdate and execute. Statement objects do not themselves contain an SQL statement; therefore, one must be provided as the argument to the Statement.execute methods. PreparedStatement objects do not supply an SQL statement as a parameter to these methods because they already contain a precompiled SQL statement. CallableStatement objects inherit the PreparedStatement forms of these methods. Using a query parameter with the PreparedStatement or CallableStatement versions of these methods will cause an SQLException to be thrown. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;&lt;span style="font-weight: bold;"&gt;Statement Completion&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;When a connection is in auto-commit mode, the statements being executed within it are committed or rolled back when they are completed. A statement is considered complete when it has been executed and all its results have been returned. For the method executeQuery, which returns one result set, the statement is completed when all the rows of the ResultSet object have been retrieved. For the method executeUpdate, a statement is completed when it is executed. In the rare cases where the method execute is called, however, a statement is not complete until all of the result sets or update counts it generated have been retrieved. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Some DBMSs treat each statement in a stored procedure as a separate statement; others treat the entire procedure as one compound statement. This difference becomes important when auto-commit is enabled because it affects when the method commit is called. In the first case, each statement is individually committed; in the second, all are committed together. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;" &gt;Closing Statement Objects&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Statement objects will be closed automatically by the Java garbage collector. Nevertheless, it is recommended as good programming practice that they be closed explicitly when they are no longer needed. This frees DBMS resources immediately and helps avoid potential memory problems. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Using the Method execute&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;/span&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>generic-class-generic-method</title><link>http://www.javaexamples4u.com/2009/04/genericclass-genericmethod.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Mon, 06 Apr 2009 03:22:58 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-665096742527561405</guid><description>&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;" &gt;Generic classes:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;We are allowed to define type parameter for the classes.such type of parametrized classes are called generic classes.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);font-family:verdana;" &gt;//Type parameter T&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;class Generictest&amp;lt;T,X&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;T ob;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);font-family:verdana;" &gt;//Generic variable&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Generictest(T ob)&lt;/span&gt;&lt;span style="font-family:verdana;"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);font-family:verdana;" &gt; //Generic constructor&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;this.ob=ob;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;void show()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(the type is:ob.getClass().getName());&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;T getob()&lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);font-family:verdana;" &gt; //Generic method&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;return ob;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;class GenericDemo&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;public static void main(Strin arg[])&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Generictest&amp;lt;Integer&amp;gt; g=new Generictest&amp;lt;Integer&amp;gt;(10);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;g.show(); &lt;span style="color: rgb(0, 102, 0);"&gt; //java.lang.Integer&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(g.getob());    &lt;span style="color: rgb(0, 102, 0);"&gt;// 10&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Generictest&amp;lt;String&amp;gt; g=new Generictest&amp;lt;String&amp;gt;(“Laxman”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;g.show(); &lt;span style="color: rgb(0, 102, 0);"&gt;  //java.lang.String&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(g.getob());   &lt;span style="color: rgb(0, 102, 0);"&gt;// Laxman&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;" &gt;Bound Types:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;We can bound the type parameter I the generic classes by using extends keyword.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Example:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Gen&amp;lt;T&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;We are allowed to create an instance of class by passing any parameter type.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Gen&amp;lt;T extends Number&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul style="font-family: verdana;"&gt;&lt;li&gt;we can create a gen object by passing the type parameter which must be child class of number violation leads to error.&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family:verdana;"&gt;i.e Gen&amp;lt;String&amp;gt; g=new Gen&amp;lt;String&amp;gt;();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;CTE saying type parameter &lt;/span&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;java.lang.String is not with in its bound&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Extends means both extends as well as implements.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;class Gen&amp;lt;T extends X&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;If   X is a class any child class of X (including X) is allowed as T.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;If X is any interface Any implemented class of X is allowed as T.&lt;/span&gt;&lt;br /&gt;&lt;span style=";font-family:verdana;font-size:130%;"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;Generic Methods:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;class&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;public static void main(String arg[])&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ArrayList&amp;lt;String&amp;gt; st=new ArrayList&amp;lt;String&amp;gt;();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;st.add(“aaa”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;st.add(“bbb”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;st.add(“ccc”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;show(s1);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ArrayList&amp;lt;Integer&amp;gt; st=new ArrayList&amp;lt;Integer&amp;gt;();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;st.add(10);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;st.add(20);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;st.add(30);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;show(s2);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;public static void main(String arg[])&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(s);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;wild card(?)character in generic conclusions:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;1&lt;/span&gt;.m1(ArrayList&amp;lt;String&amp;gt; l)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;This can be applied only for ArrayList of String type only.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;2&lt;/span&gt;.m1(ArrayList&amp;lt;?&amp;gt; l)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;This can be applied for ArrayList of any type  ? means unknown type.which is known as wild card character .&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;3&lt;/span&gt;.m1(ArrayList&amp;lt;? Extends X&amp;gt;  l)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;If X is class this method can be applied for ArrayList of any class ,which is the child class of X is allowed.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;If X is interface then any class which implements X is allowed .&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="color: rgb(153, 0, 0); font-weight: bold;"&gt;4&lt;/span&gt;.m1(ArrayList &amp;lt;? Super X&amp;gt;  l)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;any class which is super class of X is allowed as the type parameter.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Conclusions:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;class Test&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;public static void main(Strin arg[])&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ArrayList&amp;lt;String&amp;gt;  l=new ArrayList&amp;lt;String&amp;gt;();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;l.add(“a”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;l.add(“b”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;l.add(“c”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;show(l);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:verdana;" &gt;//If type is string&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;show(ArrayList&amp;lt;String&amp;gt; l)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;l.add(“e”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;l.add(10);   &lt;span style="color: rgb(0, 102, 0);"&gt;// invalid&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt; (&lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);font-family:verdana;" &gt;error&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;: we are only allowed to add String objects&lt;/span&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(l);&lt;span style="color: rgb(0, 102, 0);"&gt;   // [a,b,c,e]&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:verdana;" &gt;//If type is wild char (?)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;show(ArrayList&amp;lt;?&amp;gt;  l)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;l.add(“e”);     &lt;span style="color: rgb(0, 102, 0);"&gt;//  error&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;l.add(“null”);  &lt;span style="color: rgb(0, 102, 0);"&gt;// valid&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(l);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul style="font-family: verdana;"&gt;&lt;li&gt;Here we doesn’t know what kind of parameter is coming for this method.Because this method is applicable for Arraylist of any type of parameter.&lt;/li&gt;&lt;li&gt;If we use wild card character ‘?’ in the method declaration ,then we are allowed to perform only READ operation with in that method.&lt;/li&gt;&lt;li&gt;we are not allowed to add any element because what kind of arraylist is coming as argument we can’t give any assurance.&lt;/li&gt;&lt;li&gt;But we can add null because null is a valid value for any object type.&lt;/li&gt;&lt;li&gt;We are allowed to use wild card character ? in the declaration part but we are not allowed to use in the construction part (Right hand side)&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Example:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ArrayList&amp;lt;?&amp;gt;  l=new ArrayList&amp;lt;String&amp;gt;(); &lt;span style="color: rgb(0, 102, 0);"&gt;    //valid&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ArrayList&amp;lt;?&amp;gt;  l=new ArrayList&amp;lt;Integer&amp;gt;();     &lt;span style="color: rgb(0, 102, 0);"&gt;//valid&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ArrayList&amp;lt;? Extends Number&amp;gt;  l=new ArrayList&amp;lt;Integer&amp;gt;(); &lt;span style="color: rgb(0, 102, 0);"&gt;    //valid&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ArrayList&amp;lt;? Extendes Number&amp;gt;  l=new ArrayList&amp;lt;Integer&amp;gt;();    &lt;span style="color: rgb(0, 102, 0);"&gt;// not valid&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;CTE:incompatable types&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Found:ArrayList&amp;lt;string&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Reqire:ArrayList&amp;lt;Number&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ArrayList&amp;lt;String&amp;gt; l=new ArrayList&amp;lt;?&amp;gt;();&lt;span style="color: rgb(0, 102, 0);"&gt;  //not valid&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;CTE: unexcepetedtype found:?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Req: class or interface with out bounds.&lt;/span&gt;&lt;br /&gt;&lt;ul style="font-family: verdana;"&gt;&lt;li&gt;On the right hand side we are not allowed to impose any boundaries by using extends or super key words.&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Communication with legacy code:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;To provide support for legacy code Sun people compromised some rules of generics.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;class Test&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;public static void main(String arg[])&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ArrayList &amp;lt;String&amp;gt; l=new ArrayList&amp;lt;String&amp;gt; ();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;l.add(“a”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;l.add(“b”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;l.add(“c”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;show(l);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;public static void show(ArrayList l)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;l.add(“e”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;l.add(new Integer(10));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(l);  &lt;span style="color: rgb(0, 102, 0);"&gt;// [ a,b,c ,d,e,10]&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;ul style="font-family: verdana;"&gt;&lt;li&gt;Here we won’t get any errors but we get some warning.&lt;/li&gt;&lt;li&gt;To sport 1.4 version methods Sun people some how compromised in this generics area  in 1.5 version.&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family:verdana;"&gt;ArrayList l=new ArrayLiat&amp;lt;String&amp;gt;();   &lt;span style="color: rgb(0, 102, 0);"&gt;// valid&lt;/span&gt;&lt;/span&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>try-catch</title><link>http://www.javaexamples4u.com/2009/04/try-catch.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Sat, 04 Apr 2009 10:03:48 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-1242898684891006828</guid><description>&lt;span style="font-family: verdana;font-family:verdana;" &gt;We can handle exceptions by using the fallowing keywords.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;1). &lt;/span&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;try&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt; 2). &lt;/span&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;catch&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt; 3). &lt;/span&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;finally&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;try&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;//Risky  code&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;catch(XException e)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;//Define the  handler&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Example:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;try&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println(10/0);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;catch(ArithematicException  e)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println(“caught”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println(10/2);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println(“hello”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;output:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;caught &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;5&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;hello&lt;/span&gt;&lt;br /&gt; &lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Example:&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt; try {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Statement 1;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Stmt 2;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Stmt  3;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;catch(XException e){ Statement 4; }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;stmt5;&lt;/span&gt;&lt;br /&gt; &lt;br /&gt; &lt;span style="font-weight: bold; font-family: verdana;"&gt;See the below cases:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Case 1:&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;- If  there is no Exception -&gt;1,2,3,5 are executes. So normal termination.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Case  2:&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;- If an Exception raised at stmt2 and the corresponding catch block found then 1 fallowed 4,5 are executes. So, normal termination.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Case 3:&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;- If an Exception is raised at stmt2, but the corresponding catch block not found. Then stmt1 fallowed by abnormal termination.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Case 4:&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;- If an Exception raised at stmt2 and the corresponding catch block found; but while executing catch block raises another Execution then stmt1 fallowed by abnormal termination.&lt;/span&gt;&lt;br /&gt; &lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Methods For Displaying Error Information&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;  :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;The class Throwable contains the fallowing methods for displaying Error  information.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;1&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;. &lt;/span&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;printStackTrace()&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Name of the Exception:  Description of Exception Stack trace.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;catch(ArithmaticException  e)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;e.printStackTrace();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println(“hai..”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;output:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;java.lang.ArithmaticException:  /by zero at sample.main(Sample.java)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Hai&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;2. public String toString():&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Name of the  Exception: Description of Exception&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;catch(ArithmaticException  e)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println(e.toString());&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println(“hai..”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;output:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;java.lang.ArithmaticException:  /by zero&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Hai&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;3. public String  getMessage():&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Description of  Exception&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;catch(ArithmaticException  e)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println(e.getMessage());&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println(“hai..”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;output:&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;  /by zero&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;hai&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Try with Multiple catch  blocks&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;• The way of handling the exception is varied from exception to exception, hence it is a good programming practice to keep separate catch block for every exception.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Example:&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;try&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println(10/0);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;catch(ArithmeticException  e) &lt;span style="color: rgb(0, 102, 0);"&gt;//child&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;//code&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;catch(Exception e) &lt;span style="color: rgb(0, 102, 0);"&gt; //parent&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;//code&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:worddocument&gt;   &lt;w:view&gt;Normal&lt;/w:View&gt;   &lt;w:zoom&gt;0&lt;/w:Zoom&gt;   &lt;w:compatibility&gt;    &lt;w:breakwrappedtables/&gt;    &lt;w:snaptogridincell/&gt;    &lt;w:wraptextwithpunct/&gt;    &lt;w:useasianbreakrules/&gt;   &lt;/w:Compatibility&gt;   &lt;w:browserlevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;  &lt;/w:WordDocument&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;style&gt; &lt;!--  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal  {mso-style-parent:"";  margin:0in;  margin-bottom:.0001pt;  mso-pagination:widow-orphan;  font-size:12.0pt;  font-family:"Times New Roman";  mso-fareast-font-family:"Times New Roman";} @page Section1  {size:8.5in 11.0in;  margin:1.0in 1.25in 1.0in 1.25in;  mso-header-margin:.5in;  mso-footer-margin:.5in;  mso-paper-source:0;} div.Section1  {page:Section1;} --&gt; &lt;/style&gt;&lt;!--[if gte mso 10]&gt; &lt;style&gt;  /* Style Definitions */  table.MsoNormalTable  {mso-style-name:"Table Normal";  mso-tstyle-rowband-size:0;  mso-tstyle-colband-size:0;  mso-style-noshow:yes;  mso-style-parent:"";  mso-padding-alt:0in 5.4pt 0in 5.4pt;  mso-para-margin:0in;  mso-para-margin-bottom:.0001pt;  mso-pagination:widow-orphan;  font-size:10.0pt;  font-family:"Times New Roman";} &lt;/style&gt; &lt;![endif]--&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Here in the above example ArithmeticException is the child class of Exception class.It is Valid since child --&amp;gt; to ---&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt; parent hierarchy&lt;/span&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;.&lt;br /&gt;&lt;br /&gt;Example:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;try&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println(10/0);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;catch(Exception e)  &lt;span style="color: rgb(0, 102, 0);"&gt;//parent&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;//code&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;catch(ArithmeticException e)  &lt;span style="color: rgb(0, 102, 0);"&gt;//child&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;//code&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:worddocument&gt;   &lt;w:view&gt;Normal&lt;/w:View&gt;   &lt;w:zoom&gt;0&lt;/w:Zoom&gt;   &lt;w:compatibility&gt;    &lt;w:breakwrappedtables/&gt;    &lt;w:snaptogridincell/&gt;    &lt;w:wraptextwithpunct/&gt;    &lt;w:useasianbreakrules/&gt;   &lt;/w:Compatibility&gt;   &lt;w:browserlevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;  &lt;/w:WordDocument&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;style&gt; &lt;!--  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal  {mso-style-parent:"";  margin:0in;  margin-bottom:.0001pt;  mso-pagination:widow-orphan;  font-size:12.0pt;  font-family:"Times New Roman";  mso-fareast-font-family:"Times New Roman";} @page Section1  {size:8.5in 11.0in;  margin:1.0in 1.25in 1.0in 1.25in;  mso-header-margin:.5in;  mso-footer-margin:.5in;  mso-paper-source:0;} div.Section1  {page:Section1;} --&gt; &lt;/style&gt;&lt;!--[if gte mso 10]&gt; &lt;style&gt;  /* Style Definitions */  table.MsoNormalTable  {mso-style-name:"Table Normal";  mso-tstyle-rowband-size:0;  mso-tstyle-colband-size:0;  mso-style-noshow:yes;  mso-style-parent:"";  mso-padding-alt:0in 5.4pt 0in 5.4pt;  mso-para-margin:0in;  mso-para-margin-bottom:.0001pt;  mso-pagination:widow-orphan;  font-size:10.0pt;  font-family:"Times New Roman";} &lt;/style&gt; &lt;![endif]--&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Here in the above example Exception class is the child class of ArithmeticException class.It is InValid since parent --&gt;to ---&gt; child hierarchy&lt;/span&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;.&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;compile time error(CTE) : Exception has already been caught by  catch (&lt;/span&gt;&lt;em style="font-family: verdana;"&gt;ArithmeticException&lt;/em&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt; e).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;• If multiple catch blocks are defined for the try statement, the order of the catch blocks is important. We should take the catch blocks from child to parent, violation leads to CTE saying “Exception” has already been caught”.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Control Flow in try with multiple catch  blocks&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;try&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Statement  1;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Stmt2;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Stmt3;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;catch(XException e)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Stmt  4;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;catch(YException e1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Stmt 5;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Stmt6;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;"&gt;see the below cases:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Case 1:&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;-  If there is no Exception -&gt;1,2,3,6 is executes. So normal  termination.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Case 2:&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;- If an Exception raised at stmt2 and the corresponding catch block(Y Exception e1) is matches then 1,5,6 are executes. So, normal termination.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Case 3:&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;- If an Exception is raised at stmt2, but the corresponding catch block not found. Then stmt1 fallowed by abnormal termination.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Control Flow in Nested try  catch &lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;try&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Statement  1;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Stmt2;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Stmt3;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;try&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Stmt4;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Stmt5;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Stmt6;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;catch(XException  e)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Stmt7;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Stmt8;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;catch(YException  e)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Stmt9;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Stmt10;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana; font-weight: bold;"&gt;See the below cases:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Case 1:&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;- If there is no Exception  -&gt;1, 2, and 3,4,5,6,8,10 is executes. So normal termination.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Case 2:&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;- If an Exception raised at stmt2 and the corresponding catch block is matches then 1,9,10 are executes. So, normal termination.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Case 3:&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;- If an Exception raised  at stmt2 and the corresponding catch block not found. 1 fallowed by abnormal  termination.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Case 4:&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;- If an Exception raised at stmt5 and the corresponding  catch block is matches then 1,2,3,4,7,10 and Normal Termination.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Case 5:&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;- If an Exception raised at stmt5 and the corresponding catch block is not matched but outer catch block has matched 1,2,3,4,9,10 and Normal Termination.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Case  6:&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;- An Exception raised at stmt2 and the corresponding catch block has matched but while executing that catch block another exception raised then fallowed by abnormal termination.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Case 7:&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;- An Exception raised at stmt8 and the corresponding catch block has matched then 1,2,3,9,10 fallowed by Normal Termination. If the catch block has not matched abnormal termination.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>array-length-string-length()</title><link>http://www.javaexamples4u.com/2009/04/array-length-string-length.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Fri, 03 Apr 2009 22:09:05 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-2965453319790200938</guid><description>&lt;span style="color: rgb(153, 0, 0); font-weight: bold; font-family: verdana;font-family:verdana;font-size:130%;"  &gt;length Vs length():&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;&lt;br /&gt;length:This is a variable.applicable for only for array objects represents the number of elements or the size of the array.&lt;/span&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;&lt;br /&gt;&lt;br /&gt;Example:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;int a=new int[6];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println(a.length); ------------------&amp;gt; &lt;span style="color: rgb(0, 102, 0); font-weight: bold;"&gt;output: 6&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul style="font-family: verdana;"&gt;&lt;li&gt;length variable Can’t apply to String&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;int a=new int[6];  Here 6 is length,But the index is starts with 0,1,2,3,4,5.If we are try to access the index a[6] we will get &lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;a ArrayIndexOutOfBoundsException.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;&lt;span style="font-weight: bold;"&gt;Array length example:&lt;/span&gt;&lt;br /&gt;public class LengthExample {&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;{&lt;br /&gt;    int a[]=new int[6];&lt;br /&gt;    for(int i=0;i &amp;lt;a.length;i++)&lt;br /&gt;    {&lt;br /&gt;        a[i]=i;&lt;br /&gt;        System.out.print(a[i]);&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;       // System.out.println(a[6]); //exception&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    System.out.println(".....length="+a.length);&lt;br /&gt;}&lt;a.length;i++)&gt;&lt;br /&gt;}&lt;/a.length;i++)&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;&lt;br /&gt;output:&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;&lt;span style="color: rgb(0, 102, 0);"&gt;012345   length=6&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;&lt;br /&gt;&lt;br /&gt;Example:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;String s=”Laxman”;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println(s.length);&lt;/span&gt;&lt;span style="color: rgb(0, 102, 0); font-family: verdana;font-family:verdana;" &gt; //error&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Given CTE because length variable applicable only for array objects.&lt;/span&gt;&lt;br /&gt;&lt;ul style="font-family: verdana;"&gt;&lt;li&gt;length(): It is a final method applicable for string objects.&lt;/li&gt;&lt;li&gt;It represents the number of characters present in the String Object.&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Ex:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;String s=”Laxman”;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println(s.length()); ---------&amp;gt; &lt;span style="font-weight: bold; color: rgb(0, 102, 0);"&gt;6&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println(s.length); ----------&amp;gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;"&gt; //error&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul style="font-family: verdana;"&gt;&lt;li&gt;In case string also index value start with zero only.&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;String length() example:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;public class StringlengthEx {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;public static void main(String arg[])&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;    String mystring="abcde";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;    System.out.println(mystring.length());  &lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(0, 102, 0); font-family: verdana;font-family:verdana;" &gt;//5&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;    System.out.println(mystring.charAt(3));  &lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(0, 102, 0); font-family: verdana;font-family:verdana;" &gt;//d&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;    System.out.println(mystring.indexOf('4'));  &lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(0, 102, 0); font-family: verdana;font-family:verdana;" &gt;//2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Array of strings Example:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;public class ArrayStrings {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;    public static void main(String arg[])&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;        String stringarray[]=new String[6];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;        stringarray[0]="corejava";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;        stringarray[1]="jdbc";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;        stringarray[2]="hibernate";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;        stringarray[3]="servlets";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;        stringarray[4]="jsp";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;        stringarray[5]="ejb";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;        System.out.println("Array length"+stringarray.length); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;        for(int i=0;i&lt;stringarray.length;i++)&gt;&lt;/stringarray.length;i++)&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;            System.out.println(stringarray[i]+"....length="+stringarray[i].length());&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;            &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;    }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0); font-family: verdana;font-family:verdana;" &gt;output:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Array length6&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;corejava....length=8&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;jdbc....length=4&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;hibernate....length=9&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;servlets....length=8&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;jsp....length=3&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;ejb....length=3&lt;/span&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>java-instanceof-Shortcircuit-Relational-operators</title><link>http://www.javaexamples4u.com/2009/04/java-instanceof.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Fri, 03 Apr 2009 20:35:09 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-34941617435675998</guid><description>&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;Instanceof operator :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Thread t =new Thread();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(t instanceof thread); &lt;span style="color: rgb(0, 102, 0);"&gt;// true&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(t instanceof object); &lt;span style="color: rgb(0, 102, 0);"&gt;//true&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(t instanceof runnable); &lt;span style="color: rgb(0, 102, 0);"&gt;//true&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(t instanceof string); &lt;span style="color: rgb(0, 102, 0);"&gt;// compile time error saying convertible &lt;/span&gt;type found java .lang .thread Required: java. .lang .string a instanceof x&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The type of a and x must be related, otherwise compile time error saying convertible type.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex: &lt;/span&gt;&lt;span style="font-family:verdana;"&gt;Object o= new Object();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(o instanceof string); &lt;span style="color: rgb(0, 102, 0);"&gt;// false&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex:&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;  null instanceof x;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The result always false&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;Short-circuit operator( &amp;amp;&amp;amp; , || ) :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;In the normal logical operator (&amp;amp; or |) we have to calculate both arguments compulsory, some times it may creates performance problems ,to improve the performance short-circuit operators were introduce.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Comparison between bitwise and short-circuit operators&lt;/span&gt;&lt;br /&gt;&lt;ul style="font-family: verdana;"&gt;&lt;li&gt;Bitwise operators can be applicable for both Boolean, integral types,Short - circute operators can be applicable only for Boolean type .&lt;/li&gt;&lt;li&gt;Bitwise operators Both operands must be evaluated,Short - circute operators evaluation of second argument is optional.&lt;/li&gt;&lt;li&gt;Bitwise operators performance is low ,Short - circute operators performance is high.&lt;/li&gt;&lt;/ul&gt;   &lt;span style="font-family:verdana;"&gt;x &amp;amp;&amp;amp; y ----&amp;gt; If x is true then y will evaluate.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;x || y ------&amp;gt; If x is false then y will evaluate.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a style="font-family: verdana;" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_Pc8VSCmbaAo/SZunlTa9d0I/AAAAAAAAAG4/HGv0ahTuovI/s1600-h/operators.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 333px; height: 235px;" src="http://4.bp.blogspot.com/_Pc8VSCmbaAo/SZunlTa9d0I/AAAAAAAAAG4/HGv0ahTuovI/s400/operators.png" alt="" id="BLOGGER_PHOTO_ID_5304017245469243202" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Example:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;int x=10,y=20;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;if( (x &amp;lt;y)||(y gt; x/0))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(“hi”); &lt;span style="color: rgb(0, 102, 0);"&gt;// hi&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(“hello”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;Equality operator:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;We can use equality operators for the comparision of primitive numbers , characters,boolean values. Return type is Boolean.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Ex: 10 = = 10; &lt;span style="color: rgb(0, 102, 0);"&gt;// true&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;10 = = 10.0; &lt;span style="color: rgb(0, 102, 0);"&gt;// true&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;‘a’ = = 97 &lt;span style="color: rgb(0, 102, 0);"&gt;// true&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul style="font-family: verdana;"&gt;&lt;li&gt;We can apply these two operators = = and!= both for primitive types and object references. In the case of primitives these operators via check magnitudes or the values.Smaller data type promote bigger data type automatically. In the case of object references double equal operator always cheeks for address comparison.i.e s1= =s2 true iff and only if both s1 and s2 pointing to the same object.&lt;/li&gt;&lt;/ul&gt; &lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;: Sample s1= new sample( );&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Sample s2=new sample( );&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Sample s3=s1;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println (s1= =s2); &lt;span style="color: rgb(0, 102, 0);"&gt;// false&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println (s1= =s3);&lt;span style="color: rgb(0, 102, 0);"&gt; // true&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println (s1= =”durga”);&lt;span style="color: rgb(0, 153, 0);"&gt; // compile time error&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul style="font-family: verdana;"&gt;&lt;li&gt;We can not use double equeal operator for different types of objects, violation leads compile time error saying incomparable types.&lt;/li&gt;&lt;/ul&gt; &lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;: “java”==new Integer(10); &lt;span style="color: rgb(0, 102, 0);"&gt;// incompatible types&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;: Sample s=new Sample();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;s=null;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;s = = null;&lt;span style="color: rgb(153, 0, 0);"&gt; // the result always false.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;: “java”=null ; &lt;span style="color: rgb(0, 102, 0);"&gt;// false&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;new Integer(10) = = null; &lt;span style="color: rgb(0, 102, 0);"&gt;// false&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;null==null ;&lt;span style="color: rgb(0, 102, 0);"&gt; // true&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;:System.out.println( 10 = = 10 = = 10.0); &lt;span style="color: rgb(0, 102, 0);"&gt;// Compile time error&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;In the above example 10==10 returns true,true = = 10.0 ---&amp;gt; this shows error&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println( 10 = = 10 = = true) ; &lt;span style="color: rgb(0, 102, 0);"&gt;// now it returns true&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;Relational operator ( &amp;lt; , &amp;lt; = , &amp;gt; , &amp;gt;= ) :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;These operators  applicable for primitives, except Boolean&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex:&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;10&amp;lt;20 ----&amp;gt; true&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;20&amp;lt;=50 ----&amp;gt; true&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;”Java “&amp;lt;”Laxman” -----&amp;gt; Compile time error saying operator java.lang.String,java.lang.String.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex:&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;10&amp;lt;=true; compile time error saying can not be applied to boolean , int&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;Bitwise operator:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;AND(&amp;amp;):- If both are true then only the result is true&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;OR( |):- if at least one is true , then only the result is true&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;X-OR( ^):- If both are different then only the result is true.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex:&lt;/span&gt;&lt;span style="font-family:verdana;"&gt; true &amp;amp; false ----&amp;gt; false&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;true | false ---&amp;gt; true&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;true ^ false----&amp;gt; true&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex: &lt;/span&gt;&lt;span style="font-family:verdana;"&gt;4&amp;amp; 5 ---&amp;gt; 4&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;4 | 5 ---&amp;gt;5&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;4^ 5 ----&amp;gt; 1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&amp;amp; , | , ^ ------&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;ul style="font-family: verdana;"&gt;&lt;li&gt;we can apply these operator only for Boolean and integral types . we can’t apply these operator for the floating point data types.&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex:&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;- 4.5 ^5.5----- compile time error saying operator X-oR can’t be applied to double, double.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Bitwise Compliment Operator :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;We can apply bitwise compliment operator only for integral types, but not fir Boolean types i.e, ~4 valied&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;i.e, ~true invalied ---&amp;gt; Compile time error saying operator ~ can’t be applied to Boolean.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;boolean compliment operator:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;! true ----&amp;gt; false&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;!false -----&amp;gt; true&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;! 3 -----&amp;gt; compile time error saying operator ! can’t be applied to int.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;conclusion:-&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&amp;amp; , | , ^ -------------&amp;gt; we can apply both integral and Boolean.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;~ -----------------&amp;gt; only for integral type&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;! -----------------&amp;gt; only for Boolean type.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;Conditional operator :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The only available ternary operator is the conditional operator.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;int a=Boolean expression ? value if true : value if false;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;int a=(true)?10:12; //10&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;We can perform nesting of conditional operator also possible.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;:- int a=( false) ? 10 : ( true) ? 20 : 40 ; )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;:- byte x=( a &amp;lt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;New operator:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;This can be used for create of objects.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;new and instanceof are acts as both keywords and operators.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;[ ]-----&amp;gt; This can be used for declaration and construction of arrays.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;Assignment operator:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(1)&lt;/span&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;simple assignment:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;int x=10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;int y=x;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(2)&lt;/span&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt; compound assignment&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;:-&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;In the case of compound assignment operator compiler will take care about type casting problems . i.e it can perform internal automatic typecasting .&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;i.e &lt;/span&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;:- byte a=10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;a+=10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(a); &lt;span style="color: rgb(0, 102, 0);"&gt;// 20&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;:- byte a=10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;a=a+10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(a); //CE saying PLP.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The following are all possible compound assignment operator :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;=,+=,-=,*=,%=,&amp;gt;&amp;gt;=,&amp;lt;&amp;lt;=,&amp;gt;&amp;gt;&amp;gt;=,&amp;amp;=,|=,^=,!=&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(3)&lt;/span&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;chained assignment operator:-&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Ex:- int a ,b ,c ,d ;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;int a=b=c=d=40;//valid&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;int a=b=c=d=40; //invalid&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Why because chained assignment is not allowed at the time of declaration.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex:&lt;/span&gt;&lt;span style="font-family:verdana;"&gt; int a ,b ,c ,d;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;a=b=c=d=40;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;a+=b*c/d-=10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(a+”……..”+b+”….”+c+”……”+d); &lt;span style="color: rgb(0, 102, 0);"&gt;//80….40…..1….30&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;Precedence of java operator:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(1)Unary ---------- [], x++, x--,++x,--x, ~,!,new,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(2)arithmetic -----*,/,%,+,-&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(3) shift operator --- &amp;gt;&amp;gt;,&amp;lt;=,&amp;gt;,&amp;gt;=,&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(4)comparison:-&amp;lt;,&amp;lt;=,&amp;gt;,&amp;gt;=,instsnceof&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(5)equality:- ==,!=&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(6) bitwise :- &amp;amp;,^ ,|&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(7) short-circuit:- &amp;amp;&amp;amp;,||&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(8) Conditional : - ?,:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(9) assignment:-=,+=,-=,*=,%=,&amp;gt;&amp;gt;=,&amp;lt;&amp;lt;=,&amp;gt;&amp;gt;&amp;gt;-,&amp;amp;=,|=,^=,!=&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;Evaluation order of operators:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;class EvaluationOrder&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;public static void main(String arg[])&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(m1(1) +m1(2)*m1(3)/m1(4)-m1(5)* m1(6));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;public static int m1(int i)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(i);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;return i;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;1. 1+2*3/4-5*6&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;2. 1+6/4-5*6&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;3. 1+1-5*6&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;4. 1+1-30= -28(result)&lt;/span&gt;&lt;br /&gt;&lt;ul style="font-family: verdana;"&gt;&lt;li&gt;Before applying any operator , first we have to evaluate all the operands .The order of evaluation of operands is always from left to right . And then after evaluation of operands we have to apply the operators according to precedence&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;</description><media:thumbnail url="http://4.bp.blogspot.com/_Pc8VSCmbaAo/SZunlTa9d0I/AAAAAAAAAG4/HGv0ahTuovI/s72-c/operators.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>jdbc-connection-url-tutorial</title><link>http://www.javaexamples4u.com/2009/04/jdbc-url.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Fri, 03 Apr 2009 10:24:06 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-7353825662004013818</guid><description>&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;Connection&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;A Connection object represents a connection with a database. A connection session includes the SQL statements that are executed and the results that are returned over that connection. A single application can have one or more connections with a single database, or it can have connections with many different databases. &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0); font-weight: bold;font-size:130%;" &gt;&lt;span style="font-family:verdana;"&gt;Opening a Connection&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-size:130%;" &gt; :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The standard way to establish a connection with a database is to call the method DriverManager.getConnection. This method takes a string containing a URL. The DriverManager class, referred to as the JDBC management layer, attempts to locate a driver than can connect to the database represented by that URL. The DriverManager class maintains a list of registered Driver classes, and when the method getConnection is called, it checks with each driver in the list until it finds one that can connect to the database specified in the URL. The Driver method connect uses this URL to actually establish the connection. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;A user can bypass the JDBC management layer and call Driver methods directly. This could be useful in the rare case that two drivers can connect to a database and the user wants to explicitly select a particular driver. Normally, however, it is much easier to just let the DriverManager class handle opening a connection. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The following code exemplifies opening a connection to a database located at the URL "jdbc:oracle:thin:@localhost:1521:xe"&lt;/span&gt;&lt;span style="font-family:verdana;"&gt; with a user ID of "oracle" and "tiger" as the password : &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    String url = "&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;jdbc:oracle:thin:@localhost:1521:xe&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    Connection con = DriverManager.getConnection(url, "oracle", "tiger");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;" &gt;URLs in General Use&lt;/span&gt;&lt;/span&gt; :&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Since URLs often cause some confusion, we will first give a brief explanation of URLs in general and then go on to a discussion of JDBC URLs. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;A URL (Uniform Resource Locator) gives information for locating a resource on the Internet. It can be thought of as an address. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The first part of a URL specifies the protocol used to access information, and it is always followed by a colon. Some common protocols are "ftp", which specifies "file transfer protocol," and "http," which specifies "hypertext transfer protocol." If the protocol is "file," it indicates that the resource is in a local file system rather than on the Internet.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ftp://javasoft.com/docs/JDK-1_apidocs.zip&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;http://java.sun.com/products/JDK/CurrentRelease&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;file:/home/haroldw/docs/tutorial.html&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The rest of a URL, everything after the first colon, gives information about where the data source is located. If the protocol is file, the rest of the URL is the path to a file. For the protocols ftp and http, the rest of the URL identifies the host and may optionally give a path to a more specific site. For example, below is the URL for the JavaSoft home page. This URL identifies only the host: &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;http://www.javasoft.com&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;By navigating from this home page, one can go to many other pages, one of which is the JDBC home page. The URL for the JDBC home page is more specific and looks like this: &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;http://www.javasoft.com/products/jdbc&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;" &gt;JDBC URLs &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:180%;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;A JDBC URL provides a way of identifying a database so that the appropriate driver will recognize it and establish a connection with it. Driver writers are the ones who actually determine what the JDBC URL that identifies their particular driver will be. Users do not need to worry about how to form a JDBC URL; they simply use the URL supplied with the drivers they are using. JDBC's role is to recommend some conventions for driver writers to follow in structuring their JDBC URLs. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Since JDBC URLs are used with various kinds of drivers, the conventions are of necessity very flexible. First, they allow different drivers to use different schemes for naming databases. The odbc subprotocol, for example, lets the URL contain attribute values (but does not require them). &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Second, JDBC URLs allow driver writers to encode all necessary connection information within them. This makes it possible, for example, for an applet that wants to talk to a given database to open the database connection without requiring the user to do any system administration chores. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Third, JDBC URLs allow a level of indirection. This means that the JDBC URL may refer to a logical host or database name that is dynamically translated to the actual name by a network naming system. This allows system administrators to avoid specifying particular hosts as part of the JDBC name. There are a number of different network name services (such as DNS, NIS, and DCE), and there is no restriction about which ones can be used. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The standard syntax for JDBC URLs is shown below. It has three parts, which are separated by colons: &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      jdbc:&lt;subprotocol&gt;:&lt;subname&gt;&lt;/subname&gt;&lt;/subprotocol&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The three parts of a JDBC URL are broken down as follows: &lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:verdana;"&gt;jdbc-the protocol. The protocol in a JDBC URL is always jdbc. &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:verdana;"&gt;&lt;subprotocol&gt;-the name of the driver or the name of a database connectivity mechanism, which may be supported by one or more drivers. A prominent example of a subprotocol name is "odbc", which has been reserved for URLs that specify ODBC-style data source names. For example, to access a database through a JDBC-ODBC bridge, one might use a URL such as the following: &lt;/subprotocol&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family:verdana;"&gt;    jdbc:odbc:fred&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;In this example, the subprotocol is "odbc", and the subname "fred" is a local ODBC data source.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;If one wants to use a network name service (so that the database name in the JDBC URL does not have to be its actual name), the naming service can be the sub protocol. So, for example, one might have a URL like: &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      jdbc:dcenaming:accounts-payable&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt; In this example, the URL specifies that the local DCE naming service should resolve the database name "accounts-payable" into a more specific name that can be used to connect to the real database.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;subname&gt;-a way to identify the database. The subname can vary, depending on the subprotocol, and it can have a subsubname with any internal syntax the driver writer chooses. The point of a subname is to give enough information to locate the database. In the previous example, "fred" is enough because ODBC provides the remainder of the information. A database on a remote server requires more information, however. If the database is to be accessed over the Internet, for example, the network address should be included in the JDBC URL as part of the subname and should follow the standard URL naming convention of &lt;/subname&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;           //hostname:port/subsubname &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Supposing that "dbnet" is a protocol for connecting to a host on the Internet, a JDBC URL might look like this:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      jdbc:dbnet://wombat:356/fred&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;" &gt;The "odbc" Subprotocol&lt;/span&gt; :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The sub protocol odbc is a special case. It has been reserved for URLs that specify ODBC-style data source names and has the special feature of allowing any number of attribute values to be specified after the surname (the data source name). The full syntax for the odbc sub protocol is: &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      jdbc:odbc:&lt;data-source-name&gt;[;&lt;attribute-name&gt;=&lt;attribute-value&gt;]*&lt;/attribute-value&gt;&lt;/attribute-name&gt;&lt;/data-source-name&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Thus all of the following are valid jdbc:odbc names: &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      jdbc:odbc:qeor7&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      jdbc:odbc:wombat&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      jdbc:odbc:wombat;CacheSize=20;ExtensionCase=LOWER&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      jdbc:odbc:qeora;UID=kgh;PWD=fooey&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;" &gt;Registering Subprotocols&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt; :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;A driver developer can reserve a name to be used as the subprotocol in a JDBC URL. When the DriverManager class presents this name to its list of registered drivers, the driver for which this name is reserved should recognize it and establish a connection to the database it identifies. For example, odbc is reserved for the JDBC- ODBC Bridge. If there were, for another example, a Miracle Corporation, it might want to register "miracle" as the subprotocol for the JDBC driver that connects to its Miracle DBMS so that no one else would use that name. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;JavaSoft is acting as an informal registry for JDBC subprotocol names. To register a subprotocol name, send email to: &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;      jdbc@wombat.eng.sun.com&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>java-switch-break-if-else</title><link>http://www.javaexamples4u.com/2009/04/java-switch-break-if-else.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Thu, 02 Apr 2009 11:19:37 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-2301636107260145605</guid><description>&lt;span style="font-weight: bold;font-family:verdana;" &gt;Control Flow(Flow-control ):&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Flow control describes the order of execution of code at runtime. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;i.e it describes the order in which the statement will execute.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;Selection statement  &lt;/span&gt;          &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(1)if-else                                     &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(2)switch                                     &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;Iteration statement &lt;/span&gt;                                                           &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(1)for (2)while &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(3)do-while                        &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Transfer statement&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(1)break&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(2)continue&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(3)return&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(4)try-catch-finally&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(5)assertion&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:verdana;font-size:130%;"  &gt;(1)&lt;span style="font-weight: bold;"&gt;if –else &lt;/span&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;   if: {} and else part both are optional. The valid  argument for if statement is always Boolean otherwise compile time error.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;If Examples:&lt;/span&gt;&lt;br /&gt;if(boolean)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Example:&lt;/span&gt;&lt;span style="font-family:verdana;"&gt; int i=10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;if (i) &lt;span style="font-weight: bold; color: rgb(0, 153, 0);"&gt;//This is valid in c++, but invalid java&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(“hi”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(“hello”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex :&lt;/span&gt;&lt;span style="font-family:verdana;"&gt; int i=10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;if (i==10)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(“hi”); &lt;span style="font-weight: bold; color: rgb(0, 153, 0);"&gt;//hi&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(“hello”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex&lt;/span&gt;&lt;span style="font-family:verdana;"&gt; : int i=10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;if (i=20)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(“hi”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(“hello”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;} &lt;span style="font-weight: bold; color: rgb(0, 153, 0);"&gt;// Compile time error&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;Ex&lt;/span&gt;: boolean b =true;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;if (b=false)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(“hi”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(“hello”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;} &lt;span style="font-weight: bold; color: rgb(0, 153, 0);"&gt;// hello&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex&lt;/span&gt;&lt;span style="font-family:verdana;"&gt; : boolean b=true;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;if(b)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;int i=10; &lt;span style="font-weight: bold; color: rgb(0, 153, 0);"&gt;//invalid&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(i); &lt;span style="color: rgb(0, 153, 0);"&gt;//Compile time error&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Under if with out curly braces only one statement is allowed ,but that statement never be declarative statement violation leads to compile time error.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;Ex&lt;/span&gt;:- boolean b= true;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;if(b)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;int i=10; &lt;span style="font-weight: bold;"&gt;// invalid&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;Ex&lt;/span&gt;:- boolean b=true;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;if(b)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;int i=10; &lt;span style="font-weight: bold;"&gt;// valid&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-size:130%;" &gt;Switch statement:&lt;/span&gt;In switch statement {} are mandatory, violation leads to compile time error.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Both case and default are optional.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;Eg&lt;/span&gt;:-              int i=10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                     switch(x) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                      {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                          ……………&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                          ……………no case and default statements.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                        }     &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt; The valid arguments of switch statement are byte, int, short, char until 1.4 version, from 1.5 version onwards the corresponding wrapper class objects Byte, Short, Integer, Character are also allowed.switch can take an enum object are also as argument.If we want keep any statement inside switch it must under some case or default, otherwise COMPILE TIME ERROR.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;       Eg&lt;/span&gt;:-    int x=4;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                 switch(x)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                  {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                       System.out.println (“hello”);&lt;span style="font-weight: bold; color: rgb(0, 153, 0);"&gt; //hello&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                        }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;case-labels : &lt;/span&gt; All the case –labels must be compile time Constance, otherwise COMPILE TIME ERROR saying Constance expression required.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;Ex&lt;/span&gt;: int x=40;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                         int y=10&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                          switch(x)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                            {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                              case y: &lt;span style="color: rgb(0, 153, 0);"&gt;  // CE      saying Constance expression required.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                              }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;Ex:&lt;/span&gt;final  int x=40;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                                  int y=10&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                                 switch(x)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                                  {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                                    case y:   &lt;span style="color: rgb(0, 102, 0);"&gt;// valid&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                                   }&lt;br /&gt;All the case labels must be in the range of switch arguments otherwise compile time error.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;   &lt;span style="font-weight: bold;"&gt;Ex&lt;/span&gt;: byte b=10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;switch(b)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;case 10:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;case20:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;case100:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;case10000:&lt;span style="color: rgb(0, 102, 0);"&gt;//CE saying PLP found: int but required: byte&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The case label should not be duplicated ,violation leads to COMPILE TIME ERROR&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;       &lt;span style="font-weight: bold;"&gt;Ex:&lt;/span&gt;-  int x=10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;               switch(x)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;case 98:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;case98:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;case a:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}//CE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Hence the case labels&lt;br /&gt;(1)must be   compile time Constance &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(2) must be in the range of switch arguments&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(3)must not be duplicated&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;default case&lt;/span&gt;:- The default case we can keep any where, but it is conversion to keep default case is always at last place.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Ex:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;switch(x)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;case 0:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(“0”); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;case 1:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(“1”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;case 2:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(“2”);  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;default:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(“default”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Once any case are default are matched , all the statements will execute from top to bottom until break or end of switch statements. This is called fall-through inside switch.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Ex:- int x=1;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;switch(x)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;default:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(“default”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;case 0:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(“0”); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;case 1:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(“1”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;break;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;case 2:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;System.out.println(“2”);  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;br /&gt;&lt;/span&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>java-for-foreach-while-dowhile</title><link>http://www.javaexamples4u.com/2009/04/java-for-foreach-while-dowhile.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Thu, 02 Apr 2009 11:10:42 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-2921102025637966084</guid><description>&lt;span style="font-family: verdana;font-family:verdana;" &gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;Iteration statement :&lt;/span&gt;          &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-size:130%;" &gt;while&lt;/span&gt;:-if we don’t know the number of iteration in advance then we should go for while loop. The valid argument for the while loop is Boolean &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;  { } are optional , without { } only one statement is allow, that statement never be declarative statement .&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;    &lt;span style="font-weight: bold;"&gt;Syntax&lt;/span&gt;:- while(true) { &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println  (“hello”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt; }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;  System.out.println (“hi”); &lt;span style="color: rgb(0, 153, 0);"&gt;//Compile time error unreachable statement                &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;ex&lt;/span&gt;:-while(false)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                        {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                   System.out.println (“hello”) ;&lt;span style="color: rgb(0, 153, 0);"&gt;//CE    Unreachable statement            &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                        }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                                System.out.println(“hi”)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                   &lt;span style="font-weight: bold;"&gt;   &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Ex&lt;/span&gt;:- int a=10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                             int b=20;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                            while (b&amp;gt;a)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                              {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                                    System.out.println(“hello”); hello  hello  hello …........&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                                  }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                               System.out.println (“hi”); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                         &lt;span style="font-weight: bold;"&gt;   ex&lt;/span&gt;:-   final int  a=10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                                     final int b =20;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                                     while (b&amp;gt;a)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                                 {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                                  System.out.println (“hi”) ;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                                 }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                         System.out.println (“hello”);&lt;span style="color: rgb(0, 153, 0);"&gt;//CE saying unreachable statement&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0); font-family: verdana;font-family:verdana;font-size:130%;"  &gt;&lt;span style="font-weight: bold;"&gt;do..while statement:-&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;    If the loop body as to execute at least once ,then we should go for while loop&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                   &lt;span style="font-weight: bold;"&gt;syntax&lt;/span&gt;:- &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                     do{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                                        ………………..&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                                       }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                         while (b);&lt;span style="font-weight: bold; color: rgb(0, 153, 0);"&gt;// mandatory .&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;without { } we should give exactly one statement between do and while . that may be empty statement .&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                    &lt;span style="font-weight: bold;"&gt;ex&lt;/span&gt;:- do&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                            ;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                           while (b); &lt;span style="color: rgb(0, 153, 0); font-weight: bold;"&gt;// valid &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;without { } only one statement is allowed but it should not be declarative statement &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;ex:-&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt; do&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;while (b); &lt;span style="font-weight: bold; color: rgb(0, 153, 0);"&gt;// valid&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;ex:-&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;do&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println(“hi”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;} while (true);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println(“hello”); &lt;span style="font-weight: bold; color: rgb(0, 153, 0);"&gt;// compile time error unreachable statement&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;font-family:verdana;" &gt;Ex:&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt; int x = 10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;do&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;while(x &amp;gt;0);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println("hai"); // compile time error saying since after do there is no loop In the while continue statement will shift the transfer conditional checking.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt; &lt;span style="font-weight: bold;"&gt;Eg&lt;/span&gt;:- int a=10;                                                                             &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;int b=20;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;     do{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;         System.out.println(“hi”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;       }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;        while(a&amp;lt;b)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;        System.out.println(”hello”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;&lt;span style="font-weight: bold;"&gt;Eg&lt;/span&gt;:-final  int a=10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;       final int b=20;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;     do {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;        System.out.println(“hi”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;    while (a&amp;lt;b)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;      System.out.println(”hello”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;     }/&lt;span style="color: rgb(0, 153, 0);"&gt;/CE saying unreachable statement because here a and b are constants&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0); font-family: verdana;font-size:130%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-size:130%;" &gt;for loop:&lt;/span&gt;The most commonly used loop, if we know the iteration in advance, then we should go for for loop&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;syntax:-&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;      for(initialization part; conditional check; inc/ dec)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;           { &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                //loop body&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;&lt;span style="font-weight: bold;"&gt;initialization part&lt;/span&gt;:- Here more than one variable of different data type are not allowed to declare. i.e we have to declare all the variable of the same type and the data type must be mention only one time.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                 i.e int i=0,j=0;    right &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                   int i=0,int j=0; wrong&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                     int i=0,float f=10.0; wrong &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;More than one data type declaration is not allowed.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;As the initialization part we are allowed to take any valid java statement including sop also. initialization part is optional&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;&lt;span style="font-weight: bold;"&gt;conditional expression:-&lt;/span&gt; As the conditional expression we can take any expression ,but it should boolean value.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;The default value for condition expression is true if we are not providing. But default values are not applicable for while and do. .while loops.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;&lt;span style="font-weight: bold;"&gt; Inc/ dec part&lt;/span&gt;:- Here we are allowed to any valid java statement including sop also .&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                 All the 3 parts of for loop are optional i.e for(;;); is valid &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                        &lt;span style="font-weight: bold;"&gt;Ex:&lt;/span&gt;-for (int i=0;true; i++){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                                 System.out.println(i);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                            }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                           System.out.println(“hello”);&lt;span style="color: rgb(0, 153, 0);"&gt;//CE unreachable statement &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                                 &lt;span style="font-weight: bold;"&gt;Ex&lt;/span&gt;:- :-for (int i=0;false; i++)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                                           {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                                  System.out.println(i); &lt;span style="color: rgb(0, 153, 0);"&gt;//CE unreachable statement&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                                             }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                                                System.out.println(“hello”); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                  &lt;span style="font-weight: bold;"&gt;Ex&lt;/span&gt;:-&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                       for(int i=0;a&amp;lt;b; i++){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                        System.out.println(i);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                         }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                               System.out.println(“hello”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                            Output:-1 2 3 4 5 6 7 8…….&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                    &lt;span style="font-weight: bold;"&gt;Eg&lt;/span&gt;:-&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                         final int a=10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                           final int b=20;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                         for(int i=0;a&amp;lt;b;i++)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;               {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                       System.out.println(i);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                }System.out.println(“hello”);&lt;span style="color: rgb(0, 153, 0); font-weight: bold;"&gt;// invalid&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-size:130%;" &gt;For-each loop&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;:-&lt;/span&gt;&lt;/span&gt; introduce 1.5 version. More convenient loop for iterating the elements of arrays and collections.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;       &lt;span style="font-weight: bold;"&gt;for&lt;/span&gt; &lt;span style="font-weight: bold;"&gt;Example&lt;/span&gt;:-int [] a={10,20,30,40};&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;              for(i=0;i&amp;lt;=a.length;i++)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;               {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                  System.out.println(a[i]); &lt;span style="color: rgb(0, 153, 0); font-weight: bold;"&gt; // 10,20,30,40&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;       &lt;span style="font-weight: bold;"&gt;foreach example&lt;/span&gt;:-int [] a={10,20,30,40};&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;             for(int x: a)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;             {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;               System.out.println(x);  &lt;span style="font-weight: bold; color: rgb(0, 153, 0);"&gt;// 10, 20,30,40&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;             }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;The main limitation of for-each loop is we can’t use in general and it is applicable only for arrays and collections.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Write the code to display the two dimensional array use for-each loop.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;      int[] [] a={{10,2030,40},{50,60}}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;     for(int x : a)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;           for(int y: a){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                 for(int y : x){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                   System.out.println(y);{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;                    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0); font-family: verdana;font-family:verdana;font-size:130%;"  &gt;Transfer statement&lt;/span&gt;&lt;span style="font-family: verdana;font-size:130%;" &gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;&lt;span style="font-weight: bold;"&gt;Break statement&lt;/span&gt;:- we can use the break statement in the following cases . &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;(i)    with in the ioops &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;(ii)    in the switch statement&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;(iii)    in the lable blocks&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;if we can use any where else we will get a compile time error saying break out side switch (or) loop.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;&lt;span style="font-weight: bold;"&gt;continue statement&lt;/span&gt;:-&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;We can use continue statement only in loops to skip the current iteration and continue for the next iteration.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;int i=10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;do{i++;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println(i);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;if(i&amp;lt;=16)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;continue;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;System.out.println(i);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;while(++i&amp;lt;20);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;   In the while continue statement will shift the transfer conditional checking.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;   &lt;span style="font-weight: bold;"&gt; Ex&lt;/span&gt;:-class sample {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Public static void main(string args[])&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;int x=10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;if(x&amp;gt;10)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;continue; //CE saying continue out side of loop&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;&lt;span style="font-weight: bold;"&gt;Labeled break and labeled continue&lt;/span&gt;:-In the nested loop, if you want to break or continue a particular loop then we should go for labeled break and continue statements.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt; &lt;span style="font-weight: bold;"&gt; Ex&lt;/span&gt;:-for(int i=0;i&amp;lt;5;i++)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;  for(int j=0;j&amp;lt;5;j++)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;   if(i==j) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;   break;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;   System.out.println(i+”……”+j);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;}&lt;/span&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>Types-of-Jdbc-Drivers</title><link>http://www.javaexamples4u.com/2009/04/types-of-jdbc-drivers.html</link><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Thu, 02 Apr 2009 09:26:08 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-5773408216398319606</guid><description>&lt;span style="font-family:verdana;"&gt;JavaSoft provides three JDBC product components as part of the Java Development Kit (JDK): &lt;/span&gt; &lt;ul&gt;&lt;li&gt;&lt;span style="font-family:verdana;"&gt;The JDBC driver manager, &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:verdana;"&gt;The JDBC driver test suite, and&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:verdana;"&gt;The JDBC-ODBC bridge. &lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;The JDBC driver manager&lt;/span&gt; is the backbone of the JDBC architecture. It actually is quite small and simple; its primary function is to connect Java applications to the correct JDBC driver and then get out of the way. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;The JDBC driver test suite&lt;/span&gt; provides some confidence that JDBC drivers will run your program. Only drivers that pass the JDBC driver test suite can be designated JDBC COMPLIANTTM. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;The JDBC-ODBC bridge&lt;/span&gt; allows ODBC drivers to be used as JDBC drivers. It was implemented as a way to get JDBC off the ground quickly, and long term will provide a way to access some of the less popular DBMSs if JDBC drivers are not implemented for them.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_Pc8VSCmbaAo/SdTmHpX1diI/AAAAAAAAAKE/LrGr_R5_XnQ/s1600-h/jdbc-driver-types.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 75px;" src="http://2.bp.blogspot.com/_Pc8VSCmbaAo/SdTmHpX1diI/AAAAAAAAAKE/LrGr_R5_XnQ/s400/jdbc-driver-types.png" alt="" id="BLOGGER_PHOTO_ID_5320130078870697506" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;" &gt;JDBC Driver Types&lt;/span&gt; &lt;span style="color: rgb(153, 0, 0);"&gt;:&lt;/span&gt;&lt;/span&gt; &lt;span style="font-family:verdana;"&gt;The JDBC drivers that we are aware of at this time fit into one of four categories: &lt;/span&gt; &lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;1.JDBC-ODBC bridge plus ODBC driver:&lt;/span&gt; The JavaSoft bridge product provides JDBC access via ODBC drivers. Note that ODBC binary code, and in many cases database client code, must be loaded on each client machine that uses this driver. As a result, this kind of driver is most appropriate on a corporate network where client installations are not a major problem, or for application server code written in Java in a three-tier architecture. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;2.Native-API partly-Java driver:&lt;/span&gt; This kind of driver converts JDBC calls into calls on the client API for Oracle, Sybase, Informix, DB2, or other DBMS. Note that, like the bridge driver, this style of driver requires that some binary code be loaded on each client machine. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;3.JDBC-Net pure Java driver:&lt;/span&gt; This driver translates JDBC calls into a DBMS- independent net protocol which is then translated to a DBMS protocol by a server. This net server middleware is able to connect its pure Java clients to many different databases. The specific protocol used depends on the vendor. In general, this is the most flexible JDBC alternative. It is likely that all vendors of this solution will provide products suitable for Intranet use. In order for these products to also support Internet access, they must handle the additional requirements for security, access through firewalls, and so on, that the Web imposes. Several vendors are adding JDBC drivers to their existing database middle ware products. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;4.Native-protocol pure Java driver:&lt;/span&gt; This kind of driver converts JDBC calls into the network protcol used by DBMSs directly. This allows a direct call from the client machine to the DBMS server and is a practical solution for Intranet access. Since many of these protocols are proprietary, the database vendors themselves will be the primary source, and several database vendors have these in progress. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;                                                                        Eventually, we expect that driver categories 3 and 4 will be the preferred way to access databases from JDBC. Driver categories 1 and 2 are interim solutions where direct pure Java drivers are not yet available. There are possible variations on categories 1 and 2 (not shown in the table below) that require a connector, but these are generally less desirable solutions. Categories 3 and 4 offer all the advantages of Java, including automatic installation (for example, downloading the JDBC driver with an applet that uses it). &lt;/span&gt;</description><media:thumbnail url="http://2.bp.blogspot.com/_Pc8VSCmbaAo/SdTmHpX1diI/AAAAAAAAAKE/LrGr_R5_XnQ/s72-c/jdbc-driver-types.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>Collection-Interface</title><link>http://www.javaexamples4u.com/2009/04/collection-interface.html</link><category>Collections(java.util)</category><author>noreply@blogger.com (LakshmiNarayana Gorantla)</author><pubDate>Wed, 01 Apr 2009 03:05:27 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-4796886846449158195.post-2020955047577572234</guid><description>&lt;span style="font-family:verdana;"&gt;The 1.2 release of the Java platform includes a new collections framework. A collection is an object that represents a group of objects. A collections framework is a unified architecture for representing and manipulating collections, allowing them to be manipulated independently of the details of their representation. &lt;/span&gt;&lt;span style="font-family:verdana;"&gt;The Collection interface is the root of the collection hierarchy. A Collection represents a group of objects, known as its elements. Some Collection implementations allow duplicate elements and others do not. Some are ordered and others unordered. The JDK doesn't provide any direct implementations of this interface: It provides implementations of more specific subinterfaces like Set and List. This interface is the least common denominator that all collections implement.&lt;br /&gt;&lt;br /&gt;Collection is used to pass collections around and manipulate them when maximum generality is desired.Collection frame work define a set classes and interfaces which can be used for representing a group of objects as single entity.In the case of c++ the corresponding collection frame work is known as STL(Standered template library) and collection is known as container.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:worddocument&gt;   &lt;w:view&gt;Normal&lt;/w:View&gt;   &lt;w:zoom&gt;0&lt;/w:Zoom&gt;   &lt;w:compatibility&gt;    &lt;w:breakwrappedtables/&gt;    &lt;w:snaptogridincell/&gt;    &lt;w:wraptextwithpunct/&gt;    &lt;w:useasianbreakrules/&gt;   &lt;/w:Compatibility&gt;   &lt;w:browserlevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;  &lt;/w:WordDocument&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;style&gt; &lt;!--  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal  {mso-style-parent:"";  margin:0in;  margin-bottom:.0001pt;  mso-pagination:widow-orphan;  font-size:13.0pt;  mso-bidi-font-size:10.0pt;  font-family:"Times New Roman";  mso-fareast-font-family:"Times New Roman";} tt  {font-family:"Courier New";  mso-ascii-font-family:"Courier New";  mso-fareast-font-family:"Courier New";  mso-hansi-font-family:"Courier New";  mso-bidi-font-family:"Courier New";} @page Section1  {size:8.5in 11.0in;  margin:1.0in 1.25in 1.0in 1.25in;  mso-header-margin:.5in;  mso-footer-margin:.5in;  mso-paper-source:0;} div.Section1  {page:Section1;} --&gt; &lt;/style&gt;&lt;!--[if gte mso 10]&gt; &lt;style&gt;  /* Style Definitions */  table.MsoNormalTable  {mso-style-name:"Table Normal";  mso-tstyle-rowband-size:0;  mso-tstyle-colband-size:0;  mso-style-noshow:yes;  mso-style-parent:"";  mso-padding-alt:0in 5.4pt 0in 5.4pt;  mso-para-margin:0in;  mso-para-margin-bottom:.0001pt;  mso-pagination:widow-orphan;  font-size:10.0pt;  font-family:"Times New Roman";} &lt;/style&gt; &lt;![endif]--&gt;&lt;span style="font-family:verdana;"&gt;There are six collection interfaces. The most basic interface is Collection. Three interfaces extend Collection: Set, List, and SortedSet. The other two collection interfaces, Map and SortedMap, do not extend Collection, as they represent mappings rather than true collections. However, these interfaces contain collection-view operations, which allow them to be manipulated as collections.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_Pc8VSCmbaAo/SdMr_ObkETI/AAAAAAAAAJ0/N-Ln2j0h7CA/s1600-h/collections-interfaces.gif"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 259px;" src="http://2.bp.blogspot.com/_Pc8VSCmbaAo/SdMr_ObkETI/AAAAAAAAAJ0/N-Ln2j0h7CA/s400/collections-interfaces.gif" alt="" id="BLOGGER_PHOTO_ID_5319643950060146994" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);font-family:verdana;" &gt;Collection Interface&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);font-family:verdana;" &gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;It defines general methods ,which can be used for a group of individual objects.i.e a collection represents a group of individual ibjects.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Note:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Collection is an interface to represent a group of individual objects where as collections is an utility class for defining utility methods like sorting,searching… etc.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Collection Interface Methods&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;This Interface defines general methods which can be applied on any collection object.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;1&lt;/span&gt;.boolean add(Object obj)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;2&lt;/span&gt;.boolean addAll(collection c)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="color: rgb(153, 0, 0); font-weight: bold;"&gt;3&lt;/span&gt;.boolean remove(Object o)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;4&lt;/span&gt;.boolean removeAll(Collection  c)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;5&lt;/span&gt;.void clear()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;6&lt;/span&gt;.boolean retainAll(Collection c)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;removes all the elements in the collection except those present in c.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;7&lt;/span&gt;.boolean contains(Object o)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;8&lt;/span&gt;.boolean containsAll(Collection c)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;9&lt;/span&gt;.boolean isEmpty()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;10&lt;/span&gt;.int size()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;returns the number of objects present in the collection&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;11&lt;/span&gt;.Object[] toArray()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;mainly for improving the performance of the system.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;12&lt;/span&gt;. Iterator iterator()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;to return the objects one by one.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;The primary advantages of a collections framework are that it: &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;•    Reduces programming effort by providing useful data structures and algorithms so you don't have to write them yourself.&lt;br /&gt;•    Increases performance by providing high-performance implementations of useful data structures and algorithms. Because the various implementations of each interface are interchangeable, programs can be easily tuned by switching implementations.&lt;br /&gt;•    Provides interoperability between unrelated APIs by establishing a common language to pass collections back and forth.&lt;br /&gt;•    Reduces the effort required to learn APIs by eliminating the need to learn multiple ad hoc collection APIs.&lt;br /&gt;•    Reduces the effort required to design and implement APIs by eliminating the need to produce ad hoc collections APIs.&lt;br /&gt;•    Fosters software reuse by providing a standard interface for collections and algorithms to manipulate them.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a style="font-family: verdana;" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_Pc8VSCmbaAo/SZgJikX1FhI/AAAAAAAAAFY/690lk-DrNl8/s1600-h/Set+implemented+classes.png"&gt;&lt;br /&gt;&lt;/a&gt;</description><media:thumbnail url="http://2.bp.blogspot.com/_Pc8VSCmbaAo/SdMr_ObkETI/AAAAAAAAAJ0/N-Ln2j0h7CA/s72-c/collections-interfaces.gif" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></item><media:rating>nonadult</media:rating></channel></rss>
