<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4161616116436247579</id><updated>2024-11-06T08:18:41.291+05:30</updated><category term="How to solve java puzzles?"/><category term="Wildcard To Regex in Java is useful in building Like operatror in java"/><category term="Call by value and call by reference in java"/><category term="Calling Url using java servlet; good example to track URL using servlet"/><category term="Hibernate Architecture"/><category term="How locking system works in Hibernate"/><category term="How to Serializing and Deserializing Objects"/><category term="How to read Excel file in Java with jxl.jar?"/><category term="How to sort HashMap or Map in java"/><category term="How to write java secure code?"/><category term="Image Cropping in java; Image crop in java"/><category term="Inner Join"/><category term="Java Features; What for java is?; What are the features are there in java;"/><category term="Java is strictly Call-by-value"/><category term="Linkedin"/><category term="Linkedin for java"/><category term="Linkedin4j"/><category term="OuterJoin and Cross Joins in Sql server"/><category term="Sample Example for Force authentication mail using java"/><category term="Solution for Java puzzles(1)."/><category term="Solution for Java puzzles(4)."/><category term="Spring  ACEGI Filters"/><category term="Sql server pagination query"/><category term="Velocity example with conditions and loops"/><category term="Why is Hibernate better than JDBC"/><category term="finally"/><category term="java"/><category term="java cloning"/><category term="spring example to load ApplicationContext file on startup"/><category term="twitter"/><category term="twitter api integration"/><category term="twitter4j"/><category term="very good one to loading Spring applicationContext file"/><title type='text'>Developers Blog</title><subtitle type='html'>Let us share our views in java. Not only java, we can also share examples and configurations on Spring, Hibernate, javascript, CSS and Sqlserver queries. This blog will help you in giving the complete information and resolving your complete java related problems like the problems in core java, servlets, jsp spring, hibernate. And also the web technologies which includes all css related problems(Web 2.0).and java script and the latest smart jquery java script frame work</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://javanullpointer.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>28</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-4827638233358251667</id><published>2014-01-20T22:57:00.003+05:30</published><updated>2014-01-20T22:57:53.423+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="twitter"/><category scheme="http://www.blogger.com/atom/ns#" term="twitter api integration"/><category scheme="http://www.blogger.com/atom/ns#" term="twitter4j"/><title type='text'>Twitter OAuth API Integration</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&amp;nbsp;you can download jar from www.twitter4j.org and then follow bellow Steps&lt;br /&gt;
1. first register your &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD3&quot;&gt;application in&lt;/span&gt; twitter.com, there you will get &lt;b&gt;consumerKey &lt;/b&gt;and &lt;b&gt;consumerSecret&lt;/b&gt;&lt;br /&gt;
2. then include the above jar in your classpath,&lt;br /&gt;
&lt;b&gt;3. &lt;/b&gt;write the following servlet to get authenticate by the user.&lt;/h3&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
package com.servlet;&lt;br /&gt;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;&lt;br /&gt;import javax.servlet.ServletException;&lt;br /&gt;import javax.servlet.annotation.WebServlet;&lt;br /&gt;import javax.servlet.http.HttpServlet;&lt;br /&gt;import javax.servlet.http.HttpServletRequest;&lt;br /&gt;import javax.servlet.http.HttpServletResponse;&lt;br /&gt;import javax.servlet.http.HttpSession;&lt;br /&gt;&lt;br /&gt;import twitter4j.Twitter;&lt;br /&gt;import twitter4j.TwitterException;&lt;br /&gt;import twitter4j.TwitterFactory;&lt;br /&gt;import twitter4j.auth.AccessToken;&lt;br /&gt;import twitter4j.auth.RequestToken;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;@WebServlet(&quot;/twitter&quot;)&lt;br /&gt;public class TwitterLogin&amp;nbsp; extends HttpServlet {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Override&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected void doGet(HttpServletRequest req, HttpServletResponse resp)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; throws ServletException, IOException {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String CALLBACKURL = &quot;http://localhost:8080/connect/twitter&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; HttpSession session = req.getSession(true);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if(req.getParameter(&quot;oauth_verifier&quot;)== null){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Twitter twitter = new TwitterFactory().getInstance();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; twitter.setOAuthConsumer(&quot;ConsumerKey&quot;, &quot;ConsumerSecret&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RequestToken requestToken = twitter.getOAuthRequestToken(CALLBACKURL);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // String authUrl = requestToken.getAuthorizationURL();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; session.setAttribute(&quot;twitter&quot;, twitter);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; session.setAttribute(&quot;requestToken&quot;, requestToken);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; resp.sendRedirect(requestToken.getAuthorizationURL());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }else{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; AccessToken accessToken = null;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Twitter twitter = (Twitter)session.getAttribute(&quot;twitter&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; RequestToken requestToken = (RequestToken)session.getAttribute(&quot;requestToken&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; accessToken = twitter.getOAuthAccessToken(requestToken, req.getParameter(&quot;oauth_verifier&quot;));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(&quot;Got request token.&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(&quot;accessToken : &quot; + accessToken.getToken());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(&quot;accessToken&amp;nbsp; secret: &quot; + accessToken.getTokenSecret());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(&quot;screenname:&quot; + accessToken.getScreenName());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } catch (TwitterException te) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; te.printStackTrace();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } catch (IOException ioe) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ioe.printStackTrace();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;}&lt;/h4&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javanullpointer.blogspot.com/feeds/4827638233358251667/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javanullpointer.blogspot.com/2014/01/twitter-oauth-api-integration.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/4827638233358251667'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/4827638233358251667'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2014/01/twitter-oauth-api-integration.html' title='Twitter OAuth API Integration'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-6592031069620904720</id><published>2014-01-18T12:27:00.002+05:30</published><updated>2014-01-20T22:48:13.876+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linkedin"/><category scheme="http://www.blogger.com/atom/ns#" term="Linkedin for java"/><category scheme="http://www.blogger.com/atom/ns#" term="Linkedin4j"/><title type='text'>Linkedin OAuth API Integration In Java with Example </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
you can download linked4j.jar file from http://code.google.com/p/linkedin-j/ and then follow bellow code:&lt;br /&gt;
steps: &lt;br /&gt;
1. first register your application in linkedin.com, there you will get &lt;b&gt;consumerKey &lt;/b&gt;and &lt;b&gt;consumerSecret&lt;/b&gt;&lt;br /&gt;
2. then include the above jar in your classpath,&lt;br /&gt;
&lt;b&gt;3. &lt;/b&gt;write the following servlet to get authenticate by the user.&lt;br /&gt;
&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.util.EnumSet;&lt;br /&gt;
&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.http.HttpServlet;&lt;br /&gt;
import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
import javax.servlet.http.HttpSession;&lt;br /&gt;
&lt;br /&gt;
import com.cs.liveebiz.server.common.ui.ImportLinkedInProfile;&lt;br /&gt;
import com.cs.liveebiz.server.common.util.UserContextHolder;&lt;br /&gt;
import com.google.code.linkedinapi.client.LinkedInApiClient;&lt;br /&gt;
import com.google.code.linkedinapi.client.LinkedInApiClientFactory;&lt;br /&gt;
import com.google.code.linkedinapi.client.enumeration.ProfileField;&lt;br /&gt;
import com.google.code.linkedinapi.client.oauth.LinkedInAccessToken;&lt;br /&gt;
import com.google.code.linkedinapi.client.oauth.LinkedInOAuthService;&lt;br /&gt;
import com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceFactory;&lt;br /&gt;
import com.google.code.linkedinapi.client.oauth.LinkedInRequestToken;&lt;br /&gt;
import com.google.code.linkedinapi.schema.Education;&lt;br /&gt;
import com.google.code.linkedinapi.schema.Person;&lt;br /&gt;
import com.google.code.linkedinapi.schema.Position;&lt;br /&gt;
&lt;br /&gt;
@SuppressWarnings(&quot;serial&quot;)&lt;br /&gt;
public class LogonServlet extends HttpServlet {&lt;br /&gt;
private static final String AUTH_TOKEN_PARAMETER = &quot;oauth_token&quot;;&lt;br /&gt;
private static final String AUTH_TOKEN_VERIFIER_PARAMETER = &quot;oauth_verifier&quot;;&lt;br /&gt;
/**&lt;br /&gt;
* Consumer Key you can get this from linked in by adding your application at  (https://www.linkedin.com/secure/developer)&lt;br /&gt;
*/&lt;br /&gt;
private static final String CONSUMER_KEY_OPTION = &quot;consumerKey&quot;;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
* Consumer Secret you can get this from linked in by adding your application&lt;br /&gt;
*/&lt;br /&gt;
private static final String CONSUMER_SECRET_OPTION = &quot;consumerSecret&quot;;&lt;br /&gt;
&lt;br /&gt;
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { &lt;br /&gt;
try {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;              String oauthToken = req.getParameter(AUTH_TOKEN_PARAMETER);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                    String oauthVerifier = req.getParameter(AUTH_TOKEN_VERIFIER_PARAMETER);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                    final String consumerKeyValue = CONSUMER_KEY_OPTION;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                 final String consumerSecretValue = CONSUMER_SECRET_OPTION;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;           HttpSession session = req.getSession();&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;           final LinkedInOAuthService oauthService = 
LinkedInOAuthServiceFactory.getInstance().createLinkedInOAuthService(consumerKeyValue,
 consumerSecretValue);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #990000;&quot;&gt;          if &lt;/span&gt;(oauthToken == null &amp;amp;&amp;amp; oauthVerifier == null ) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;           LinkedInRequestToken requestToken = oauthService.getOAuthRequestToken(&quot;same servlet reqpath&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;           System.out.println(&quot;Fetching request token from LinkedIn...&quot;&lt;br /&gt;
+ requestToken);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                           session.setAttribute(&quot;requestToken&quot;, requestToken);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                           String authUrl = requestToken.getAuthorizationUrl();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                           resp.sendRedirect(authUrl);&lt;br /&gt;
} &lt;span style=&quot;color: #990000;&quot;&gt;else &lt;/span&gt;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                             String sVerifier = req.getParameter(&quot;oauth_verifier&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                             LinkedInRequestToken requestToken = (LinkedInRequestToken) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;           &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;           &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;           session.getAttribute(&quot;requestToken&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                             LinkedInAccessToken accessToken = oauthService.getOAuthAccessToken(requestToken,sVerifier);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                             System.out.println(&quot;Access token: &quot; + accessToken.getToken());&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                             System.out.println(&quot;Token secret: &quot; + accessToken.getTokenSecret());&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;           final LinkedInApiClientFactory factory = 
LinkedInApiClientFactory.newInstance(consumerKeyValue, 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;           &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;           consumerSecretValue);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                         final LinkedInApiClient client = factory.createLinkedInApiClient(accessToken);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                         System.out.println(&quot;Fetching profile for current user.&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                         Person profile = client.getProfileForCurrentUser(EnumSet.of(ProfileField.ID));&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                    Person profile2 = client.getProfileById(profile.getId());&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                      printResult(profile2);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;           resp.sendRedirect(&quot;page to which you want to redirect after processing the result&quot;);&lt;br /&gt;
&amp;nbsp;            
      }&lt;br /&gt;
} &lt;span style=&quot;color: #990000;&quot;&gt;catch &lt;/span&gt;(Throwable ex) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;   ex.printStackTrace();&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javanullpointer.blogspot.com/feeds/6592031069620904720/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javanullpointer.blogspot.com/2014/01/linkedin-oauth-api-integration-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/6592031069620904720'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/6592031069620904720'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2014/01/linkedin-oauth-api-integration-in-java.html' title='Linkedin OAuth API Integration In Java with Example '/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-6282393029632976423</id><published>2014-01-18T12:01:00.002+05:30</published><updated>2014-01-18T12:04:42.931+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="finally"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><title type='text'>What is the use of the finally block?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:WordDocument&gt;
  &lt;w:View&gt;Normal&lt;/w:View&gt;
  &lt;w:Zoom&gt;0&lt;/w:Zoom&gt;
  &lt;w:TrackMoves/&gt;
  &lt;w:TrackFormatting/&gt;
  &lt;w:PunctuationKerning/&gt;
  &lt;w:ValidateAgainstSchemas/&gt;
  &lt;w:SaveIfXMLInvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;
  &lt;w:IgnoreMixedContent&gt;false&lt;/w:IgnoreMixedContent&gt;
  &lt;w:AlwaysShowPlaceholderText&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;
  &lt;w:DoNotPromoteQF/&gt;
  &lt;w:LidThemeOther&gt;EN-US&lt;/w:LidThemeOther&gt;
  &lt;w:LidThemeAsian&gt;X-NONE&lt;/w:LidThemeAsian&gt;
  &lt;w:LidThemeComplexScript&gt;X-NONE&lt;/w:LidThemeComplexScript&gt;
  &lt;w:Compatibility&gt;
   &lt;w:BreakWrappedTables/&gt;
   &lt;w:SnapToGridInCell/&gt;
   &lt;w:WrapTextWithPunct/&gt;
   &lt;w:UseAsianBreakRules/&gt;
   &lt;w:DontGrowAutofit/&gt;
   &lt;w:SplitPgBreakAndParaMark/&gt;
   &lt;w:DontVertAlignCellWithSp/&gt;
   &lt;w:DontBreakConstrainedForcedTables/&gt;
   &lt;w:DontVertAlignInTxbx/&gt;
   &lt;w:Word11KerningPairs/&gt;
   &lt;w:CachedColBalance/&gt;
  &lt;/w:Compatibility&gt;
  &lt;w:BrowserLevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;
  &lt;m:mathPr&gt;
   &lt;m:mathFont m:val=&quot;Cambria Math&quot;/&gt;
   &lt;m:brkBin m:val=&quot;before&quot;/&gt;
   &lt;m:brkBinSub m:val=&quot;--&quot;/&gt;
   &lt;m:smallFrac m:val=&quot;off&quot;/&gt;
   &lt;m:dispDef/&gt;
   &lt;m:lMargin m:val=&quot;0&quot;/&gt;
   &lt;m:rMargin m:val=&quot;0&quot;/&gt;
   &lt;m:defJc m:val=&quot;centerGroup&quot;/&gt;
   &lt;m:wrapIndent m:val=&quot;1440&quot;/&gt;
   &lt;m:intLim m:val=&quot;subSup&quot;/&gt;
   &lt;m:naryLim m:val=&quot;undOvr&quot;/&gt;
  &lt;/m:mathPr&gt;&lt;/w:WordDocument&gt;
&lt;/xml&gt;&lt;![endif]--&gt;&lt;br /&gt;
&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:LatentStyles DefLockedState=&quot;false&quot; DefUnhideWhenUsed=&quot;true&quot;
  DefSemiHidden=&quot;true&quot; DefQFormat=&quot;false&quot; DefPriority=&quot;99&quot;
  LatentStyleCount=&quot;267&quot;&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;0&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Normal&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;9&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;heading 1&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;9&quot; QFormat=&quot;true&quot; Name=&quot;heading 2&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;9&quot; QFormat=&quot;true&quot; Name=&quot;heading 3&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;9&quot; QFormat=&quot;true&quot; Name=&quot;heading 4&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;9&quot; QFormat=&quot;true&quot; Name=&quot;heading 5&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;9&quot; QFormat=&quot;true&quot; Name=&quot;heading 6&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;9&quot; QFormat=&quot;true&quot; Name=&quot;heading 7&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;9&quot; QFormat=&quot;true&quot; Name=&quot;heading 8&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;9&quot; QFormat=&quot;true&quot; Name=&quot;heading 9&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; Name=&quot;toc 1&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; Name=&quot;toc 2&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; Name=&quot;toc 3&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; Name=&quot;toc 4&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; Name=&quot;toc 5&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; Name=&quot;toc 6&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; Name=&quot;toc 7&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; Name=&quot;toc 8&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; Name=&quot;toc 9&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;35&quot; QFormat=&quot;true&quot; Name=&quot;caption&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;10&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Title&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;1&quot; Name=&quot;Default Paragraph Font&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;11&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Subtitle&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;22&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Strong&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;20&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Emphasis&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;59&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Table Grid&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; UnhideWhenUsed=&quot;false&quot; Name=&quot;Placeholder Text&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;1&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;No Spacing&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;60&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Shading&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;61&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light List&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;62&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Grid&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;63&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 1&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;64&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 2&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;65&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 1&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;66&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 2&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;67&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 1&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;68&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 2&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;69&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 3&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;70&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Dark List&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;71&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Shading&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;72&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful List&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;73&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Grid&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;60&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Shading Accent 1&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;61&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light List Accent 1&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;62&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Grid Accent 1&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;63&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 1 Accent 1&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;64&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 2 Accent 1&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;65&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 1 Accent 1&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; UnhideWhenUsed=&quot;false&quot; Name=&quot;Revision&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;34&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;List Paragraph&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;29&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Quote&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;30&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Intense Quote&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;66&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 2 Accent 1&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;67&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 1 Accent 1&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;68&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 2 Accent 1&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;69&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 3 Accent 1&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;70&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Dark List Accent 1&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;71&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Shading Accent 1&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;72&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful List Accent 1&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;73&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Grid Accent 1&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;60&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Shading Accent 2&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;61&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light List Accent 2&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;62&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Grid Accent 2&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;63&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 1 Accent 2&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;64&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 2 Accent 2&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;65&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 1 Accent 2&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;66&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 2 Accent 2&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;67&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 1 Accent 2&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;68&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 2 Accent 2&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;69&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 3 Accent 2&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;70&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Dark List Accent 2&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;71&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Shading Accent 2&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;72&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful List Accent 2&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;73&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Grid Accent 2&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;60&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Shading Accent 3&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;61&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light List Accent 3&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;62&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Grid Accent 3&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;63&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 1 Accent 3&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;64&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 2 Accent 3&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;65&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 1 Accent 3&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;66&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 2 Accent 3&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;67&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 1 Accent 3&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;68&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 2 Accent 3&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;69&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 3 Accent 3&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;70&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Dark List Accent 3&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;71&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Shading Accent 3&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;72&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful List Accent 3&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;73&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Grid Accent 3&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;60&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Shading Accent 4&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;61&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light List Accent 4&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;62&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Grid Accent 4&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;63&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 1 Accent 4&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;64&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 2 Accent 4&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;65&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 1 Accent 4&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;66&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 2 Accent 4&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;67&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 1 Accent 4&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;68&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 2 Accent 4&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;69&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 3 Accent 4&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;70&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Dark List Accent 4&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;71&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Shading Accent 4&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;72&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful List Accent 4&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;73&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Grid Accent 4&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;60&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Shading Accent 5&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;61&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light List Accent 5&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;62&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Grid Accent 5&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;63&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 1 Accent 5&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;64&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 2 Accent 5&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;65&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 1 Accent 5&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;66&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 2 Accent 5&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;67&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 1 Accent 5&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;68&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 2 Accent 5&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;69&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 3 Accent 5&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;70&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Dark List Accent 5&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;71&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Shading Accent 5&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;72&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful List Accent 5&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;73&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Grid Accent 5&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;60&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Shading Accent 6&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;61&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light List Accent 6&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;62&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Light Grid Accent 6&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;63&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 1 Accent 6&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;64&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Shading 2 Accent 6&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;65&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 1 Accent 6&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;66&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium List 2 Accent 6&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;67&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 1 Accent 6&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;68&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 2 Accent 6&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;69&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Medium Grid 3 Accent 6&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;70&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Dark List Accent 6&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;71&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Shading Accent 6&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;72&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful List Accent 6&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;73&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; Name=&quot;Colorful Grid Accent 6&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;19&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Subtle Emphasis&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;21&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Intense Emphasis&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;31&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Subtle Reference&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;32&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Intense Reference&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;33&quot; SemiHidden=&quot;false&quot;
   UnhideWhenUsed=&quot;false&quot; QFormat=&quot;true&quot; Name=&quot;Book Title&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;37&quot; Name=&quot;Bibliography&quot;/&gt;
  &lt;w:LsdException Locked=&quot;false&quot; Priority=&quot;39&quot; QFormat=&quot;true&quot; Name=&quot;TOC Heading&quot;/&gt;
 &lt;/w:LatentStyles&gt;
&lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 10]&gt;
&lt;style&gt;
 /* Style Definitions */
 table.MsoNormalTable
 {mso-style-name:&quot;Table Normal&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 mso-style-noshow:yes;
 mso-style-priority:99;
 mso-style-qformat:yes;
 mso-style-parent:&quot;&quot;;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:11.0pt;
 font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;
 mso-ascii-font-family:Calibri;
 mso-ascii-theme-font:minor-latin;
 mso-fareast-font-family:&quot;Times New Roman&quot;;
 mso-fareast-theme-font:minor-fareast;
 mso-hansi-font-family:Calibri;
 mso-hansi-theme-font:minor-latin;
 mso-bidi-font-family:&quot;Times New Roman&quot;;
 mso-bidi-theme-font:minor-bidi;}
&lt;/style&gt;
&lt;![endif]--&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-US;&quot;&gt;Finally is the block of code that executes always. The code in finally
block will execute even if an exception is occurred.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-US;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;finally &lt;/span&gt;will not execute
when the user calls System.exit().&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-US;&quot;&gt;Example:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-US;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;try&lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #6aa84f;&quot;&gt;statements1;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-US;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-US;&quot;&gt;}&lt;span style=&quot;color: #990000;&quot;&gt;catch&lt;/span&gt;(Exception e){&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #6aa84f;&quot;&gt; statements2;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-US;&quot;&gt;}&lt;span style=&quot;color: #990000;&quot;&gt;finally&lt;/span&gt;{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-US;&quot;&gt;&amp;nbsp; // &amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #6aa84f;&quot;&gt;statements3;&lt;/span&gt; code will execute weather exception is occurred or not.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-US;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javanullpointer.blogspot.com/feeds/6282393029632976423/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javanullpointer.blogspot.com/2014/01/what-is-use-of-finally-block.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/6282393029632976423'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/6282393029632976423'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2014/01/what-is-use-of-finally-block.html' title='What is the use of the finally block?'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-5031950915310815644</id><published>2010-02-21T12:49:00.002+05:30</published><updated>2010-02-21T12:56:41.471+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java cloning"/><title type='text'>Shallow cloning Vs Deep cloning</title><content type='html'>&lt;meta content=&quot;text/html; charset=utf-8&quot; http-equiv=&quot;Content-Type&quot;&gt;&lt;/meta&gt;&lt;meta content=&quot;Word.Document&quot; name=&quot;ProgId&quot;&gt;&lt;/meta&gt;&lt;meta content=&quot;Microsoft Word 11&quot; name=&quot;Generator&quot;&gt;&lt;/meta&gt;&lt;meta content=&quot;Microsoft Word 11&quot; name=&quot;Originator&quot;&gt;&lt;/meta&gt;&lt;link href=&quot;file:///F:%5CDOCUME%7E1%5Creddy%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml&quot; rel=&quot;File-List&quot;&gt;&lt;/link&gt;&lt;style&gt;
&lt;!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:&quot;&quot;;
	margin:0in;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:&quot;Times New Roman&quot;;
	mso-fareast-font-family:&quot;Times New Roman&quot;;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;
	mso-header-margin:.5in;
	mso-footer-margin:.5in;
	mso-paper-source:0;}
