<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:georss="http://www.georss.org/georss" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0"><id>tag:blogger.com,1999:blog-7536416306579972030</id><updated>2009-10-04T18:29:20.497+05:30</updated><title type="text">new era in java technology</title><subtitle type="html" /><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://javadevelopersden.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://javadevelopersden.blogspot.com/" /><link rel="hub" href="http://pubsubhubbub.appspot.com/" /><author><name>Krishna Mohan</name><uri>http://www.blogger.com/profile/14677813920630624063</uri><email>noreply@blogger.com</email></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>16</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /><link rel="self" href="http://feeds.feedburner.com/NewEraInJavaTechnology" type="application/atom+xml" /><feedburner:emailServiceId>NewEraInJavaTechnology</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2FNewEraInJavaTechnology" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FNewEraInJavaTechnology" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2FNewEraInJavaTechnology" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/NewEraInJavaTechnology" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FNewEraInJavaTechnology" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FNewEraInJavaTechnology" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FNewEraInJavaTechnology" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><entry><id>tag:blogger.com,1999:blog-7536416306579972030.post-2772388017481814605</id><published>2008-03-18T15:36:00.002+05:30</published><updated>2008-03-18T16:41:25.786+05:30</updated><title type="text">Create graphics applications with Java 3D</title><content type="html">&lt;p&gt; Since version 1.2, Java 3D is developed under the &lt;a href="http://jcp.org/en/home/index" target="new"&gt;Java Community Process&lt;/a&gt;. Java 3D runs on top of OpenGL or Direct3D; it's also an interface that encapsulates graphics programming using a real, object-oriented concept. In addition, Java 3D offers extensive 3D sound support.&lt;/p&gt; &lt;p&gt;This article describes a scene that is constructed using a scene graph, which is a representation of the objects that have to be shown. This scene graph is structured as a tree containing several elements that are necessary to display the objects.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Ref:  &lt;a href="http://www.builderau.com.au/program/java/soa/Create-graphics-applications-with-Java-3D/0,339024620,339286865,00.htm"&gt;View Complete&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7536416306579972030-2772388017481814605?l=javadevelopersden.blogspot.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=9l-JVCfKaLE:6i_3F9VVqyw:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=9l-JVCfKaLE:6i_3F9VVqyw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=9l-JVCfKaLE:6i_3F9VVqyw:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=9l-JVCfKaLE:6i_3F9VVqyw:YwkR-u9nhCs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=YwkR-u9nhCs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=9l-JVCfKaLE:6i_3F9VVqyw:wF9xT3WuBAs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=9l-JVCfKaLE:6i_3F9VVqyw:wF9xT3WuBAs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=9l-JVCfKaLE:6i_3F9VVqyw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=9l-JVCfKaLE:6i_3F9VVqyw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=9l-JVCfKaLE:6i_3F9VVqyw:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=9l-JVCfKaLE:6i_3F9VVqyw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=9l-JVCfKaLE:6i_3F9VVqyw:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=9l-JVCfKaLE:6i_3F9VVqyw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=9l-JVCfKaLE:6i_3F9VVqyw:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=9l-JVCfKaLE:6i_3F9VVqyw:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=9l-JVCfKaLE:6i_3F9VVqyw:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=9l-JVCfKaLE:6i_3F9VVqyw:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=9l-JVCfKaLE:6i_3F9VVqyw:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/9l-JVCfKaLE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://javadevelopersden.blogspot.com/feeds/2772388017481814605/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=7536416306579972030&amp;postID=2772388017481814605" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/2772388017481814605" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/2772388017481814605" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/9l-JVCfKaLE/create-graphics-applications-with-java.html" title="Create graphics applications with Java 3D" /><author><name>Krishna Mohan</name><uri>http://www.blogger.com/profile/14677813920630624063</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="13118096540046841896" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by/2.0/" /><feedburner:origLink>http://javadevelopersden.blogspot.com/2008/03/create-graphics-applications-with-java.html</feedburner:origLink></entry><entry><title type="text">Links for 2007-11-29 [del.icio.us]</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/rch_xLHjPN8/krishnamohan_lvkm" /><updated>2007-11-30T00:00:00-08:00</updated><id>http://del.icio.us/krishnamohan_lvkm#2007-11-29</id><content type="html">&lt;ul&gt;
&lt;li&gt;&lt;a href="http://java.sun.com/developer/technicalArticles/releases/1.4regex/"&gt;Regular Expressions and the Java Programming Language&lt;/a&gt;&lt;br/&gt;
hhhh 	The character with hexadecimal value 0xhhhh&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/rch_xLHjPN8" height="1" width="1"/&gt;</content><feedburner:origLink>http://del.icio.us/krishnamohan_lvkm#2007-11-29</feedburner:origLink></entry><entry><title type="text">Links for 2007-09-20 [del.icio.us]</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/XMw_7oDv09s/krishnamohan_lvkm" /><updated>2007-09-21T00:00:00-07:00</updated><id>http://del.icio.us/krishnamohan_lvkm#2007-09-20</id><content type="html">&lt;ul&gt;
&lt;li&gt;&lt;a href="http://dev2dev.bea.com/pub/a/2005/04/new2java.html"&gt;Resources for new Java developers&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/XMw_7oDv09s" height="1" width="1"/&gt;</content><feedburner:origLink>http://del.icio.us/krishnamohan_lvkm#2007-09-20</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-7536416306579972030.post-3876376051989136821</id><published>2007-09-19T10:23:00.000+05:30</published><updated>2007-09-19T10:24:54.295+05:30</updated><title type="text">Struts Overview</title><content type="html">&lt;span style="font-weight: bold;"&gt;What is Struts?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Struts Frame work is the implementation of Model-View-Controller (MVC) design pattern for the JSP. Struts is maintained as a part of Apache Jakarta project and is open source. Struts Framework is suited for the application of any size. Latest version of struts can be downloaded from http://jakarta.apache.org/. We are using jakarta-struts-1.1 and jakarta-tomcat-5.0.4 for this tutorial.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is Model-View-Controller (MVC) Architecture?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Model-View-Controller architecture is all about dividing application components into three different categories Model, View and the Controller. Components of the MVC architecture has unique responsibility and each component is independent of the other component. Changes in one component will have no or less impact on other component. Responsibilities of the components are:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Model&lt;/span&gt;: Model is responsible for providing the data from the database and saving the data into the data store. All the business logic are implemented in the Model. Data entered by the user through View are check in the model before saving into the database. Data access, Data validation and the data saving logic are part of Model.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;View&lt;/span&gt;: View represents the user view of the application and is responsible for taking the input from the user, dispatching the request to the controller and then receiving response from the controller and displaying the result to the user. HTML, JSPs, Custom Tag Libraries and Resources files are the part of view component.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Controller&lt;/span&gt;: Controller is intermediary between Model and View. Controller is responsible for receiving the request from client. Once request is received from client it executes the appropriate business logic from the Model and then produce the output to the user using the View component. ActionServlet, Action, ActionForm and struts-config.xml are the part of Controller.&lt;br /&gt;&lt;br /&gt;The main aim of the MVC architecture  is to separate the business logic and application data from the presentation data to the user.&lt;br /&gt;&lt;br /&gt;Here are the reasons why we should use the MVC design pattern.&lt;br /&gt;&lt;br /&gt;   1. They are resuable : When the problems recurs, there is no need to invent a new solution, we just have to follow the pattern and adapt it as necessary.&lt;br /&gt;   2. They are expressive: By using the MVC design pattern our application becomes more expressive.&lt;br /&gt;&lt;br /&gt;1).  &lt;span style="font-weight: bold;"&gt;Model&lt;/span&gt;: The model object knows about all the data that need to be displayed. It is model who is aware about all the operations that can be applied to transform that object. It only represents the data of an application. The model represents enterprise data and the business rules that govern access to and updates of this data. Model is not aware about the presentation data and how that data will be displayed to the browser. &lt;br /&gt;&lt;br /&gt;2). &lt;span style="font-weight: bold;"&gt;View &lt;/span&gt;: The view represents the presentation of the application. The view object refers to the model. It uses the query methods of the model to obtain the contents and renders it. The view is not dependent on the application logic. It remains same if there is any modification in the business logic. In other words, we can say that it is the responsibility of the of the view's to maintain the consistency in its presentation when the model changes.&lt;br /&gt;&lt;br /&gt;3). &lt;span style="font-weight: bold;"&gt;Controller&lt;/span&gt;:  Whenever the user sends a request for something then it always go through the controller. The controller is responsible for intercepting the requests from view and passes it to the model for the appropriate action. After the action has been taken on the data, the controller is responsible for directing the appropriate view to the user. In  GUIs, the views and the controllers often work very closely together.&lt;br /&gt;&lt;br /&gt;Difference between Model 1 and Model 2 architecture:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Features of MVC1:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   1. Html or jsp files are used to code the presentation. To retrieve the data JavaBean can be used.&lt;br /&gt;   2. In mvc1 archictecture all the view, control elements are implemented using Servlets or Jsp.&lt;br /&gt;   3. In MVC1 there is tight coupling between page and model as data access is usually done using Custom tag or through java bean call.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Features of MVC2:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   1. The MVC2  architecture removes the page centric property of MVC1 architecture by separating Presentation, control logic and the application state.&lt;br /&gt;   2. In MVC2 architecture there is only one controller which receives all the request for the application and is responsible for taking appropriate action in response to each request.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Struts is an open source framework used for developing J2EE web applications using Model View Controller (MVC) design pattern. It uses and extends the Java Servlet API to encourage developers to  adopt an MVC architecture. Struts framework provides three key components:&lt;br /&gt;&lt;br /&gt;   1. A request handler provided by the application developer that is used to  mapped to a particular URI.&lt;br /&gt;   2. A response handler which is used to transfer the control to another resource which will be responsible for completing the response.&lt;br /&gt;   3. A tag library which helps developers to create the interactive form based applications with server pages.&lt;br /&gt;&lt;br /&gt;Struts provides you the basic infrastructure infrastructure for implementing MVC allowing the developers to concentrate on the business logic.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Overview of the Struts Framework&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The Struts framework is composed of approximately 300 classes and interfaces which are organized in about 12 top level packages. Along with the utility and helper classes framework also provides the classes and interfaces for working with controller and presentation by the help of the custom tag libraries. It is entirely on to us which model we want to choose. The view of the Struts architecture is given below:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The Struts Controller Components:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Whenever a user request for something, then the request is handled by the Struts Action Servlet. When the ActionServlet receives the request, it intercepts the URL and based on the Struts Configuration files, it gives the handling of the request to the Action class. Action class is a part of the controller and is responsible for communicating with the model layer.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The Struts View Components:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The view components are responsible for presenting information to the users and accepting the input from them. They are responsible for displaying the information provided by the model components. Mostly we use the Java Server Pages (JSP) for the view presentation. To extend the capability of the view we can use the Custom tags, java script etc.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; The Struts model component:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The model components provides a model of the business logic behind a Struts program. It provides interfaces to databases or back- ends systems. Model components are generally a java class. There is not any such defined format for a Model component, so it is possible for us to reuse Java code which are written for other projects. We should choose the model according to our client requirement.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7536416306579972030-3876376051989136821?l=javadevelopersden.blogspot.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=xsdZuqqowmU:Ce5_KZobT_A:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=xsdZuqqowmU:Ce5_KZobT_A:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=xsdZuqqowmU:Ce5_KZobT_A:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=xsdZuqqowmU:Ce5_KZobT_A:YwkR-u9nhCs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=YwkR-u9nhCs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=xsdZuqqowmU:Ce5_KZobT_A:wF9xT3WuBAs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=xsdZuqqowmU:Ce5_KZobT_A:wF9xT3WuBAs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=xsdZuqqowmU:Ce5_KZobT_A:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=xsdZuqqowmU:Ce5_KZobT_A:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=xsdZuqqowmU:Ce5_KZobT_A:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=xsdZuqqowmU:Ce5_KZobT_A:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=xsdZuqqowmU:Ce5_KZobT_A:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=xsdZuqqowmU:Ce5_KZobT_A:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=xsdZuqqowmU:Ce5_KZobT_A:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=xsdZuqqowmU:Ce5_KZobT_A:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=xsdZuqqowmU:Ce5_KZobT_A:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=xsdZuqqowmU:Ce5_KZobT_A:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=xsdZuqqowmU:Ce5_KZobT_A:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/xsdZuqqowmU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://javadevelopersden.blogspot.com/feeds/3876376051989136821/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=7536416306579972030&amp;postID=3876376051989136821" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/3876376051989136821" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/3876376051989136821" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/xsdZuqqowmU/struts-overview.html" title="Struts Overview" /><author><name>Krishna Mohan</name><uri>http://www.blogger.com/profile/14677813920630624063</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="13118096540046841896" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by/2.0/" /><feedburner:origLink>http://javadevelopersden.blogspot.com/2007/09/struts-overview.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-7536416306579972030.post-6115181696661334970</id><published>2007-09-13T10:52:00.000+05:30</published><updated>2007-09-13T10:55:46.210+05:30</updated><title type="text" /><content type="html">&lt;span style="font-weight: bold;"&gt;NavigableSet and ConcurrentSkipListSet&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Suppose we have a requirement, from sorted set elements [5,10,15,20] we want few things like this&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Retrieve the element which is immediately greater than or lower than element 15&lt;/li&gt;&lt;li&gt;    Retrieve all elements greater than or lower than 10&lt;/li&gt;&lt;/ul&gt;With the help of existing methods we need to take few risks to achieve them. But with NavigableSet methods it becomes just a method call.NavigableSet methods used to return the closest matches of elements for the given elements in the collection. ConcurrentSkipListSet is one of the class that implements NavigableSet.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Example&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;import java.util.concurrent.*;&lt;br /&gt;import java.util.*;&lt;br /&gt;class SkipListSetTest&lt;br /&gt;{&lt;br /&gt;   public static void main(String[] args)&lt;br /&gt;   {&lt;br /&gt;       ConcurrentSkipListSet csls = new ConcurrentSkipListSet();&lt;br /&gt;       csls.add(15);&lt;br /&gt;       csls.add(20);&lt;br /&gt;       csls.add(5);&lt;br /&gt;       csls.add(10);&lt;br /&gt;       System.out.println("Elements in the collections are");&lt;br /&gt;       for(Integer i: csls)&lt;br /&gt;       {&lt;br /&gt;           System.out.println(i);&lt;br /&gt;       }&lt;br /&gt;       /* Retrieve immediate element less than or equal to  the given element */&lt;br /&gt;       System.out.println("Floor    "+csls.floor(12));&lt;br /&gt;       /* Retrieve immediate  element greater than or equal to the given element */&lt;br /&gt;       System.out.println("Ceiling  "+csls.ceiling(12));&lt;br /&gt;       /* Retrieve immediate element less than the given element */&lt;br /&gt;       System.out.println("Lower    "+csls.lower(10));&lt;br /&gt;       /* Retrieve immediate element greater than the given element */&lt;br /&gt;       System.out.println("heigher  "+csls.higher(10));&lt;br /&gt;       System.out.println("Head Elements ");&lt;br /&gt;       Set cslsHeadView =  csls.headSet(10);&lt;br /&gt;       //HeadSet excludes the given element&lt;br /&gt;       for(Integer i: cslsHeadView)&lt;br /&gt;       {&lt;br /&gt;           System.out.println(i);&lt;br /&gt;       }&lt;br /&gt;       Set cslsTailView =  csls.tailSet(10);&lt;br /&gt;       //TailSet includes the given element&lt;br /&gt;       System.out.println("Tail Elements");&lt;br /&gt;       for(Integer i: cslsTailView)&lt;br /&gt;       {&lt;br /&gt;           System.out.println(i);&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Elements in the collections are&lt;br /&gt;5&lt;br /&gt;10&lt;br /&gt;15&lt;br /&gt;20&lt;br /&gt;Floor    10&lt;br /&gt;Ceiling  15&lt;br /&gt;Lower    5&lt;br /&gt;heigher  15&lt;br /&gt;Head Elements&lt;br /&gt;5&lt;br /&gt;Tail Elements&lt;br /&gt;10&lt;br /&gt;15&lt;br /&gt;20&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;NavigableMap and ConcurrentSkipListMap&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;NaviagableMap is similar to NaviagableSet. In NavigableSet, methods use to return values, but in NaviagableMap methods used to return the key,value pair.ConcurrentSkipListMap is the one of the class which implements NaviagableMap.&lt;br /&gt;&lt;br /&gt;import java.util.*;&lt;br /&gt;import java.util.concurrent.*;&lt;br /&gt;&lt;br /&gt;class NavigableMapExample&lt;br /&gt;{&lt;br /&gt;   public static void main(String[] args)&lt;br /&gt;   {&lt;br /&gt;       NavigableMap nm = new ConcurrentSkipListMap();&lt;br /&gt;       nm.put(1,"One");&lt;br /&gt;       nm.put(2,"Two");&lt;br /&gt;       nm.put(3,"Three");&lt;br /&gt;       nm.put(4,"Four");&lt;br /&gt;       nm.put(5,"Five");&lt;br /&gt;       /* Retrieves the key,value pair immediately lesser than the given key */&lt;br /&gt;       Map.Entry ae = nm.lowerEntry(5);&lt;br /&gt;       /* Map.Entry is a Static interface nested inside Map&lt;br /&gt;          interface,just use to hold key and value */&lt;br /&gt;       System.out.println("Key" + ae.getKey());&lt;br /&gt;       System.out.println("Value"+    ae.getValue());&lt;br /&gt;       /* Retrieves key,value pairs equal to and greater then the given key */&lt;br /&gt;       SortedMap mm = nm.tailMap(3);&lt;br /&gt;       Set s = mm.keySet();&lt;br /&gt;       System.out.println("Tail elements are");&lt;br /&gt;       for(Integer i:s)&lt;br /&gt;       {&lt;br /&gt;           System.out.println("Key "+ i + "Value "+ mm.get(i));&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;output&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Key 4&lt;br /&gt;Value Four&lt;br /&gt;Tail elements are&lt;br /&gt;Key 3  Value Three&lt;br /&gt;Key 4  Value Four&lt;br /&gt;Key 5  Value Five&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Notes :&lt;/span&gt;&lt;br /&gt;floorEntry method retrieves less than or equal to the givenkey (or) null&lt;br /&gt;lowerEntry method retrieves always less than the givenkey (or) null&lt;br /&gt;headMap method retrieves all elements less than  the givenkey&lt;br /&gt;tailMap method retrieves all elements greater than or equal to the givenkey&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;AbstractMap.SimpleEntry and AbstractMap.SimpleImmutableEntry&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;AbstractMap.SimpleEntry and AbstractMap.SimpleImmutableEntry are a static classes nested inside abstractMap class.The instance of this classes use to hold the key,value pair of one single entry in a Map.The difference between these two classes is that former one allow us to set the value and later one if we try to set the value, it throws UnsupportedOperationException&lt;br /&gt;Modified classes&lt;br /&gt;&lt;br /&gt;Classes are modified to implement the new interfaces in the existing classes.LinkedList is modified to implement Deque. TreeSet is modified to implement NavigableSet.TreeMap is modified to implement NavigableMap.In Collections 2 new methods newSetFromMap and asLifoQueue are added.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7536416306579972030-6115181696661334970?l=javadevelopersden.blogspot.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=4nYxI--qzrE:IksxdWW5yUw:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=4nYxI--qzrE:IksxdWW5yUw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=4nYxI--qzrE:IksxdWW5yUw:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=4nYxI--qzrE:IksxdWW5yUw:YwkR-u9nhCs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=YwkR-u9nhCs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=4nYxI--qzrE:IksxdWW5yUw:wF9xT3WuBAs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=4nYxI--qzrE:IksxdWW5yUw:wF9xT3WuBAs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=4nYxI--qzrE:IksxdWW5yUw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=4nYxI--qzrE:IksxdWW5yUw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=4nYxI--qzrE:IksxdWW5yUw:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=4nYxI--qzrE:IksxdWW5yUw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=4nYxI--qzrE:IksxdWW5yUw:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=4nYxI--qzrE:IksxdWW5yUw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=4nYxI--qzrE:IksxdWW5yUw:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=4nYxI--qzrE:IksxdWW5yUw:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=4nYxI--qzrE:IksxdWW5yUw:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=4nYxI--qzrE:IksxdWW5yUw:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=4nYxI--qzrE:IksxdWW5yUw:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/4nYxI--qzrE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://javadevelopersden.blogspot.com/feeds/6115181696661334970/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=7536416306579972030&amp;postID=6115181696661334970" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/6115181696661334970" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/6115181696661334970" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/4nYxI--qzrE/navigableset-and-concurrentskiplistset.html" title="" /><author><name>Krishna Mohan</name><uri>http://www.blogger.com/profile/14677813920630624063</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="13118096540046841896" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by/2.0/" /><feedburner:origLink>http://javadevelopersden.blogspot.com/2007/09/navigableset-and-concurrentskiplistset.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-7536416306579972030.post-9093093955927957286</id><published>2007-09-12T12:24:00.001+05:30</published><updated>2007-09-12T12:25:21.500+05:30</updated><title type="text">Synchronization in Java</title><content type="html">Why Synchronization&lt;br /&gt;&lt;br /&gt;The biggest problem of allowing multiple threads sharing the same data set is that one operation in one thread could collide with another operation in another threads on the same data. When this happens, the result is un-desirable.&lt;br /&gt;&lt;br /&gt;Let's use a bank application program as an example.&lt;br /&gt;Assuming that the program has multiple threads running, with each thread connecting an ATM system, and you have a saving account in the bank with $100.00, now you and your friend are going to two different ATMs at about the same time, and trying to withdraw $50.00 from your account, what do you think it will happen?&lt;br /&gt;&lt;br /&gt;If the threads are running independently, the following could happen:&lt;br /&gt;&lt;br /&gt;Time     01:01      02:01     03:01     04:01&lt;br /&gt;         +----------+---------+---------+-------&lt;br /&gt;Thread 1            Get       Set&lt;br /&gt;Action   You        Account   Account   You&lt;br /&gt;         Withdraw   Balance   Balance   Receive&lt;br /&gt;         $50.00     $100.00   $50.00    $50.00&lt;br /&gt;&lt;br /&gt;Time      01:02      02:02     03:02     04:02&lt;br /&gt;         -+----------+---------+---------+------&lt;br /&gt;Thread 2             Get       Set&lt;br /&gt;Action    Friend     Account   Account   Friend&lt;br /&gt;          Withdraw   Balance   Balance   Receive&lt;br /&gt;          $50.00     $100.00   $50.00    $50.00&lt;br /&gt;&lt;br /&gt;Time     01:01      02:01     03:01     04:01&lt;br /&gt;         -----------++--------++--------++------&lt;br /&gt;Account  $100.00    $100.00   $50.00    $50.00&lt;br /&gt;&lt;br /&gt;Both you and your friend will receive $50.00 each, and your account will still have $50.00. The bank could lose $50.00.&lt;br /&gt;&lt;br /&gt;The solution this problem is synchronization.&lt;br /&gt;&lt;br /&gt;What Is Synchronization&lt;br /&gt;&lt;br /&gt;Synchronization is a programming technique that involves 3 elements:&lt;br /&gt;&lt;br /&gt;    * Lock: An object with two states: locked and unlocked.&lt;br /&gt;    * Synchronized Block: A block of statements that is associated with a lock.&lt;br /&gt;    * Synchronization Rule: When a synchronized block is encountered in a thread of execution, the associated lock will be checked. If the lock locked, the execution will be stopped until the lock is unlocked. If the lock is unlocked, the lock will be locked, and the synchronized block of statements will be executed. When the execution reaches the end of the synchronized block, the lock will be unlocked. With this rule, two synchronized blocks associated with same lock will never be executed at the same time.&lt;br /&gt;&lt;br /&gt;Now let's see if we can use the synchronization technique in the bank application program to help the bank. Let's define a synchronization block starting from the "Get Account Balance" action to the "Set Account Balance" action in each thread, and associate the block with a lock. With this change, both you and your friend can still withdraw $50.00, but your account will have nothing left:&lt;br /&gt;&lt;br /&gt;Time     01:01      02:01     03:01      04:02&lt;br /&gt;         -----------+---------++--------++-------&lt;br /&gt;Lock     Unlocked   Locked    Locked     Unlocked&lt;br /&gt;&lt;br /&gt;Time     01:01      02:01     03:01     04:01&lt;br /&gt;         +----------+---------+---------+--------&lt;br /&gt;Thread 1            Get       Set&lt;br /&gt;Action   You        Account   Account   You&lt;br /&gt;         Withdraw   Balance   Balance   Receive&lt;br /&gt;         $50.00     $100.00   $50.00    $50.00&lt;br /&gt;&lt;br /&gt;Time      01:02      02:02     03:02     04:02     05:02&lt;br /&gt;         -+----------+---------+---------+---------+------&lt;br /&gt;Thread 2             Get       Get       Set&lt;br /&gt;Action    Friend     Account   Account   Account   Friend&lt;br /&gt;          Withdraw   Balance   Balance   Balance   Receive&lt;br /&gt;          $50.00     Stopped   $50.00    $0.00     $50.00&lt;br /&gt;&lt;br /&gt;Time     01:01      02:01     03:01      04:02     05:02&lt;br /&gt;         -----------++--------++--------++---------+------&lt;br /&gt;Account  $100.00    $100.00   $50.00     $0.00     $0.00&lt;br /&gt;&lt;br /&gt;The synchronization technique did help the bank from losing money. But it also increased the total transaction time.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Synchronization Support in Java&lt;br /&gt;&lt;br /&gt;Instead of let the programmers to design their own locks, manage the synchronization blocks, and apply the synchronization rules, Java offers a synchronization monitor on each instance of the Object class, so it can be used as a synchronization lock. Since all classes are sub classes of Object, all objects in Java can be used as synchronization locks.&lt;br /&gt;&lt;br /&gt;Java also offers three ways to define synchronized blocks.&lt;br /&gt;&lt;br /&gt;Synchronized Class Method:&lt;br /&gt;&lt;br /&gt;class class_name {&lt;br /&gt;   static synchronized type method_name() {&lt;br /&gt;      statement block&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;All the statements in the method become the synchronized block, and the class object is the lock.&lt;br /&gt;&lt;br /&gt;Synchronized Instance Method:&lt;br /&gt;&lt;br /&gt;class class_name {&lt;br /&gt;   synchronized type method_name() {&lt;br /&gt;      statement block&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;All the statements in the method become the synchronized block, and the instance object is the lock.&lt;br /&gt;&lt;br /&gt;Synchronized Statement:&lt;br /&gt;&lt;br /&gt;class class_name {&lt;br /&gt;   type method_name() {&lt;br /&gt;      synchronized (object) {&lt;br /&gt;         statement block&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;All the statements specified in the parentheses of the synchronized statement become the synchronized block, and the object specified in the statement is the lock.&lt;br /&gt;&lt;br /&gt;Java applys the synchronization rule by assigning the ownership of the lock's monitor to the threads that are running the synchronized blocks. Here is how it works:&lt;br /&gt;&lt;br /&gt;    * When a synchronized clock is reached in an execution thread, it will try to gain the ownership of the monitor of the lock object. If another thread owns the lock's monitor, it will wait.&lt;br /&gt;    * Once the lock's monitor is free, the waiting thread will become the owner of the lock's monitor, and start to execute the synchronized block.&lt;br /&gt;    * Once the synchronized block is executed to the end, the lock's monitor will be freed again.&lt;br /&gt;&lt;br /&gt;Note that one program can have many locks and each lock can be associated with many different synchronized blocks. But the synchronization rule only applies between the synchronized block and its associated lock.&lt;br /&gt;&lt;br /&gt;For example, the following code defines two synchronized blocks. Both are associated with the same lock, the instance object.&lt;br /&gt;&lt;br /&gt;class class_name {&lt;br /&gt;   type method_name() {&lt;br /&gt;      synchronized (this) {&lt;br /&gt;         statement block 1&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;   synchronized type method_name() {&lt;br /&gt;      statement block 2&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Block 1 will never be executed at the same time as block 2.&lt;br /&gt;&lt;br /&gt;The following code defines two synchronized blocks. But they are associated with two different locks, one is the class object, and the other is the instance object. Those two synchronized blocks will never wait for each other.&lt;br /&gt;&lt;br /&gt;class class_name {&lt;br /&gt;   type method_name() {&lt;br /&gt;      synchronized (this) {&lt;br /&gt;         statement block 1&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;   static synchronized type method_name() {&lt;br /&gt;      statement block 2&lt;br /&gt;   }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7536416306579972030-9093093955927957286?l=javadevelopersden.blogspot.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=-5u-mH7riig:YqkFeScg5I0:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=-5u-mH7riig:YqkFeScg5I0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=-5u-mH7riig:YqkFeScg5I0:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=-5u-mH7riig:YqkFeScg5I0:YwkR-u9nhCs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=YwkR-u9nhCs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=-5u-mH7riig:YqkFeScg5I0:wF9xT3WuBAs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=-5u-mH7riig:YqkFeScg5I0:wF9xT3WuBAs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=-5u-mH7riig:YqkFeScg5I0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=-5u-mH7riig:YqkFeScg5I0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=-5u-mH7riig:YqkFeScg5I0:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=-5u-mH7riig:YqkFeScg5I0:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=-5u-mH7riig:YqkFeScg5I0:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=-5u-mH7riig:YqkFeScg5I0:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=-5u-mH7riig:YqkFeScg5I0:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=-5u-mH7riig:YqkFeScg5I0:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=-5u-mH7riig:YqkFeScg5I0:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=-5u-mH7riig:YqkFeScg5I0:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=-5u-mH7riig:YqkFeScg5I0:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/-5u-mH7riig" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://javadevelopersden.blogspot.com/feeds/9093093955927957286/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=7536416306579972030&amp;postID=9093093955927957286" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/9093093955927957286" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/9093093955927957286" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/-5u-mH7riig/synchronization-in-java.html" title="Synchronization in Java" /><author><name>Krishna Mohan</name><uri>http://www.blogger.com/profile/14677813920630624063</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="13118096540046841896" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by/2.0/" /><feedburner:origLink>http://javadevelopersden.blogspot.com/2007/09/synchronization-in-java.html</feedburner:origLink></entry><entry><title type="text">Links for 2007-09-07 [del.icio.us]</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/jaMnQ2xnoZU/krishnamohan_lvkm" /><updated>2007-09-08T00:00:00-07:00</updated><id>http://del.icio.us/krishnamohan_lvkm#2007-09-07</id><content type="html">&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.ciol.com/content/190799541.aspx"&gt;Developer: Breaching Java rules with reflection&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/jaMnQ2xnoZU" height="1" width="1"/&gt;</content><feedburner:origLink>http://del.icio.us/krishnamohan_lvkm#2007-09-07</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-7536416306579972030.post-2991784913917345545</id><published>2007-09-06T16:35:00.000+05:30</published><updated>2007-09-06T17:07:29.748+05:30</updated><title type="text">Java 6.0 New Collection APIs</title><content type="html">&lt;span style="font-weight: bold;"&gt;Java 6.0 New Collection APIs&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The following are the new collection APIs introduced in Java 6.0. I listes them as Interfaces and classes.&lt;br /&gt;&lt;br /&gt;New Interfaces&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Deque&lt;/li&gt;&lt;li&gt;BlockingDeque&lt;/li&gt;&lt;li&gt;NavigableSet&lt;/li&gt;&lt;li&gt;NavigableMap&lt;/li&gt;&lt;/ul&gt;New Classes&lt;br /&gt;&lt;ul&gt;&lt;li&gt;ArrayDeque&lt;/li&gt;&lt;li&gt;LinkedBlockingDeque&lt;/li&gt;&lt;li&gt;ConcurrentSkipListSet&lt;/li&gt;&lt;li&gt;ConcurrentSkipListMap&lt;/li&gt;&lt;li&gt;AbstractMap.SimpleEntry&lt;/li&gt;&lt;li&gt;AbstractMap.SimpleImmutableEntry&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;Updated Classes in Java 6.0&lt;br /&gt;&lt;ul&gt;&lt;li&gt;LinkedList&lt;/li&gt;&lt;li&gt;TreeSet&lt;/li&gt;&lt;li&gt;TreeMap&lt;/li&gt;&lt;li&gt;Collections&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;"&gt;Deque and ArrayDeque&lt;/span&gt;&lt;br /&gt;Deque is the abbreviation of “Double Ended Queue”. A Collection that allows us to add (or) remove elements at both ends. Deque supports total size of collection for both fixed and unspecified size limits.&lt;br /&gt;Deque implementation can be used as Stack(Last in first out ) or Queue(First in First Out). For each insertion, retrieval and removal of elements from deque there exists methods in 2 flavours. One will throw exception if it fails in an operation and another one returns status or special value for each operation.&lt;br /&gt; Operation  Special value method  Exception throwing method&lt;br /&gt;&lt;br /&gt;    &lt;span style="font-weight: bold;"&gt;Operation &lt;/span&gt;                &lt;span style="font-weight: bold;"&gt;Special value method&lt;/span&gt;     &lt;span style="font-weight: bold;"&gt;Exception throwing method&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    Insertion at head         offerFirst(e)                               addFirst(e)&lt;br /&gt;    Removal at head          pollFirst()                                    removeFirst()&lt;br /&gt;    Retrieval at Head        peekFirst()                                 getFirst()&lt;br /&gt;    Insertion at Tail           offerLast(e)                               addLast(e)&lt;br /&gt;    Removal at Tail           pollLast()                                    removeLast()&lt;br /&gt;    Retrieval at Tail          peekLast()                                  getLast()&lt;br /&gt;Implementation of Deque doesn’t require preventing the insertion of null, but when we are using special value method null is return to indicate that collection is empty. So it is recommendable not to allow insertion of null.&lt;br /&gt;&lt;br /&gt;ArrayDeque is a class that implements Deque. It has no capacity restrictions. It will perform faster than stack when used as stack and faster than linked list when used as queue. ArrayDeque is not thread Safe. The following example explains how to write program using ArrayDeque.&lt;br /&gt;&lt;br /&gt;Example&lt;br /&gt;&lt;br /&gt;import java.util.ArrayDeque;&lt;br /&gt;import java.util.Iterator;&lt;br /&gt;&lt;br /&gt;public class DequeExample&lt;br /&gt;{&lt;br /&gt;  public static void main(String as[])&lt;br /&gt;  {&lt;br /&gt;      ArrayDeque adObj = new ArrayDeque();&lt;br /&gt;      //Insertion by using various methods&lt;br /&gt;&lt;br /&gt;      adObj.add("Oracle");&lt;br /&gt;      adObj.addFirst("DB2");&lt;br /&gt;      adObj.offerFirst("MySQL");   //returns boolean - true R false&lt;br /&gt;      adObj.offerLast("Postgres");   //returns boolean - true R false&lt;br /&gt;&lt;br /&gt;      //Retrievals&lt;br /&gt;&lt;br /&gt;      System.out.println("Retrieving First Element :" + adObj.peekFirst());&lt;br /&gt;      System.out.println("Retrieving Last Element  :"+ adObj.peekLast());&lt;br /&gt;&lt;br /&gt;      //Removals&lt;br /&gt;&lt;br /&gt;      System.out.println("Removing First  Element  :"+ adObj.pollFirst());&lt;br /&gt;      System.out.println("Removing Last  Element   :"+ adObj.pollLast());&lt;br /&gt;&lt;br /&gt;      //Reverse traversal&lt;br /&gt;&lt;br /&gt;      System.out.println("Remaining Elements :");&lt;br /&gt;      Iterator it = adObj.descendingIterator();&lt;br /&gt;      while(it.hasNext())&lt;br /&gt;      {&lt;br /&gt;          System.out.println(it.next());&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Output:&lt;br /&gt;&lt;br /&gt;Retrieving First Element :MySQL&lt;br /&gt;Retrieving Last Element  :Postgres&lt;br /&gt;Removing First  Element  :MySQL&lt;br /&gt;Removing Last  Element   :Postgres&lt;br /&gt;Remaining Elements :&lt;br /&gt;Oracle&lt;br /&gt;DB2&lt;br /&gt;&lt;br /&gt;BlockingDeque and LinkedBlockingDeque&lt;br /&gt;&lt;br /&gt;A BlockingDeque is similar to Deque and provides additionally functionality. When we tries to insert an element in a BlockingDeque, which is already full, it can wait till the space becomes available to insert an element. We can also specify the time limit for waiting.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://tinyurl.com/2yu445"&gt;&lt;img src="http://tinyurl.com/yrmhlc" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7536416306579972030-2991784913917345545?l=javadevelopersden.blogspot.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=WRUjtwmW19Y:VEy-S32ZJaY:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=WRUjtwmW19Y:VEy-S32ZJaY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=WRUjtwmW19Y:VEy-S32ZJaY:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=WRUjtwmW19Y:VEy-S32ZJaY:YwkR-u9nhCs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=YwkR-u9nhCs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=WRUjtwmW19Y:VEy-S32ZJaY:wF9xT3WuBAs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=WRUjtwmW19Y:VEy-S32ZJaY:wF9xT3WuBAs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=WRUjtwmW19Y:VEy-S32ZJaY:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=WRUjtwmW19Y:VEy-S32ZJaY:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=WRUjtwmW19Y:VEy-S32ZJaY:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=WRUjtwmW19Y:VEy-S32ZJaY:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=WRUjtwmW19Y:VEy-S32ZJaY:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=WRUjtwmW19Y:VEy-S32ZJaY:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=WRUjtwmW19Y:VEy-S32ZJaY:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=WRUjtwmW19Y:VEy-S32ZJaY:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=WRUjtwmW19Y:VEy-S32ZJaY:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/WRUjtwmW19Y" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://javadevelopersden.blogspot.com/feeds/2991784913917345545/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=7536416306579972030&amp;postID=2991784913917345545" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/2991784913917345545" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/2991784913917345545" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/WRUjtwmW19Y/java-60-new-collection-apis.html" title="Java 6.0 New Collection APIs" /><author><name>Krishna Mohan</name><uri>http://www.blogger.com/profile/14677813920630624063</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="13118096540046841896" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by/2.0/" /><feedburner:origLink>http://javadevelopersden.blogspot.com/2007/09/java-60-new-collection-apis.html</feedburner:origLink></entry><entry><title type="text">Links for 2007-09-01 [del.icio.us]</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/0G9DeEEy-e8/krishnamohan_lvkm" /><updated>2007-09-02T00:00:00-07:00</updated><id>http://del.icio.us/krishnamohan_lvkm#2007-09-01</id><content type="html">&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.codefutures.com/"&gt;www.codefutures.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.javacamp.org/"&gt;www.javacamp.org&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://resources.corejsp.com/"&gt;http://resources.corejsp.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.javaperformancetuning.com/"&gt;http://www.javaperformancetuning.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://java.sys-con.com/"&gt;http://java.sys-con.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.pdftunnel.com/pdf2word"&gt;http://www.pdftunnel.com/pdf2word&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/0G9DeEEy-e8" height="1" width="1"/&gt;</content><feedburner:origLink>http://del.icio.us/krishnamohan_lvkm#2007-09-01</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-7536416306579972030.post-6921507184970659366</id><published>2007-09-01T16:16:00.001+05:30</published><updated>2007-09-01T16:37:17.622+05:30</updated><title type="text">Implicit Objects</title><content type="html">Implicit Objects in JSP are objects that are automatically available in JSP. Implicit Objects are Java objects that the JSP Container provides to a developer to access them in their program using JavaBeans and Servlets. These objects are called implicit objects because they are automatically instantiated.&lt;br /&gt;&lt;br /&gt;There are many implicit objects available. Some of them are:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;request:&lt;/span&gt; The class or the interface name of the object request is http.httpservletrequest. The object request is of type Javax.servlet.http.httpservletrequest. This denotes the data included with the HTTP Request. The client first makes a request that is then passed to the server. The requested object is used to take the value from client’s web browser and pass it to the server. This is performed using HTTP request like headers, cookies and arguments.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;response:&lt;/span&gt; This denotes the HTTP Response data. The result or the information from a request is denoted by this object. This is in contrast to the request object. The class or the interface name of the object response is http.HttpServletResponse. The object response is of type Javax.servlet.http. &gt;httpservletresponse. Generally, the object response is used with cookies. The response object is also used with HTTP Headers.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Session:&lt;/span&gt; This denotes the data associated with a specific session of user. The class or the interface name of the object Session is http.HttpSession. The object Session is of type Javax.servlet.http.httpsession. The previous two objects, request and response, are used to pass information from web browser to server and from server to web browser respectively. The Session Object provides the connection or association between the client and the server. The main use of Session Objects is for maintaining states when there are multiple page requests. This will be explained in further detail in following sections.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Out:&lt;/span&gt;  This denotes the Output stream in the context of page. The class or the interface name of the Out object is jsp.JspWriter. The Out object is written: Javax.servlet.jsp.JspWriter&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;PageContext:&lt;/span&gt;  This is used to access page attributes and also to access all the namespaces associated with a JSP page. The class or the interface name of the object PageContext is jsp.pageContext. The object PageContext is written: Javax.servlet.jsp.pagecontext&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Application:&lt;/span&gt;  This is used to share the data with all application pages. The class or the interface name of the Application object is ServletContext. The Application object is written: Javax.servlet.http.ServletContext&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Config:&lt;/span&gt; This is used to get information regarding the Servlet configuration, stored in the Config object. The class or the interface name of the Config object is ServletConfig. The object Config is written Javax.servlet.http.ServletConfig&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Page:&lt;/span&gt; The Page object denotes the JSP page, used for calling any instance of a Page's servlet. The class or the interface name of the Page object is jsp.HttpJspPage. The Page object is written: Java.lang.Object&lt;br /&gt;&lt;br /&gt;The most commonly used implicit objects are request, response and session objects&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7536416306579972030-6921507184970659366?l=javadevelopersden.blogspot.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=p-NwZArcqKs:tt0ZtbX52iM:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=p-NwZArcqKs:tt0ZtbX52iM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=p-NwZArcqKs:tt0ZtbX52iM:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=p-NwZArcqKs:tt0ZtbX52iM:YwkR-u9nhCs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=YwkR-u9nhCs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=p-NwZArcqKs:tt0ZtbX52iM:wF9xT3WuBAs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=p-NwZArcqKs:tt0ZtbX52iM:wF9xT3WuBAs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=p-NwZArcqKs:tt0ZtbX52iM:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=p-NwZArcqKs:tt0ZtbX52iM:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=p-NwZArcqKs:tt0ZtbX52iM:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=p-NwZArcqKs:tt0ZtbX52iM:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=p-NwZArcqKs:tt0ZtbX52iM:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=p-NwZArcqKs:tt0ZtbX52iM:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=p-NwZArcqKs:tt0ZtbX52iM:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=p-NwZArcqKs:tt0ZtbX52iM:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=p-NwZArcqKs:tt0ZtbX52iM:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/p-NwZArcqKs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://javadevelopersden.blogspot.com/feeds/6921507184970659366/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=7536416306579972030&amp;postID=6921507184970659366" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/6921507184970659366" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/6921507184970659366" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/p-NwZArcqKs/implicit-objects.html" title="Implicit Objects" /><author><name>Krishna Mohan</name><uri>http://www.blogger.com/profile/14677813920630624063</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="13118096540046841896" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by/2.0/" /><feedburner:origLink>http://javadevelopersden.blogspot.com/2007/09/implicit-objects.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-7536416306579972030.post-7003078339589101357</id><published>2007-09-01T12:18:00.000+05:30</published><updated>2007-09-01T12:22:13.927+05:30</updated><title type="text">Servlet and JSP performance tuning</title><content type="html">Improve your enterprise application's performance by tweaking your servlets and JSPs&lt;br /&gt;&lt;br /&gt;Do your J2EE applications run slow? &lt;br /&gt;Can they sustain rising traffic? This article describes performance-tuning techniques (PTT) for developing high performance and scalable JSP (JavaServer Pages) pages and servlets. &lt;br /&gt;That means building applications that are reasonably and consistently fast, and can scale up to the increasing number of users and/or requests. In this article, I walk you through the practical and proven performance-tuning techniques that will boost the performance of your servlets and JSP pages tremendously, thus improving the performance of your J2EE applications. &lt;br /&gt;Some of these techniques apply during the development phase, i.e., while you design your application and write the code. And some of these techniques are configuration-related.&lt;br /&gt;&lt;br /&gt;PTT 1: Use the HttpServlet init() method for caching data&lt;br /&gt;&lt;br /&gt;The server calls the servlet's init() method after the server constructs the servlet instance and before the servlet handles any requests. It is called only once in a servlet's lifetime. init() can be used to improve performance by caching the static data and/or completing the expensive operations that need to be performed only during initialization.&lt;br /&gt;&lt;br /&gt;For example, it is a best practice to use JDBC (Java Database Connectivity) connection pooling, which involves the use of the javax.sql.DataSource interface. DataSource is obtained from the JNDI (Java Naming and Directory Interface) tree. Performing the JNDI lookup for DataSource for every SQL call is expensive and severely affects an application's performance. Servlet's init() method should be used to acquire DataSource and cache it for later reuse:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class ControllerServlet extends HttpServlet&lt;br /&gt;{&lt;br /&gt;   private javax.sql.DataSource testDS = null;&lt;br /&gt;   public void init(ServletConfig config) throws ServletException&lt;br /&gt;   {&lt;br /&gt;      super.init(config);   &lt;br /&gt;      Context ctx  = null;&lt;br /&gt;      try&lt;br /&gt;      { &lt;br /&gt;         ctx = new InitialContext();&lt;br /&gt;         testDS = (javax.sql.DataSource)ctx.lookup("jdbc/testDS");&lt;br /&gt;      }&lt;br /&gt;      catch(NamingException ne)&lt;br /&gt;      {&lt;br /&gt;         ne.printStackTrace();              &lt;br /&gt;       }&lt;br /&gt;       catch(Exception e)&lt;br /&gt;       {&lt;br /&gt;          e.printStackTrace();&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;   public javax.sql.DataSource getTestDS()&lt;br /&gt;      {&lt;br /&gt;         return testDS;&lt;br /&gt;      }&lt;br /&gt;   ...&lt;br /&gt;   ...   &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PTT 2: Disable servlet and JSP auto-reloading&lt;br /&gt;&lt;br /&gt;Servlet/JSP auto-reloading proves useful during the development phase because it reduces development time, as you do not have to restart the server after every change in the servlet/JSP. However, it is expensive in the production phase; servlet/JSP auto-reloading gives poor performance because of unnecessary loading and burdening on the classloader. Also, it may put your application in strange conflicts when classes loaded by a certain classloader cannot cooperate with classes loaded by the current classloader. So turn off auto-reloading for servlet/JSP in a production environment to receive better performance.&lt;br /&gt;&lt;br /&gt;PTT 3: Control HttpSession&lt;br /&gt;&lt;br /&gt;Many applications require a series of client requests so they can associate with one another. Web-based applications are responsible for maintaining such state, called a session, because the HTTP protocol is stateless. To support applications that must maintain state, Java servlet technology provides an API for managing sessions and allows several mechanisms for implementing sessions. Sessions are represented by an HttpSession object, but a cost is involved while using it. An HttpSession must be read by the servlet whenever it is used and rewritten when it is updated. You can improve performance by applying the following techniques:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    *  Do not create HttpSessions in JSP pages by default: By default, JSP pages create HttpSessions. If you do not use HttpSession in your JSP pages, to save some performance overhead, use the following page directive to prevent HttpSessions from being created automatically when they are unnecessary in JSP pages:&lt;br /&gt;&lt;br /&gt;      &lt;%@ page session="false"%&gt;&lt;br /&gt;&lt;br /&gt;    * Do not store large object graphs inside an HttpSession: If you store the data in the HttpSession as one large object graph, the application server will have to process the entire HttpSession object each time. This forces Java serialization and adds computational overhead. The throughput decreases as the size of the objects stored in the HttpSession increases because of the serialization cost.&lt;br /&gt;&lt;br /&gt;    * Release HttpSessions when done: Invalidate sessions when they are no longer needed using the HttpSession.invalidate() method.&lt;br /&gt;&lt;br /&gt;    * Set session time-out value: A servlet engine has a default session time-out value set. If you do not either remove the session or use it for the time equal to the session time-out, the servlet engine will remove the session from memory. The larger the session time-out value, the more it affects scalability and performance because of overhead on memory and garbage collection. Try to keep the session time-out value as low as possible.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PTT 4: Use gzip compression&lt;br /&gt;&lt;br /&gt;Compression is the act of removing redundant information, representing what you want in as little possible space. Using gzip (GNU zip) to compress the document can dramatically reduce download times for HTML files. The smaller your information's size, the faster it can all be sent. Therefore, if you compress the content your Web application generates, it will get to a user faster and appear to display on the user's screen faster. Not every browser supports gzip compression, but you can easily check whether a browser supports it and then send gzip-compressed content to only those browsers that do.&lt;br /&gt;&lt;br /&gt;Here is the code snippet that shows how to send compressed content whenever possible:&lt;br /&gt;&lt;br /&gt;public void doGet(HttpServletRequest request, HttpServletResponse response)&lt;br /&gt;          throws IOException, ServletException &lt;br /&gt;{&lt;br /&gt;          &lt;br /&gt;   OutputStream out = null&lt;br /&gt;   // Check the Accepting-Encoding header from the HTTP request.&lt;br /&gt;   // If the header includes gzip, choose GZIP.&lt;br /&gt;   // If the header includes compress, choose ZIP.&lt;br /&gt;   // Otherwise choose no compression.&lt;br /&gt;   String encoding = request.getHeader("Accept-Encoding");    &lt;br /&gt;      &lt;br /&gt;   if (encoding != null &amp;&amp; encoding.indexOf("gzip") != -1)&lt;br /&gt;   {&lt;br /&gt;       response.setHeader("Content-Encoding" , "gzip");&lt;br /&gt;       out = new GZIPOutputStream(response.getOutputStream());&lt;br /&gt;   }&lt;br /&gt;   else if (encoding != null &amp;&amp; encoding.indexOf("compress") != -1)&lt;br /&gt;   {&lt;br /&gt;       response.setHeader("Content-Encoding" , "compress");&lt;br /&gt;       out = new ZIPOutputStream(response.getOutputStream());&lt;br /&gt;   } &lt;br /&gt;   else&lt;br /&gt;   {&lt;br /&gt;       out = response.getOutputStream();&lt;br /&gt;   }&lt;br /&gt;   ...&lt;br /&gt;   ...                        &lt;br /&gt;}  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PTT 5: Do not use SingleThreadModel&lt;br /&gt;&lt;br /&gt;SingleThreadModel ensures that servlets handle only one request at a time. If a servlet implements this interface, the servlet engine will create separate servlet instances for each new request, which will cause a great amount of system overhead. If you need to solve thread safety issues, use other means instead of implementing this interface. SingleThreadModel interface is deprecated in Servlet 2.4.&lt;br /&gt;&lt;br /&gt;PTT 6: Use thread pool&lt;br /&gt;&lt;br /&gt;A servlet engine creates a separate thread for every request, assigns that thread to the service() method, and removes that thread after service() executes. By default, the servlet engine may create a new thread for every request. This default behavior reduces performance because creating and removing threads is expensive. Performance can be improved by using the thread pool. Depending on the expected number of concurrent users, configure a thread pool by setting the values for minimum and maximum number of both threads in a pool and increments. At startup, the servlet engine creates a thread pool with number of threads in a pool equal to the minimum number of threads configured. Then the servlet engine assigns a thread from the pool to every request instead of creating a new thread every time, and returns that thread to the pool after completion. Using the thread pool, performance can drastically improve. If needed, more threads can be created based on the values for maximum number of threads and increments.&lt;br /&gt;&lt;br /&gt;PTT 7: Choose the right include mechanism&lt;br /&gt;&lt;br /&gt;There are two ways you can include files in a JSP page: include directive (&lt;%@ include file="test.jsp" %&gt;) and include action (&lt;jsp:include page="test.jsp" flush="true" /&gt;). The include directive includes the specified file's content during the translation phase; i.e., when the page converts to a servlet. The include action includes the file's content during the request processing phase; i.e., when a user requests the page. Include directive is faster than include action. So unless the included file changes often, use include directive for better performance.&lt;br /&gt;&lt;br /&gt;PTT 8: Choose the right scope in useBean action&lt;br /&gt;&lt;br /&gt;One of the most powerful ways to use JSP pages is in cooperation with a JavaBeans component. JavaBeans can be directly embedded in a JSP page using the &lt;jsp:useBean&gt; action tag. The syntax is as follows:&lt;br /&gt;&lt;br /&gt;&lt;jsp:useBean id="name" scope="page|request|session|application" class=&lt;br /&gt;  "package.className" type="typeName"&gt;&lt;br /&gt;&lt;/jsp:useBean&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The scope attribute specifies the scope of the bean's visibility. The default value for scope attribute is page. You should select the correct scope based on your application's requirements, otherwise it will affect application performance.&lt;br /&gt;&lt;br /&gt;For example, if you need an object only for a particular request, but your scope is set to session, that object will remain in memory even after you are done with the request. It will stay in memory until you explicitly remove it from memory, you invalidate the session, or the session times out as per the session time-out value configured with the servlet engine. If you do not select the right scope attribute value, it will affect the performance because of overhead on memory and garbage collection. So set the exact scope value for the objects and remove them immediately when finished with them.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Miscellaneous techniques&lt;br /&gt;&lt;br /&gt;    * Avoid string concatenation: The use of the + operator to concatenate strings results in the creation of many temporary objects because strings are immutable objects. The more you use +, the more temporary objects are created, which will adversely affect performance. Use StringBuffer instead of + when you concatenate multiple strings.&lt;br /&gt;&lt;br /&gt;    * Avoid the use of System.out.println: System.out.println synchronizes processing for the duration of disk I/O, and that can slow throughput significantly. As much as possible, avoid the use of System.out.println. Even though sophisticated debugging tools are available, sometimes System.out.println remains useful for tracing purpose, or for error and debugging situations. You should configure System.out.println so it turns on during error and debugging situations only. Do that by using a final Boolean variable, which, when configured to false, optimizes out both the check and execution of the tracing at compile time.&lt;br /&gt;&lt;br /&gt;    * ServletOutputStream versus PrintWriter: Using PrintWriter involves small overhead because it is meant for character output stream and encodes data to bytes. So PrintWriter should be used to ensure all character-set conversions are done correctly. On the other hand, use ServletOutputStream when you know that your servlet returns only binary data, thus you can eliminate the character-set conversion overhead as the servlet container does not encode the binary data.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Conclusion&lt;br /&gt;&lt;br /&gt;The goal of this article was to present you with some of the practical and proven performance-tuning techniques that will boost the performance of servlets and JSP pages tremendously, thus improving the performance of J2EE applications.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7536416306579972030-7003078339589101357?l=javadevelopersden.blogspot.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=i45txMmXAIs:QVhfikwYKW8:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=i45txMmXAIs:QVhfikwYKW8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=i45txMmXAIs:QVhfikwYKW8:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=i45txMmXAIs:QVhfikwYKW8:YwkR-u9nhCs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=YwkR-u9nhCs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=i45txMmXAIs:QVhfikwYKW8:wF9xT3WuBAs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=i45txMmXAIs:QVhfikwYKW8:wF9xT3WuBAs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=i45txMmXAIs:QVhfikwYKW8:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=i45txMmXAIs:QVhfikwYKW8:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=i45txMmXAIs:QVhfikwYKW8:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=i45txMmXAIs:QVhfikwYKW8:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=i45txMmXAIs:QVhfikwYKW8:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=i45txMmXAIs:QVhfikwYKW8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=i45txMmXAIs:QVhfikwYKW8:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=i45txMmXAIs:QVhfikwYKW8:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=i45txMmXAIs:QVhfikwYKW8:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=i45txMmXAIs:QVhfikwYKW8:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=i45txMmXAIs:QVhfikwYKW8:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/i45txMmXAIs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://javadevelopersden.blogspot.com/feeds/7003078339589101357/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=7536416306579972030&amp;postID=7003078339589101357" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/7003078339589101357" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/7003078339589101357" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/i45txMmXAIs/servlet-and-jsp-performance-tuning.html" title="Servlet and JSP performance tuning" /><author><name>Krishna Mohan</name><uri>http://www.blogger.com/profile/14677813920630624063</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="13118096540046841896" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by/2.0/" /><feedburner:origLink>http://javadevelopersden.blogspot.com/2007/09/servlet-and-jsp-performance-tuning.html</feedburner:origLink></entry><entry><title type="text">Links for 2007-08-29 [del.icio.us]</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/jPt47z3tOEQ/krishnamohan_lvkm" /><updated>2007-08-30T00:00:00-07:00</updated><id>http://del.icio.us/krishnamohan_lvkm#2007-08-29</id><content type="html">&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.java2s.com/"&gt;Complete Java&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dreamincode.net/"&gt;Programming in Web and Development Community&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/jPt47z3tOEQ" height="1" width="1"/&gt;</content><feedburner:origLink>http://del.icio.us/krishnamohan_lvkm#2007-08-29</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-7536416306579972030.post-6166363596605605947</id><published>2007-08-29T12:27:00.000+05:30</published><updated>2007-08-29T12:28:37.067+05:30</updated><title type="text">Screen Capture Using Java</title><content type="html">/**&lt;br /&gt; * Capture the screen using Java Code&lt;br /&gt; **/&lt;br /&gt;import java.awt.Rectangle;&lt;br /&gt;import java.awt.Robot;&lt;br /&gt;import java.awt.Toolkit;&lt;br /&gt;import java.awt.image.BufferedImage;&lt;br /&gt;import java.io.File;&lt;br /&gt;&lt;br /&gt;import javax.imageio.ImageIO;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class ScrnCapture {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  try{&lt;br /&gt;   //Capture the image&lt;br /&gt;   BufferedImage image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));&lt;br /&gt;   &lt;br /&gt;   // for JPG Image&lt;br /&gt;   File filejpg = new File("c:/ScrnCapture/screencapture.jpg");&lt;br /&gt;   ImageIO.write(image, "jpg", filejpg);&lt;br /&gt;   &lt;br /&gt;   // for PNG Image&lt;br /&gt;   File filepng = new File("c:/ScrnCapture/screencapture.png");&lt;br /&gt;   ImageIO.write(image, "png", filepng); &lt;br /&gt;  }&lt;br /&gt;  catch (Exception e) {&lt;br /&gt;   e.printStackTrace();&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7536416306579972030-6166363596605605947?l=javadevelopersden.blogspot.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=w8dz0wqNS7c:33nj9X6s4kE:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=w8dz0wqNS7c:33nj9X6s4kE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=w8dz0wqNS7c:33nj9X6s4kE:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=w8dz0wqNS7c:33nj9X6s4kE:YwkR-u9nhCs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=YwkR-u9nhCs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=w8dz0wqNS7c:33nj9X6s4kE:wF9xT3WuBAs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=w8dz0wqNS7c:33nj9X6s4kE:wF9xT3WuBAs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=w8dz0wqNS7c:33nj9X6s4kE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=w8dz0wqNS7c:33nj9X6s4kE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=w8dz0wqNS7c:33nj9X6s4kE:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=w8dz0wqNS7c:33nj9X6s4kE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=w8dz0wqNS7c:33nj9X6s4kE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=w8dz0wqNS7c:33nj9X6s4kE:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=w8dz0wqNS7c:33nj9X6s4kE:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=w8dz0wqNS7c:33nj9X6s4kE:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=w8dz0wqNS7c:33nj9X6s4kE:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=w8dz0wqNS7c:33nj9X6s4kE:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=w8dz0wqNS7c:33nj9X6s4kE:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/w8dz0wqNS7c" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://javadevelopersden.blogspot.com/feeds/6166363596605605947/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=7536416306579972030&amp;postID=6166363596605605947" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/6166363596605605947" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/6166363596605605947" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/w8dz0wqNS7c/screen-capture-using-java.html" title="Screen Capture Using Java" /><author><name>Krishna Mohan</name><uri>http://www.blogger.com/profile/14677813920630624063</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="13118096540046841896" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by/2.0/" /><feedburner:origLink>http://javadevelopersden.blogspot.com/2007/08/screen-capture-using-java.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-7536416306579972030.post-1019894649952190640</id><published>2007-08-29T10:32:00.000+05:30</published><updated>2007-08-29T10:33:35.728+05:30</updated><title type="text">Create an Microsoft Excel File Using Java Code</title><content type="html">/*&lt;br /&gt; * This Example Demonstrate to Create an Microsoft Excel File Using Java Code&lt;br /&gt; *&lt;br /&gt; * For this we need two JAR files poi.jar and commons-logging.jar&lt;br /&gt; * &lt;br /&gt; **/&lt;br /&gt;import java.io.FileOutputStream;&lt;br /&gt;&lt;br /&gt;import org.apache.poi.hssf.usermodel.HSSFRow;&lt;br /&gt;import org.apache.poi.hssf.usermodel.HSSFSheet;&lt;br /&gt;import org.apache.poi.hssf.usermodel.HSSFWorkbook;&lt;br /&gt;&lt;br /&gt;public class CreateExcel {&lt;br /&gt; public static void main(String[] args)  {&lt;br /&gt;  &lt;br /&gt;  try{&lt;br /&gt;   HSSFWorkbook wb = new HSSFWorkbook();&lt;br /&gt;   HSSFSheet sheet = wb.createSheet("new sheet");&lt;br /&gt;   &lt;br /&gt;   HSSFRow row = sheet.createRow((short)0);&lt;br /&gt;   row.createCell((short)0).setCellValue("HelloWorld");&lt;br /&gt;   &lt;br /&gt;   FileOutputStream fileOut = new FileOutputStream("workbook.xls");&lt;br /&gt;   wb.write(fileOut);&lt;br /&gt;   fileOut.close();&lt;br /&gt;  }&lt;br /&gt;  catch (Exception e)&lt;br /&gt;  {&lt;br /&gt;   e.printStackTrace();&lt;br /&gt;  }&lt;br /&gt; } &lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7536416306579972030-1019894649952190640?l=javadevelopersden.blogspot.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=BV7QUUJhqfY:FmSO7MCYPKc:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=BV7QUUJhqfY:FmSO7MCYPKc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=BV7QUUJhqfY:FmSO7MCYPKc:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=BV7QUUJhqfY:FmSO7MCYPKc:YwkR-u9nhCs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=YwkR-u9nhCs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=BV7QUUJhqfY:FmSO7MCYPKc:wF9xT3WuBAs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=BV7QUUJhqfY:FmSO7MCYPKc:wF9xT3WuBAs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=BV7QUUJhqfY:FmSO7MCYPKc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=BV7QUUJhqfY:FmSO7MCYPKc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=BV7QUUJhqfY:FmSO7MCYPKc:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=BV7QUUJhqfY:FmSO7MCYPKc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=BV7QUUJhqfY:FmSO7MCYPKc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=BV7QUUJhqfY:FmSO7MCYPKc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=BV7QUUJhqfY:FmSO7MCYPKc:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=BV7QUUJhqfY:FmSO7MCYPKc:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=BV7QUUJhqfY:FmSO7MCYPKc:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=BV7QUUJhqfY:FmSO7MCYPKc:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=BV7QUUJhqfY:FmSO7MCYPKc:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/BV7QUUJhqfY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://javadevelopersden.blogspot.com/feeds/1019894649952190640/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=7536416306579972030&amp;postID=1019894649952190640" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/1019894649952190640" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/1019894649952190640" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/BV7QUUJhqfY/create-microsoft-excel-file-using-java.html" title="Create an Microsoft Excel File Using Java Code" /><author><name>Krishna Mohan</name><uri>http://www.blogger.com/profile/14677813920630624063</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="13118096540046841896" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by/2.0/" /><feedburner:origLink>http://javadevelopersden.blogspot.com/2007/08/create-microsoft-excel-file-using-java.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-7536416306579972030.post-3246729048240725466</id><published>2007-08-28T18:19:00.000+05:30</published><updated>2007-08-28T18:20:18.785+05:30</updated><title type="text">Java Code to Get the MotherBoard Serial Number Dynamically</title><content type="html">import java.io.File;&lt;br /&gt;import java.io.FileWriter;&lt;br /&gt;import java.io.BufferedReader;&lt;br /&gt;import java.io.InputStreamReader;&lt;br /&gt;&lt;br /&gt;public class MiscUtils {&lt;br /&gt;  private MiscUtils() {  }&lt;br /&gt;&lt;br /&gt;  public static String getMotherboardSN() {&lt;br /&gt; String result = "";&lt;br /&gt; try {&lt;br /&gt;  File file = File.createTempFile("realhowto",".vbs");&lt;br /&gt;  file.deleteOnExit();&lt;br /&gt;  FileWriter fw = new java.io.FileWriter(file);&lt;br /&gt;&lt;br /&gt;  String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"&lt;br /&gt;    + "Set colItems = objWMIService.ExecQuery _ \n"&lt;br /&gt;    + "   (\"Select * from Win32_BaseBoard\") \n"&lt;br /&gt;    + "For Each objItem in colItems \n"&lt;br /&gt;    + "    Wscript.Echo objItem.SerialNumber \n"&lt;br /&gt;    + "    exit for  ' do the first cpu only! \n"&lt;br /&gt;    + "Next \n";&lt;br /&gt;&lt;br /&gt;  fw.write(vbs);&lt;br /&gt;  fw.close();&lt;br /&gt;&lt;br /&gt;  Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());&lt;br /&gt;  BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));&lt;br /&gt;  String line;&lt;br /&gt;  while ((line = input.readLine()) != null) {&lt;br /&gt;   result += line;&lt;br /&gt;  }&lt;br /&gt;  input.close();&lt;br /&gt; }&lt;br /&gt; catch(Exception e){&lt;br /&gt;  e.printStackTrace();&lt;br /&gt; }&lt;br /&gt; return result.trim();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public static void main(String[] args){&lt;br /&gt; String cpuId = MiscUtils.getMotherboardSN();&lt;br /&gt; javax.swing.JOptionPane.showConfirmDialog((java.awt.Component) null, cpuId, "Motherboard serial number",javax.swing.JOptionPane.DEFAULT_OPTION);&lt;br /&gt;}&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7536416306579972030-3246729048240725466?l=javadevelopersden.blogspot.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=cBZvnLs_Xh4:HRTcJc4eByU:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=cBZvnLs_Xh4:HRTcJc4eByU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=cBZvnLs_Xh4:HRTcJc4eByU:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=cBZvnLs_Xh4:HRTcJc4eByU:YwkR-u9nhCs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=YwkR-u9nhCs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=cBZvnLs_Xh4:HRTcJc4eByU:wF9xT3WuBAs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=cBZvnLs_Xh4:HRTcJc4eByU:wF9xT3WuBAs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=cBZvnLs_Xh4:HRTcJc4eByU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=cBZvnLs_Xh4:HRTcJc4eByU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=cBZvnLs_Xh4:HRTcJc4eByU:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=cBZvnLs_Xh4:HRTcJc4eByU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=cBZvnLs_Xh4:HRTcJc4eByU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=cBZvnLs_Xh4:HRTcJc4eByU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=cBZvnLs_Xh4:HRTcJc4eByU:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=cBZvnLs_Xh4:HRTcJc4eByU:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=cBZvnLs_Xh4:HRTcJc4eByU:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=cBZvnLs_Xh4:HRTcJc4eByU:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=cBZvnLs_Xh4:HRTcJc4eByU:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/cBZvnLs_Xh4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://javadevelopersden.blogspot.com/feeds/3246729048240725466/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=7536416306579972030&amp;postID=3246729048240725466" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/3246729048240725466" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/3246729048240725466" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/cBZvnLs_Xh4/java-code-to-get-motherboard-serial.html" title="Java Code to Get the MotherBoard Serial Number Dynamically" /><author><name>Krishna Mohan</name><uri>http://www.blogger.com/profile/14677813920630624063</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="13118096540046841896" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by/2.0/" /><feedburner:origLink>http://javadevelopersden.blogspot.com/2007/08/java-code-to-get-motherboard-serial.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-7536416306579972030.post-2651672908521934454</id><published>2007-08-28T10:03:00.000+05:30</published><updated>2007-08-28T10:04:19.676+05:30</updated><title type="text">Load Configuration file Using Java Code</title><content type="html">In Java, configuration file are stored in properties file. By convention, the filename extension is props or  properties.&lt;br /&gt;&lt;br /&gt;NOTE: The structure is very similar to Windows INI file with except that there is no [...] section.&lt;br /&gt;&lt;br /&gt;[Props file : user.properties]&lt;br /&gt;&lt;br /&gt;# this a comment&lt;br /&gt;! this a comment too&lt;br /&gt;db.user=anonymous&lt;br /&gt;db.password=&amp;8djsx&lt;br /&gt;db.location=bigone&lt;br /&gt;&lt;br /&gt;[JAVA code]&lt;br /&gt;&lt;br /&gt;import java.util.*;&lt;br /&gt;import java.io.*;&lt;br /&gt;&lt;br /&gt;class ReadProps {&lt;br /&gt;  public static void main(String args[]) {&lt;br /&gt;    new ReadProps().doit();&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public void doit() {&lt;br /&gt;    try{&lt;br /&gt;      Properties p = new Properties();&lt;br /&gt;      p.load(new FileInputStream("user.properties"));&lt;br /&gt;      System.out.println("user = " + p.getProperty("db.user"));&lt;br /&gt;      System.out.println("password = " + p.getProperty("db.password"));&lt;br /&gt;      System.out.println("location = " + p.getProperty("db.location"));&lt;br /&gt;      p.list(System.out);&lt;br /&gt;    }&lt;br /&gt;    catch (Exception e) {&lt;br /&gt;      System.out.println(e);&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;We manipulate the Properties through the get and put methods. The modified data can be saved back to a file with the store method. This can be useful to store user preferences for example. &lt;br /&gt;Note that the order and the comments are not preserved.&lt;br /&gt;&lt;br /&gt;import java.util.*;&lt;br /&gt;import java.io.*;&lt;br /&gt;&lt;br /&gt;class WriteProps {&lt;br /&gt;  public static void main(String args[]) {&lt;br /&gt;    new WriteProps().doit();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;  public void doit() {&lt;br /&gt;    try{&lt;br /&gt;      Properties p = new Properties();&lt;br /&gt;      p.load(new FileInputStream("user.properties"));&lt;br /&gt;      p.list(System.out);&lt;br /&gt;      // new Property&lt;br /&gt;      p.put("today", new Date().toString());&lt;br /&gt;      // modify a Property&lt;br /&gt;      p.put("db.password","foo");&lt;br /&gt;      FileOutputStream out = new FileOutputStream("user.properties");&lt;br /&gt;      p.store(out, "/* properties updated */");&lt;br /&gt;    }&lt;br /&gt;    catch (Exception e) {&lt;br /&gt;      System.out.println(e);&lt;br /&gt;    }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Note : This is ok with an application but you can't do it from an Applet since you can't write directly on the server without some kind of a server-side process.&lt;br /&gt;&lt;br /&gt;To read a Properties file via an Applet, load the Properties files this way :&lt;br /&gt;&lt;br /&gt;p.load((new URL(getCodeBase(), "user.props")).openStream());&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7536416306579972030-2651672908521934454?l=javadevelopersden.blogspot.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=imw9ccDethE:3vzFgpoDQ6g:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=imw9ccDethE:3vzFgpoDQ6g:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=imw9ccDethE:3vzFgpoDQ6g:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=imw9ccDethE:3vzFgpoDQ6g:YwkR-u9nhCs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=YwkR-u9nhCs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=imw9ccDethE:3vzFgpoDQ6g:wF9xT3WuBAs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=imw9ccDethE:3vzFgpoDQ6g:wF9xT3WuBAs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=imw9ccDethE:3vzFgpoDQ6g:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=imw9ccDethE:3vzFgpoDQ6g:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=imw9ccDethE:3vzFgpoDQ6g:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=imw9ccDethE:3vzFgpoDQ6g:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=imw9ccDethE:3vzFgpoDQ6g:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=imw9ccDethE:3vzFgpoDQ6g:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=imw9ccDethE:3vzFgpoDQ6g:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=imw9ccDethE:3vzFgpoDQ6g:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=imw9ccDethE:3vzFgpoDQ6g:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=imw9ccDethE:3vzFgpoDQ6g:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=imw9ccDethE:3vzFgpoDQ6g:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/imw9ccDethE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://javadevelopersden.blogspot.com/feeds/2651672908521934454/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=7536416306579972030&amp;postID=2651672908521934454" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/2651672908521934454" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/2651672908521934454" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/imw9ccDethE/load-configuration-file-using-java-code.html" title="Load Configuration file Using Java Code" /><author><name>Krishna Mohan</name><uri>http://www.blogger.com/profile/14677813920630624063</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="13118096540046841896" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by/2.0/" /><feedburner:origLink>http://javadevelopersden.blogspot.com/2007/08/load-configuration-file-using-java-code.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-7536416306579972030.post-2013153436975940660</id><published>2007-08-25T14:29:00.000+05:30</published><updated>2007-09-06T15:48:03.374+05:30</updated><title type="text">Sample Code to send an email with an attachment</title><content type="html">A common need across many software applications is the ability to send email messages.&lt;br /&gt;Fortunately, virtually every email sent today are sent using two popular protocols known as SMTP (Simple Mail Transfer Protocol) and MIME (Multipurpose Internet Mail Extensions).&lt;br /&gt;Using the Java based SMTP and MIME components provided in Secure iNet Factory this article will demonstrate how you can easily embed email capabilities into your own Java applications.&lt;br /&gt;&lt;br /&gt;Sample Code to send an email with an attachment&lt;br /&gt;&lt;br /&gt;import java.util.Date;&lt;br /&gt;import java.util.Properties;&lt;br /&gt;import javax.activation.DataHandler;&lt;br /&gt;import javax.activation.FileDataSource;&lt;br /&gt;import javax.mail.Message;&lt;br /&gt;import javax.mail.MessagingException;&lt;br /&gt;import javax.mail.Multipart;&lt;br /&gt;import javax.mail.Session;&lt;br /&gt;import javax.mail.Transport;&lt;br /&gt;import javax.mail.internet.InternetAddress;&lt;br /&gt;import javax.mail.internet.MimeBodyPart;&lt;br /&gt;import javax.mail.internet.MimeMessage;&lt;br /&gt;import javax.mail.internet.MimeMultipart;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class sendfile {&lt;br /&gt;public static void main(String[] args) {&lt;br /&gt; String to = "totest@yahoo.com";&lt;br /&gt; String from = "fromtest@yahoo.com";&lt;br /&gt; String host = "mail.yahoo.com";&lt;br /&gt; String filename = "c:\\mail\\mail.txt";&lt;br /&gt; boolean debug = true;&lt;br /&gt; String msgText1 = "Sending a file.\n";&lt;br /&gt; String subject = "Sending a file";&lt;br /&gt;&lt;br /&gt; // create some properties and get the default Session&lt;br /&gt; Properties props = System.getProperties();&lt;br /&gt; props.put("mail.smtp.host", host);&lt;br /&gt; Session session = Session.getInstance(props, null);&lt;br /&gt;&lt;br /&gt; session.setDebug(debug);&lt;br /&gt;&lt;br /&gt; try {&lt;br /&gt;  // create a message&lt;br /&gt;  MimeMessage msg = new MimeMessage(session);&lt;br /&gt;  msg.setFrom(new InternetAddress(from));&lt;br /&gt; &lt;br /&gt;  InternetAddress[] address = {new InternetAddress(to)};&lt;br /&gt;  msg.setRecipients(Message.RecipientType.TO, address);&lt;br /&gt;  msg.setSubject(subject);&lt;br /&gt; &lt;br /&gt;  // create and fill the first message part&lt;br /&gt;  MimeBodyPart mbp1 = new MimeBodyPart();&lt;br /&gt;  mbp1.setText(msgText1);&lt;br /&gt; &lt;br /&gt;  // create the second message part&lt;br /&gt;  MimeBodyPart mbp2 = new MimeBodyPart();&lt;br /&gt; &lt;br /&gt;  // attach the file to the message&lt;br /&gt;  FileDataSource fds = new FileDataSource(filename);&lt;br /&gt;  mbp2.setDataHandler(new DataHandler(fds));&lt;br /&gt;  mbp2.setFileName(fds.getName());&lt;br /&gt; &lt;br /&gt;  // create the Multipart and add its parts to it&lt;br /&gt; &lt;br /&gt;  Multipart mp = new MimeMultipart();&lt;br /&gt;  mp.addBodyPart(mbp1);&lt;br /&gt;  mp.addBodyPart(mbp2);&lt;br /&gt; &lt;br /&gt;  // add the Multipart to the message&lt;br /&gt;  msg.setContent(mp);&lt;br /&gt; &lt;br /&gt;  // set the Date: header&lt;br /&gt;  msg.setSentDate(new Date());&lt;br /&gt; &lt;br /&gt;  // send the message&lt;br /&gt;  Transport.send(msg);&lt;br /&gt; } catch (MessagingException mex) {&lt;br /&gt;  mex.printStackTrace();&lt;br /&gt;  Exception ex = null;&lt;br /&gt;  if ((ex = mex.getNextException()) != null) {&lt;br /&gt;   ex.printStackTrace();&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt; &lt;a href="http://tinyurl.com/2yu445"&gt;&lt;img src="http://tinyurl.com/yrmhlc" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7536416306579972030-2013153436975940660?l=javadevelopersden.blogspot.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=mCywMtTwInE:XGNtU33TfcE:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=mCywMtTwInE:XGNtU33TfcE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=mCywMtTwInE:XGNtU33TfcE:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=mCywMtTwInE:XGNtU33TfcE:YwkR-u9nhCs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=YwkR-u9nhCs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=mCywMtTwInE:XGNtU33TfcE:wF9xT3WuBAs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=mCywMtTwInE:XGNtU33TfcE:wF9xT3WuBAs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=mCywMtTwInE:XGNtU33TfcE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=mCywMtTwInE:XGNtU33TfcE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=mCywMtTwInE:XGNtU33TfcE:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=mCywMtTwInE:XGNtU33TfcE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=mCywMtTwInE:XGNtU33TfcE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=mCywMtTwInE:XGNtU33TfcE:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=mCywMtTwInE:XGNtU33TfcE:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=mCywMtTwInE:XGNtU33TfcE:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=mCywMtTwInE:XGNtU33TfcE:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=mCywMtTwInE:XGNtU33TfcE:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=mCywMtTwInE:XGNtU33TfcE:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/mCywMtTwInE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://javadevelopersden.blogspot.com/feeds/2013153436975940660/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=7536416306579972030&amp;postID=2013153436975940660" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/2013153436975940660" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/2013153436975940660" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/mCywMtTwInE/java-email-with-attachment.html" title="Sample Code to send an email with an attachment" /><author><name>Krishna Mohan</name><uri>http://www.blogger.com/profile/14677813920630624063</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="13118096540046841896" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by/2.0/" /><feedburner:origLink>http://javadevelopersden.blogspot.com/2007/08/java-email-with-attachment.html</feedburner:origLink></entry><entry><title type="text">Links for 2007-08-25 [del.icio.us]</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/G0WL-RMqdLk/krishnamohan_lvkm" /><updated>2007-08-26T00:00:00-07:00</updated><id>http://del.icio.us/krishnamohan_lvkm#2007-08-25</id><content type="html">&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.kodejava.org/"&gt;Java&lt;/a&gt;&lt;br/&gt;
Java Technology&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.joegrip.com/javagui-course.html"&gt;# Beginning Java, Java GUI Programming&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/G0WL-RMqdLk" height="1" width="1"/&gt;</content><feedburner:origLink>http://del.icio.us/krishnamohan_lvkm#2007-08-25</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-7536416306579972030.post-5086573139311123284</id><published>2007-08-24T18:44:00.000+05:30</published><updated>2007-08-24T18:54:05.119+05:30</updated><title type="text">Adding Object Persistence to Java Applications Using Serialization</title><content type="html">This article discusses and demonstrates how to incorporate object persistence into a Java application using the serialization mechanism in Java.&lt;br /&gt;&lt;br /&gt;Serialization involves saving the current state of an object to a stream, and restoring an equivalent object from that stream. The stream functions as a container for the object. Its contents include a partial representation of the object's internal structure, including variable types, names, and values. The container may be transient (RAM-based) or persistent (disk-based). A transient container may be used to prepare an object for transmission from one computer to another. A persistent container, such as a file on disk, allows storage of the object after the current session is finished. In both cases the information stored in the container can later be used to construct an equivalent object containing the same data as the original. The example code in this article will focus on persistence.&lt;br /&gt;&lt;br /&gt;Serialization allows you to save the current state of an object to a container, typically a file. &lt;br /&gt;&lt;br /&gt;At some later time, you can retrieve the saved data values and create an equivalent object. &lt;br /&gt;&lt;br /&gt;Depending on which interface you implement, you can choose to have the object and all its referenced objects saved and restored automatically, or you can specify which fields should be saved and restored. &lt;br /&gt;&lt;br /&gt;Java also provides several ways of protecting sensitive data in a serialized object, so objects loaded from a serialized representation should prove no less secure than those classes loaded at application startup. &lt;br /&gt;&lt;br /&gt;The code needed to add serialization to your application is simple and flexible.&lt;br /&gt;&lt;br /&gt;The Sample Code for Serialize and Deserialize an Object&lt;br /&gt;&lt;br /&gt;import java.io.FileInputStream;&lt;br /&gt;import java.io.FileOutputStream;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.io.ObjectInputStream;&lt;br /&gt;import java.io.ObjectOutputStream;&lt;br /&gt;import java.io.Serializable;&lt;br /&gt;import java.util.Date;&lt;br /&gt;class Employee implements Serializable&lt;br /&gt;{&lt;br /&gt; private static final long serialVersionUID = 1L;&lt;br /&gt; String fName, lName, address;&lt;br /&gt; double salary;&lt;br /&gt; java.util.Date hireDate;&lt;br /&gt;}&lt;br /&gt;public class Example4serializationNdeserialization {&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt; &lt;br /&gt;  Employee emp = new Employee();&lt;br /&gt;  emp.lName = "John";&lt;br /&gt;  emp.fName = "Smith"; &lt;br /&gt;  emp.salary = 50000;&lt;br /&gt;  emp.address = "12 main street";&lt;br /&gt;  emp.hireDate = new Date(); &lt;br /&gt;     &lt;br /&gt;     FileOutputStream fOut=null;&lt;br /&gt;     ObjectOutputStream oOut=null;&lt;br /&gt;  FileInputStream fIn = null;   &lt;br /&gt;  ObjectInputStream oIn = null;&lt;br /&gt;  &lt;br /&gt;     try{&lt;br /&gt;      fOut= new FileOutputStream("c:\\serialize\\NewEmployee.ser");&lt;br /&gt;      oOut = new ObjectOutputStream(fOut);&lt;br /&gt;      oOut.writeObject(emp); //serializing employee&lt;br /&gt;      fIn = new FileInputStream("c:\\serialize\\NewEmployee.ser");&lt;br /&gt;      oIn = new ObjectInputStream(fIn);&lt;br /&gt;      Employee emp1 = (Employee) oIn.readObject();&lt;br /&gt;      System.out.println(emp1);&lt;br /&gt;      &lt;br /&gt;      System.out.println("An employee is serialized into c:\\serialize\\NewEmployee.ser");&lt;br /&gt;     }catch(IOException e){&lt;br /&gt;      e.printStackTrace();&lt;br /&gt;     }catch (ClassNotFoundException e){&lt;br /&gt;      e.printStackTrace();&lt;br /&gt;     }&lt;br /&gt;     finally{&lt;br /&gt;      try {&lt;br /&gt;       oOut.flush();&lt;br /&gt;       oOut.close();&lt;br /&gt;       fOut.close();&lt;br /&gt;       oIn.close();&lt;br /&gt;       fIn.close();&lt;br /&gt;      } catch (IOException ioe) {&lt;br /&gt;       ioe.printStackTrace();&lt;br /&gt;      }&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7536416306579972030-5086573139311123284?l=javadevelopersden.blogspot.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=5Uxqtf7_4kA:djPf9AsF9GE:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=5Uxqtf7_4kA:djPf9AsF9GE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=5Uxqtf7_4kA:djPf9AsF9GE:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=5Uxqtf7_4kA:djPf9AsF9GE:YwkR-u9nhCs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=YwkR-u9nhCs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=5Uxqtf7_4kA:djPf9AsF9GE:wF9xT3WuBAs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=5Uxqtf7_4kA:djPf9AsF9GE:wF9xT3WuBAs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=5Uxqtf7_4kA:djPf9AsF9GE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=5Uxqtf7_4kA:djPf9AsF9GE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=5Uxqtf7_4kA:djPf9AsF9GE:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=5Uxqtf7_4kA:djPf9AsF9GE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=5Uxqtf7_4kA:djPf9AsF9GE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=5Uxqtf7_4kA:djPf9AsF9GE:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=5Uxqtf7_4kA:djPf9AsF9GE:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=5Uxqtf7_4kA:djPf9AsF9GE:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=5Uxqtf7_4kA:djPf9AsF9GE:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=5Uxqtf7_4kA:djPf9AsF9GE:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=5Uxqtf7_4kA:djPf9AsF9GE:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/5Uxqtf7_4kA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://javadevelopersden.blogspot.com/feeds/5086573139311123284/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=7536416306579972030&amp;postID=5086573139311123284" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/5086573139311123284" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/5086573139311123284" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/5Uxqtf7_4kA/adding-object-persistence-to-java.html" title="Adding Object Persistence to Java Applications Using Serialization" /><author><name>Krishna Mohan</name><uri>http://www.blogger.com/profile/14677813920630624063</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="13118096540046841896" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by/2.0/" /><feedburner:origLink>http://javadevelopersden.blogspot.com/2007/08/adding-object-persistence-to-java.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-7536416306579972030.post-8636385799391693069</id><published>2007-08-24T15:24:00.000+05:30</published><updated>2007-08-24T15:26:39.975+05:30</updated><title type="text">Java reflection is useful because it supports dynamic retrieval of information about classes</title><content type="html">Reflection is a feature in the Java programming language. It allows an executing Java program to examine or "introspect" upon itself, and manipulate internal properties of the program. &lt;br /&gt;&lt;br /&gt;For example, it's possible for a Java class to obtain the names of all its members and display them.&lt;br /&gt;&lt;br /&gt;The ability to examine and manipulate a Java class from within itself may not sound like very much, but in other programming languages this feature simply doesn't exist. &lt;br /&gt;For example, there is no way in a Pascal, C, or C++ program to obtain information about the functions defined within that program.&lt;br /&gt;&lt;br /&gt;One tangible use of reflection is in JavaBeans, where software components can be manipulated visually via a builder tool. &lt;br /&gt;The tool uses reflection to obtain the properties of Java components (classes) as they are dynamically loaded.&lt;br /&gt;&lt;br /&gt;A Simple Example&lt;br /&gt;&lt;br /&gt;To see how reflection works, consider this simple example:&lt;br /&gt;&lt;br /&gt;import java.lang.reflect.*;&lt;br /&gt;&lt;br /&gt;class ExampleClass&lt;br /&gt;{&lt;br /&gt; int a;&lt;br /&gt; void setData(int a){&lt;br /&gt;  this.a = a;&lt;br /&gt; }&lt;br /&gt; int getData(){&lt;br /&gt;  return this.a;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class ExReflection {&lt;br /&gt;   public static void main(String args[])&lt;br /&gt;   {&lt;br /&gt;    try {&lt;br /&gt;         Class c = Class.forName("ExampleClass");&lt;br /&gt;         Method m[] = c.getDeclaredMethods();&lt;br /&gt;         for (int i = 0; i &lt; m.length; i++)&lt;br /&gt;         System.out.println(m[i].toString());&lt;br /&gt;      }&lt;br /&gt;      catch (Throwable e) {&lt;br /&gt;         System.err.println(e);&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;the output is:&lt;br /&gt;&lt;br /&gt;void ExampleClass.setData(int)&lt;br /&gt;int ExampleClass.getData()&lt;br /&gt;&lt;br /&gt;This program loads the specified class using class.forName, and then calls getDeclaredMethods to retrieve the list of methods defined in the class. java.lang.reflect.Method is a class representing a single class method.&lt;br /&gt;&lt;br /&gt;Setting Up to Use Reflection&lt;br /&gt;&lt;br /&gt;The reflection classes, such as Method, are found in java.lang.reflect. There are three steps that must be followed to use these classes. The first step is to obtain a java.lang.Class object for the class that you want to manipulate. java.lang.Class is used to represent classes and interfaces in a running Java program.&lt;br /&gt;&lt;br /&gt;One way of obtaining a Class object is to say:&lt;br /&gt;&lt;br /&gt;   Class c = Class.forName("java.lang.String");&lt;br /&gt;&lt;br /&gt;to get the Class object for String. Another approach is to use:&lt;br /&gt;&lt;br /&gt;   Class c = int.class;&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;  Class c = Integer.TYPE;&lt;br /&gt;&lt;br /&gt;to obtain Class information on fundamental types. The latter approach accesses the predefined TYPE field of the wrapper (such as Integer) for the fundamental type.&lt;br /&gt;&lt;br /&gt;The second step is to call a method such as getDeclaredMethods, to get a list of all the methods declared by the class.&lt;br /&gt;&lt;br /&gt;Once this information is in hand, then the third step is to use the reflection API to manipulate the information. For example, the sequence:&lt;br /&gt;&lt;br /&gt;   Class c = Class.forName("java.lang.String");&lt;br /&gt;   Method m[] = c.getDeclaredMethods();&lt;br /&gt;   System.out.println(m[0].toString());&lt;br /&gt;&lt;br /&gt;will display a textual representation of the first method declared in String.&lt;br /&gt;&lt;br /&gt;In the examples below, the three steps are combined to present self contained illustrations of how to tackle specific applications using reflection.&lt;br /&gt;Simulating the instanceof Operator&lt;br /&gt;&lt;br /&gt;Once Class information is in hand, often the next step is to ask basic questions about the Class object. For example, the Class.isInstance method can be used to simulate the instanceof operator:&lt;br /&gt;&lt;br /&gt;   class A {}&lt;br /&gt;&lt;br /&gt;   public class instance1 {&lt;br /&gt;      public static void main(String args[])&lt;br /&gt;      {&lt;br /&gt;         try {&lt;br /&gt;            Class cls = Class.forName("A");&lt;br /&gt;            boolean b1 &lt;br /&gt;              = cls.isInstance(new Integer(37));&lt;br /&gt;            System.out.println(b1);&lt;br /&gt;            boolean b2 = cls.isInstance(new A());&lt;br /&gt;            System.out.println(b2);&lt;br /&gt;         }&lt;br /&gt;         catch (Throwable e) {&lt;br /&gt;            System.err.println(e);&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In this example, a Class object for A is created, and then class instance objects are checked to see whether they are instances of A. Integer(37) is not, but new A() is.&lt;br /&gt;Finding Out About Methods of a Class&lt;br /&gt;&lt;br /&gt;One of the most valuable and basic uses of reflection is to find out what methods are defined within a class. To do this the following code can be used:&lt;br /&gt;&lt;br /&gt;   import java.lang.reflect.*;&lt;br /&gt;&lt;br /&gt;   public class ExampleReflection {&lt;br /&gt;      private int f1(Object p, int x) throws NullPointerException  {&lt;br /&gt;         if (p == null)&lt;br /&gt;            throw new NullPointerException();&lt;br /&gt;         return x;&lt;br /&gt;      }&lt;br /&gt;        &lt;br /&gt;      public static void main(String args[]) {&lt;br /&gt;         try {&lt;br /&gt;           Class cls = Class.forName("ExampleReflection");&lt;br /&gt;           Method methlist[] = cls.getDeclaredMethods();&lt;br /&gt;           for (int i = 0; i &lt; methlist.length;i++) {  &lt;br /&gt;               Method m = methlist[i];&lt;br /&gt;               System.out.println("name = " + m.getName());&lt;br /&gt;               System.out.println("decl class = " +m.getDeclaringClass());&lt;br /&gt;               Class pvec[] = m.getParameterTypes();&lt;br /&gt;               for (int j = 0; j &lt; pvec.length; j++)&lt;br /&gt;                  System.out.println("param #" + j + " " + pvec[j]);&lt;br /&gt;               Class evec[] = m.getExceptionTypes();&lt;br /&gt;               for (int j = 0; j &lt; evec.length; j++)&lt;br /&gt;                  System.out.println("exc #" + j + " " + evec[j]);&lt;br /&gt;               System.out.println("return type = " + m.getReturnType());&lt;br /&gt;               System.out.println("-----");&lt;br /&gt;            }&lt;br /&gt;         }&lt;br /&gt;         catch (Throwable e) {&lt;br /&gt;            System.err.println(e);&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The program first gets the Class description for ExampleReflection, and then calls getDeclaredMethods to retrieve a list of Method objects, one for each method defined in the class. These include public, protected, package, and private methods. If you use getMethods in the program instead of getDeclaredMethods, you can also obtain information for inherited methods.&lt;br /&gt;&lt;br /&gt;Once a list of the Method objects has been obtained, it's simply a matter of displaying the information on parameter types, exception types, and the return type for each method. Each of these types, whether they are fundamental or class types, is in turn represented by a Class descriptor.&lt;br /&gt;The output of the program is:&lt;br /&gt;&lt;br /&gt;name = main&lt;br /&gt;decl class = class ExampleReflection&lt;br /&gt;param #0 class [Ljava.lang.String;&lt;br /&gt;return type = void&lt;br /&gt;-----&lt;br /&gt;name = f1&lt;br /&gt;decl class = class ExampleReflection&lt;br /&gt;param #0 class java.lang.Object&lt;br /&gt;param #1 int&lt;br /&gt;exc #0 class java.lang.NullPointerException&lt;br /&gt;return type = int&lt;br /&gt;-----&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Obtaining Information About Constructors&lt;br /&gt;&lt;br /&gt;A similar approach is used to find out about the constructors of a class. For example:&lt;br /&gt;&lt;br /&gt; import java.lang.reflect.*;&lt;br /&gt;        &lt;br /&gt;   public class constructor1 {&lt;br /&gt;      public constructor1()&lt;br /&gt;      {&lt;br /&gt;      }&lt;br /&gt;        &lt;br /&gt;      protected constructor1(int i, double d)&lt;br /&gt;      {&lt;br /&gt;      }&lt;br /&gt;        &lt;br /&gt;      public static void main(String args[])&lt;br /&gt;      {&lt;br /&gt;         try {&lt;br /&gt;           Class cls = Class.forName("constructor1");&lt;br /&gt;        &lt;br /&gt;           Constructor ctorlist[] = cls.getDeclaredConstructors();&lt;br /&gt;         for (int i = 0; i &lt; ctorlist.length; i++) {&lt;br /&gt;               Constructor ct = ctorlist[i];&lt;br /&gt;               System.out.println("name = " + ct.getName());&lt;br /&gt;               System.out.println("decl class = " +ct.getDeclaringClass());&lt;br /&gt;               Class pvec[] = ct.getParameterTypes();&lt;br /&gt;               for (int j = 0; j &lt; pvec.length; j++)&lt;br /&gt;                  System.out.println("param #" + j + " " + pvec[j]);&lt;br /&gt;               Class evec[] = ct.getExceptionTypes();&lt;br /&gt;               for (int j = 0; j &lt; evec.length; j++)&lt;br /&gt;                  System.out.println("exc #" + j + " " + evec[j]);&lt;br /&gt;               System.out.println("-----");&lt;br /&gt;            }&lt;br /&gt;          }&lt;br /&gt;          catch (Throwable e) {&lt;br /&gt;             System.err.println(e);&lt;br /&gt;          }&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;There is no return-type information retrieved in this example, because constructors don't really have a true return type.&lt;br /&gt;&lt;br /&gt;When this program is run, the output is:&lt;br /&gt;&lt;br /&gt;   name = constructor1&lt;br /&gt;   decl class = class constructor1&lt;br /&gt;   -----&lt;br /&gt;   name = constructor1&lt;br /&gt;   decl class = class constructor1&lt;br /&gt;   param #0 int&lt;br /&gt;   param #1 double&lt;br /&gt;   -----&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Finding Out About Class Fields&lt;br /&gt;&lt;br /&gt;It's also possible to find out which data fields are defined in a class. To do this, the following code can be used:&lt;br /&gt;&lt;br /&gt;   import java.lang.reflect.*;&lt;br /&gt;        &lt;br /&gt;   public class field1 {&lt;br /&gt;      private double d;&lt;br /&gt;      public static final int i = 37;&lt;br /&gt;      String s = "testing";&lt;br /&gt;        &lt;br /&gt;      public static void main(String args[])&lt;br /&gt;      {&lt;br /&gt;         try {&lt;br /&gt;            Class cls = Class.forName("field1");&lt;br /&gt;        &lt;br /&gt;            Field fieldlist[] = cls.getDeclaredFields();&lt;br /&gt;            for (int i=0; i &lt; fieldlist.length; i++) {&lt;br /&gt;               Field fld = fieldlist[i];&lt;br /&gt;               System.out.println("name= " + fld.getName());&lt;br /&gt;               System.out.println("decl class = " +fld.getDeclaringClass());&lt;br /&gt;               System.out.println("type= " + fld.getType());&lt;br /&gt;               int mod = fld.getModifiers();&lt;br /&gt;               System.out.println("modifiers = " +Modifier.toString(mod));&lt;br /&gt;               System.out.println("-----");&lt;br /&gt;            }&lt;br /&gt;          }&lt;br /&gt;          catch (Throwable e) {&lt;br /&gt;             System.err.println(e);&lt;br /&gt;          }&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This example is similar to the previous ones. One new feature is the use of Modifier. This is a reflection class that represents the modifiers found on a field member, for example "private int". The modifiers themselves are represented by an integer, and Modifier.toString is used to return a string representation in the "official" declaration order (such as "static" before "final"). The output of the program is:&lt;br /&gt;&lt;br /&gt;  name = d&lt;br /&gt;   decl class = class field1&lt;br /&gt;   type = double&lt;br /&gt;   modifiers = private&lt;br /&gt;   -----&lt;br /&gt;   name = i&lt;br /&gt;   decl class = class field1&lt;br /&gt;   type = int&lt;br /&gt;   modifiers = public static final&lt;br /&gt;   -----&lt;br /&gt;   name = s&lt;br /&gt;   decl class = class field1&lt;br /&gt;   type = class java.lang.String&lt;br /&gt;   modifiers =&lt;br /&gt;   ----- &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As with methods, it's possible to obtain information about just the fields declared in a class (getDeclaredFields), or to also get information about fields defined in superclasses (getFields).&lt;br /&gt;&lt;br /&gt;Invoking Methods by Name&lt;br /&gt;&lt;br /&gt;So far the examples that have been presented all relate to obtaining class information. But it's also possible to use reflection in other ways, for example to invoke a method of a specified name.&lt;br /&gt;&lt;br /&gt;To see how this works, consider the following example:&lt;br /&gt;&lt;br /&gt;   import java.lang.reflect.*;&lt;br /&gt;        &lt;br /&gt;   public class ExampleReflection {&lt;br /&gt;      public int add(int a, int b)&lt;br /&gt;      {&lt;br /&gt;         return a + b;&lt;br /&gt;      }&lt;br /&gt;        &lt;br /&gt;      public static void main(String args[])&lt;br /&gt;      {&lt;br /&gt;         try {&lt;br /&gt;           Class cls = Class.forName("ExampleReflection");&lt;br /&gt;           Class partypes[] = new Class[2];&lt;br /&gt;           partypes[0] = Integer.TYPE;&lt;br /&gt;           partypes[1] = Integer.TYPE;&lt;br /&gt;           Method meth = cls.getMethod("add", partypes);&lt;br /&gt;           ExampleReflection methobj = new ExampleReflection();&lt;br /&gt;           Object arglist[] = new Object[2];&lt;br /&gt;           arglist[0] = new Integer(37);&lt;br /&gt;           arglist[1] = new Integer(47);&lt;br /&gt;           &lt;br /&gt;           Object retobj = meth.invoke(methobj, arglist);&lt;br /&gt;           Integer retval = (Integer)retobj;&lt;br /&gt;           System.out.println(retval.intValue());&lt;br /&gt;         }&lt;br /&gt;         catch (Throwable e) {&lt;br /&gt;            System.err.println(e);&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Suppose that a program wants to invoke the add method, but doesn't know this until execution time. That is, the name of the method is specified during execution (this might be done by a JavaBeans development environment, for example). The above program shows a way of doing this.&lt;br /&gt;&lt;br /&gt;getMethod is used to find a method in the class that has two integer parameter types and that has the appropriate name. Once this method has been found and captured into a Method object, it is invoked upon an object instance of the appropriate type. To invoke a method, a parameter list must be constructed, with the fundamental integer values 37 and 47 wrapped in Integer objects. The return value (84) is also wrapped in an Integer object.&lt;br /&gt;&lt;br /&gt;Creating New Objects&lt;br /&gt;&lt;br /&gt;There is no equivalent to method invocation for constructors, because invoking a constructor is equivalent to creating a new object (to be the most precise, creating a new object involves both memory allocation and object construction). So the nearest equivalent to the previous example is to say:&lt;br /&gt;&lt;br /&gt;   import java.lang.reflect.*;&lt;br /&gt;        &lt;br /&gt;   public class constructor2 {&lt;br /&gt;      public constructor2()&lt;br /&gt;      {&lt;br /&gt;      }&lt;br /&gt;        &lt;br /&gt;      public constructor2(int a, int b)&lt;br /&gt;      {&lt;br /&gt;         System.out.println("a = " + a + " b = " + b);&lt;br /&gt;      }&lt;br /&gt;        &lt;br /&gt;      public static void main(String args[])&lt;br /&gt;      {&lt;br /&gt;         try {&lt;br /&gt;           Class cls = Class.forName("constructor2");&lt;br /&gt;           Class partypes[] = new Class[2];&lt;br /&gt;            partypes[0] = Integer.TYPE;&lt;br /&gt;            partypes[1] = Integer.TYPE;&lt;br /&gt;            Constructor ct = cls.getConstructor(partypes);&lt;br /&gt;            Object arglist[] = new Object[2];&lt;br /&gt;            arglist[0] = new Integer(37);&lt;br /&gt;            arglist[1] = new Integer(47);&lt;br /&gt;            Object retobj = ct.newInstance(arglist);&lt;br /&gt;         }&lt;br /&gt;         catch (Throwable e) {&lt;br /&gt;            System.err.println(e);&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;which finds a constructor that handles the specified parameter types and invokes it, to create a new instance of the object. The value of this approach is that it's purely dynamic, with constructor lookup and invocation at execution time, rather than at compilation time.&lt;br /&gt;Changing Values of Fields&lt;br /&gt;&lt;br /&gt;Another use of reflection is to change the values of data fields in objects. The value of this is again derived from the dynamic nature of reflection, where a field can be looked up by name in an executing program and then have its value changed. This is illustrated by the following example:&lt;br /&gt;&lt;br /&gt;   import java.lang.reflect.*;&lt;br /&gt;        &lt;br /&gt;   public class field2 {&lt;br /&gt;      public double d;&lt;br /&gt;        &lt;br /&gt;      public static void main(String args[])&lt;br /&gt;      {&lt;br /&gt;         try {&lt;br /&gt;            Class cls = Class.forName("field2");&lt;br /&gt;            Field fld = cls.getField("d");&lt;br /&gt;            field2 f2obj = new field2();&lt;br /&gt;            System.out.println("d = " + f2obj.d);&lt;br /&gt;            fld.setDouble(f2obj, 12.34);&lt;br /&gt;            System.out.println("d = " + f2obj.d);&lt;br /&gt;         }&lt;br /&gt;         catch (Throwable e) {&lt;br /&gt;            System.err.println(e);&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In this example, the d field has its value set to 12.34.&lt;br /&gt;Using Arrays&lt;br /&gt;&lt;br /&gt;One final use of reflection is in creating and manipulating arrays. Arrays in the Java language are a specialized type of class, and an array reference can be assigned to an Object reference.&lt;br /&gt;&lt;br /&gt;To see how arrays work, consider the following example:&lt;br /&gt;&lt;br /&gt;   import java.lang.reflect.*;&lt;br /&gt;        &lt;br /&gt;   public class array1 {&lt;br /&gt;      public static void main(String args[])&lt;br /&gt;      {&lt;br /&gt;         try {&lt;br /&gt;            Class cls = Class.forName("java.lang.String");&lt;br /&gt;            Object arr = Array.newInstance(cls, 10);&lt;br /&gt;            Array.set(arr, 5, "this is a test");&lt;br /&gt;            String s = (String)Array.get(arr, 5);&lt;br /&gt;            System.out.println(s);&lt;br /&gt;         }&lt;br /&gt;         catch (Throwable e) {&lt;br /&gt;            System.err.println(e);&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This example creates a 10-long array of Strings, and then sets location 5 in the array to a string value. The value is retrieved and displayed.&lt;br /&gt;&lt;br /&gt;A more complex manipulation of arrays is illustrated by the following code:&lt;br /&gt;&lt;br /&gt;   import java.lang.reflect.*;&lt;br /&gt;        &lt;br /&gt;   public class array2 {&lt;br /&gt;      public static void main(String args[])&lt;br /&gt;      {&lt;br /&gt;         int dims[] = new int[]{5, 10, 15};&lt;br /&gt;         Object arr &lt;br /&gt;           = Array.newInstance(Integer.TYPE, dims);&lt;br /&gt;        &lt;br /&gt;         Object arrobj = Array.get(arr, 3);&lt;br /&gt;         Class cls = &lt;br /&gt;           arrobj.getClass().getComponentType();&lt;br /&gt;         System.out.println(cls);&lt;br /&gt;         arrobj = Array.get(arrobj, 5);&lt;br /&gt;         Array.setInt(arrobj, 10, 37);&lt;br /&gt;        &lt;br /&gt;         int arrcast[][][] = (int[][][])arr;&lt;br /&gt;         System.out.println(arrcast[3][5][10]);&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This example creates a 5 x 10 x 15 array of ints, and then proceeds to set location [3][5][10] in the array to the value 37. Note here that a multi-dimensional array is actually an array of arrays, so that, for example, after the first Array.get, the result in arrobj is a 10 x 15 array. This is peeled back once again to obtain a 15-long array, and the 10th slot in that array is set using Array.setInt.&lt;br /&gt;&lt;br /&gt;Note that the type of array that is created is dynamic, and does not have to be known at compile time.&lt;br /&gt;&lt;br /&gt;Summary&lt;br /&gt;&lt;br /&gt;Java reflection is useful because it supports dynamic retrieval of information about classes and data structures by name, and allows for their manipulation within an executing Java program. This feature is extremely powerful and has no equivalent in other conventional languages such as C, C++, Fortran, or Pascal&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7536416306579972030-8636385799391693069?l=javadevelopersden.blogspot.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=1EQ5GT9TYtc:VBeE0kP2iPk:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=1EQ5GT9TYtc:VBeE0kP2iPk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=1EQ5GT9TYtc:VBeE0kP2iPk:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=1EQ5GT9TYtc:VBeE0kP2iPk:YwkR-u9nhCs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=YwkR-u9nhCs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=1EQ5GT9TYtc:VBeE0kP2iPk:wF9xT3WuBAs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=1EQ5GT9TYtc:VBeE0kP2iPk:wF9xT3WuBAs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=1EQ5GT9TYtc:VBeE0kP2iPk:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=1EQ5GT9TYtc:VBeE0kP2iPk:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=1EQ5GT9TYtc:VBeE0kP2iPk:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=1EQ5GT9TYtc:VBeE0kP2iPk:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=1EQ5GT9TYtc:VBeE0kP2iPk:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=1EQ5GT9TYtc:VBeE0kP2iPk:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=1EQ5GT9TYtc:VBeE0kP2iPk:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=1EQ5GT9TYtc:VBeE0kP2iPk:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=1EQ5GT9TYtc:VBeE0kP2iPk:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=1EQ5GT9TYtc:VBeE0kP2iPk:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=1EQ5GT9TYtc:VBeE0kP2iPk:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/1EQ5GT9TYtc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://javadevelopersden.blogspot.com/feeds/8636385799391693069/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=7536416306579972030&amp;postID=8636385799391693069" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/8636385799391693069" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/8636385799391693069" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/1EQ5GT9TYtc/java-reflection-is-useful-because-it.html" title="Java reflection is useful because it supports dynamic retrieval of information about classes" /><author><name>Krishna Mohan</name><uri>http://www.blogger.com/profile/14677813920630624063</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="13118096540046841896" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by/2.0/" /><feedburner:origLink>http://javadevelopersden.blogspot.com/2007/08/java-reflection-is-useful-because-it.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-7536416306579972030.post-910238491115508087</id><published>2007-08-24T14:24:00.000+05:30</published><updated>2007-08-24T14:34:08.763+05:30</updated><title type="text">Java Server Pages</title><content type="html">What is JavaServer Pages technology?&lt;br /&gt;&lt;br /&gt;    JavaServer Pages (JSP) technology provides a simplified, fast way to create web pages that display dynamically-generated content. The JSP specification, developed through an industry-wide initiative led by Sun Microsystems, defines the interaction between the server and the JSP page, and describes the format and syntax of the page. &lt;br /&gt;&lt;br /&gt;How does the JavaServer Pages technology work?&lt;br /&gt;&lt;br /&gt;    JSP pages use XML tags and scriptlets written in the Java programming language to encapsulate the logic that generates the content for the page. It passes any formatting (HTML or XML) tags directly back to the response page. In this way, JSP pages separate the page logic from its design and display.&lt;br /&gt;&lt;br /&gt;    JSP technology is part of the Java technology family. JSP pages are compiled into servlets and may call JavaBeans components (beans) or Enterprise JavaBeans components (enterprise beans) to perform processing on the server. As such, JSP technology is a key component in a highly scalable architecture for web-based applications.&lt;br /&gt;&lt;br /&gt;    JSP pages are not restricted to any specific platform or web server. The JSP specification represents a broad spectrum of industry input. &lt;br /&gt;&lt;br /&gt;What is a servlet?&lt;br /&gt;&lt;br /&gt;    A servlet is a program written in the Java programming language that runs on the server, as opposed to the browser (applets). Detailed information can be found at http://java.sun.com/products/servlet. &lt;br /&gt;&lt;br /&gt;Why do I need JSP technology if I already have servlets?&lt;br /&gt;&lt;br /&gt;    JSP pages are compiled into servlets, so theoretically you could write servlets to support your web-based applications. However, JSP technology was designed to simplify the process of creating pages by separating web presentation from web content. In many applications, the response sent to the client is a combination of template data and dynamically-generated data. In this situation, it is much easier to work with JSP pages than to do everything with servlets. &lt;br /&gt;&lt;br /&gt;Where can I get the most current version of the JSP specification?&lt;br /&gt;&lt;br /&gt;    The JavaServer Pages 2.1 specification is available for download from here. &lt;br /&gt;&lt;br /&gt;How does the JSP specification relate to the Java Enterprise Edition 5 Platform?&lt;br /&gt;&lt;br /&gt;    The JSP 2.1 specification is an important part of the Java EE 5 Platform. Using JSP and Enterprise JavaBeans technologies together is a great way to implement distributed enterprise applications with web-based front ends. &lt;br /&gt;&lt;br /&gt;Which web servers support JSP technology?&lt;br /&gt;&lt;br /&gt;    There are a number of JSP technology implementations for different web servers. The latest information on officially-announced support can be found at http://java.sun.com/products/jsp/industry.html. &lt;br /&gt;&lt;br /&gt;Is Sun providing a reference implementation for the JSP specification?&lt;br /&gt;&lt;br /&gt;    The GlassFish project is Sun's free, open-source Java EE 5 implementation.  It includes an implementation of JSP technology version 2.1.  You can download GlassFish builds from https://glassfish.dev.java.net/.  &lt;br /&gt;&lt;br /&gt;How is JSP technology different from other products?&lt;br /&gt;&lt;br /&gt;    JSP technology is the result of industry collaboration and is designed to be an open, industry-standard method supporting numerous servers, browsers and tools. JSP technology speeds development with reusable components and tags, instead of relying heavily on scripting within the page itself. All JSP implementations support a Java programming language-based scripting language, which provides inherent scalability and support for complex operations. &lt;br /&gt;&lt;br /&gt;Where do I get more information on JSP technology?&lt;br /&gt;&lt;br /&gt;    The first place to check for information on JSP technology is http://java.sun.com/products/jsp/. This site includes numerous resources, as well as pointers to mailing lists and discussion groups for JSP technology-related topics. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Technical FAQ&lt;br /&gt;&lt;br /&gt;What is a JSP page?&lt;br /&gt;&lt;br /&gt;    A JSP page is a page created by the web developer that includes JSP technology-specific and custom tags, in combination with other static (HTML or XML) tags. A JSP page has the extension .jsp or .jspx; this signals to the web server that the JSP engine will process elements on this page. Using the web.xml deployment descriptor, additional extensions can be associated with the JSP engine.&lt;br /&gt;&lt;br /&gt;    The exact format of a JSP page is described in the JSP specification.. &lt;br /&gt;&lt;br /&gt;How do JSP pages work?&lt;br /&gt;&lt;br /&gt;    A JSP engine interprets tags, and generates the content required - for example, by calling a bean, accessing a database with the JDBC API or including a file. It then sends the results back in the form of an HTML (or XML) page to the browser. The logic that generates the content is encapsulated in tags and beans processed on the server. &lt;br /&gt;&lt;br /&gt;Does JSP technology require the use of other Java platform APIs?&lt;br /&gt;&lt;br /&gt;    JSP pages are typically compiled into Java platform servlet classes. As a result, JSP pages require a Java virtual machine that supports the Java platform servlet specification. &lt;br /&gt;&lt;br /&gt;How is a JSP page invoked and compiled?&lt;br /&gt;&lt;br /&gt;    Pages built using JSP technology are typically implemented using a translation phase that is performed once, the first time the page is called. The page is compiled into a Java Servlet class and remains in server memory, so subsequent calls to the page have very fast response times. &lt;br /&gt;&lt;br /&gt;What is the syntax for JavaServer Pages technology?&lt;br /&gt;&lt;br /&gt;    The syntax card and reference can be viewed or downloaded from our website. &lt;br /&gt;&lt;br /&gt;Can I create XML pages using JSP technology?&lt;br /&gt;&lt;br /&gt;    Yes, the JSP specification does support creation of XML documents. For simple XML generation, the XML tags may be included as static template portions of the JSP page. Dynamic generation of XML tags occurs through bean components or custom tags that generate XML output. See the white paper Developing XML Solutions with JavaServer Pages Technology (PDF) for details. &lt;br /&gt;&lt;br /&gt;Can I generate and manipulate JSP pages using XML tools?&lt;br /&gt;&lt;br /&gt;    The JSP 2.0 specification describes a mapping between JSP pages and XML documents. The mapping enables the creation and manipulation of JSP pages using XML tools. &lt;br /&gt;&lt;br /&gt;How do I use JavaBeans components (beans) from a JSP page?&lt;br /&gt;&lt;br /&gt;    The JSP specification includes standard tags for bean use and manipulation. The useBean tag creates an instance of a specific JavaBeans class. If the instance already exists, it is retrieved. Otherwise, it is created. The setProperty and getProperty tags let you manipulate properties of the given object. These tags are described in more detail in the JSP specification and tutorial.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7536416306579972030-910238491115508087?l=javadevelopersden.blogspot.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=gZWQMitH1iQ:m7XtOowgUTQ:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=gZWQMitH1iQ:m7XtOowgUTQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=gZWQMitH1iQ:m7XtOowgUTQ:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=gZWQMitH1iQ:m7XtOowgUTQ:YwkR-u9nhCs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=YwkR-u9nhCs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=gZWQMitH1iQ:m7XtOowgUTQ:wF9xT3WuBAs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=gZWQMitH1iQ:m7XtOowgUTQ:wF9xT3WuBAs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=gZWQMitH1iQ:m7XtOowgUTQ:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=gZWQMitH1iQ:m7XtOowgUTQ:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=gZWQMitH1iQ:m7XtOowgUTQ:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=gZWQMitH1iQ:m7XtOowgUTQ:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=gZWQMitH1iQ:m7XtOowgUTQ:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=gZWQMitH1iQ:m7XtOowgUTQ:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=gZWQMitH1iQ:m7XtOowgUTQ:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=gZWQMitH1iQ:m7XtOowgUTQ:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=gZWQMitH1iQ:m7XtOowgUTQ:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=gZWQMitH1iQ:m7XtOowgUTQ:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=gZWQMitH1iQ:m7XtOowgUTQ:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/gZWQMitH1iQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://javadevelopersden.blogspot.com/feeds/910238491115508087/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=7536416306579972030&amp;postID=910238491115508087" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/910238491115508087" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/910238491115508087" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/gZWQMitH1iQ/java-server-pages.html" title="Java Server Pages" /><author><name>Krishna Mohan</name><uri>http://www.blogger.com/profile/14677813920630624063</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="13118096540046841896" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by/2.0/" /><feedburner:origLink>http://javadevelopersden.blogspot.com/2007/08/java-server-pages.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-7536416306579972030.post-8214466791295005095</id><published>2007-08-24T12:05:00.000+05:30</published><updated>2007-08-24T12:58:25.592+05:30</updated><title type="text">Servlets in Java</title><content type="html">&lt;b&gt;Java Servlet&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The Java Servlet API allows a software developer to add dynamic content to a Web server using the Java platform. The generated content is commonly HTML, but may be other data such as XML. Servlets are the Java counterpart to non-Java dynamic Web content technologies such as PHP, CGI and ASP.NET. Servlets can maintain state across many server transactions by using HTTP cookies, session variables or URL rewriting.&lt;br /&gt;&lt;p&gt;The Servlet API, contained in the Java package hierarchy javax.servlet, defines the expected interactions of a Web container and a servlet. A Web container is essentially the component of a Web server that interacts with the servlets. The Web container is responsible for managing the lifecycle of servlets, mapping a URL to a particular servlet and ensuring that the URL requester has the correct access rights.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;A Servlet is an object that receives a request and generates a response based on that request. The basic servlet package defines Java objects to represent servlet requests and responses, as well as objects to reflect the servlet's configuration parameters and execution environment. The package javax.servlet.http defines HTTP-specific subclasses of the generic servlet elements, including session management objects that track multiple requests and responses between the Web server and a client. Servlets may be packaged in a WAR file as a Web application.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Servlets can be generated automatically by JavaServer Pages (JSP), or alternately by template engines such as WebMacro. Often servlets are used in conjunction with JSPs in a pattern called "Model 2", which is a flavor of the model-view-controller pattern.&lt;br /&gt;&lt;/p&gt;&lt;b&gt;History&lt;/b&gt;&lt;br /&gt;&lt;p&gt;The original servlet specification was created by Sun Microsystems (version 1.0 was finalized in June 1997). Starting with version 2.3, the servlet specification was developed under the Java Community Process. JSR 53 defined both the Servlet 2.3 and JavaServer Page 1.2 specifications. JSR 154 specifies the Servlet 2.4 and 2.5 specifications. As of May 10, 2006, the current version of the servlet specification is 2.5.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;b&gt;Life Cycle of a Servlet&lt;/b&gt;&lt;br /&gt;&lt;p&gt;The Servlet life cycle consists of the following steps:&lt;/p&gt;1. The Servlet class is loaded by the container during start-up.&lt;br /&gt;2. The container calls the init() method. This method initializes the servlet and must be called before the servlet can service any requests. In the entire life of a servlet, the init() method is called only once.&lt;br /&gt;3. After initialization, the servlet can service client-requests. Each request is serviced in its own separate thread. The container calls the service() method of the servlet for every request. The service() method determines the kind of request being made and dispatches it to an appropriate method to handle the request. The developer of the servlet must provide an implementation for these methods. If a request for a method that is not implemented by the servlet is made, the method of the parent class is called, typically resulting in an error being returned to the requester.&lt;br /&gt;4. Finally, the container calls the destroy() method which takes the servlet out of service. The destroy() method like init() is called only once in the life-cycle of a Servlet.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;ServletConfig and ServletContext&lt;/b&gt;&lt;br /&gt;&lt;p&gt;There is only one ServletContext in every application. This object can be used by all the servlets to obtain application level information or container details. Every servlet, on the other hand, gets its own ServletConfig object. This object provides initialization parameters for a servlet. A developer can obtain the reference to ServletContext using either the ServletConfig object or ServletRequest object.&lt;br /&gt;&lt;/p&gt;&lt;b&gt;Servlet Containers&lt;/b&gt;&lt;br /&gt;&lt;p&gt;A Servlet container is a specialized web server that supports Servlet execution. It combines the basic functionality of a web server with certain Java/Servlet specific optimizations and extensions – such as an integrated Java runtime environment, and the ability to automatically translate specific URLs into Servlet requests. Individual Servlets are registered with a Servlet container, providing the container with information about what functionality they provide, and what URL or other resource locator they will use to identify themselves. The Servlet container is then able to initialize the Servlet as necessary and deliver requests to the Servlet as they arrive. Many containers have the ability to dynamically add and remove Servlets from the system, allowing new Servlets to quickly be deployed or removed without affecting other Servlets running from the same container. Servlet containers are also referred to as web containers or web engines.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Like the other Java APIs, different vendors provide their own implementation of the Servlet container standard. Below is a list of some of the free and commercial web containers. (Note that 'free' means that non-commercial use is free. Some of the commercial containers, e.g. Resin and Orion, are free to use in a server environment for non-profit organizations).&lt;br /&gt;&lt;/p&gt;&lt;b&gt;Non-commercial web containers&lt;/b&gt;&lt;br /&gt;&lt;p&gt;    * Apache Tomcat (formerly Jakarta Tomcat) is an open source web container available free of charge under the Apache Software License. It is used in the official reference implementation and has a reputation for being stable.[citation needed]&lt;br /&gt; * Geronimo Application Server is a full J2EE implementation by Apache.&lt;br /&gt; * Jetty&lt;br /&gt; * Jaminid contains a higher abstraction than servlets.&lt;br /&gt; * Enhydra&lt;br /&gt; * jo!&lt;br /&gt; * Winstone supports specification v2.4, has a focus on minimal configuration and the ability to strip the container down to only what you need.&lt;br /&gt; * tjws spec 2.4, small footprint, modular design&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;b&gt;Commercial web containers&lt;/b&gt;&lt;br /&gt;&lt;p&gt;   * Java System Application Server&lt;br /&gt; * Java System Web Server&lt;br /&gt; * Caucho's Resin Server&lt;br /&gt; * BEA WebLogic Server or Weblogic Express&lt;br /&gt; * Borland Enterprise Server&lt;br /&gt; * Oracle Application Server&lt;br /&gt; * IBM's WebSphere&lt;br /&gt; * Macromedia JRun&lt;br /&gt; * IronFlare Orion Application Server&lt;br /&gt; * WebObjects&lt;br /&gt;&lt;/p&gt;&lt;b&gt;Commercial open source web containers&lt;/b&gt;&lt;br /&gt;&lt;p&gt;    * JBoss&lt;br /&gt;* GlassFish&lt;br /&gt;* LiteWebServer&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7536416306579972030-8214466791295005095?l=javadevelopersden.blogspot.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=G42x_rKUmSk:TKCSAAG891w:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=G42x_rKUmSk:TKCSAAG891w:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=G42x_rKUmSk:TKCSAAG891w:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=G42x_rKUmSk:TKCSAAG891w:YwkR-u9nhCs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=YwkR-u9nhCs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=G42x_rKUmSk:TKCSAAG891w:wF9xT3WuBAs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=G42x_rKUmSk:TKCSAAG891w:wF9xT3WuBAs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=G42x_rKUmSk:TKCSAAG891w:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=G42x_rKUmSk:TKCSAAG891w:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=G42x_rKUmSk:TKCSAAG891w:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=G42x_rKUmSk:TKCSAAG891w:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=G42x_rKUmSk:TKCSAAG891w:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=G42x_rKUmSk:TKCSAAG891w:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=G42x_rKUmSk:TKCSAAG891w:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?a=G42x_rKUmSk:TKCSAAG891w:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/NewEraInJavaTechnology?i=G42x_rKUmSk:TKCSAAG891w:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/NewEraInJavaTechnology/~4/G42x_rKUmSk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://javadevelopersden.blogspot.com/feeds/8214466791295005095/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=7536416306579972030&amp;postID=8214466791295005095" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/8214466791295005095" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7536416306579972030/posts/default/8214466791295005095" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/NewEraInJavaTechnology/~3/G42x_rKUmSk/servlets-in-java.html" title="Servlets in Java" /><author><name>Krishna Mohan</name><uri>http://www.blogger.com/profile/14677813920630624063</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="13118096540046841896" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by/2.0/" /><feedburner:origLink>http://javadevelopersden.blogspot.com/2007/08/servlets-in-java.html</feedburner:origLink></entry></feed>