div.Section1
	{page:Section1;}
--&gt;
&lt;/style&gt;  &lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;text-indent: 0.5in;&quot;&gt;The default behavior of an objects clone() method automatically yields a shallow copy. So to achieve a deep copy the classes mush be edited or adusted.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;Shallow copy:&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If a shallow copy is performed on obj-1 as shown in fig-2. then its copied but its contained objects are not. The contained objects obj-1 and obj-2 are affected by changes to cloned obj-2. java supports shallow cloning of objects by default when a class implements the java.lang.Cloneable&amp;nbsp; interface.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;Deep copy:&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If a deep copy is performed on obj-1 as shown in fig-3 then not only obj-1 has been copied but the objects contained within it have been copied as well. Serialization can be used to achieved deep cloning. Deep cloning through serialization is faster to develop and easier to maintain but carries a performance overhead.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3flMqzQsUqRdw8QZOvEm796zAEhuRp3DMiwK4RI_MT2XPGkP9hPtIDAVStdVr0pJ5yl3_y4nxBRnifbaPfhuTPjFVUfpXybd65Rw4gaxuTXQbZTZtMbNvDvRQeOB8UZy6cKiK4FcRopGx/s1600-h/clonong.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;132&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3flMqzQsUqRdw8QZOvEm796zAEhuRp3DMiwK4RI_MT2XPGkP9hPtIDAVStdVr0pJ5yl3_y4nxBRnifbaPfhuTPjFVUfpXybd65Rw4gaxuTXQbZTZtMbNvDvRQeOB8UZy6cKiK4FcRopGx/s400/clonong.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;Ex:&lt;/b&gt; invoking clone() method on a collection like HashMap, List etc returns a shallow copy of HashMap, List instances. This means if you clone a HashMap, the map instance is cloned but the keys and values themselves are not cloned. If you want a deep copy then a simple method is to serialize the HashMap to a ByteArrayOutputStream and then deserialize it. This creates a deep copy but does require that all kes and values in the hashMap are Serializable. Main advantage of this is that is will deep copy any arbitrary values graph. Alternatively you can provide a static factory method to deep copy.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javanullpointer.blogspot.com/feeds/5031950915310815644/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javanullpointer.blogspot.com/2010/02/shallow-cloning-vs-deep-cloning.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/5031950915310815644'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/5031950915310815644'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2010/02/shallow-cloning-vs-deep-cloning.html' title='Shallow cloning Vs Deep cloning'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3flMqzQsUqRdw8QZOvEm796zAEhuRp3DMiwK4RI_MT2XPGkP9hPtIDAVStdVr0pJ5yl3_y4nxBRnifbaPfhuTPjFVUfpXybd65Rw4gaxuTXQbZTZtMbNvDvRQeOB8UZy6cKiK4FcRopGx/s72-c/clonong.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-7746045235047837310</id><published>2009-12-20T16:25:00.007+05:30</published><updated>2010-01-21T17:18:00.342+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="How to write java secure code?"/><title type='text'>Twelve rules for developing more secure Java code</title><content type='html'>&lt;div style=&quot;color: #666666;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;i&gt;Writing security-conscious Java code can help you avoid security surprises&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;color: #666666;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;i&gt;By&amp;nbsp;Gary Mcgraw&amp;nbsp;and&amp;nbsp;Edward Felten,&amp;nbsp;JavaWorld.com,&amp;nbsp;12/01/98&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;b&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;i&gt;&lt;a href=&quot;http://www.ziddu.com/download/7819669/Twelverules.pdf.html&quot;&gt;download&lt;/a&gt; PDF format of this article &lt;/i&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;color: #666666;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-bottom: 0.17in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;This article introduces 12 rules for writing security-critical Java code; 12 rules that all Java developers should abide by. If you are charged with managing a gaggle of Java developers, or if your business relies on the security of Java, make sure your developers follow these rules.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;These rules haven&#39;t been sugar-coated for mass consumption. They get fairly technical and require broad knowledge of Java to understand. Though experienced Java developers will understand all the rules that follow, less experienced Java developers may have a bit of homework to do. Nevertheless, following these rules will make your Java code more secure. &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;We base these rules on the experience of many people who have generously discussed their experience in building secure Java code.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;In creating these 12 rules, we&#39;ve drawn from much experience in hunting down Java security bugs, and on advice and observations from people who write and review security-critical Java code for a living. Each rule is designed to eliminate an unexpected &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;i&gt;gotcha&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt; that you might face. &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Of course, security is an elusive goal. Following these rules certainly won&#39;t provide any guarantee that your code is completely secure. It is easy to write insecure code that follows these rules. By following these goals, however, you will minimize or eliminate certain kinds of security attacks that you might not have thought of. &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Think of these rules as a first step. If you are writing code that may be linked or run in conjunction with untrusted code, then you should definitely consider following these rules. &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Every attempt has been made to keep the rules simple enough that you can treat them as a checklist to be followed in mechanical fashion. That way you can save your brainpower for other security issues. &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;  &lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Rule 1: Don&#39;t depend on initialization&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Most Java developers think there is no way to allocate an object without running a constructor. But this isn&#39;t true: there are several ways to allocate non-initialized objects. &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;The easy way to protect yourself against this problem is to write your classes so that before any object does anything, it verifies that it has been initialized. You can do this as follows:&lt;iframe align=&quot;left&quot; frameborder=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;http://rcm.amazon.com/e/cm?t=knowle03-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0596001576&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr&quot; style=&quot;height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;&quot;&gt;&lt;/iframe&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;ul&gt;&lt;li&gt; &lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0.17in; margin-top: 0.19in; text-align: left;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;Make  all variables private. If you want to allow outside code to access  variables in an object, this should be done via get and set methods.  (This keeps outside code from accessing noninitialized variables.)  If you&#39;re following Rule 3, you&#39;ll make the get and set methods  final.&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;li style=&quot;text-align: left;&quot;&gt; &lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;Add  a new private boolean variable, initialized, to each object.&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style=&quot;text-align: left;&quot;&gt;  &lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0.17in; margin-top: 0.19in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;Have  each constructor set the initialized variable as its last action  before returning.&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;li style=&quot;text-align: left;&quot;&gt;   &lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0.17in; margin-top: 0.19in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;Have  each nonconstructor method verify that initialized is true before  doing anything. (Note that you may have to make exceptions to this  rule for methods called by your constructors. If you do this, it&#39;s  best to make the constructors call only private methods.)&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;li style=&quot;text-align: left;&quot;&gt;   &lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0.17in; margin-top: 0.19in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;If  your class has a static initializer, you will need to do the same  thing at the class level. Specifically, for any class that has a  static initializer, follow these steps:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;li style=&quot;text-align: left;&quot;&gt;   &lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0.17in; margin-top: 0.19in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;Make  all static variables private. If you want to allow outside code to  access static variables in the class, this should be done via static  get and set methods. This keeps outside code from accessing  noninitialized static variables. If you&#39;re following Rule 3, you&#39;ll  make the get and set methods final.&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;li style=&quot;text-align: left;&quot;&gt; &lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0.17in; margin-top: 0.19in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;Add  a new private static boolean variable, classInitialized, to the  class.&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;li style=&quot;text-align: left;&quot;&gt;   &lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0.17in; margin-top: 0.19in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;Have  the static constructor set the initialized variable as its last  action before returning.&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 100%; margin-bottom: 0.17in; margin-top: 0.19in; text-align: left;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;Before  doing anything, have each static method and each constructor verify  that classInitialized is true. (Note: constructors are required to  call a constructor of the superclass, or another constructor of the  same class, as their first action. So you will have to do that  before you check classInitialized.)&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;line-height: 0.19in; margin-bottom: 0.17in;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;b&gt;Rule 2: Limit access to your classes, methods, and variables&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Every class, method, and variable that is not private provides a potential entry point for an attacker. By default, everything should be private. Make something nonprivate only with good reason, and document that reason.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;b&gt;Rule 3: Make everything final (unless there&#39;s a good reason not to)&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-bottom: 0.17in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;If a class or method isn&#39;t final, an attacker could try to extend it in a dangerous and unforeseen way. By default, everything should be final. Make something nonfinal only if there is a good reason, and document that reason. &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;You might think you can prevent an attacker from extending your class or its methods by declaring the class nonpublic. But if a class isn&#39;t public, it must be accessible from within the same package, and as Rule 4 (below) says, you shouldn&#39;t to rely on package scope access restrictions for security. &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;This advice may seem harsh. After all, the rule is asking you to give up extensibility, which is one of the main benefits of using an object-oriented language like Java. But when you&#39;re trying to provide security, extensibility is your enemy: it just provides an attacker with more ways to cause trouble.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;b&gt;Rule 4: Don&#39;t depend on package scope&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Classes, methods, and variables that aren&#39;t explicitly labeled as public, private, or protected are accessible within the same package. Don&#39;t rely on this for security. Java classes aren&#39;t closed, so an attacker could introduce a new class into your package and use this new class to access the things you thought you were hiding. (A few packages, such as &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;java.lang&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;, are closed by default, and a few Java virtual machines (JVMs) let you close your own packages. But you&#39;re better off assuming packages aren&#39;t closed.) &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Package scope makes a lot of sense from a software-engineering standpoint, since it prevents innocent, accidental access to things you want to hide. But don&#39;t depend on it for security. &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Maybe we&#39;ll get sealed classes in the future.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;b&gt;Rule 5: Don&#39;t use inner classes&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Some Java language books say inner classes can be accessed only by the outer classes that enclose them. But this isn&#39;t true. Java bytecode has no concept of inner classes, so inner classes are translated by the compiler into ordinary classes that happen to be accessible to any code in the same package. And Rule 4 says not to depend on package scope for protection.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;But wait, it gets worse. An inner class gets access to the fields of the enclosing outer class, even if the these fields are declared private. And the inner class is translated into a separate class. To let this separate class access the fields of the outer class, the compiler silently changes these fields from private to package scope! It&#39;s bad enough that the inner class is exposed; but it&#39;s even worse that the compiler is silently overruling your decision to make some fields private. Don&#39;t use inner classes if you can help it. (Ironically, the new JDK 1.2 PrivilegedAction API requires you to use an inner class to write privileged code. For more details, see our book &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;i&gt;Securing Java&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt; and the &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;i&gt;developer.com&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt; article referenced below.) That&#39;s one reason we don&#39;t like the PrivilegedAction API.)&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;b&gt;Rule 6: Avoid signing your code&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Code that isn&#39;t signed will run without any special privileges. And code with no special privileges is much less likely to do damage. &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Of course, some of your code might have to acquire and use privileges to perform some dangerous operation. Work hard to minimize the amount of privileged code, and audit the privileged code more carefully than the rest.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;b&gt;Rule 7: If you must sign your code, put it all in one archive file&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;By following this rule, you will help prevent an attacker from carrying out a mix-and-match attack, in which the attacker constructs a new applet or library that links some of your signed classes together with malicious classes, or links together signed classes that you never meant to be used together. By signing a group of classes together, you make such attacks more difficult. Existing code-signing systems do an inadequate job of preventing mix-and-match attacks, so this rule cannot prevent such attacks completely. But using a single archive can&#39;t hurt. &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Some code-signing systems let you examine other classes to see who signed them. If you&#39;re using a code-signing system that allows this, you can put code into the static constructors of your classes to verify that the &quot;surrounding&quot; classes have been signed by the expected person. &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;This measure doesn&#39;t completely prevent mix-and-match attacks, since an adversary can still mix together classes you signed at different times -- for example, by mixing version 1 of Class A with version 2 of Class B. If you&#39;re worried about this kind of inter-version mix-and-match attack, you can put each class&#39;s &quot;version stamp&quot; in a public final variable, and then have each class check the version stamps of its surrounding classes.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;b&gt;Rule 8: Make your classes noncloneable&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Java&#39;s object cloning mechanism can allow an attacker to manufacture new instances of classes you define, without executing any of your constructors. If your class isn&#39;t cloneable, the attacker can define a subclass of your class, and make the subclass implement &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;java.lang.Cloneable&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;. This lets an attacker create new instances of your class. The new instances are made by copying the memory images of existing objects; though this is sometimes an acceptable way to make a new object, it often is not.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Rather than worry about this, you&#39;re better off making your objects noncloneable. You can do this by defining the following method in each of your classes:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;public final void clone() throws java.lang.CloneNotSupportedException {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;        &lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;throw new java.lang.CloneNotSupportedException();&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;If you want your class to be cloneable, and you&#39;ve considered the &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;consequences of that choice, then you can still protect yourself. If you&#39;re &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;defining a clone method yourself, make it final. If you&#39;re relying on a &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;nonfinal clone method in one of your superclasses, then define this &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;method:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;public final void clone() throws java.lang.CloneNotSupportedException {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;        &lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;super.clone();&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;This prevents an attacker from redefining your clone method.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-bottom: 0.17in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;b&gt;Rule 9: Make your classes nonserializeable&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Serialization is dangerous because it allows adversaries to get their hands on the internal state of your objects. An adversary can serialize one of your objects into a byte array that can be read. This allows the adversary to inspect the full internal state of your object, including any fields you marked private, and including the internal state of any objects you reference. &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;To prevent this, you can make your object impossible to serialize. To achieve this goal, declare the &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;writeObject&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt; method:&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;private final void writeObject(ObjectOutputStream out)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;throws java.io.IOException {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;        &lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;throw new java.io.IOException(&quot;Object cannot be serialized&quot;);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.21in; margin-bottom: 0.1in; margin-top: 0.1in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;This method is declared final so that a subclass defined by the adversary cannot override it.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;h3 class=&quot;western&quot; style=&quot;line-height: 0.21in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Rule 10: Make your classes nondeserializeable&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div style=&quot;line-height: 0.21in; margin-bottom: 0.1in; margin-top: 0.1in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;This rule is even more important than the previous one. Even if your class isn&#39;t serializeable, it may still be deserializeable. An adversary can create a sequence of bytes that happens to deserialize to an instance of your class. This is dangerous, since you do not have control over what state the deserialized object is in. You can think of deserialization as another kind of public constructor for your object; unfortunately it&#39;s a kind of constructor that is difficult for you to control. &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;You can prevent this kind of attack by making it impossible to deserialize a byte stream into an instance of your class. You can do this by declaring the &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Courier New,monospace; font-size: small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;readObject&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt; method: &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;private final void readObject(ObjectInputStream in)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;throws java.io.IOException {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;        &lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;throw new java.io.IOException(&quot;Class cannot be deserialized&quot;);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.21in; margin-bottom: 0.17in;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.21in; margin-bottom: 0.1in; margin-top: 0.1in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;As above, this method is declared final to prevent the adversary from overriding it.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;h3 class=&quot;western&quot; style=&quot;line-height: 0.21in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Rule 11: Don&#39;t compare classes by name&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div style=&quot;line-height: 0.21in; margin-bottom: 0.1in; margin-top: 0.1in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Sometimes you want to compare the classes of two objects to see whether they are the same; or you want to see whether an object has a particular class. When you do this, be aware that there can be multiple classes with the same name in a JVM. It is a mistake to compare classes by name since different classes can have the same name. A better method is to compare class objects for equality directly. For example, given two objects, A and B, if you want to see whether they are the same class, use this code: &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;if(a.getClass() == b.getClass()){&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;        &lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;// objects have the same class&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;}else{&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;        &lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;// objects have different classes&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;You should also be on the lookout for cases of less direct by-name &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;comparisons. Suppose, for example, you want to see whether an object &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;has the class &quot;Foo.&quot; Here is the wrong way to do it:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;if(obj.getClass().getName().equals(&quot;Foo&quot;))   // Wrong!&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;        &lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;// objects class is named Foo&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;}else{&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;        &lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;// object&#39;s class has some other name&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;Here&#39;s a better way to do it:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;if(obj.getClass() == this.getClassLoader().loadClass(&quot;Foo&quot;)){&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;        &lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;// object&#39;s class is equal to the class that this class calls &quot;Foo&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;}else{&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;        &lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;// object&#39;s class is not equal to the class that &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;   &lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;// this class calls &quot;Foo&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier New,monospace;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(241, 242, 243) none repeat scroll 0% 0%; line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.21in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Do note the legalistic comments in the last example. Whenever you use class names, you open yourself up to mix-and-match attacks, as described in Rule 7. You should also know that the Java language forces you to use class names all the time: in variable declarations, &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Courier New,monospace; font-size: small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;instanceof&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt; expressions, and exception-catching blocks. Only the designers of Java can prevent mix-and-match attacks, but you can avoid making the problem worse by avoiding by-name class comparisons.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;a href=&quot;http://www.amazon.com/Core-Security-Patterns-Strategies-Management/dp/0131463071?ie=UTF8&amp;amp;tag=knowle03-20&amp;amp;link_code=btl&amp;amp;camp=213689&amp;amp;creative=392969&quot; target=&quot;_blank&quot;&gt;Core Security Patterns: Best Practices and Strategies for J2EE(TM), Web Services, and Identity Management&lt;/a&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://www.assoc-amazon.com/e/ir?t=knowle03-20&amp;amp;l=btl&amp;amp;camp=213689&amp;amp;creative=392969&amp;amp;o=1&amp;amp;a=0131463071&quot; style=&quot;border: medium none ! important; margin: 0px ! important;&quot; width=&quot;1&quot; /&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;b&gt;Rule 12: Secrets stored in your code won&#39;t protect you&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;You might be tempted to store secrets such as cryptographic keys in the code for your application or library. Secrets stored in this way are completely accessible to anybody who runs your code. There is nothing to stop a malicious programmer or virtual machine from looking inside your code and learning its secrets. &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Code obfuscation is another way of storing a secret in your code; in the case of obfuscation the secret is simply the algorithm used by your code. There&#39;s not much harm in using an obfuscator, but you shouldn&#39;t believe it will provide strong protection. There is no real evidence that it is possible to obfuscate Java source code or bytecode so that a dedicated adversary with good tools cannot reverse the obfuscation. &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; margin-top: 0.09in;&quot;&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Arial,sans-serif;&quot;&gt;Writing secure Java code is very difficult. There is no magic bullet that will solve your security problems; all you can do is think hard (perhaps with help from formal analysis tools) and use prudent engineering practices to minimize risks. Sometimes a pair of objective outside eyes can help. The rules set forth here are intended to describe prudent engineering practices for writing secure Java code. They won&#39;t solve your security problems, but they will reduce the number of ways things can go wrong. &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javanullpointer.blogspot.com/feeds/7746045235047837310/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javanullpointer.blogspot.com/2009/12/twelve-rules-for-developing-more-secure.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/7746045235047837310'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/7746045235047837310'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2009/12/twelve-rules-for-developing-more-secure.html' title='Twelve rules for developing more secure Java code'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-9167580320409039138</id><published>2009-10-07T20:28:00.002+05:30</published><updated>2009-10-17T09:04:24.299+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java Features; What for java is?; What are the features are there in java;"/><title type='text'>Features of Java</title><content type='html'>&lt;span xmlns=&quot;&quot;&gt;&lt;p&gt;&lt;span style=&quot;;font-family:Times New Roman;font-size:12pt;&quot;  &gt;&lt;strong&gt;Platform Independent&lt;br /&gt;&lt;/strong&gt;The concept of Write-once-run-anywhere (known as the Platform independent) is one of the important key feature of java language that makes java as the most powerful language. Not even a single language is idle to this feature but java is more closer to this feature. The programs written on one platform can run on any platform provided the platform must have the JVM.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:Times New Roman;&quot;&gt;&lt;span style=&quot;font-size:12pt;&quot;&gt;&lt;strong&gt;Simple&lt;br /&gt;&lt;/strong&gt;There are various features that makes the java as a simple language. Programs are easy to write and debug because java does not use the pointers explicitly. It is much harder to write the &lt;/span&gt;java&lt;span style=&quot;text-decoration: underline;&quot;&gt; programs&lt;/span&gt;&lt;span style=&quot;font-size:12pt;&quot;&gt; that can crash the system but we can not say about the other &lt;/span&gt;programming languages&lt;span style=&quot;font-size:12pt;&quot;&gt;. Java provides the bug free system due to the strong memory management. It also has the automatic memory allocation and deallocation system.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;;font-family:Times New Roman;font-size:12pt;&quot;  &gt;&lt;strong&gt;Object Oriented&lt;br /&gt;&lt;/strong&gt;To be an Object Oriented language, any language must follow at least the four characteristics.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style=&quot;;font-family:Times New Roman;font-size:12pt;&quot;  &gt;Inheritance           :       It is the process of creating the new classes and using the behavior of the existing classes by extending them just to                                    reuse  the existing code and adding the additional features as needed.&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;;font-family:Times New Roman;font-size:12pt;&quot;  &gt;Encapsulation:      :       It is the mechanism of combining the information and providing the abstraction.&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;;font-family:Times New Roman;font-size:12pt;&quot;  &gt;Polymorphism:     :       As the name suggest one name multiple form, Polymorphism is the way of providing the different functionality by the    &lt;br /&gt;                                   functions  having the same name based on the signatures of the methods.&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;;font-family:Times New Roman;font-size:12pt;&quot;  &gt;Dynamic binding  :       Sometimes we don&#39;t have the knowledge of objects about their specific types while writing our code. It is the way                                   of providing the maximum functionality to a program about the specific type at runtime.       &lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style=&quot;;font-family:Times New Roman;font-size:12pt;&quot;  &gt;As the languages like Objective C, C++ fulfills the above four characteristics yet they  are not fully object oriented languages because they are structured as well as object oriented languages. But in case of java,  it is a fully Object Oriented language because object is at the outer most level of data structure in java. No stand alone methods, constants, and variables are there in java. Everything in java is object even the primitive data types can also be converted into object by using the wrapper class.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;;font-family:Times New Roman;font-size:12pt;&quot;  &gt;&lt;strong&gt;Robust&lt;br /&gt;&lt;/strong&gt;Java has the strong memory allocation and automatic garbage collection mechanism. It provides the powerful exception handling and type checking mechanism as compare to other programming languages. Compiler checks the program whether there any error and interpreter checks any run time error and makes the system secure from crash. All of the above features makes the java language robust.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:Times New Roman;&quot;&gt;&lt;span style=&quot;font-size:12pt;&quot;&gt;&lt;strong&gt;Distributed&lt;br /&gt;&lt;/strong&gt;The widely used protocols like HTTP and FTP are developed in java. Internet &lt;/span&gt;programmers&lt;span style=&quot;font-size:12pt;&quot;&gt; can call functions on these protocols and can get access the files from any remote machine on the internet rather than writing codes on their local system.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;;font-family:Times New Roman;font-size:12pt;&quot;  &gt;&lt;strong&gt;Portable&lt;br /&gt;&lt;/strong&gt;The feature Write-once-run-anywhere  makes the java language portable provided that the system must have interpreter for the JVM. Java also have the standard data size irrespective of operating system or the processor. These features makes the java as a portable language.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;;font-family:Times New Roman;font-size:12pt;&quot;  &gt;&lt;strong&gt;Dynamic&lt;br /&gt;&lt;/strong&gt;While executing the java program the user can get the required files dynamically from a local drive or from a computer thousands of miles away from the user just by connecting with the Internet.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;;font-family:Times New Roman;font-size:12pt;&quot;  &gt;&lt;strong&gt;Secure&lt;br /&gt;&lt;/strong&gt;Java does not use memory pointers explicitly. All the programs in java are run under an area known as the sand box. Security manager determines the accessibility options of a class like reading and writing a file to the local disk. Java uses the public key encryption system to allow the java applications to transmit over the internet in the secure encrypted form. The bytecode Verifier checks the classes after loading.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;;font-family:Times New Roman;font-size:12pt;&quot;  &gt;&lt;strong&gt;Performance&lt;br /&gt;&lt;/strong&gt;Java uses native code usage, and lightweight process called  threads. In the beginning interpretation of bytecode resulted the performance slow but the advance version of JVM uses the adaptive and just in time compilation technique that improves the performance.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:Times New Roman;&quot;&gt;&lt;span style=&quot;font-size:12pt;&quot;&gt;&lt;strong&gt;Multithreaded&lt;/strong&gt;&lt;br /&gt;As we all know several features of Java like Secure, Robust, Portable, dynamic etc; you will be more delighted to know another feature of Java which is &lt;strong&gt;Multithreaded.&lt;br /&gt;&lt;/strong&gt;Java is also a Multithreaded programming language. Multithreading means a single program having different threads executing independently at the same time. Multiple threads execute instructions according to the program code in a process or a program. Multithreading works the similar way as multiple processes run on one computer. &lt;br /&gt;Multithreading &lt;/span&gt;programming&lt;span style=&quot;font-size:12pt;&quot;&gt; is a very interesting concept in Java. In multithreaded programs not even a single thread disturbs the execution of other thread. Threads are obtained from the pool of available ready to run threads and they run on the system CPUs. This is how Multithreading works in Java which you will soon come to know in details in later chapters.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;;font-family:Times New Roman;font-size:12pt;&quot;  &gt;&lt;strong&gt;Interpreted&lt;br /&gt;&lt;/strong&gt;We all know that Java is an interpreted language as well. With an interpreted language such as Java, programs run directly from the source code.&lt;br /&gt;The interpreter program reads the source code and translates it on the fly into computations. Thus, Java as an interpreted language depends on an interpreter program.&lt;br /&gt;The versatility of being &lt;strong&gt;platform independent &lt;/strong&gt;makes Java to outshine from other languages. The source code to be written and distributed is platform independent. &lt;br /&gt;Another advantage of Java as an interpreted language is its error debugging quality. Due to this any error occurring in the program gets traced. This is how it is different to work with Java.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:Times New Roman;&quot;&gt;&lt;span style=&quot;font-size:12pt;&quot;&gt;&lt;strong&gt;Architecture Neutral&lt;br /&gt;&lt;/strong&gt;The term architectural neutral seems to be weird, but yes Java is an architectural neutral language as well. The growing popularity of &lt;/span&gt;networks&lt;span style=&quot;font-size:12pt;&quot;&gt; makes developers think distributed. In the world of network it is essential that the applications must be able to migrate easily to different computer systems. Not only to &lt;/span&gt;computer&lt;span style=&quot;text-decoration: underline;&quot;&gt;&lt;br /&gt;     &lt;/span&gt;systems&lt;span style=&quot;font-size:12pt;&quot;&gt; but to a wide variety of hardware architecture and Operating system architectures as well.  The Java compiler does this by generating byte code instructions, to be easily interpreted on any machine and to be easily translated into native machine code on the fly.&lt;strong&gt;&lt;br /&gt;      &lt;/strong&gt;The compiler generates an architecture-neutral object file format to enable a Java application to execute anywhere on the network and then the compiled code is executed on many processors, given the presence of the Java runtime system.&lt;br /&gt;Hence Java was designed to support applications on network. This feature of Java has thrived the programming language.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://javanullpointer.blogspot.com/feeds/9167580320409039138/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javanullpointer.blogspot.com/2009/10/features-of-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/9167580320409039138'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/9167580320409039138'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2009/10/features-of-java.html' title='Features of Java'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-7984367637287961177</id><published>2009-08-27T11:55:00.002+05:30</published><updated>2009-11-06T14:44:57.197+05:30</updated><title type='text'>Microsoft SQL Server Constraints</title><content type='html'>&lt;span style=&quot;font-family: Verdana; font-size: 10pt;&quot;&gt;A constraint is a property assigned to a column or the set of columns in a table that prevents certain types of inconsistent data values from being placed in the column(s). Constraints are used to enforce the data integrity. This ensures the accuracy and reliability of the data in the database. The following categories of the data integrity exist:&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;span style=&quot;font-family: Verdana; font-size: 10pt;&quot;&gt;&lt;b&gt;Entity Integrity &lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana; font-size: 10pt;&quot;&gt;&lt;b&gt;Domain Integrity &lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana; font-size: 10pt;&quot;&gt;&lt;b&gt;Referential integrity &lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 10pt;&quot;&gt;User-Defined Integrity&lt;/span&gt;&lt;span style=&quot;font-family: Times New Roman; font-size: 12pt;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;span style=&quot;font-family: Times New Roman; font-size: 12pt;&quot;&gt;&lt;b&gt;Entity Integrity&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times New Roman; font-size: 12pt;&quot;&gt;Entity integrity ensures that there are no duplicate rows in a table. You can apply entity integrity to a table by specifying a PRIMARY KEY constraint. For example, the ProductID column of the Products table is a primary key for the table. &lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times New Roman; font-size: 12pt;&quot;&gt;&lt;b&gt;Domain Integrity&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times New Roman; font-size: 12pt;&quot;&gt;Domain integrity ensures the data values inside a database follow defined rules for values, range, and format. A database can enforce these rules using a variety of techniques, including CHECK constraints, UNIQUE constraints, and DEFAULT constraints. These are the constraints we will cover in this article, but be aware there are other options available to enforce domain integrity. Even the selection of the data type for a column enforces domain integrity to some extent. For instance, the selection of datetime for a column data type is more restrictive than a free format varchar field. &lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times New Roman; font-size: 12pt;&quot;&gt;&lt;b&gt;Referential Integrity&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times New Roman; font-size: 12pt;&quot;&gt;Referential integrity ensures the relationships between tables remain preserved as data is inserted, deleted, and modified. You can apply referential integrity using a FOREIGN KEY constraint. The ProductID column of the Order Details table has a foreign key constraint applied referencing the Orders table. The constraint prevents an Order Detail record from using a ProductID that does not exist in the database. Also, you cannot remove a row from the Products table if an order detail references the ProductID of the row. &lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times New Roman; font-size: 12pt;&quot;&gt;Entity and referential integrity together form &lt;b&gt;key &lt;/b&gt;integrity. &lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times New Roman; font-size: 12pt;&quot;&gt;&lt;b&gt;User-Defined Integrity &lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times New Roman; font-size: 12pt;&quot;&gt;User-Defined Integrity enforces some specific business rules that do not fall into entity, domain, or referential integrity categories.&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; font-size: 10pt;&quot;&gt;&lt;br /&gt;
Each of these categories of the data integrity can be enforced by the appropriate constraints. Microsoft SQL Server supports the following constraints:&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;span style=&quot;font-family: Verdana; font-size: 10pt;&quot;&gt;PRIMARY KEY &lt;br /&gt;
&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana; font-size: 10pt;&quot;&gt;UNIQUE &lt;br /&gt;
&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana; font-size: 10pt;&quot;&gt;FOREIGN KEY &lt;br /&gt;
&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana; font-size: 10pt;&quot;&gt;CHECK &lt;br /&gt;
&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana; font-size: 10pt;&quot;&gt;NOT NULL&lt;br /&gt;
&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;span style=&quot;font-family: Verdana; font-size: 10pt;&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
A &lt;b&gt;PRIMARY KEY&lt;/b&gt; constraint is a unique identifier for a row within a database table. Every table should have a primary key constraint to uniquely identify each row and only one primary key constraint can be created for each table. The primary key constraints are used to enforce entity integrity.&lt;br /&gt;
&lt;br /&gt;
A &lt;b&gt;UNIQUE&lt;/b&gt; constraint enforces the uniqueness of the values in a set of columns, so no duplicate values are entered. The unique key constraints are used to enforce entity integrity as the primary key constraints.&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times New Roman; font-size: 12pt;&quot;&gt;From a SQL point of view, there are three methods available to add a unique constraint to a table. The first method is to create the constraint inside of CREATE TABLE as a column constraint. A column constraint applies to only a single column. The following SQL will create a unique constraint on a new table: Products_2. &lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;b&gt;CREATE TABLE Products_2 &lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;b&gt;( &lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;b&gt;    ProductID int PRIMARY KEY,&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;b&gt;    ProductName nvarchar (40) Constraint IX_ProductName UNIQUE&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-family: Verdana;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-family: Verdana;&quot;&gt;&lt;br /&gt;
A &lt;b&gt;FOREIGN KEY&lt;/b&gt; constraint prevents any actions that would destroy link between tables with the corresponding data values. A foreign key in one table points to a primary key in another table. Foreign keys prevent actions that would leave rows with foreign key values when there are no primary keys with that value. The foreign key constraints are used to enforce referential integrity.&lt;br /&gt;
&lt;br /&gt;
A &lt;b&gt;CHECK&lt;/b&gt; constraint is used to limit the values that can be placed in a column. The check constraints are used to enforce domain integrity.&lt;/span&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times New Roman; font-size: 12pt;&quot;&gt;Check constraints contain an expression the database will evaluate when you modify or insert a row. If the expression evaluates to false, the database will not save the row. Building a check constraint is similar to building a WHERE clause. You can use many of the same operators (&amp;gt;, &amp;lt;, &amp;lt;=, &amp;gt;=, &amp;lt;&amp;gt;, =) in additional to BETWEEN, IN, LIKE, and NULL. You can also build expressions around AND and OR operators. You can use check constraints to implement business rules, and tighten down the allowed values and formats allowed for a particular column.&lt;/span&gt;&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;b&gt;CREATE TABLE Products_2&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;b&gt;(&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;b&gt;    ProductID int PRIMARY KEY,&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;b&gt;    UnitPrice money CHECK(UnitPrice &amp;gt; 0 AND UnitPrice &amp;lt; 100)&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;b&gt;)&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 10pt;&quot;&gt;&lt;br /&gt;
A &lt;b&gt;NOT NULL&lt;/b&gt; constraint enforces that the column will not accept null values. The not null constraints are used to enforce domain integrity, as the check constraints.&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times New Roman; font-size: 12pt;&quot;&gt;Using SQL you can use NULL or NOT NULL on a column definition to explicitly set the nullability of a column. In the following example table, the FirstName column will accept NULL values while LastName always requires a non NULL value. Primary key columns require a NOT NULL setting, and default to this setting if not specified.&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;b&gt;CREATE TABLE Employees_2 &lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;b&gt;(&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;b&gt;    EmployeeID int PRIMARY KEY,&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;b&gt;    FirstName varchar(50) NULL,&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;b&gt;    LastName varchar(50) NOT NULL,&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times New Roman; font-size: 12pt;&quot;&gt;&lt;b&gt;Disabling Constraints&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times New Roman; font-size: 12pt;&quot;&gt;Special situations often arise in database development where it is convenient to temporarily relax the rules. For example, it is often easier to load initial values into a database one table at a time, without worrying with foreign key constraints and checks until all of the tables have finished loading. After the import is complete, you can turn constraint checking back on and know the database is once again protecting the integrity of the data.&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times New Roman; font-size: 12pt;&quot;&gt;Note: The only constraints you can disable are the FOREIGN KEY constraint, and the CHECK constraint. PRIMARY KEY, UNIQUE, and DEFAULT constraints are always active.&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times New Roman; font-size: 12pt;&quot;&gt;Disabling a constraint using SQL is done through the ALTER TABLE command. The following statements disable the CHECK constraint on the UnitsOnOrder column, and the FOREIGN KEY constraint on the CategoryID column.&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;b&gt;ALTER TABLE Products NOCHECK CONSTRAINT CK_UnitsOnOrder &lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;b&gt;ALTER TABLE Products NOCHECK CONSTRAINT FK_Products_Categories&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times New Roman; font-size: 12pt;&quot;&gt;If you need to disable all of the constraints on a table, manually navigating through the interface or writing a SQL command for each constraint may prove to be a laborious process. There is an easy alternative using the ALL keyword, as shown below:&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New; font-size: 10pt;&quot;&gt;&lt;b&gt;ALTER TABLE Products NOCHECK CONSTRAINT ALL&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://javanullpointer.blogspot.com/feeds/7984367637287961177/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javanullpointer.blogspot.com/2009/08/microsoft-sql-server-constraints.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/7984367637287961177'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/7984367637287961177'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2009/08/microsoft-sql-server-constraints.html' title='Microsoft SQL Server Constraints'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-6198822678200312196</id><published>2009-08-22T13:54:00.004+05:30</published><updated>2009-08-22T15:00:25.314+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Inner Join"/><category scheme="http://www.blogger.com/atom/ns#" term="OuterJoin and Cross Joins in Sql server"/><title type='text'>Joins examples in SQL Server 2005</title><content type='html'>Joins in SQL Server allows the retrieval of data records from one or more tables having some relation between them. Logical operators can also be used to drill down the number of records to get the desired output from sql join queries.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Inner Join:&lt;/strong&gt; Inner Join is a default type join of SQL Server. It uses logical operators such as =, &amp;gt;,&amp;lt; to match the records in two tables. Inner Join includes equi join and natural joins.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;SQL Inner Join Examples &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;SELECT C.CATEGORYID, C.CATEGORYNAME, P.PRODUCTID, P.PRODUCTNAME, P.UNITPRICE FROM CATEGORIES C INNER JOINPRODUCTS P ON P.CATEGORYID = C.CATEGORYIDWHERE P.UNITPRICE = 10ORDER BY C.CATEGORYNAME, P.PRODUCTNAME&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;SQL Inner Natural&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This inner join query will return the categoryid, categoryname, productid, productname, unitprice where product unit price = 10&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;SQL Inner Natural Join Examples&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;SELECT C.*, P.PRODUCTID, P.PRODUCTNAME FROM CATEGORIES C INNER JOINPRODUCTS P ON P.CATEGORYID = C.CATEGORYID&lt;br /&gt;&lt;br /&gt;This natural join query will return all the columns of categories table and prodcutId and productName from products table. You can further modify this natural inner join query as per your requirements to visualize the data by specifying the column names of categories table also.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;SQL Inner Equi Join Examples&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Inner join is a default type of SQL Join that return the records matching in all the tables joined in sql query satisfying the condition specified in WHERE clause.&lt;br /&gt;Inner join includes 3 types of joins similar to one another.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Self Join:&lt;/strong&gt; Self join joins a single sql database table to itself. Equi Join: Equi Join returns all the columns from both tables and filters the records satisfying the matching condition specified in Join “ON” statement of sql inner join query.&lt;br /&gt;&lt;br /&gt;USE NORTHWIND SELECT * FROM CATEGORIES C INNER JOINPRODUCTS P ON P.CATEGORYID = C.CATEGORYID&lt;br /&gt;&lt;br /&gt;Result will display the following columns: CategoryID, CategoryName, Description, Picture, ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued Above equi join sql query will display the categoryId two times in a row because both the tables have categoryId column. You can convert the result into natural join by elimination the identical columns and unnecessary columns.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Outer Join:&lt;/strong&gt; Outer Join has further 3 sub categories as left, right and full. Outer Join uses these category names as keywords that can be specified in the FROM clause. Left Outer Join: Left Outer Join returns all the rows from the table specified first in the Left Outer Join Clause. If in the left table any row has no matching record in the right side table then that row returns null column values for that particular tuple. Inner joins return only those rows from both sql database tables having matching records in both the tables whereas left outer join returns all the rows from the left table and related matching records from the other one.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;SQL Left Outer Join Example: &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;SELECT A.AU_FNAME, A.AU_LNAME, P.PUB_NAMEFROM AUTHORS A LEFT OUTER JOIN PUBLISHERS PON A.CITY = P.CITYORDER BY A.AU_LNAME, A.AU_FNAME&lt;br /&gt;&lt;br /&gt;This left outer join query retrieves the author names and publisher name having same cities. Here all rows retrieved from the left table i.e. authors and publisher name having the similar city other columns of pub_name column are null due to no match found in the right table. Right Outer Join: Right Outer Join is exactly the reverse method of Left Outer Join. It returns all the rows from right table and returns null values for the rows having no match in the left joined table. Just change the left keyword to right outer join in above example; you will get the reverse output of left outer join in the form of right outer join.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;SQL Right Outer Join query Example: &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;SELECT A.AU_FNAME, A.AU_LNAME, P.PUB_NAMEFROM AUTHORS A RIGHT OUTER JOIN PUBLISHERS PON A.CITY = P.CITYORDER BY A.AU_LNAME, A.AU_FNAME&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Full Outer Join:&lt;/strong&gt; Full outer join returns all the rows from both left and right joined tables. If there is any match missing from the left table then it returns null column values for left side table and if there is any match missing from right table then it returns null value columns for the right side table. To retrieve all the records from left as well as right table unless the records have matching relations in each row you can use SQL FULL OUTER JOIN. You can consider the examples of last two articles about left outer join and right outer join, in which left outer join retrieves all records from the left table and as all records of right table in right outer join along with null values for the columns having no matching records in any tuple. To retain all the records of left as well as right table along with null values for non matching rows displaying the combination of results of left outer and right outer join, FULL OUTER JOIN is the best solution.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;SQL FULL outer join example:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt; SELECT A.AU_FNAME, A.AU_LNAME, P.PUB_NAMEFROM AUTHORS A FULL OUTER JOIN PUBLISHERS PON A.CITY = P.CITYORDER BY A.AU_LNAME, A.AU_FNAME&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Cross Join: &lt;/strong&gt;Cross join works as a Cartesian product of rows for both left and right table. It combined each row of left table with all the rows of right table. SQL Cross join returns the output result as a Cartesian product of both database tables. Let left table has 10 rows and right table has 8 rows then SQL CROSS Join will return 180 rows combining each record of left table with all records of right side table.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Consider the following example of CROSS Join: &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;USE PUBSSELECT AU_FNAME, AU_LNAME, PUB_NAMEFROM AUTHORS CROSS JOIN PUBLISHERS ORDER BY AU_FNAME&lt;br /&gt;&lt;br /&gt;Above cross join will return 23 * 8 = 184 results by multiplying each row of authors table with publishers table. SQL CROSS Join with WHERE clause By just adding the where clause with Cross join sql query it turns the output result into inner join.</content><link rel='replies' type='application/atom+xml' href='http://javanullpointer.blogspot.com/feeds/6198822678200312196/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javanullpointer.blogspot.com/2009/08/joins-examples-in-sql-server-2005.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/6198822678200312196'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/6198822678200312196'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2009/08/joins-examples-in-sql-server-2005.html' title='Joins examples in SQL Server 2005'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-7738449708978309790</id><published>2009-08-05T10:39:00.002+05:30</published><updated>2009-08-05T10:43:23.348+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Call by value and call by reference in java"/><category scheme="http://www.blogger.com/atom/ns#" term="Java is strictly Call-by-value"/><title type='text'>Call-by-value Vs Call-by-reference in Java</title><content type='html'>The terms &quot;Call-by-value&quot; semantics and &quot;Call-by-reference&quot; semantics have very precise definitions, and they&#39;re often horribly abused when folks talk about Java. I want to correct that... The following is how I&#39;d describe these&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Call-by-value&lt;/span&gt;&lt;br /&gt;    The actual parameter (or argument expression) is fully evaluated and the resulting value is copied into a location being used to hold the formal parameter&#39;s value during method/function execution. That location is typically a chunk of memory on the runtime stack for the application (which is how Java handles it), but other languages could choose parameter storage differently.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Call-by-reference&lt;/span&gt;&lt;br /&gt;    The formal parameter merely acts as an alias for the actual parameter. Anytime the method/function uses the formal parameter (for reading or writing), it is actually using the actual parameter.&lt;br /&gt;&lt;br /&gt;When you call a method by reference, the callee sees the caller’s original variables passed as parameters, not copies. References to the callee’s objects are treated the same way. Thus any changes the callee makes to the caller’s variables affect the caller’s original variables. Java never uses call by reference. Java always uses call by value.&lt;br /&gt;&lt;br /&gt;How do you fake call by reference in Java, or more precisely, how can a callee influence the values of it’s caller’s variables?&lt;br /&gt;&lt;br /&gt;    * Use a holder/wrapper object passed to the callee as a parameter. The callee can change the object’s fields. That object may be as simple as an Object[]. In Java, a callee may change the fields of a caller’s object passed as a parameter, but not the caller’s reference to that object. It can’t make the caller’s variable passed as a parameter point to a different object. It can only make its local copy point to a different object. A holder class is just a class with fields to hold your values. It has no methods other than accessors for the fields.&lt;br /&gt;&lt;br /&gt;    * Have the callee return the new values, perhaps wrapped in an holder class or Object[], and have the caller store them away somewhere.&lt;br /&gt;    * Communicate via a static or instance variable visible to both caller and callee.&lt;br /&gt;    * Use a delegate object. The callee calls its methods to save the results for the caller.&lt;br /&gt;&lt;br /&gt;Dale King points out that attempts to fake call by reference are usually a sign of poor object-oriented design. A function should not be trying to return more than one thing. He uses the term thing because it is proper to return more than one value (e.g. returning a Point that contains two values). If you are trying to return two values, the test he like to apply is whether you can come up with a logical name for the values as a group. If you can’t, you had better look to see if maybe you what you have is really two functions lumped together.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Java is &lt;/span&gt;&lt;b style=&quot;font-weight: bold;&quot;&gt;&lt;i&gt;strictly&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; Call-by-value&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://javanullpointer.blogspot.com/feeds/7738449708978309790/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javanullpointer.blogspot.com/2009/08/call-by-value-vs-call-by-reference-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/7738449708978309790'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/7738449708978309790'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2009/08/call-by-value-vs-call-by-reference-in.html' title='Call-by-value Vs Call-by-reference in Java'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-7308815821431023116</id><published>2009-08-01T19:39:00.001+05:30</published><updated>2009-08-01T19:43:17.384+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="How to Serializing and Deserializing Objects"/><title type='text'>Serializing and Deserializing Objects</title><content type='html'>&lt;span style=&quot;font-weight: bold;&quot;&gt;Serializing and Deserializing Objects&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The serialization mechanism in Java provides the means for persisting objects beyond a single run of a Java program. To serialize an object, make sure that the declaring class implements the java.io.Serializable interface. Then obtain an ObjectOutputStream to write the object to and call the writeObject() method on the ObjectOutputStream. To deserialize an object, obtain an ObjectInputStream to read the object from and call the readObject() method on the ObjectInputStream. The following code excerpts illustrate how an object is stored in the file by Serialize and getting object from file by Deserialize.&lt;br /&gt;&lt;br /&gt; &lt;span style=&quot;font-weight: bold; color: rgb(153, 0, 0);&quot;&gt;private static String&lt;/span&gt; fileName = &quot;./objectholder.ser&quot;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(153, 0, 0); font-weight: bold;&quot;&gt; public static void&lt;/span&gt; serializeObject(Object obj) {&lt;br /&gt;  try {&lt;br /&gt;           &lt;span style=&quot;font-weight: bold; color: rgb(204, 0, 0);&quot;&gt;ObjectOutput &lt;/span&gt;out = new ObjectOutputStream(new FileOutputStream(fileName));&lt;br /&gt;           out.writeObject(obj);&lt;br /&gt;            out.close();&lt;br /&gt;    } catch (&lt;span style=&quot;font-weight: bold;&quot;&gt;IOException &lt;/span&gt;e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold; color: rgb(204, 0, 0);&quot;&gt;public static Object&lt;/span&gt; deSerializeObject(){&lt;br /&gt; try {&lt;br /&gt;          Object obj = null;&lt;br /&gt;           File file = new File(fileName);&lt;br /&gt;         if(file.exists()) {&lt;br /&gt;               ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));&lt;br /&gt;              // Deserialize the object&lt;br /&gt;             obj = in.readObject();&lt;br /&gt;             in.close();&lt;br /&gt;       }&lt;br /&gt;         return obj;&lt;br /&gt;    } catch (Exception e) {&lt;br /&gt;          e.printStackTrace();&lt;br /&gt;          return null;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(255, 204, 153);&quot;&gt;how to call these methods?&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: rgb(153, 255, 153);&quot;&gt;//serialize the object&lt;/span&gt;&lt;br /&gt;    MyObject fileObjs = new MyObject();&lt;br /&gt;    serializeObject(fileObjs);&lt;br /&gt;&lt;br /&gt;  &lt;span style=&quot;color: rgb(102, 255, 153);&quot;&gt;  // Deserialize the object&lt;/span&gt;&lt;br /&gt;    MyObject fileObjs = (MyObject)deSerializeObject();&lt;br /&gt;&lt;br /&gt;Where MyObject is class with implements of &lt;span style=&quot;font-weight: bold; color: rgb(204, 0, 0);&quot;&gt;Serializable &lt;/span&gt;interface.&lt;br /&gt;&lt;br /&gt;Serialize the object myObject of type &lt;span style=&quot;font-weight: bold;&quot;&gt;MyObject&lt;/span&gt;. The file output stream is created for the file named myObject.ser. The object is actually persisted in this file on ,and read the object back from the file &lt;span style=&quot;font-weight: bold;&quot;&gt;objectholder.ser&lt;/span&gt;. If you list the files in the directory where this code&#39;s .class file is stored, you will see a new file called objectholder.ser added to the listing.</content><link rel='replies' type='application/atom+xml' href='http://javanullpointer.blogspot.com/feeds/7308815821431023116/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javanullpointer.blogspot.com/2009/08/serializing-and-deserializing-objects.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/7308815821431023116'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/7308815821431023116'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2009/08/serializing-and-deserializing-objects.html' title='Serializing and Deserializing Objects'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-6579424573329482163</id><published>2009-07-31T20:33:00.003+05:30</published><updated>2009-08-01T15:32:19.145+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hibernate Architecture"/><title type='text'>Basic Architecture of Hibernate</title><content type='html'>&lt;p&gt;Introduction to Hibernate:&lt;/p&gt;&lt;p&gt;Hibernate is an Object-Relational Mapping (ORM) solution for JAVA. It is a powerful, highperformance object/relational persistence and query service. It allows us to develop persistent classesfollowing object-oriented idiom – including association, inheritance and polymorphism.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Hibernate Architecture&lt;br /&gt;&lt;/p&gt;&lt;p&gt;1) itself opens connection to database,&lt;/p&gt;&lt;p&gt;2) converts HQL (Hibernate Query Language) statements to database specific statement,&lt;/p&gt;&lt;p&gt;3) receives result set,&lt;/p&gt;&lt;p&gt;4) then performs mapping of these database specific data to Java objects which are directly used by Java application.&lt;/p&gt;&lt;p&gt;Hibernate uses the database specification from Hibernate Properties file. Automatic mapping is performed on the basis of the properties defined in hbm XML file defined for particular Java object.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh827i6DBLoMWyc9uX-P0qwRXHJFcDEnPF4bta2sJ-1JfWlzeNeblIdxc_OnRlTMCy6LaB99jMywTkXvcXekDNH4fb91OgwbtqffCY4pJDQTDBpGtfTVrnt42mG_3PJXHbfSNIgJ4wjJcJ0/s1600-h/hib.jpg&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 351px; height: 353px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh827i6DBLoMWyc9uX-P0qwRXHJFcDEnPF4bta2sJ-1JfWlzeNeblIdxc_OnRlTMCy6LaB99jMywTkXvcXekDNH4fb91OgwbtqffCY4pJDQTDBpGtfTVrnt42mG_3PJXHbfSNIgJ4wjJcJ0/s400/hib.jpg&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5364933391082497522&quot; /&gt;&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://javanullpointer.blogspot.com/feeds/6579424573329482163/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javanullpointer.blogspot.com/2009/07/basic-architecture-of-hibernate.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/6579424573329482163'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/6579424573329482163'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2009/07/basic-architecture-of-hibernate.html' title='Basic Architecture of Hibernate'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh827i6DBLoMWyc9uX-P0qwRXHJFcDEnPF4bta2sJ-1JfWlzeNeblIdxc_OnRlTMCy6LaB99jMywTkXvcXekDNH4fb91OgwbtqffCY4pJDQTDBpGtfTVrnt42mG_3PJXHbfSNIgJ4wjJcJ0/s72-c/hib.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-224253851629108279</id><published>2009-07-31T20:28:00.004+05:30</published><updated>2010-01-01T19:54:54.650+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Why is Hibernate better than JDBC"/><title type='text'>JDBC Vs Hibernate</title><content type='html'>&lt;b&gt;Why is Hibernate better than JDBC&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
1) Relational Persistence for JAVAWorking with both Object-Oriented software and Relational Database is complicated task withJDBC because there is mismatch between how data is represented in objects versus relationaldatabase. So with JDBC, developer has to write code to map an object model&#39;s data representationto a relational data model and its corresponding database schema. Hibernate is flexible andpowerful ORM solution to map Java classes to database tables. Hibernate itself takes care of thismapping using XML files so developer does not need to write code for this.&lt;br /&gt;
&lt;br /&gt;
2) Transparent PersistenceThe automatic mapping of Java objects with database tables and vice versa is called TransparentPersistence. Hibernate provides transparent persistence and developer does not need to write codeexplicitly to map database tables tuples to application objects during interaction with RDBMS.With JDBC this conversion is to be taken care of by the developer manually with lines of code.&lt;br /&gt;
&lt;br /&gt;
3) Support for Query LanguageJDBC supports only native Structured Query Language (SQL). Developer has to find out theefficient way to access database, i.e to select effective query from a number of queries to performsame task. Hibernate provides a powerful query language Hibernate Query Language(independent from type of database) that is expressed in a familiar SQL like syntax and includesfull support for polymorphic queries. Hibernate also supports native SQL statements. It also selectsan effective way to perform a database manipulation task for an application.&lt;br /&gt;
&lt;br /&gt;
4) Database Dependent CodeApplication using JDBC to handle persistent data (database tables) having database specific codein large amount. The code written to map table data to application objects and vice versa isactually to map table fields to object properties. As table changed or database changed then it’sessential to change object structure as well as to change code written to map table-to-object/objectto-table. Hibernate provides this mapping itself. The actual mapping between tables andapplication objects is done in XML files. If there is change in Database or in any table then theonly need to change XML file properties.&lt;br /&gt;
&lt;br /&gt;
5) Maintenance CostWith JDBC, it is developer’s responsibility to handle JDBC result set and convert it to Java objectsthrough code to use this persistent data in application. So with JDBC, mapping between Javaobjects and database tables is done manually. Hibernate reduces lines of code by maintainingobject-table mapping itself and returns result to application in form of Java objects. It relievesprogrammer from manual handling of persistent data, hence reducing the development time andmaintenance cost.&lt;br /&gt;
&lt;br /&gt;
6) Optimize PerformanceCaching is retention of data, usually in application to reduce disk access. Hibernate, withTransparent Persistence, cache is set to application work space. Relational tuples are moved to thiscache as a result of query. It improves performance if client application reads same data manytimes for same write. Automatic Transparent Persistence allows the developer to concentrate moreon business logic rather than this application code. With JDBC, caching is maintained by handcoding.&lt;br /&gt;
&lt;br /&gt;
7) Automatic Versioning and Time StampingBy database versioning one can be assured that the changes done by one person is not being rollbacked by another one unintentionally. Hibernate enables developer to define version type field toapplication, due to this defined field Hibernate updates version field of database table every timerelational tuple is updated in form of Java class object to that table. So if two users retrieve sametuple and then modify it and one user save this modified tuple to database, version is automaticallyupdated for this tuple by Hibernate. When other user tries to save updated tuple to database then itdoes not allow to save it because this user does not has updated data. In JDBC there is no checkthat always every user has updated data. This check has to be added by the developer.&lt;br /&gt;
&lt;br /&gt;
8) Open-Source, Zero-Cost Product LicenseHibernate is an open source and free to use for both development and production deployments.&lt;br /&gt;
&lt;br /&gt;
9) Enterprise-Class Reliability and ScalabilityHibernate scales well in any environment, no matter if use it in-house Intranet that serves hundredsof users or for mission-critical applications that serve hundreds of thousands. JDBC can not bescaled easily.&lt;a href=&quot;http://www.amazon.com/Hibernate-Made-Easy-Persistence-Annotations/dp/0615201954?ie=UTF8&amp;amp;tag=knowle03-20&amp;amp;link_code=btl&amp;amp;camp=213689&amp;amp;creative=392969&quot; target=&quot;_blank&quot;&gt;Hibernate Made Easy: Simplified Data Persistence with Hibernate and JPA (Java Persistence API) Annotations&lt;/a&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://www.assoc-amazon.com/e/ir?t=knowle03-20&amp;amp;l=btl&amp;amp;camp=213689&amp;amp;creative=392969&amp;amp;o=1&amp;amp;a=0615201954&quot; style=&quot;border: medium none ! important; margin: 0px ! important;&quot; width=&quot;1&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #ffcc99;&quot;&gt;Disadvantages of Hibernate&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
1) Steep learning curve.&lt;br /&gt;
&lt;br /&gt;
2) Use of Hibernate is an overhead for the applications which are :• simple and use one database that never change• need to put data to database tables, no further SQL queries• there are no objects which are mapped to two different tablesHibernate increases extra layers and complexity. So for these types of applications JDBC is thebest choice.&lt;br /&gt;
&lt;br /&gt;
3) Support for Hibernate on Internet is not sufficient.&lt;br /&gt;
&lt;br /&gt;
4) Anybody wanting to maintain application using Hibernate will need to know Hibernate.&lt;br /&gt;
&lt;br /&gt;
5) For complex data, mapping from Object-to-tables and vise versa reduces performance andincreases time of conversion.&lt;br /&gt;
&lt;br /&gt;
6) Hibernate does not allow some type of queries which are supported by JDBC. For example It doesnot allow to insert multiple objects (persistent data) to same table using single query. Developerhas to write separate query to insert each object.</content><link rel='replies' type='application/atom+xml' href='http://javanullpointer.blogspot.com/feeds/224253851629108279/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javanullpointer.blogspot.com/2009/07/jdbc-vs-hibernate.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/224253851629108279'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/224253851629108279'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2009/07/jdbc-vs-hibernate.html' title='JDBC Vs Hibernate'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-2747569867637491594</id><published>2009-07-29T13:42:00.002+05:30</published><updated>2009-07-29T13:49:46.737+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="How locking system works in Hibernate"/><title type='text'>How DB locking system works in Hibernate (In Concurrency operations)</title><content type='html'>Database&lt;span style=&quot;font-style: italic;&quot;&gt; locking&lt;/span&gt; can apply to any database applications.&lt;br /&gt;There are two common strategies when dealing with updates to database&lt;br /&gt;records,&lt;span style=&quot;font-weight: bold;&quot;&gt; pessimistic locking&lt;/span&gt; and &lt;span style=&quot;font-weight: bold;&quot;&gt;optimistic locking&lt;/span&gt;.&lt;br /&gt;&quot;&lt;span style=&quot;font-weight: bold; color: rgb(153, 255, 153);&quot;&gt;Optimistic locking&lt;/span&gt;&quot; is more scalable than pessimistic locking when dealing with a&lt;br /&gt;highly concurrent environment. However pessimistic locking is a better solution for situations&lt;br /&gt;where the possibility of simultaneous updates to the same data by multiple sources&lt;br /&gt;(for example, different applications use same database to update) is common, hence making the possibility of &quot;&lt;span style=&quot;font-weight: bold;&quot;&gt;data clobbering&lt;/span&gt;&quot; , a&lt;br /&gt;likely scenario. Lets look at a brief explanation of each of these two locking strategies.&lt;br /&gt;Pessimistic locking is when you want to reserve a record for exclusive update by&lt;br /&gt;locking the database record(entire table). Hibernate supports pessimistic locking&lt;br /&gt;(using the underlying database, not in-memory) via one of the following methods:&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;1. Session.get&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;2. Session.load&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;3. Session.lock&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;4. Session.refresh&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;5. Query.setLockMode&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Although each of the methods accepts different params, the one common parameter&lt;br /&gt;across all is the LockMode class, which provides various locking modes such as &lt;span style=&quot;font-weight: bold;&quot;&gt;NONE,&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;READ, UPGRADE, UPGRADE_NOWAIT&lt;/span&gt;, and &lt;span style=&quot;font-weight: bold;&quot;&gt;WRITE&lt;/span&gt;.&lt;br /&gt;For example, to obtain a &lt;span style=&quot;color: rgb(255, 255, 0); font-style: italic;&quot;&gt;Timesheet &lt;/span&gt;record for updating,&lt;br /&gt;we could use the following code: (assume database supports locking system):&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;public Timesheet getTimesheetWithLock(int timesheetId)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;        session.beginTransaction();&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;        Timesheet timesheet = (Timesheet)session.get(Timesheet.class,&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;        new Integer(timesheetId), LockMode.UPGRADE);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;        session.getTransaction().commit();&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;        session.close();&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;        return timesheet;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;    } &lt;/span&gt;&lt;br /&gt;Optimistic locking means that you will not lock a given database record or table and&lt;br /&gt;instead check a &lt;span style=&quot;font-style: italic;&quot;&gt;property &lt;/span&gt;of some sort (for example, a &lt;span style=&quot;color: rgb(255, 255, 51);&quot;&gt;timestamp &lt;/span&gt;column) to&lt;br /&gt;ensure the data has not changed since &lt;span style=&quot;font-style: italic;&quot;&gt;you read&lt;/span&gt; it. Hibernate supports this using a&lt;br /&gt;version property, which can either be checked manually by the application or automatically&lt;br /&gt;by Hibernate for a given session. For example, the following code excerpt is taken&lt;br /&gt;verbatim out of the Hibernate reference documentation and shows how an application&lt;br /&gt;can manually compare the oldVersion with the current version using a getter method&lt;br /&gt;(for example):&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;// foo is an instance loaded by a previous Session&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;session = factory.openSession();&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;int oldVersion = foo.getVersion();&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;session.load( foo, foo.getKey() );&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;&lt;br /&gt;if ( oldVersion!=foo.getVersion )&lt;br /&gt;      throw new StaleObjectStateException();&lt;/span&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;   &lt;br /&gt;&lt;br /&gt;foo.setProperty(“bar”);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;session.flush();&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;session.connection().commit();&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic; font-weight: bold;&quot;&gt;session.close();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic; color: rgb(255, 0, 0);&quot;&gt;StaleObjectStateException,  is an exception in the org.hibernate package.&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://javanullpointer.blogspot.com/feeds/2747569867637491594/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javanullpointer.blogspot.com/2009/07/how-db-locking-system-works-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/2747569867637491594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/2747569867637491594'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2009/07/how-db-locking-system-works-in.html' title='How DB locking system works in Hibernate (In Concurrency operations)'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-7884766169850464434</id><published>2009-07-27T19:34:00.003+05:30</published><updated>2009-07-27T20:56:08.805+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Velocity example with conditions and loops"/><title type='text'>Velocity example with FOR LOOP and Date format</title><content type='html'>/*Velocity example with Lists, date formate with htmls*/&lt;br /&gt;import java.io.StringWriter;&lt;br /&gt;import java.io.Writer;&lt;br /&gt;import java.util.Date;&lt;br /&gt;import java.util.HashSet;&lt;br /&gt;import java.util.Set;&lt;br /&gt;&lt;br /&gt;import org.apache.velocity.Template;&lt;br /&gt;import org.apache.velocity.VelocityContext;&lt;br /&gt;import org.apache.velocity.app.Velocity;&lt;br /&gt;import org.apache.velocity.tools.generic.DateTool;&lt;br /&gt;&lt;br /&gt;public class &lt;span style=&quot;font-weight: bold;&quot;&gt;VelocityExp &lt;/span&gt;{&lt;br /&gt;&lt;br /&gt;  public static void main(String[] args) throws Exception {&lt;br /&gt;    Velocity.init();&lt;br /&gt;    Template t = Velocity.getTemplate(&quot;./src/test/VelocityExp.html&quot;);&lt;br /&gt;   &lt;br /&gt;    VelocityContext ctx = new VelocityContext();&lt;br /&gt;    Set&lt;Demov&gt; names =new HashSet&lt;Demov&gt;();&lt;br /&gt;    Demov d1 = new Demov();&lt;br /&gt;    d1.setName(&quot;one&quot;);&lt;br /&gt;    d1.setAge(&quot;24&quot;);&lt;br /&gt;    d1.setKe(new demo2(&quot;one&quot;));&lt;br /&gt;    Demov d2 = new Demov();&lt;br /&gt;    d2.setName(&quot;two&quot;);&lt;br /&gt;    d2.setAge(&quot;23&quot;);&lt;br /&gt;    d2.setKe(new demo2(&quot;two&quot;));&lt;br /&gt;    Demov d3 = new Demov();&lt;br /&gt;    d3.setName(&quot;true&quot;);&lt;br /&gt;    d3.setAge(&quot;22&quot;);&lt;br /&gt;    d3.setKe(new demo2(&quot;three&quot;));&lt;br /&gt;    Demov d4 = new Demov();&lt;br /&gt;    d4.setName(&quot;ofour&quot;);&lt;br /&gt;    d4.setAge(&quot;21&quot;);&lt;br /&gt;    d4.setKe(new demo2(&quot;four&quot;));&lt;br /&gt;   &lt;br /&gt;    names.add(d1);&lt;br /&gt;    names.add(d2);&lt;br /&gt;    names.add(d3);&lt;br /&gt;    names.add(d4);   &lt;br /&gt;    ctx.put(&quot;products&quot;,names);&lt;br /&gt;    ctx.put(&quot;date&quot;, new DateTool());&lt;br /&gt;    ctx.put(&quot;dbdate&quot;,new Date());&lt;br /&gt;    ctx.put(&quot;rowCount&quot;,new Integer(1));&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;    Writer writer = new StringWriter();&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;    t.merge(ctx, writer);&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;    System.out.println(writer);&lt;/span&gt;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Html file content:&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;    &amp;lt;head&amp;gt;&lt;br /&gt;        &amp;lt;title&amp;gt;velocity test&amp;lt;/title&amp;gt;&lt;br /&gt;    &amp;lt;/head&amp;gt;&lt;br /&gt;    &amp;lt;body&amp;gt;&lt;br /&gt;        &amp;lt;table&amp;gt;&lt;br /&gt;           #foreach($product in $products)&lt;br /&gt;                #if ($rowCount % 2 == 0)&lt;br /&gt;                    #set ($bgcolor = &quot;#0000FF&quot;)&lt;br /&gt;                    Applying  BLUE color here &lt;br /&gt;                #else&lt;br /&gt;                 Applying RED color here&lt;br /&gt;                    #set ($bgcolor = &quot;#FF0000&quot;)                &lt;br /&gt;             #end&lt;br /&gt;                &amp;lt;tr&amp;gt;&lt;br /&gt;                    &amp;lt;td bgcolor=&quot;$bgcolor&quot;&amp;gt;$product.name&amp;lt;/td&amp;gt;&lt;br /&gt;                    &amp;lt;td bgcolor=&quot;$bgcolor&quot;&amp;gt;$product.age&amp;lt;/td&amp;gt;&lt;br /&gt;                    &amp;lt;td bgcolor=&quot;$bgcolor&quot;&amp;gt;$product.ke.k&amp;lt;/td&amp;gt;&lt;br /&gt;                &amp;lt;/tr&amp;gt;                        &lt;br /&gt;                #set ($rowCount = $rowCount + 1)&lt;br /&gt;            #end&lt;br /&gt;        &amp;lt;/table&amp;gt;&lt;br /&gt;        Displaying how to use date format here:&lt;br /&gt;        $dbdate&lt;br /&gt;        $date.get(&#39;medium&#39;)&lt;br /&gt;        $date.format(&#39;medium&#39;,$dbdate)&lt;br /&gt;    &amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/7884766169850464434'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/7884766169850464434'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2009/07/velocity-example-with-for-loops.html' title='Velocity example with FOR LOOP and Date format'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-5114117867852224842</id><published>2009-07-25T15:03:00.002+05:30</published><updated>2009-07-25T15:20:30.956+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Wildcard To Regex in Java is useful in building Like operatror in java"/><title type='text'>Java class with  regExp</title><content type='html'>&lt;strong&gt;&lt;span style=&quot;color:#000099;&quot;&gt;package&lt;/span&gt; com;&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#990000;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color:#000099;&quot;&gt;class&lt;/span&gt;&lt;/strong&gt; Name {&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#000099;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color:#990000;&quot;&gt;static&lt;/span&gt;&lt;/strong&gt; void &lt;span style=&quot;color:#66ffff;&quot;&gt;main&lt;/span&gt;(String[] args) {&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;color:#ff0000;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color:#000099;&quot;&gt;out&lt;/span&gt;&lt;/strong&gt;.&lt;strong&gt;println&lt;/strong&gt;(Name.class.getName().replaceAll(&quot;.&quot;, &quot;/&quot;) + &quot;.class&quot;);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;br /&gt;&lt;strong&gt;////////.class&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;actually everyone thinks the output will be &lt;b&gt;com/Name.class&lt;/b&gt;&lt;br /&gt;In the case of replace &#39;.&#39; will treat as regExp, in regExp &#39;.&#39; means any type of character, here replacing with &#39;/&#39; , and it becomes output like &quot;////////.class &quot;&lt;br /&gt;&lt;br /&gt;so, for expected answer, change the code as follows,&lt;br /&gt;&lt;br /&gt;Name.class.getName().replaceAll(&quot;\\.&quot;, &quot;/&quot;) + &quot;.class&quot;);&lt;br /&gt;&lt;br /&gt;then the output will, what you exprected,&lt;br /&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;com/Name.class&lt;/strong&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/5114117867852224842'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/5114117867852224842'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2009/07/java-class-with-regexp.html' title='Java class with  regExp'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-5723079392441968793</id><published>2009-07-21T15:00:00.001+05:30</published><updated>2009-07-28T10:35:27.585+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Solution for Java puzzles(4)."/><title type='text'>Small Answer for Small java pzzule!</title><content type='html'>&lt;p class=&quot;MsoNoSpacing&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;&quot; &gt;&lt;span style=&quot;&quot;&gt;/* &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;;font-family:&amp;quot;;&quot; &gt;What declaration turns this loop into infinitive loop.*/&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNoSpacing&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;&quot; &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;&quot; &gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;public class&lt;/span&gt; GhostOfLooper {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;&quot; &gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;public static&lt;/span&gt; void &lt;span style=&quot;font-style: italic;&quot;&gt;main&lt;/span&gt;(String[] args) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;&quot; &gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;// Place your declaration for i here&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;&quot; &gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;&quot; &gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt; &lt;span style=&quot;&quot;&gt;        &lt;/span&gt;while (i != 0)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;&quot; &gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt; &lt;span style=&quot;&quot;&gt;            &lt;/span&gt;i &gt;&gt;&gt;= 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;&quot; &gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt; &lt;span style=&quot;&quot;&gt;    &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;&quot; &gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt; }&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Solution&lt;/span&gt;:&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;&quot; &gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt;// Place your declaration for i here&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;&quot; &gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;byte &lt;/span&gt;i = -1;&lt;/span&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://javanullpointer.blogspot.com/feeds/5723079392441968793/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javanullpointer.blogspot.com/2009/07/small-answer-for-small-java-pzzule.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/5723079392441968793'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/5723079392441968793'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2009/07/small-answer-for-small-java-pzzule.html' title='Small Answer for Small java pzzule!'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-6718700579758469539</id><published>2009-07-21T14:53:00.002+05:30</published><updated>2009-07-21T14:56:32.171+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="How to solve java puzzles?"/><title type='text'>Solution for java puzzles(3)</title><content type='html'>/*What declaration turns this loop into infinitive loop.*/&lt;br /&gt;&lt;br /&gt;  &lt;span style=&quot;color: rgb(153, 0, 0); font-weight: bold;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 153); font-weight: bold;&quot;&gt;class &lt;/span&gt;Looper {&lt;br /&gt;  &lt;span style=&quot;font-weight: bold; color: rgb(153, 0, 0);&quot;&gt;public static &lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: rgb(51, 102, 255);&quot;&gt;void &lt;/span&gt;main(String[] args) {&lt;br /&gt;&lt;span style=&quot;color: rgb(51, 204, 0);&quot;&gt;   // Place your declaration for i here&lt;/span&gt;&lt;br /&gt; &lt;br /&gt;     &lt;span style=&quot;color: rgb(0, 0, 153);&quot;&gt;while &lt;/span&gt;(i == i + 1) {&lt;br /&gt;     }&lt;br /&gt;         }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Solution&lt;/span&gt;:&lt;br /&gt;// Place your declaration for i here&lt;br /&gt;&lt;span style=&quot;color: rgb(153, 0, 0); font-weight: bold;&quot;&gt;double &lt;/span&gt;i = 1.0/0.0</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/6718700579758469539'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/6718700579758469539'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2009/07/solution-for-java-puzzles3.html' title='Solution for java puzzles(3)'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-322556625926418581</id><published>2009-07-21T14:50:00.001+05:30</published><updated>2009-07-21T14:51:57.772+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="How to solve java puzzles?"/><title type='text'>Solution for java puzzles(2)!</title><content type='html'>/*Provide declarations for the variables x and i such that*/&lt;br /&gt;&lt;br /&gt;   public class Tweedledum {&lt;br /&gt;       public static void main(String[] args) {&lt;br /&gt;           // Put your declarations for x and i here&lt;br /&gt;     x += i;     // Must be LEGAL&lt;br /&gt;           x = x + i;  // Must be ILLEGAL&lt;br /&gt;       }&lt;br /&gt;  }&lt;br /&gt;solution:&lt;br /&gt; // Put your declarations for x and i here&lt;br /&gt;int x=0;&lt;br /&gt;byte i;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/322556625926418581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/322556625926418581'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2009/07/solution-for-java-puzzles2.html' title='Solution for java puzzles(2)!'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-852582486174605793</id><published>2009-07-21T14:33:00.003+05:30</published><updated>2011-05-30T23:06:17.396+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Solution for Java puzzles(1)."/><title type='text'>Solution for Java puzzles(1).</title><content type='html'>/*Provide a declaration for Enigma that makes the program print false.*/&lt;br /&gt;
&lt;br /&gt;
public class TestClass{&lt;br /&gt;
public static void main(String[] args) {&lt;br /&gt;
Enigma e = new Enigma();&lt;br /&gt;
System.out.println(e.equals(e));&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
final class Enigma {&lt;br /&gt;
// Provide body that makes TestClass print false.&lt;br /&gt;
// Do n&#39;t override equals method in object class.&lt;br /&gt;
}&lt;br /&gt;
:Solution&lt;br /&gt;
final class Enigma {&lt;br /&gt;
public Enigma(){&lt;br /&gt;
System.out.print(&quot;false&quot;);&lt;br /&gt;
System.exit(0);&lt;br /&gt;
}      &lt;br /&gt;
}&lt;br /&gt;
Any other solution will be appreciated ...</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/852582486174605793'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/852582486174605793'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2009/07/solution-for-java-puzzles1.html' title='Solution for Java puzzles(1).'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-4908248888075923906</id><published>2009-07-18T20:27:00.004+05:30</published><updated>2009-08-01T18:47:41.536+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="How to read Excel file in Java with jxl.jar?"/><title type='text'>How to read Excel file in Java with jxl.jar?</title><content type='html'>/*Reading Excel file (with default locale) with jxl.jar file ,you can use file object to read file in workbook settings*/&lt;br /&gt; public void processExcelFile(InputStream fileInput)throws Exception {&lt;br /&gt;        WorkbookSettings ws = new WorkbookSettings();&lt;br /&gt;        ws.setLocale(new Locale(&quot;en&quot;, &quot;EN&quot;));&lt;br /&gt;        Workbook workbook = Workbook.getWorkbook(fileInput, ws);&lt;br /&gt;         //Workbook workbook = Workbook.getWorkbook(file, ws);&lt;br /&gt;        //Cell[] headCells = sheet.getRow(0);&lt;br /&gt;       for (row = 1; row &lt; sheet.getRows(); row++) {&lt;br /&gt;                String errorStr = &quot;&quot;;&lt;br /&gt;                Cell[] cells = sheet.getRow(row);&lt;br /&gt;                 System.out.println(&quot;column1 value:&quot;+cells[0].getContents());&lt;br /&gt;                 System.out.println(&quot;column2 value:&quot;+cells[1].getContents());&lt;br /&gt;                 System.out.println(&quot;column3 value:&quot;+cells[2].getContents());  &lt;br /&gt;        }&lt;br /&gt;}&lt;br /&gt;To download jxl.jar file go through this link&lt;br /&gt;http://www.docjar.com/jar/jxl-2.6.jar</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/4908248888075923906'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/4908248888075923906'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2009/07/how-to-read-excel-file-in-java-with.html' title='How to read Excel file in Java with jxl.jar?'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-2626592838479754724</id><published>2009-03-22T13:31:00.003+05:30</published><updated>2009-07-18T20:23:54.460+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="How to sort HashMap or Map in java"/><title type='text'>How to Sort HashMap or Map in java?</title><content type='html'>/* Sorting Map and return LinkedHashMap, u can send HashMap implemented Object but it should a map like&lt;br /&gt;Map map = new HashMap();&lt;br /&gt;ma p = sortHashMapByValues(map);&lt;br /&gt;*/&lt;br /&gt; public LinkedHashMap sortHashMapByValues(Map passedMap) {&lt;br /&gt;         List mapKeys = new ArrayList(passedMap.keySet());&lt;br /&gt;         List mapValues = new ArrayList(passedMap.values());&lt;br /&gt;         Collections.sort(mapValues);&lt;br /&gt;         Collections.sort(mapKeys);&lt;br /&gt;             &lt;br /&gt;         LinkedHashMap sortedMap = &lt;br /&gt;             new LinkedHashMap();&lt;br /&gt;         &lt;br /&gt;         Iterator valueIt = mapValues.iterator();&lt;br /&gt;         while (valueIt.hasNext()) {&lt;br /&gt;             Object val = valueIt.next();&lt;br /&gt;             Iterator keyIt = mapKeys.iterator();&lt;br /&gt;             &lt;br /&gt;             while (keyIt.hasNext()) {&lt;br /&gt;                 Object key = keyIt.next();&lt;br /&gt;                 String comp1 = passedMap.get(key).toString();&lt;br /&gt;                 String comp2 = val.toString();&lt;br /&gt;                 &lt;br /&gt;                 if (comp1.equals(comp2)){&lt;br /&gt;                     passedMap.remove(key);&lt;br /&gt;                     mapKeys.remove(key);&lt;br /&gt;                     sortedMap.put((String)key, val);&lt;br /&gt;                     break;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;         return sortedMap;&lt;br /&gt;     }</content><link rel='replies' type='application/atom+xml' href='http://javanullpointer.blogspot.com/feeds/2626592838479754724/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javanullpointer.blogspot.com/2009/03/sorting-hashmap-or-map-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/2626592838479754724'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/2626592838479754724'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2009/03/sorting-hashmap-or-map-in-java.html' title='How to Sort HashMap or Map in java?'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-1381183628230728189</id><published>2009-03-18T15:14:00.003+05:30</published><updated>2009-03-18T15:21:44.601+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sql server pagination query"/><title type='text'>Sql server pagination query</title><content type='html'>&lt;span style=&quot;font-weight:bold;&quot;&gt;select* from ( &lt;/span&gt; SELECT ROW_NUMBER() OVER (ORDER BY ja.AppName) AS RowNumber, ja.* from Applicant ja &lt;span style=&quot;font-weight:bold;&quot;&gt;)a where&lt;/span&gt; a.&lt;span style=&quot;font-style:italic;&quot;&gt;RowNumber &lt;/span&gt;&lt;= uplt  and a.&lt;span style=&quot;font-style:italic;&quot;&gt;RowNumber &lt;/span&gt;&gt; lowlt</content><link rel='replies' type='application/atom+xml' href='http://javanullpointer.blogspot.com/feeds/1381183628230728189/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javanullpointer.blogspot.com/2009/03/sql-server-pagination-query.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/1381183628230728189'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/1381183628230728189'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2009/03/sql-server-pagination-query.html' title='Sql server pagination query'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-1246389122692766001</id><published>2008-10-16T01:04:00.000+05:30</published><updated>2008-10-16T01:05:05.496+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Spring  ACEGI Filters"/><title type='text'>how to use ACEGI filter</title><content type='html'>&lt;!-- ======================== FILTER CHAIN ======================= --&gt;&lt;br /&gt;&lt;br /&gt;  &lt;bean id=&quot;filterChainProxy&quot; class=&quot;org.acegisecurity.util.FilterChainProxy&quot;&gt;&lt;br /&gt;    &lt;property name=&quot;filterInvocationDefinitionSource&quot;&gt;&lt;br /&gt;      &lt;value&gt;&lt;br /&gt;        CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON&lt;br /&gt;        PATTERN_TYPE_APACHE_ANT&lt;br /&gt;  /javascript/**=#NONE#&lt;br /&gt;        /css/**=#NONE#&lt;br /&gt;        /images/**=#NONE#&lt;br /&gt;  /sounds.*=#NONE#&lt;br /&gt;  /secureimg=#NONE#&lt;br /&gt;  /**/tmplt.*=#NONE#&lt;br /&gt;        /**/.*popup.xhtml=securityFilter&lt;br /&gt;        /**/*.jsp=securityFilter&lt;br /&gt;  /**/*.xhtml=channelProcessingFilter,httpSessionContextIntegrationFilter,logoutFilter,casProcessingFilter,basicProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor,securityFilter&lt;br /&gt;  /**=httpSessionContextIntegrationFilter,logoutFilter,casProcessingFilter,basicProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor,securityFilter&lt;br /&gt;      &lt;/value&gt;&lt;br /&gt;    &lt;/property&gt;&lt;br /&gt;  &lt;/bean&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/1246389122692766001'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/1246389122692766001'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2008/10/how-to-use-acegi-filter.html' title='how to use ACEGI filter'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-895381354885862503</id><published>2008-07-12T10:35:00.003+05:30</published><updated>2009-03-22T13:26:40.276+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sample Example for Force authentication mail using java"/><title type='text'>Force authentication with Java Mail API</title><content type='html'>package com;&lt;br /&gt;&lt;br /&gt;import java.util.Properties;&lt;br /&gt;&lt;br /&gt;import javax.mail.Authenticator;&lt;br /&gt;import javax.mail.MessagingException;&lt;br /&gt;import javax.mail.PasswordAuthentication;&lt;br /&gt;import javax.mail.Session;&lt;br /&gt;import javax.mail.Transport;&lt;br /&gt;import javax.mail.internet.MimeMessage;&lt;br /&gt;&lt;br /&gt;import org.springframework.mail.javamail.MimeMessageHelper;&lt;br /&gt;&lt;br /&gt;public class EmailTest {&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * @param args&lt;br /&gt;  */&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  try {&lt;br /&gt;   String[] strarr = { &quot;recipient@email.addresses&quot; };   &lt;br /&gt;   postMail(strarr, &quot;Test u&quot;, &quot;Test Mesage&quot;, &quot;from@email.address&quot;, false);&lt;br /&gt;   System.out.println(&quot;Mail sent!...&quot;);&lt;br /&gt;  } catch (MessagingException e) {&lt;br /&gt;   e.printStackTrace();&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;  public static void postMail(String recipients[], String subject, String message, String from, boolean isHtml) throws MessagingException {&lt;br /&gt;         boolean debug = false;&lt;br /&gt;&lt;br /&gt;         // Set the host smtp address&lt;br /&gt;         Properties props = new Properties();&lt;br /&gt;         props.put(&quot;mail.smtp.host&quot;,&quot;hostipaddr&quot;);&lt;br /&gt;         String hostEmail = &quot;admin@mail.com&quot;;&lt;br /&gt;         String pwd = &quot;password&quot;;&lt;br /&gt;         // create some properties and get the default Session&lt;br /&gt;        // Session session = Session.getDefaultInstance(props, null);&lt;br /&gt;         Session session = Session.getInstance(props, new ForcedAuthenticator(hostEmail,pwd));&lt;br /&gt;         session.setDebug(debug);&lt;br /&gt;&lt;br /&gt;         // create a message&lt;br /&gt;         MimeMessage msg = new MimeMessage(session);&lt;br /&gt;&lt;br /&gt;         MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(msg);&lt;br /&gt;&lt;br /&gt;         mimeMessageHelper.setTo(recipients);&lt;br /&gt;         mimeMessageHelper.setFrom(from);&lt;br /&gt;         mimeMessageHelper.setSubject(subject);&lt;br /&gt;         mimeMessageHelper.setReplyTo(from);&lt;br /&gt;         mimeMessageHelper.setText(message, isHtml);&lt;br /&gt;&lt;br /&gt;         Transport.send(mimeMessageHelper.getMimeMessage());&lt;br /&gt;     }&lt;br /&gt;}&lt;br /&gt;class ForcedAuthenticator extends Authenticator {&lt;br /&gt; String username;&lt;br /&gt; String password;&lt;br /&gt; public ForcedAuthenticator(String username, String password) {&lt;br /&gt;  this.username = username;&lt;br /&gt;  this.password = password;  &lt;br /&gt; }&lt;br /&gt; @Override&lt;br /&gt;    public PasswordAuthentication getPasswordAuthentication() {&lt;br /&gt;  return new PasswordAuthentication(this.username, this.password);&lt;br /&gt; } &lt;br /&gt;}</content><link rel='replies' type='application/atom+xml' href='http://javanullpointer.blogspot.com/feeds/895381354885862503/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javanullpointer.blogspot.com/2008/07/force-authentication-with-java-mail-api.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/895381354885862503'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/895381354885862503'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2008/07/force-authentication-with-java-mail-api.html' title='Force authentication with Java Mail API'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4161616116436247579.post-8751038702310257638</id><published>2008-06-09T14:43:00.001+05:30</published><updated>2009-08-22T15:15:34.120+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Wildcard To Regex in Java is useful in building Like operatror in java"/><title type='text'>Wildcard To Regex in Java</title><content type='html'>This code works like wild card expression in java. there is no in-built methods to identify which are using wild card chars &#39;?&#39;, and &#39;*&#39;.&lt;br /&gt;Every programmer know about these(&#39;?&#39;,&#39;*&#39;) chars how there are working.&lt;br /&gt;Here the code snippet to work like their behavior &lt;br /&gt;&lt;br /&gt;public static String wildcardToRegex(String wildcard){&lt;br /&gt;    StringBuffer s = new StringBuffer(wildcard.length());&lt;br /&gt;    s.append(&#39;^&#39;);&lt;br /&gt;     for (int i = 0, is = wildcard.length(); i &lt; is; i++) {&lt;br /&gt;        char c = wildcard.charAt(i);&lt;br /&gt;         switch(c) {&lt;br /&gt;             case &#39;*&#39;:&lt;br /&gt;                      s.append(&quot;.*&quot;);&lt;br /&gt;                      break;&lt;br /&gt;              case &#39;?&#39;:&lt;br /&gt;                      s.append(&quot;.&quot;);&lt;br /&gt;                      break;&lt;br /&gt;              // escape special regexp-characters&lt;br /&gt;              case &#39;(&#39;: case &#39;)&#39;: case &#39;[&#39;: case &#39;]&#39;: case &#39;$&#39;:&lt;br /&gt;              case &#39;^&#39;: case &#39;.&#39;: case &#39;{&#39;: case &#39;}&#39;: case &#39;|&#39;:&lt;br /&gt;              case &#39;\\&#39;:&lt;br /&gt;                    s.append(&quot;\\&quot;);&lt;br /&gt;                   s.append(c);&lt;br /&gt;                   break;&lt;br /&gt;             default:&lt;br /&gt;                   s.append(c);&lt;br /&gt;                     break;&lt;br /&gt;             }&lt;br /&gt;       }&lt;br /&gt;        s.append(&#39;$&#39;);&lt;br /&gt;     return(s.toString());&lt;br /&gt;  }</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/8751038702310257638'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4161616116436247579/posts/default/8751038702310257638'/><link rel='alternate' type='text/html' href='http://javanullpointer.blogspot.com/2008/06/wildcard-to-regex-in-java.html' title='Wildcard To Regex in Java'/><author><name>Picture abi baaki hain</name><uri>http://www.blogger.com/profile/02895888824071056615</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JNobFar1tPPO8AdxiXDDeLe8whgGnlBNzjFZ9be2cnMa8d2InZ64mu5gEb9rcwRaPJFtTIoN49laCUIxd4Bky3_sNTta9vcjeu_BPskYRBcj6PfAU0RPg29bnZpkSw/s220/004+copy.jpg'/></author></entry></feed>