tag:blogger.com,1999:blog-16336386658393577382024-03-19T22:24:36.659-07:00java postsUnknownnoreply@blogger.comBlogger24125tag:blogger.com,1999:blog-1633638665839357738.post-64335734800548316262016-02-05T22:03:00.002-08:002016-02-05T22:03:52.680-08:00How to set path in Java<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background-color: white; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; line-height: 23px;">
The path is required to be set for using tools such as javac, java etc.</div>
<div style="background-color: white; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; line-height: 23px;">
If you are saving the java source file inside the jdk/bin directory, path is not required to be set because all the tools will be available in the current directory.</div>
<div style="background-color: white; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; line-height: 23px;">
But If you are having your java file outside the jdk/bin folder, it is necessary to set path of JDK.</div>
<div style="background-color: white; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; line-height: 23px;">
There are 2 ways to set java path:</div>
<ol style="background-color: white; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; line-height: 23px;">
<li style="font-family: Verdana; font-stretch: normal; line-height: 1.5; margin-top: 3px;">temporary</li>
<li style="font-family: Verdana; font-stretch: normal; line-height: 1.5; margin-top: 3px;">permanent</li>
</ol>
<div style="background-color: white; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; line-height: 23px;">
</div>
<h3 class="h3" style="background-color: white; color: #610b4b; font-family: erdana, helvetica, arial, sans-serif; font-size: 21px; font-weight: 400; line-height: 23px;">
1) How to set Temporary Path of JDK in Windows</h3>
<div style="background-color: white; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; line-height: 23px;">
To set the temporary path of JDK, you need to follow following steps:</div>
<ul style="background-color: white; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; line-height: 23px;">
<li style="font-family: Verdana; font-stretch: normal; line-height: 1.5; margin-top: 3px;">Open command prompt</li>
<li style="font-family: Verdana; font-stretch: normal; line-height: 1.5; margin-top: 3px;">copy the path of jdk/bin directory</li>
<li style="font-family: Verdana; font-stretch: normal; line-height: 1.5; margin-top: 3px;">write in command prompt: set path=copied_path</li>
</ul>
<h3 class="h4" style="background-color: white; color: #610b4b; font-family: erdana, helvetica, arial, sans-serif; font-size: 18px; line-height: 23px; margin-left: 0px; padding: 0px;">
For Example:</h3>
<div class="codeblock" style="background-color: white; border: 1px solid rgb(213, 221, 198); box-shadow: rgb(212, 212, 212) 5px 3px 10px; font-family: verdana; font-size: 13px; line-height: 23px; margin: 5px 0px 10px; padding: 0px; width: 100%;">
<pre style="margin-bottom: 5px; margin-left: 10px; margin-top: 5px;">set path=C:\Program Files\Java\jdk1.6.0_23\bin
</pre>
</div>
<div style="background-color: white; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; line-height: 23px;">
Let's see it in the figure given below:</div>
<hr style="background-color: #d4d4d4; border: 0px; clear: both; color: #d4d4d4; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; height: 1px; line-height: 23px;" />
<div style="background-color: white; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; line-height: 23px;">
<a href="https://www.blogger.com/null" id="pathtemporary" style="color: green;"></a><img alt="how to set path in java" src="http://www.javatpoint.com/images/temporarypath.jpg" style="height: auto; max-width: 100%;" /></div>
<hr style="background-color: #d4d4d4; border: 0px; clear: both; color: #d4d4d4; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; height: 1px; line-height: 23px;" />
<h3 class="h3" style="background-color: white; color: #610b4b; font-family: erdana, helvetica, arial, sans-serif; font-size: 21px; font-weight: 400; line-height: 23px;">
2) How to set Permanent Path of JDK in Windows</h3>
<div style="background-color: white; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; line-height: 23px;">
For setting the permanent path of JDK, you need to follow these steps:</div>
<div style="background-color: white; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; line-height: 23px;">
<a href="https://www.blogger.com/null" id="pathpermanent" style="color: green;"></a></div>
<ul style="background-color: white; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; line-height: 23px;">
<li style="font-family: Verdana; font-stretch: normal; line-height: 1.5; margin-top: 3px;">Go to MyComputer properties -> advanced tab -> environment variables -> new tab of user variable -> write path in variable name -> write path of bin folder in variable value -> ok -> ok -> ok</li>
</ul>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-71749312228765295602016-02-02T09:20:00.002-08:002016-02-02T09:20:40.559-08:00Classpath<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="b_entitySubTitle">
Java</div>
<div class="b_lBottom b_snippet">
Classpath is a parameter in the Java Virtual Machine or the Java compiler that specifies the location of user-defined classes and packages. The parameter may set either on the command-line, or through an environment variable</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<h2>
<span class="mw-headline" id="Setting_the_path_to_execute_Java_programs">Setting the path to execute Java programs</span></h2>
<h3>
<span class="mw-headline" id="Supplying_as_application_argument" style="color: #660000;">Supplying as application argument</span></h3>
Suppose we have a package called <i>org.mypackage</i> containing the classes:<br />
<ul>
<li><i>HelloWorld</i> (main class)</li>
<li><i>SupportClass</i></li>
<li><i>UtilClass</i></li>
</ul>
and the files defining this package are stored physically under the directory <i>D:\myprogram</i> (on <a href="https://en.wikipedia.org/wiki/Microsoft_Windows" title="Microsoft Windows">Windows</a>) or <i>/home/user/myprogram</i> (on <a href="https://en.wikipedia.org/wiki/Linux" title="Linux">Linux</a>).<br />
The file structure looks like this:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<table class="wikitable" style="font-size: 90%;"><tbody>
<tr><th><br />
<a href="https://en.wikipedia.org/wiki/Microsoft_Windows" title="Microsoft Windows"><span style="color: #990000;">Microsoft Windows</span></a></th><th><a href="https://en.wikipedia.org/wiki/Linux" title="Linux"><span style="color: #990000;">Linux</span></a></th></tr>
<tr><td><pre>D:\myprogram\
|
---> org\
|
---> mypackage\
|
---> HelloWorld.class
---> SupportClass.class
---> UtilClass.class
</pre>
</td><td><pre>/home/user/myprogram/
|
---> org/
|
---> mypackage/
|
---> HelloWorld.class
---> SupportClass.class
---> UtilClass.class
</pre>
</td></tr>
</tbody></table>
<br />
<br />
When we invoke Java, we specify the name of the application to run: org.mypackage.HelloWorld. However we must also tell Java where to look for the files and directories defining our package. So to launch the program, we use the following command:<br />
<table class="wikitable" style="font-size: 90%;"><tbody>
<tr><th><br />
<a href="https://en.wikipedia.org/wiki/Microsoft_Windows" title="Microsoft Windows">Microsoft Windows</a></th><th><a href="https://en.wikipedia.org/wiki/Linux" title="Linux">Linux</a></th></tr>
<tr><td><pre> java -classpath D:\myprogram org.mypackage.HelloWorld
</pre>
</td><td><pre> java -cp /home/user/myprogram org.mypackage.HelloWorld
</pre>
</td></tr>
</tbody></table>
where:<br />
<ul>
<li><code>java</code> is a <a href="https://en.wikipedia.org/wiki/Java_virtual_machine#Execution_environment" title="Java virtual machine">java application launcher</a>, a type of sdkTool(A command-line tool, such as javac, javadoc, or apt)</li>
<li><i>-classpath D:\myprogram</i> sets the path to the packages used in the program (on Linux, <i>-cp /home/user/myprogram</i>) and</li>
<li><i>org.mypackage.HelloWorld</i> is the name of the main class</li>
</ul>
<h3>
<span class="mw-headline" id="Setting_the_path_through_an_environment_variable" style="color: #660000;">Setting the path through an environment variable</span></h3>
The <a href="https://en.wikipedia.org/wiki/Environment_variable" title="Environment variable">environment variable</a> named <code>CLASSPATH</code> may be alternatively used to set the classpath. For the above example, we could also use on Windows:<br />
<div class="mw-highlight mw-content-ltr" dir="ltr">
<pre><span class="k">
</span></pre>
<pre><span class="k">set</span> <span class="nv">CLASSPATH</span><span class="o">=</span>D:\myprogram
java org.mypackage.HelloWorld
</pre>
</div>
<br />
The rule is that <code>-classpath</code> option, when used to start the java application, overrides the <code>CLASSPATH</code> environment variable. If none are specified, the <a href="https://en.wikipedia.org/wiki/Working_directory" title="Working directory">current working directory</a> is used as classpath. This means that when our working directory is <code>D:\myprogram\</code> (on Linux, <code>/home/user/myprogram/</code>), we would not need to specify the classpath explicitly. When overriding however, it is advised to include current folder <code>"."</code> into the classpath in the case when loading classes from current folder is desired.<br />
The same applies not only to java launcher but also to <a href="https://en.wikipedia.org/wiki/Javac" title="Javac">javac</a>, the java compiler.<br />
<h3>
<span class="mw-headline" id="Setting_the_path_of_a_Jar_file" style="color: #660000;">Setting the path of a Jar file</span></h3>
If a program uses a supporting library enclosed in a <a href="https://en.wikipedia.org/wiki/JAR_(file_format)" title="JAR (file format)">Jar file</a> called <i>supportLib.jar</i>, physically in the directory <i>D:\myprogram\lib\</i> and the corresponding physical file structure is:<br />
<pre>D:\myprogram\
|</pre>
<pre> ---> lib\
</pre>
<pre> |
---> supportLib.jar
|
---> org\
|
--> mypackage\
|
---> HelloWorld.class
---> SupportClass.class
---> UtilClass.class
</pre>
<br />
<br />
the following <a href="https://en.wikipedia.org/wiki/Command-line_interface#Command-line_option" title="Command-line interface">command-line option</a> is needed:<br />
<pre>
</pre>
<pre>java -classpath D:\myprogram;D:\myprogram\lib\supportLib.jar org.mypackage.HelloWorld
</pre>
or alternatively:<br />
<pre>
</pre>
<pre>set CLASSPATH=D:\myprogram;D:\myprogram\lib\supportLib.jar
java org.mypackage.HelloWorld
</pre>
<h3>
<span class="mw-headline" id="Adding_all_JAR_files_in_a_directory" style="color: #660000;">Adding all JAR files in a directory</span></h3>
In <a class="mw-redirect" href="https://en.wikipedia.org/wiki/Java_6" title="Java 6">Java 6</a> and higher, one can add all jar-files in a specific directory to the classpath using wildcard notation.<br />
<br />
<span style="color: #cc0000;">Windows example:</span><br />
<pre>java -classpath ".;c:\mylib\*" MyApp</pre>
<br />
<br />
<span style="color: #990000;">Linux example:</span><br />
<pre>java -classpath '.:/mylib/*' MyApp
</pre>
<br />
This works for both <code>-classpath</code> options and environment classpaths.</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<b></b><i></i><u></u><sub></sub><sup></sup><strike><br /></strike></div>
<div class="b_lBottom b_snippet">
<br /></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-58631607580465612612016-01-28T23:56:00.000-08:002016-01-29T21:40:02.269-08:00Hibernate<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
</h2>
<br />
<a href="http://howtodoinjava.com/category/frameworks/hibernate/" title="hibernate"><strong><em>Hibernate</em></strong></a> an open source Java persistence framework project. Perform powerful object relational mapping and query databases using HQL and SQL. Hibernate is a great tool for ORM mappings in java. It can cut down a lot of complexity and thus defects as well from your application, which may otherwise find a way to exist. This is specially boon for developers with limited knowledge of SQL.<br />
In this page, I have categorize all available hibernate tutorials in this blog. This page will be updated every time, a new hibernate tutorial is published in this blog. <br />
<span style="color: yellow;"><br /></span>
<h3 style="text-align: left;">
<span style="color: red;">Hibernate Framework</span></h3>
<br />
Hibernate framework simplifies the development of java application to interact with the database. Hibernate is an open source, lightweight, <a href="http://en.wikipedia.org/wiki/Object-relational_mapping" target="_blank">ORM (Object Relational Mapping)</a> tool. <br />
An ORM tool simplifies the data creation, data manipulation and data access. It is a programming technique that maps the object to the data stored in the database.<br />
<img alt="hibernate tutorial, An introduction to hibernate" src="http://www.javatpoint.com/images/hibernate/orm.jpg" /> <br />
The ORM tool internally uses the JDBC API to interact with the database. <br />
<hr />
<a class="hibernateframeworkadvantage" href="https://www.blogger.com/null"><br /></a> <br />
<h3 class="h3">
Advantages of Hibernate Framework</h3>
There are many advantages of Hibernate Framework. They are as follows:<br />
<strong>1) Opensource and Lightweight:</strong> Hibernate framework is opensource under the LGPL license and lightweight.<br />
<strong><br /></strong>
<strong>2) Fast performance:</strong> The performance of hibernate framework is fast because cache is internally used in hibernate framework. There are two types of cache in hibernate framework first level cache and second level cache. First level cache is enabled bydefault.<br />
<strong><br /></strong>
<strong>3) Database Independent query:</strong> HQL (Hibernate Query Language) is the object-oriented version of SQL. It generates the database independent queries. So you don't need to write database specific queries. Before Hibernate, If database is changed for the project, we need to change the SQL query as well that leads to the maintenance problem.<br />
<strong><br /></strong>
<strong>4) Automatic table creation:</strong> Hibernate framework provides the facility to create the tables of the database automatically. So there is no need to create tables in the database manually.<br />
<strong><br /></strong>
<strong>5) Simplifies complex join:</strong> To fetch data form multiple tables is easy in hibernate framework.<br />
<strong><br /></strong>
<br />
<div style="text-align: left;">
6) <b>Provides query statistics and database status</b>: Hibernate supports Query cache and provide statistics about query and database status.</div>
<!-- Quick Adsense WordPress Plugin: http://quicksense.net/ --><br />
<div style="float: left; margin: 0px 0px 0px 0;">
<div id="adsensead1" style="height: 280px; margin: 0px 20px 20px 0px; width: 336px;">
<div>
<!-- HowToDoInJava - At Post Start --> <br />
<ins class="adsbygoogle" data-ad-client="ca-pub-2827350136257294" data-ad-slot="6068795363" data-adsbygoogle-status="done" style="display: inline-block; height: 280px; width: 336px;"><ins id="aswift_0_expand" style="background-color: transparent; border: none; display: inline-table; height: 280px; margin: 0; padding: 0; position: relative; visibility: visible; width: 336px;"><ins id="aswift_0_anchor" style="background-color: transparent; border: none; display: block; height: 280px; margin: 0; padding: 0; position: relative; visibility: visible; width: 336px;"><iframe allowfullscreen="true" allowtransparency="true" frameborder="0" height="280" hspace="0" id="aswift_0" marginheight="0" marginwidth="0" name="aswift_0" scrolling="no" style="left: 0; position: absolute; top: 0;" vspace="0" width="336"></iframe></ins></ins></ins></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
</div>
</div>
</div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-85653120824454371512016-01-27T07:09:00.000-08:002016-01-27T07:09:01.819-08:00Operators<div dir="ltr" style="text-align: left;" trbidi="on">
. Operators are special symbols that perform specific operations on one, two, or three <i>operands</i>, and then return a result.<br />
<br />
As we explore the operators of the Java programming language, it may be helpful for you to know ahead of time which operators have the highest precedence. The operators in the following table are listed according to precedence order. The closer to the top of the table an operator appears, the higher its precedence. Operators with higher precedence are evaluated before operators with relatively lower precedence. Operators on the same line have equal precedence. When operators of equal precedence appear in the same expression, a rule must govern which is evaluated first. All binary operators except for the assignment operators are evaluated from left to right; assignment operators are evaluated right to left.<br />
<table border="1" cellpadding="5" summary="This table lists operators according to precedence order"><caption id="nutsandbolts-precedence"><strong>Operator Precedence</strong></caption><tbody>
<tr><th id="h1">Operators</th><th id="h2">Precedence</th></tr>
<tr><td headers="h1">postfix</td><td headers="h2"><code><em><span style="font-family: Courier;">expr</span></em><span style="font-family: Courier;">++ </span><em><span style="font-family: Courier;">expr</span></em><span style="font-family: Courier;">--</span></code></td></tr>
<tr><td headers="h1">unary</td><td headers="h2"><code><span style="font-family: Courier;">++</span><em><span style="font-family: Courier;">expr</span></em><span style="font-family: Courier;"> --</span><em><span style="font-family: Courier;">expr</span></em><span style="font-family: Courier;"> +</span><em><span style="font-family: Courier;">expr</span></em><span style="font-family: Courier;"> -</span><em><span style="font-family: Courier;">expr</span></em><span style="font-family: Courier;"> ~ !</span></code></td></tr>
<tr><td headers="h1">multiplicative</td><td headers="h2"><code><span style="font-family: Courier;">* / %</span></code></td></tr>
<tr><td headers="h1">additive</td><td headers="h2"><code><span style="font-family: Courier;">+ -</span></code></td></tr>
<tr><td headers="h1">shift</td><td headers="h2"><code><span style="font-family: Courier;"><< >> >>></span></code></td></tr>
<tr><td headers="h1">relational</td><td headers="h2"><code><span style="font-family: Courier;">< > <= >= instanceof</span></code></td></tr>
<tr><td headers="h1">equality</td><td headers="h2"><code><span style="font-family: Courier;">== !=</span></code></td></tr>
<tr><td headers="h1">bitwise AND</td><td headers="h2"><code><span style="font-family: Courier;">&</span></code></td></tr>
<tr><td headers="h1">bitwise exclusive OR</td><td headers="h2"><code><span style="font-family: Courier;">^</span></code></td></tr>
<tr><td headers="h1">bitwise inclusive OR</td><td headers="h2"><code><span style="font-family: Courier;">|</span></code></td></tr>
<tr><td headers="h1">logical AND</td><td headers="h2"><code><span style="font-family: Courier;">&&</span></code></td></tr>
<tr><td headers="h1">logical OR</td><td headers="h2"><code><span style="font-family: Courier;">||</span></code></td></tr>
<tr><td headers="h1">ternary</td><td headers="h2"><code><span style="font-family: Courier;">? :</span></code></td></tr>
<tr><td headers="h1">assignment</td><td headers="h2"><code><span style="font-family: Courier;">= += -= *= /= %= &= ^= |= <<= >>= >>>=</span></code></td></tr>
</tbody></table>
<span style="font-family: Courier;"></span><br />
In general-purpose programming, certain operators tend to appear more frequently than others;<br />
<br />
for example, the assignment operator "<code><span style="font-family: Courier;">=</span></code>" is far more common than the unsigned right shift operator "<code><span style="font-family: Courier;">>>></span></code>". With that in mind, the following discussion focuses first on the operators that you're most likely to use on a regular basis, and ends focusing on those that are less common. Each discussion is accompanied by sample code that you can compile and and run. Studying its output will help reinforce what you've just learned<b></b><i></i><u></u><sub></sub><sup></sup><strike></strike></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-36256737929730290862016-01-26T08:40:00.002-08:002016-01-26T08:41:25.251-08:00Difference between Java and C++ language:<div dir="ltr" style="text-align: left;" trbidi="on">
<ul style="text-align: left;">
<li>According to some experts, Java is pure object oriented programming language while C++ is object based programming language.</li>
<li>The code written in Java can run on different platforms whereas this not possible with C++.</li>
<li>Java is mainly used for developed applets and e-commerce based applications while C++ is used for developing system software.</li>
</ul>
<b></b><i></i><u></u><sub></sub><sup></sup><strike></strike><br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-16557096460263721832015-01-24T20:27:00.003-08:002015-01-24T20:27:56.959-08:00 Comparable vs Comparator in Java <div dir="ltr" style="text-align: left;" trbidi="on">
<b><span style="color: blue;">Comparable vs Comparator is very important question asked in java interviews especially for experienced developer.</span></b><br /><br /><table border="1" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; border-spacing: 0px; color: #333333; font-family: Arial, serif; font-size: 14px; line-height: 22.8199996948242px;"><tbody>
<tr><td style="margin: 0px; padding: 0px;"><b>Parameter</b></td><td style="margin: 0px; padding: 0px;"><b>Comparable</b></td><td style="margin: 0px; padding: 0px;"><b>Comparator</b></td></tr>
<tr><td style="margin: 0px; padding: 0px;">Sorting logic</td><td style="margin: 0px; padding: 0px;">Sorting logic must be in same class whose objects are being sorted. Hence this is called natural ordering of objects</td><td style="margin: 0px; padding: 0px;">Sorting logic is in separate class. Hence we can write different sorting based on different attributes of objects to be sorted. E.g. Sorting using id,name etc.</td></tr>
<tr><td style="margin: 0px; padding: 0px;">Implementation</td><td style="margin: 0px; padding: 0px;">Class whose objects to be sorted must implement this interface.e.g Country class needs to implement comparable to collection of country object by id</td><td style="margin: 0px; padding: 0px;">Class whose objects to be sorted do not need to implement this interface.Some other class can implement this interface. E.g.-CountrySortByIdComparator class can implement Comparator interface to sort collection of country object by id</td></tr>
<tr><td style="margin: 0px; padding: 0px;"><a class="ext-link" data-wpel-target="_blank" href="http://www.blogger.com/blogger.g?blogID=1114068605611316469" name="_GoBack" rel="external nofollow" style="color: #326693; text-decoration: none;" title=""></a><br />Sorting method</td><td style="margin: 0px; padding: 0px;">int compareTo(Object o1)<br />This method compares this object with o1 object and returns a integer.Its value has following meaning<br />1. positive – this object is greater than o1<br />2. zero – this object equals to o1<br />3. negative – this object is less than o1</td><td style="margin: 0px; padding: 0px;">int compare(Object o1,Object o2)<br />This method compares o1 and o2 objects. and returns a integer.Its value has following meaning.<br />1. positive – o1 is greater than o2<br />2. zero – o1 equals to o2<br />3. negative – o1 is less than o1</td></tr>
<tr><td style="margin: 0px; padding: 0px;">Calling method</td><td style="margin: 0px; padding: 0px;">Collections.sort(List)<br />Here objects will be sorted on the basis of CompareTo method</td><td style="margin: 0px; padding: 0px;">Collections.sort(List, Comparator)<br />Here objects will be sorted on the basis of Compare method in Comparator</td></tr>
<tr><td style="margin: 0px; padding: 0px;">Package</td><td style="margin: 0px; padding: 0px;">Java.lang.Comparable<div style="margin-bottom: 20px; margin-top: 10px; padding: 0px;">
</div>
<div style="margin-bottom: 20px; margin-top: 10px; padding: 0px;">
<br /></div>
</td><td style="margin: 0px; padding: 0px;">Java.util.Comparator<br /></td></tr>
</tbody></table>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-2525225505672900302014-12-13T04:59:00.001-08:002014-12-13T04:59:30.450-08:00Difference between checked and unchecked exceptions<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background: rgb(255, 255, 255); border: 0px; clear: both; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
<span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="font-size: 14px; line-height: 17.8048000335693px;"><b>Most of the java developers reads checked and unchecked exception difference, while reading difference below question may came in his/her mind. </b></span></span></div>
<h3 style="text-align: left;">
<b style="line-height: 17.8048000335693px;">Question- </b></h3>
<div style="background: rgb(255, 255, 255); border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 17.8048000335693px; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
<span style="line-height: 17.8048000335693px;">In a tutorial I found </span><strong style="background: transparent; border: 0px; line-height: 17.8048000335693px; margin: 0px; padding: 0px; vertical-align: baseline;">that Unchecked Exception can't be handled by your code</strong><span style="line-height: 17.8048000335693px;"> </span><span style="line-height: 17.8048000335693px;">i.e. we can't use</span><span style="line-height: 17.8048000335693px;"> </span><code style="background: rgb(238, 238, 238); border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; line-height: 17.8048000335693px; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;">try/catch</code><span style="line-height: 17.8048000335693px;"> </span><span style="line-height: 17.8048000335693px;">block and the examples are exceptions like</span><span style="line-height: 17.8048000335693px;"> </span><code style="background: rgb(238, 238, 238); border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; line-height: 17.8048000335693px; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;">ArrayIndexOutOfBoundsException, NullPointerException.</code><span style="line-height: 17.8048000335693px;"> </span><span style="line-height: 17.8048000335693px;">But these exceptions can be handled using try/catch block. I think i am not clear about the concept !!</span></div>
<div style="background: rgb(255, 255, 255); border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 17.8048000335693px; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
Also i think throw keyword can be used only with <code style="background: rgb(238, 238, 238); border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;">try/catch</code> block.can throw Keyword be used with <code style="background: rgb(238, 238, 238); border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;">UncheckedException</code>?</div>
<div style="background: rgb(255, 255, 255); border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 17.8048000335693px; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
<h3>
<b style="line-height: 17.8048000335693px;">Answer - </b></h3>
</div>
<div style="background: rgb(255, 255, 255); border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 17.8048000335693px; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
The only difference between checked and unchecked exceptions is that checked ones <em style="background: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">have</em> to be either caught or declared in the method signature using <code style="background: rgb(238, 238, 238); border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;">throws</code>, whereas with unchecked ones this is optional.</div>
<blockquote style="background: rgb(238, 238, 238); border: 0px; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 17.8048000335693px; margin: 0px 0px 10px; padding: 10px 10px 1px; quotes: none; vertical-align: baseline;">
<div style="background: transparent; border: 0px; clear: both; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
Unchecked Exception can't be handled by your code i.e. we can't use try/catch block</div>
</blockquote>
<div style="background: rgb(255, 255, 255); border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 17.8048000335693px; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
Sure we can - but we don't have to.</div>
<blockquote style="background: rgb(238, 238, 238); border: 0px; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 17.8048000335693px; margin: 0px 0px 10px; padding: 10px 10px 1px; quotes: none; vertical-align: baseline;">
<div style="background: transparent; border: 0px; clear: both; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
Also i think throw keyword can be used only with try/catch block.can throw Keyword be used with Unchecked Exception?</div>
</blockquote>
<div style="background: rgb(255, 255, 255); border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 17.8048000335693px; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
Note that there are <em style="background: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">two</em> keywords:</div>
<ul style="background: rgb(255, 255, 255); border: 0px; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 17.8048000335693px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1em 30px; padding: 0px; vertical-align: baseline;">
<li style="background: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(238, 238, 238); border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;">throw</code> explicitly throws an exception object you created. <code style="background: rgb(238, 238, 238); border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;">throw new NullPointerException();</code>works perfectly fine, though explicitly creating that particular exception is uncommon and most would consider it bad style.</li>
<li style="background: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(238, 238, 238); border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;">throws</code> declares that a method may throw that exception. With unchecked exceptions this is optional, but can be useful to document the fact (again, one would normally not declared <code style="background: rgb(238, 238, 238); border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;">throws NullPointerException</code> because that is pretty much a given).</li>
</ul>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-68410247531923557522014-12-13T04:33:00.000-08:002014-12-13T04:33:43.906-08:00Java Singleton Design Pattern Best Practices with Examples<div dir="ltr" style="text-align: left;" trbidi="on">
<h1 style="background: white; margin-bottom: 13.5pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; mso-line-height-alt: 19.45pt; vertical-align: baseline;">
</h1>
<div>
<strong style="line-height: 21px;"><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1pt none windowtext; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt; padding: 0in;">Singleton</span></strong><span class="apple-converted-space" style="line-height: 21px;"><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;"> </span><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;">is one of the<span class="apple-converted-space"> </span></span><strong style="font-stretch: inherit;"><span style="border: 1pt none windowtext; font-family: Arial, sans-serif; padding: 0in;">Gangs of Four Design patterns</span></strong><span class="apple-converted-space"> and comes in the<span class="apple-converted-space"> </span></span><strong style="font-stretch: inherit;"><span style="border: 1pt none windowtext; font-family: Arial, sans-serif; padding: 0in;">Creational Design Pattern </span></strong>category</span><span style="background-color: white; line-height: 21px;">. Here we will learn about Singleton design pattern principles, different ways to implement Singleton and some of the best practices for its usage.</span></div>
<div>
<span style="background-color: white; line-height: 21px;"><br /></span></div>
<h2 style="background: white; margin-bottom: 13.5pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; mso-line-height-alt: 19.45pt; vertical-align: baseline;">
<span style="color: #333333; font-family: "Oswald","serif"; font-size: 24.0pt; font-weight: normal; letter-spacing: .75pt;">Singleton Pattern<o:p></o:p></span></h2>
<div class="MsoNormal" style="background: white; margin-bottom: 3pt;">
<span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;">Singleton pattern
restricts the instantiation of a class and ensures that only one instance of
the class exists in the java virtual machine. The singleton class must provide
a global access point to get the instance of the class. Singleton pattern is
used for<span class="apple-converted-space"> </span></span><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1pt none windowtext; font-family: Arial, sans-serif; font-size: 11.5pt; padding: 0in;">logging</span><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;">, driver’s objects, and caching and<span class="apple-converted-space"> </span></span><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1pt none windowtext; font-family: Arial, sans-serif; font-size: 11.5pt; padding: 0in;">thread pool</span><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;">.</span><o:p></o:p></div>
<div class="MsoNormal" style="background: white; margin-bottom: 3pt;">
<span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;">Singleton design pattern
is also used in other design patterns like<span class="apple-converted-space"> </span></span><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1pt none windowtext; font-family: Arial, sans-serif; font-size: 11.5pt; padding: 0in;">Abstract
Factory</span><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;">,<span class="apple-converted-space"> </span></span><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1pt none windowtext; font-family: Arial, sans-serif; font-size: 11.5pt; padding: 0in;">Builder</span><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;">,<span class="apple-converted-space"> </span></span><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1pt none windowtext; font-family: Arial, sans-serif; font-size: 11.5pt; padding: 0in;">Prototype</span><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;">,</span> Façade<span class="apple-converted-space"><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;"> </span></span><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;">etc. Singleton design
pattern is used in core java classes also, for example<span class="apple-converted-space"> </span></span><code style="background-attachment: initial; background-clip: initial; background-image: linear-gradient(rgb(248, 248, 248), rgb(243, 243, 243)); background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-radius: 4px; box-shadow: rgba(0, 0, 0, 0.2) 0px 1px 1px; font-stretch: inherit;"><b><span style="border: none windowtext 1.0pt; color: #333333; font-family: Consolas; font-size: 9.0pt; mso-border-alt: none windowtext 0in; mso-fareast-font-family: Calibri; padding: 0in;">java.lang.Runtime</span></b></code><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;">, </span><code><b><span style="border: none windowtext 1.0pt; color: #333333; font-family: Consolas; font-size: 9.0pt; mso-border-alt: none windowtext 0in; mso-fareast-font-family: Calibri; padding: 0in;">java.awt.Desktop</span></b></code><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;">.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; margin-bottom: 3pt;">
<br /></div>
<h2 style="background: white; margin-bottom: 13.5pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; mso-line-height-alt: 19.45pt; vertical-align: baseline;">
<span style="color: #333333; font-family: "Oswald","serif"; font-size: 24.0pt; font-weight: normal; letter-spacing: .75pt;">Java Singleton Pattern<o:p></o:p></span></h2>
<div class="MsoNormal" style="background: white; margin-bottom: 3pt;">
<span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;">To implement Singleton
pattern, we have different approaches but all of them have following common
concepts.</span><o:p></o:p></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 3.0pt; mso-list: l1 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="color: #333333; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.5pt; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">Private constructor to restrict instantiation of the class from
other classes.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 3.0pt; mso-list: l1 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="color: #333333; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.5pt; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">Private static variable of the same class that is the only
instance of the class.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 3.0pt; mso-list: l1 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="color: #333333; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.5pt; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">Public static method that returns the instance of the class,
this is the global access point for outer world to get the instance of the
singleton class.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 3.0pt; vertical-align: baseline;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .25in; vertical-align: baseline;">
<b><span style="color: #333333; font-family: "Arial","sans-serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">Different approaches of Singleton pattern</span></b><span style="color: #333333; font-family: "Arial","sans-serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> implementation and design concerns with the
implementation.<o:p></o:p></span><br />
<span style="color: #333333; font-family: "Arial","sans-serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><br /></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo2; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="background-color: white;"><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: inherit; mso-fareast-font-family: inherit;">1.<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";"><span style="color: #21759b; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">Eager initialization</span><o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo2; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="background-color: white;"><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: inherit; mso-fareast-font-family: inherit;">2.<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";"><span style="color: #21759b; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">Static block initialization</span><o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo2; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="background-color: white;"><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: inherit; mso-fareast-font-family: inherit;">3.<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";"><span style="color: #21759b; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">Lazy Initialization</span><o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo2; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="background-color: white;"><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: inherit; mso-fareast-font-family: inherit;">4.<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";"><span style="color: #21759b; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">Thread Safe Singleton</span><o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo2; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="background-color: white;"><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: inherit; mso-fareast-font-family: inherit;">5.<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";"><span style="color: #21759b; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">Bill Pugh Singleton Implementation</span><o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo2; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="background-color: white;"><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: inherit; mso-fareast-font-family: inherit;">6.<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";"><span style="color: #21759b; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">Using Reflection to destroy Singleton Pattern</span><o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo2; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="background-color: white;"><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: inherit; mso-fareast-font-family: inherit;">7.<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";"><span style="color: #21759b; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">Enum Singleton</span><o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo2; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="background-color: white;"><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: inherit; mso-fareast-font-family: inherit;">8.<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--></span><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";"><span style="color: #21759b; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">Serialization and Singleton</span><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo2; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";"><span style="color: #21759b; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;"><br /></span></span></div>
<div class="MsoNormal" style="background: white; margin-bottom: 3pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; margin-bottom: 3pt;">
<b><span style="color: #333333; font-family: "Arial","sans-serif"; font-size: 11.5pt;">Eager Initialization</span></b><b><span style="color: #3c3c3c; font-family: "Arial","sans-serif"; font-size: 10.5pt;"><o:p></o:p></span></b></div>
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: 18.2pt; margin: 0in 0in 0.25in; vertical-align: baseline;">
<span style="color: #333333; font-family: "Arial","sans-serif"; font-size: 11.5pt;">In
eager initialization, the instance of Singleton Class is created at the time of
class loading, this is the easiest method to create a singleton class but it
has a drawback that instance is created even though client application might
not be using it.<o:p></o:p></span></div>
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; font-stretch: inherit; line-height: 18.2pt; margin: 0in 0in 0.25in; vertical-align: baseline;">
<span style="color: #333333; font-family: "Arial","sans-serif"; font-size: 11.5pt;">Here is the implementation of static initialization singleton
class.<o:p></o:p></span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="background: #FBD4B4; border-collapse: collapse; border: none; mso-background-themecolor: accent6; mso-background-themetint: 102; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 0in 0in 0in; mso-yfti-tbllook: 1184; width: 672px;">
<tbody>
<tr>
<td colspan="2" style="border-bottom: none; border: solid windowtext 1.0pt; mso-border-left-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> EagerInitializedSingleton.java<o:p></o:p></span></b></div>
</td>
</tr>
<tr>
<td style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">1<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">2<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">3<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">4<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">5<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">6<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">7<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">8<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">9<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">10<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">11<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">12<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">13<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 0in 0in 0in; width: 604.5pt;" width="806"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">package</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">com.journaldev.singleton;</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">public</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">class</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">EagerInitializedSingleton {</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> private</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">static</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">final</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">EagerInitializedSingleton
instance = new</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">EagerInitializedSingleton();</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> //private
constructor to avoid client applications to use constructor</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> private</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">EagerInitializedSingleton(){}</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> public</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">static</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">EagerInitializedSingleton getInstance(){</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> return</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">instance;</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> }</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">}</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
</div>
<h3 style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: 19.45pt; margin: 0in 0in 13.5pt; vertical-align: baseline;">
<span style="color: #333333; font-family: "Oswald","serif"; font-size: 18.0pt; font-weight: normal; letter-spacing: .75pt;">Static block initialization<o:p></o:p></span></h3>
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: 18.2pt; margin: 0in 0in 0.25in; vertical-align: baseline;">
<span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1pt none windowtext; color: #21759b; font-family: Arial, sans-serif; font-size: 11.5pt; padding: 0in;">Static block</span><span class="apple-converted-space"><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;"> </span><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;">initialization implementation is similar to eager
initialization, except that instance of class is created in the static block
that provides option for<span class="apple-converted-space"> </span></span></span><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1pt none windowtext; color: #21759b; font-family: Arial, sans-serif; font-size: 11.5pt; padding: 0in;">exception handling</span><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;">.<o:p></o:p></span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="background: #FBD4B4; border-collapse: collapse; border: none; mso-background-themecolor: accent6; mso-background-themetint: 102; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 0in 0in 0in; mso-yfti-tbllook: 1184; width: 672px;">
<tbody>
<tr>
<td colspan="2" style="border-bottom: none; border: solid windowtext 1.0pt; mso-border-left-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> StaticBlockSingleton.java<o:p></o:p></span></b></div>
</td>
</tr>
<tr>
<td style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">1<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">2<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">3<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">4<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">5<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">6<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">7<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">8<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">9<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">10<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">11<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">12<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">13<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">14<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">15<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">16<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">17<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">18<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">19<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">20<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">21<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 0in 0in 0in; width: 585.75pt;" width="781"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">package</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">com.journaldev.singleton;</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">public</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">class</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">StaticBlockSingleton {</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> private</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">static</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">StaticBlockSingleton instance;</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> private</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">StaticBlockSingleton(){}</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> //static
block initialization for exception handling</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> static{</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> try{</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> instance
= new</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">StaticBlockSingleton();</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> }catch(Exception
e){</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> throw</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">new</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">RuntimeException("Exception occured in creating <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> singleton instance");</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> }</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> }</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> public</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">static</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">StaticBlockSingleton getInstance(){</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> return</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">instance;</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> }</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">}</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
</div>
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: 18.2pt; margin: 0in 0in 0.25in; vertical-align: baseline;">
<span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;">Both eager initialization and static block initialization
creates the instance even before it’s being used and that is not the best
practice to use. So in further sections, we will learn how to create Singleton
class that supports lazy initialization.</span><span style="color: #333333; font-family: "Arial","sans-serif"; font-size: 11.5pt;"><o:p></o:p></span></div>
<h3 style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: 19.45pt; margin: 0in 0in 13.5pt; vertical-align: baseline;">
<span style="color: #333333; font-family: "Oswald","serif"; font-size: 18.0pt; font-weight: normal; letter-spacing: .75pt;">Lazy Initialization<o:p></o:p></span></h3>
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; font-stretch: inherit; line-height: 18.2pt; margin: 0in 0in 0.25in; vertical-align: baseline;">
<span style="color: #333333; font-family: "Arial","sans-serif"; font-size: 11.5pt;">Lazy initialization method to implement Singleton pattern
creates the instance in the global access method. Here is the sample code for
creating Singleton class with this approach.<o:p></o:p></span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="background: #FBD4B4; border-collapse: collapse; border: none; mso-background-themecolor: accent6; mso-background-themetint: 102; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 0in 0in 0in; mso-yfti-tbllook: 1184; width: 672px;">
<tbody>
<tr>
<td colspan="2" style="border-bottom: none; border: solid windowtext 1.0pt; mso-border-left-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> LazyInitializedSingleton.java<o:p></o:p></span></b></div>
</td>
</tr>
<tr>
<td style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">1<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">2<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">3<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">4<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">5<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">6<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">7<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">8<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">9<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">10<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">11<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">12<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">13<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">14<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">15<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 0in 0in 0in; width: 529.5pt;" width="706"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">package</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">com.journaldev.singleton;</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">public</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">class</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">LazyInitializedSingleton {</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> private</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">static</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">LazyInitializedSingleton instance;</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> private</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">LazyInitializedSingleton(){}</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> public</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">static</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">LazyInitializedSingleton getInstance(){</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> if(instance
== null){</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> instance
= new</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">LazyInitializedSingleton();</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> }</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> return</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">instance;</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> }</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">}</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
</div>
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: 18.2pt; margin: 0in 0in 0.25in; vertical-align: baseline;">
<span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;">The above implementation works fine incase of single threaded
environment but when it comes to multithreaded systems, it can cause issues if
multiple threads are inside the if loop at the same time. It will destroy the
singleton pattern and both threads will get the different instances of
singleton class. In next section, we will see different ways to create a<span class="apple-converted-space"> </span></span><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1pt none windowtext; font-family: Arial, sans-serif; font-size: 11.5pt; padding: 0in;">thread-safe</span><span class="apple-converted-space"><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;"> </span></span><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt;">singleton
class.</span><o:p></o:p></div>
<h3 style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: 19.45pt; margin: 0in 0in 13.5pt; vertical-align: baseline;">
<span style="color: #333333; font-family: "Oswald","serif"; font-size: 18.0pt; font-weight: normal; letter-spacing: .75pt;">Thread Safe Singleton<o:p></o:p></span></h3>
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; font-stretch: inherit; line-height: 18.2pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;">
<span style="color: #333333; font-family: "Arial","sans-serif"; font-size: 11.5pt;">The
easier way to create a thread-safe singleton class is to make the global access
method<span class="apple-converted-space"> </span></span><span style="border: none windowtext 1.0pt; color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-border-alt: none windowtext 0in; padding: 0in;">synchronized</span><span style="color: #333333; font-family: "Arial","sans-serif"; font-size: 11.5pt;">, so that only one thread can execute this method at a time.
General implementation of this approach is like the below class.<o:p></o:p></span></div>
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: 18.2pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;">
<br /></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="background: #FBD4B4; border-collapse: collapse; border: none; mso-background-themecolor: accent6; mso-background-themetint: 102; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 0in 0in 0in; mso-yfti-tbllook: 1184; width: 672px;">
<tbody>
<tr>
<td colspan="2" style="border-bottom: none; border: solid windowtext 1.0pt; mso-border-left-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 0in 0in 0in;"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
<b><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">ThreadSafeSingleton.java<o:p></o:p></span></b></div>
</td>
</tr>
<tr>
<td style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">1<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">2<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">3<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">4<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">5<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">6<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">7<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">8<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">9<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">10<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">11<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">12<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">13<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">14<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">15<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">16<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 0in 0in 0in; width: 529.5pt;" width="706"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">package</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">com.journaldev.singleton;</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">public</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">class</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">ThreadSafeSingleton {</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> private</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">static</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">ThreadSafeSingleton instance;</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> private</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">ThreadSafeSingleton(){}</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> public</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">static</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">synchronized</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">ThreadSafeSingleton getInstance(){</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> if(instance
== null){</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> instance
= new</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">ThreadSafeSingleton();</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> }</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> return</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">instance;</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> }</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">}</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
</div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; margin-bottom: 3pt;">
</div>
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: 18.2pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;">
<br /></div>
<h3 style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: 19.45pt; margin: 0in 0in 13.5pt; vertical-align: baseline;">
<span style="color: #333333; font-family: "Oswald","serif"; font-size: 18.0pt; font-weight: normal; letter-spacing: .75pt;">Bill Pugh Singleton Implementation<o:p></o:p></span></h3>
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; font-stretch: inherit; line-height: 18.2pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;">
<span style="color: #333333; font-family: "Arial","sans-serif"; font-size: 11.5pt;">Prior
to Java 5, java memory model had a lot of issues and above approaches used to
fail in certain scenarios where too many threads try to get the instance of the
Singleton class simultaneously. So Bill Pugh came up with a different approach
to create the Singleton class using an<span class="apple-converted-space"> </span><span style="border: none windowtext 1.0pt; color: #21759b; font-family: "inherit","serif"; mso-border-alt: none windowtext 0in; padding: 0in; text-decoration: none; text-underline: none;">inner static helper class</span>. The Bill Pugh Singleton
implementation goes like this;<o:p></o:p></span></div>
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: 18.2pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;">
<br /></div>
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: 18.2pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;">
</div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="background: #FABF8F; border-collapse: collapse; border: none; mso-background-themecolor: accent6; mso-background-themetint: 153; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 0in 0in 0in; mso-yfti-tbllook: 1184; width: 672px;">
<tbody>
<tr>
<td colspan="2" style="border-bottom: none; border: solid windowtext 1.0pt; mso-border-left-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">BillPughSingleton.java<o:p></o:p></span></b></div>
</td>
</tr>
<tr>
<td style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">1<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">2<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">3<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">4<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">5<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">6<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">7<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">8<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">9<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">10<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">11<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">12<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">13<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";">14<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 0in 0in 0in; width: 530.25pt;" width="707"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">package</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">com.journaldev.singleton;</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">public</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">class</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">BillPughSingleton {</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> private</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">BillPughSingleton(){}</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> private</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">static</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">class</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">SingletonHelper{</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> private</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">static</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">final</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">BillPughSingleton
INSTANCE = new</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">BillPughSingleton();</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> }</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> public</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">static</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">BillPughSingleton getInstance(){</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> return</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">SingletonHelper.INSTANCE;</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> }</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #333333; font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">}</span><span style="color: #333333; font-family: "Times New Roman","serif"; font-size: 11.5pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
</div>
</div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-70252188608187894222014-12-13T03:45:00.001-08:002014-12-13T03:45:07.484-08:00Java Synchronization<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="background: white; margin-bottom: 13.5pt; mso-line-height-alt: 19.45pt; mso-outline-level: 2; vertical-align: baseline;">
<span style="color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt; line-height: 18.2pt;">Synchronization is the tool using which we can achieve thread
safety, JVM guarantees that synchronized code will be executed by only one thread
at a time.</span><span style="color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt; line-height: 18.2pt;"> </span><b style="line-height: 18.2pt;"><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">java keyword synchronized</span></b><span style="color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt; line-height: 18.2pt;"> </span><span style="color: #333333; font-family: Arial, sans-serif; font-size: 11.5pt; line-height: 18.2pt;">is used to create synchronized code and
internally it uses locks on Object or Class to make sure only one thread is
executing the synchronized code.</span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 3.0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="color: #333333; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.5pt; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">Java synchronization works on locking and unlocking of resource,
before any thread enters into synchronized code, it has to acquire lock on the
Object and when code execution ends, it unlocks the resource that can be locked
by other threads. In the mean time other threads are in wait state to lock the
synchronized resource.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 3.0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="color: #333333; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.5pt; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">We can use synchronized keyword in two ways, one is to make a
complete method synchronized and other way is to create synchronized block.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="color: #333333; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.5pt; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">When a method is synchronized, it locks the</span><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> <b>Object</b></span><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">, if method is static it locks the</span><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> <b>Class</b></span><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">, so it’s always best practice to use</span><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> <i>synchronized block</i> </span><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">to lock the only
sections of method that needs synchronization.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 3.0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="color: #333333; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.5pt; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">While creating synchronized block, we need to provide the
resource on which lock will be acquired, it can be XYZ.class or any Object
field of the class.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="color: #333333; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.5pt; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: Consolas; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">synchronized(this)</span><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">will lock the
Object before entering into the synchronized block.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="color: #333333; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.5pt; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">You should use the</span><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> <i>lowest
level of locking</i></span><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">, for example if there are multiple synchronized block in a
class and one of them is locking the Object, then other synchronized blocks
will also be not available for execution by other threads. When we lock an
Object, it acquires lock on all the fields of the Object.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 3.0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="color: #333333; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.5pt; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">Java Synchronization provides data integrity on the cost of
performance, so it should be used only when it’s absolutely necessary.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 3.0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="color: #333333; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.5pt; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">Java Synchronization works only in the same JVM, so if you need
to lock some resource in multiple JVM environments, it will not work and you
might have to look after some global locking mechanism.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="color: #333333; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.5pt; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">Java Synchronization could result in deadlocks; check this post
about</span><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";"><a href="http://www.journaldev.com/1058/java-deadlock-example-and-how-to-analyze-deadlock-situation" title="Java Deadlock Example and How to analyze deadlock situation"><span style="color: #21759b; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">deadlock in java and how to avoid them</span></a>.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 3.0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="color: #333333; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.5pt; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">Java synchronized keyword cannot be used for constructors and
variables.<o:p></o:p></span></div>
<div style="background-color: white; border: 0px; color: #333333; font-family: Oswald, sans-serif; font-size: 32px; font-stretch: inherit; letter-spacing: 1px; line-height: 1.62em; margin-bottom: 18px; padding: 0px; vertical-align: baseline;">
</div>
<div class="MsoNormal" style="background: white; line-height: 18.2pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 22.5pt; margin-right: 0in; margin-top: 3.0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="color: #333333; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.5pt; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; font-stretch: normal; line-height: normal;">
</span></span><!--[endif]--><span style="color: #333333; font-family: "inherit","serif"; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">It is preferable to create a dummy private Object to use for
synchronized block, so that its reference can’t be changed by any other code.
For example if you have a setter method for Object on which you are
synchronizing, it’s reference can be changed by some other code leads to
parallel execution of the synchronized block.<o:p></o:p></span></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-52340725073374772052014-11-17T21:09:00.001-08:002014-11-17T21:09:40.027-08:00What is JDBC Driver ?<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
JDBC drivers implement the defined interfaces in the JDBC API for interacting with your database server.<br />
<br />
For example, using JDBC drivers enable you to open database connections and to interact with it by sending SQL or database commands then receiving results with Java.<br />
<br />
The Java.sql package that ships with JDK contains various classes with their behaviours defined and their actual implementaions are done in third-party drivers. Third party vendors implements the java.sql.Driver interface in their database driver.<br />
<br />
<h3 style="text-align: left;">
<b>JDBC Drivers Types:</b></h3>
JDBC driver implementations vary because of the wide variety of operating systems and hardware platforms in which Java operates. Sun has divided the implementation types into four categories, Types 1, 2, 3, and 4, which is explained below:<br />
<br />
<h4 style="text-align: left;">
<b>Type 1: JDBC-ODBC Bridge Driver:</b></h4>
In a Type 1 driver, a JDBC bridge is used to access ODBC drivers installed on each client machine. Using ODBC requires configuring on your system a Data Source Name (DSN) that represents the target database.<br />
<br />
When Java first came out, this was a useful driver because most databases only supported ODBC access but now this type of driver is recommended only for experimental use or when no other alternative is available.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjabB1TOs8uKMGxH8jfrKI2ZUtxDwMLXfzMk2CTEq_3Swo1XAtNDgHBfnyVNzGIjt0IefDsDEDEqOXs2KEe97p8ZG_DNRlbY2b8OxBOtEcOhNhf4hVA1SlMw4d-R_hfN-tWmaFlqS7wKNsY/s1600/driver-type1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjabB1TOs8uKMGxH8jfrKI2ZUtxDwMLXfzMk2CTEq_3Swo1XAtNDgHBfnyVNzGIjt0IefDsDEDEqOXs2KEe97p8ZG_DNRlbY2b8OxBOtEcOhNhf4hVA1SlMw4d-R_hfN-tWmaFlqS7wKNsY/s1600/driver-type1.jpg" height="270" width="320" /></a></div>
The JDBC-ODBC bridge that comes with JDK 1.2 is a good example of this kind of driver.<br />
<br />
<h3 style="text-align: left;">
Type 2: JDBC-Native API:</h3>
In a Type 2 driver, JDBC API calls are converted into native C/C++ API calls which are unique to the database. These drivers typically provided by the database vendors and used in the same manner as the JDBC-ODBC Bridge, the vendor-specific driver must be installed on each client machine.<br />
<br />
If we change the Database we have to change the native API as it is specific to a database and they are mostly obsolete now but you may realize some speed increase with a Type 2 driver, because it eliminates ODBC's overhead.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmnzIcmZhxjzaq3fsyXGmlhdwM9AIMZ3pxXMf6NLieo0moXWeLl1_6Qwl47gwqey_9DsyUumqg2f-dnN-wkJqswCDdcPRWw4l_YkafQmak3l3qTfGvbzSMUVhUztTx9IhubBZg4gl9hsTd/s1600/driver-type2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmnzIcmZhxjzaq3fsyXGmlhdwM9AIMZ3pxXMf6NLieo0moXWeLl1_6Qwl47gwqey_9DsyUumqg2f-dnN-wkJqswCDdcPRWw4l_YkafQmak3l3qTfGvbzSMUVhUztTx9IhubBZg4gl9hsTd/s1600/driver-type2.jpg" height="270" width="320" /></a></div>
The Oracle Call Interface (OCI) driver is an example of a Type 2 driver.<br />
<br />
<h3 style="text-align: left;">
Type 3: JDBC-Net pure Java:</h3>
In a Type 3 driver, a three-tier approach is used to accessing databases. The JDBC clients use standard network sockets to communicate with an middleware application server. The socket information is then translated by the middleware application server into the call format required by the DBMS, and forwarded to the database server.<br />
<br />
This kind of driver is extremely flexible, since it requires no code installed on the client and a single driver can actually provide access to multiple databases.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTFbeO4EAKOTP73-xvlYsH2thGuy3mCklayZevlD-8pYLHIfr3Bflf2cor6ekGlh1Y7g04fc-oQRAwVFtRjR5vtKRd-hrfuyEhgaU4_6zUZ9NmuaJ2DyIsRyTiH0QYIG2sbBHss1qYVy5m/s1600/driver-type3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTFbeO4EAKOTP73-xvlYsH2thGuy3mCklayZevlD-8pYLHIfr3Bflf2cor6ekGlh1Y7g04fc-oQRAwVFtRjR5vtKRd-hrfuyEhgaU4_6zUZ9NmuaJ2DyIsRyTiH0QYIG2sbBHss1qYVy5m/s1600/driver-type3.jpg" height="242" width="320" /></a></div>
<br />
<br />
You can think of the application server as a JDBC "proxy," meaning that it makes calls for the client application. As a result, you need some knowledge of the application server's configuration in order to effectively use this driver type.<br />
<br />
Your application server might use a Type 1, 2, or 4 driver to communicate with the database, understanding the nuances will prove helpful.<br />
<br />
<h3 style="text-align: left;">
Type 4: 100% pure Java:</h3>
In a Type 4 driver, a pure Java-based driver that communicates directly with vendor's database through socket connection. This is the highest performance driver available for the database and is usually provided by the vendor itself.<br />
<br />
This kind of driver is extremely flexible, you don't need to install special software on the client or server. Further, these drivers can be downloaded dynamically.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNEprViOQ2fx9fozxYOKX2xgRXjbb37BSjNDWgcJH0GlYGko21s5FvIwwuWEetC21x2buucjJk2dYnLfFrIOnPj0bctXdGelkPqJSgb9Mt7TwFmi387RlGp9i0R5hLfzHRxnuk8MOFGX-Q/s1600/driver-type4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNEprViOQ2fx9fozxYOKX2xgRXjbb37BSjNDWgcJH0GlYGko21s5FvIwwuWEetC21x2buucjJk2dYnLfFrIOnPj0bctXdGelkPqJSgb9Mt7TwFmi387RlGp9i0R5hLfzHRxnuk8MOFGX-Q/s1600/driver-type4.jpg" height="293" width="320" /></a></div>
<br />
MySQL's Connector/J driver is a Type 4 driver. Because of the proprietary nature of their network protocols, database vendors usually supply type 4 drivers.<br />
<br />
<h3 style="text-align: left;">
Which Driver should be used?</h3>
If you are accessing one type of database, such as Oracle, Sybase, or IBM, the preferred driver type is 4.<br />
If your Java application is accessing multiple types of databases at the same time, type 3 is the preferred driver.<br />
Type 2 drivers are useful in situations where a type 3 or type 4 driver is not available yet for your database.<br />
The type 1 driver is not considered a deployment-level driver and is typically used for development and testing purposes only</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-78242915219320817182014-11-17T20:37:00.001-08:002014-11-17T20:37:14.449-08:00Arraylist vs Vector in Java<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<b>1. Synchronization and Thread-Safe</b><br />
<br />
Vector is synchronized while ArrayList is not synchronized . Synchronization and thread safe means at a time only one thread can access the code .In Vector class all the methods are synchronized .Thats why the Vector object is already synchronized when it is created .<br />
<br />
<b>2. Performance</b><br />
<br />
Vector is slow as it is thread safe . In comparison ArrayList is fast as it is non synchronized . Thus in ArrayList two or more threads can access the code at the same time , while Vector is limited to one thread at a time.<br />
<br />
<b>3. Automatic Increase in Capacity</b><br />
<br />
A Vector defaults to doubling size of its array . While when you insert an element into the ArrayList , it increases<br />
its Array size by 50% .<br />
<br />
<br />
By default ArrayList size is 10 . It checks whether it reaches the last element then it will create the new array ,copy the new data of last array to new array ,then old array is garbage collected by the Java Virtual Machine (JVM) .<br />
<br />
<b>4. Set Increment Size</b><br />
<br />
ArrayList does not define the increment size . Vector defines the increment size .<br />
<br />
You can find the following method in Vector Class<br />
<br />
public synchronized void setSize(int i) { //some code }<br />
<br />
There is no setSize() method or any other method in ArrayList which can manually set the increment size.<br />
<br />
<b>5. Enumerator</b><br />
<br />
Other than Hashtable ,Vector is the only other class which uses both Enumeration and Iterator .While ArrayList can only use Iterator for traversing an ArrayList .<br />
<br />
<b>6. Introduction in Java </b><br />
<br />
java.util.Vector class was there in java since the very first version of the java development kit (jdk).<br />
java.util.ArrayList was introduced in java version 1.2 , as part of Java Collections framework . In java version 1.2 , Vector class has been refactored to implement the List Inteface .<br />
<br />
<br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-68707347531990095492014-10-12T07:45:00.000-07:002014-10-12T07:45:03.818-07:00Difference between Struts1.X and Struts2.X<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 113.4pt;" valign="top" width="151"><div class="MsoNormal">
<b><span style="color: #7030a0; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">Difference Area<o:p></o:p></span></b></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 184.5pt;" valign="top" width="246"><div class="MsoNormal">
<b><span style="color: #7030a0; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"> Struts 1.X<o:p></o:p></span></b></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 180.9pt;" valign="top" width="241"><div class="MsoNormal">
<b><span style="color: #7030a0; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"> Struts 2.X<o:p></o:p></span></b></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 113.4pt;" valign="top" width="151"><div class="MsoNormal">
Action Class<o:p></o:p></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 184.5pt;" valign="top" width="246"><div class="MsoNormal">
In Struts 1
it's mandatory to extend org.apache.struts.action.Action and implement
execute() method which returns ActionForward and accept HttpServletRequest
and HttpServletResponse.<o:p></o:p></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 180.9pt;" valign="top" width="241"><div class="MsoNormal">
This is not the
case with Struts 2, here Action class can be a simple POJO or Java object
with execute() method. Also execute() method returns String rather than
returning ActionForward object. You
can still use ActionSupport class or
Action interface but those are completely optional.<o:p></o:p></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 113.4pt;" valign="top" width="151"><div class="MsoNormal">
Configuration
Files<o:p></o:p></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 184.5pt;" valign="top" width="246"><div class="MsoNormal">
<br /></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 180.9pt;" valign="top" width="241"><div class="MsoNormal">
<br /></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 113.4pt;" valign="top" width="151"><div class="MsoNormal">
<span style="color: #313131;"><span style="background-color: white;">Front Controller</span></span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 184.5pt;" valign="top" width="246"><div class="MsoNormal">
In struts 1.x front controller is ActionServlet</div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 180.9pt;" valign="top" width="241"><div class="MsoNormal">
In struts 2.x front controller is FilterDispatcher</div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 113.4pt;" valign="top" width="151"><div class="MsoNormal">
Servlet
Dependency<o:p></o:p></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 184.5pt;" valign="top" width="246"><div class="MsoNormal">
<div class="MsoNormal">
<span style="color: #333333;"><span style="background-color: white;">In action class, execute() method , it has HttpServletRequest and HttpServletResponse Object, both comes from servlet API</span></span></div>
</div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 180.9pt;" valign="top" width="241"><div class="MsoNormal">
<span style="color: #333333;"><span style="background-color: white;">Not needed in struts 2 execute() method</span></span></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 113.4pt;" valign="top" width="151"><div class="MsoNormal">
<span style="background: white; color: #333333; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">No Action Form</span><o:p></o:p></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 184.5pt;" valign="top" width="246"><div class="MsoNormal">
<span style="background: white; color: #333333; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">Struts 1 uses an ActionForm object to capture input. Like
Actions, all ActionForms must extend a base class. Since other
JavaBeans cannot be used as ActionForms, developers often create redundant
classes to capture input. </span><o:p></o:p></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 180.9pt;" valign="top" width="241"><div class="MsoNormal">
<span style="background: white; color: #333333; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">Struts 2 uses Action properties as input properties,
eliminating the need for a second input object</span><o:p></o:p></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 113.4pt;" valign="top" width="151"><div class="MsoNormal">
<span style="background: white; color: #333333; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">Control Of Action Execution</span><o:p></o:p></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 184.5pt;" valign="top" width="246"><div class="MsoNormal">
<span style="background: white;">Struts1 supports separate Request Processor (lifecycles)
for each module, but all the Actions in a module must share the same lifecycle</span><o:p></o:p></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 180.9pt;" valign="top" width="241"><div class="MsoNormal">
<span style="background: white; color: #333333; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">Struts 2 supports creating different lifecycles on a per
Action basis via Interceptor Stacks.</span><o:p></o:p></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 113.4pt;" valign="top" width="151"><h4 style="background: white;">
<span style="font-size: 11pt; line-height: 115%;"> </span><span style="font-size: 11pt; font-weight: normal; line-height: 115%;">Threading Model<o:p></o:p></span></h4>
<div class="MsoNormal">
<br /></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 184.5pt;" valign="top" width="246"><div class="MsoNormal">
Struts 1
Actions are singletons and must be thread-safe since there will only be one
instance of a class to handle all requests for that Action. The singleton
strategy places restrictions on what can be done with Struts 1 Actions and
requires extra care to develop. Action resources must be thread-safe or
synchronized.<o:p></o:p></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 180.9pt;" valign="top" width="241"><div class="MsoNormal">
<span style="background-color: white;">Struts2, Action objects are instantiated for each request, so there are no thread-safety issues</span></div>
</td>
</tr>
</tbody></table>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-30572986320195618202014-10-07T21:07:00.001-07:002014-10-07T21:48:40.879-07:00Java 8 Features <div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="background: white; margin: 0.1in 0in 0.2in; vertical-align: baseline;">
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 22.533332824707px;">Java 8 release e.g. lambda expressions, functional interface, stream API, default methods and new Date and Time API. </span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 22.533332824707px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 22.533332824707px;"><b>1. Lambda Expressions </b></span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 22.533332824707px;">One of feature, which is synonymous to this release, is lambda expressions, which will provide ability to pass behaviours to methods. Prior to Java 8, if you want to pass behaviour to a method, then your only option was Anonymous class, which will take 6 lines of code and most important line, which defines the behaviour is lost in between. Lambda expression replaces anonymous classes and removes all boiler plate, enabling you to write code in functional style, which is some time more readable and expression.</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 22.533332824707px;"><br /></span></span>
<br />
<h2 style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: 18pt; margin: 0in 0in 6pt;">
<span style="color: #00003f; font-family: "Arial","sans-serif"; font-size: 14.5pt;">Lambda Expressions Syntax<o:p></o:p></span></h2>
<br />
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: 13.65pt; margin: 0in 0in 0.25in;">
<span style="font-family: Arial, sans-serif; font-size: 10pt;">The basic syntax of a lambda is
either:</span></div>
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: 13.65pt; margin: 0in 0in 0.25in;">
<code style="line-height: 13.65pt;"><span style="font-size: 10pt;">(</span></code><em style="line-height: 13.65pt;"><span style="font-family: Arial, sans-serif; font-size: 10pt;">parameters</span></em><code style="line-height: 13.65pt;"><span style="font-size: 10pt;">) -></span></code><em style="line-height: 13.65pt;"><span style="font-family: Arial, sans-serif; font-size: 10pt;">expression </span></em><span class="apple-converted-space" style="line-height: 13.65pt;"><i><span style="font-family: Arial, sans-serif; font-size: 10pt;"> </span></i></span><span style="font-family: Arial, sans-serif; font-size: 10pt; line-height: 13.65pt;">or
(parameters) ->{ statements; }</span></div>
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; margin: 0in 0in 0.25in;">
<span style="font-family: Arial, sans-serif; font-size: x-small;"><span style="line-height: 18.2000007629395px;"><b>The following are examples of Java lambda expression:</b></span></span></div>
<div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1.5pt solid rgb(245, 243, 215); padding: 4pt 8pt;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">
<i><span style="font-family: 'Courier New'; font-size: 10pt;">1. </span></i><span style="font-family: 'Courier New'; font-size: 10pt;">(<i>) -> 5 </i>//
<b>takes no value and returns 5</b><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">
<span style="font-family: 'Courier New'; font-size: 10pt;">2. x
-> 2 * x // <b>takes a number and
returns the result of doubling it</b><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">
<i><span style="font-family: 'Courier New'; font-size: 10pt;">3. </span></i><span style="font-family: 'Courier New'; font-size: 10pt;">(<i>x, y) -> x – y </i>// <b>takes two
numbers and returns their difference</b><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">
<span style="font-family: 'Courier New'; font-size: 10pt;">4. (int
x, int y) -> x + y // <b>takes two integers and returns their sum</b><o:p></o:p></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">
<span style="font-family: 'Courier New'; font-size: 10pt;">5.
(<i>String s) -> System.out.print(s) </i>//
<b>takes a string and prints it to console without returning anything</b></span></div>
</div>
</div>
<h2 style="background: white; line-height: 18.0pt; margin-bottom: 6.0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;">
<span style="color: #00003f; font-family: "Arial","sans-serif"; font-size: 14.5pt;">Basic Lambdas Examples<o:p></o:p></span></h2>
<h2 style="background: white; line-height: 18pt; margin: 0in 0in 6pt; text-align: left;">
<span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; font-family: Arial, sans-serif; font-size: 10pt;"><u>Example 1</u></span><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; font-family: Arial, sans-serif; font-size: 10pt; font-weight: normal;">- In this section, we will see how lambda expressions
affect the way we code. Having a list of players, the “for loop”, as
programmers often refers to the, for statement, can be translated in Java SE 8
as below:</span></h2>
<div style="background: white; border: solid #F5F3D7 1.5pt; mso-element: para-border-div; padding: 4.0pt 8.0pt 4.0pt 8.0pt;">
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">String[] studentNames = {"Jeet", "Harsh", "Merry", "David", "Roger", "Andy ", "Tomas", "John"};<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">List<String> students = Arrays.asList(studentNames);<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"> <o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"><b>// Old looping</b><o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">for (String student : students) {<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"> System.out.print(student + "; ");<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">}<span style="line-height: 12pt;"> </span></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"><o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"><b>// Using lambda expression and functional operations</b><o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">students.forEach((student) -> System.out.print(student + "; "));<o:p></o:p></pre>
<br />
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"><b>// Using double colon operator in Java 8</b><o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">students.forEach(System.out::println);<o:p></o:p></pre>
</div>
<br />
<h2 style="background: white; line-height: 18pt; margin: 0in 0in 6pt;">
<span style="font-family: Arial, sans-serif; font-size: 10pt; line-height: 18pt;"><u>Example 2</u></span><span style="font-family: Arial, sans-serif; font-size: 10pt; font-weight: normal; line-height: 18pt;"> - </span><span style="font-family: Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 15.3333320617676px;">As you saw, lambda expressions can reduced our code to one single line. Another example is in a graphical user interface application, when anonymous classes can be replaced with lambda expressions:</span></h2>
<div style="background: white; border: solid #F5F3D7 1.5pt; mso-element: para-border-div; padding: 4.0pt 8.0pt 4.0pt 8.0pt;">
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">// <b>using anonymous innerclass</b><o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">button.setOnAction(new EventHandler<ActionEvent>() {<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"> @Override<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"> public void handle(ActionEvent event) {<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"> System.out.println("Hello World!!"); <o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"> }<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"> });<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"> <o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">// <b>using lambda expression</b><o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">button.setOnAction(event -> System.out.println("Hello World!!"));</pre>
</div>
<br />
<h2 style="background: white; line-height: 18pt; margin: 0in 0in 6pt;">
<b style="font-size: medium; line-height: normal;"><u><span style="font-family: Arial, sans-serif; font-size: 10pt; line-height: 15.3333320617676px;">Example 3<span class="apple-converted-space"> </span></span></u></b><span style="font-family: Arial, sans-serif; font-size: 10pt; font-weight: normal; line-height: 15.3333320617676px;">- Implementing<span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;"> the Runnable interface, see below how we can write Runnable using lambda expression:</span></span></h2>
<div style="background: white; border: solid #F5F3D7 1.5pt; mso-element: para-border-div; padding: 4.0pt 8.0pt 4.0pt 8.0pt;">
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">// Using anonymous innerclass <o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">new Thread(new Runnable() {<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"> @Override<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"> public void run() {<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"> System.out.println("Hello world !!");<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"> }<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">}).start();<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"> <o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">// Using lambda expression<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">new Thread(() -> System.out.println("Hello world !!")).start();<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"> <o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">// Using anonymous innerclass<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">Runnable run1= new Runnable() {<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"> @Override<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"> public void run() {<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"> System.out.println("Hello world !!");<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"> }<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">};<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"> <o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">// Using lambda expression<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">Runnable run2= () -> System.out.println("Hello world !!");<span style="line-height: 12pt;"> </span></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"><o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;">// Run em!<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"><span style="line-height: 12pt;">run1</span>.run();<o:p></o:p></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; line-height: 12pt; margin: 2.25pt 0in 7.5pt; padding: 0in;"><span style="line-height: 12pt;">run2</span>.run();<o:p></o:p></pre>
</div>
<span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;">
</span>
<span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"><br /></span>
<span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"><br /></span>
<span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; font-family: Arial, sans-serif; font-size: 10pt; line-height: 115%;"><br /></span></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-17843571648354273782014-10-03T23:29:00.000-07:002014-10-03T23:29:54.179-07:0010 Frequently asked SQL Queries In Interviews<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="background: white; margin: 9pt 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> In this article I am
giving example of some SQL query which is asked in most the of interviews who
is having one or two year experience on this field .whenever you go for java
developer position or any other programmer position interviewee expect that if
you are working from one or two years on any project definitely you come across
to handle this database query, so they test your skill by asking this type of
simple query.</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> Que 1: SQL Query to
find second highest salary of Employee</span></b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> <b>Ans </b></span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"><b>:</b> There are many ways
to find second highest salary of Employee in SQL, you can either use SQL Join
or Subquery to solve this problem. Here is SQL query using Subquery :</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: #002240; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #ff9d00; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> select</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #ffb054; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">MAX</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">(Salary) </span><span style="color: #ff9d00; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">from</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> Employee </span><span style="color: #ff9d00; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">WHERE</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> Salary NOT </span><span style="color: #ff9d00; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">IN</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> (</span><span style="color: #ff9d00; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">select</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #ffb054; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">MAX</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">(Salary) </span><span style="color: #ff9d00; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">from</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> Employee );</span><span style="color: #222222; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #002240; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> Que 2: SQL Query to
find Max Salary from each department.</span></b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> <b>Ans</b></span><b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">:</span></b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: #002240; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #ff9d00; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> SELECT</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> DeptID, </span><span style="color: #ffb054; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">MAX</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">(Salary) </span><span style="color: #ff9d00; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">FROM</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> Employee </span><span style="color: #ff9d00; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">GROUP BY</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> DeptID.</span><span style="color: #222222; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #002240; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> Que 3: Write SQL Query
to display current date.</span></b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> <b>Ans: </b>SQL has
built in function called</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #222222; font-family: "Courier New"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">GetDate()</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">which returns current timestamp.</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: #002240; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #ff9d00; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> SELECT</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> GetDate();</span><span style="color: #222222; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #002240; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> Que 4: Write an SQL
Query</span></b><b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> to check </span></b><b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">whether date passed to Query is date of given format or not</span></b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">.</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> <b>Ans: </b>SQL has</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #222222; font-family: "Courier New"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">IsDate()</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">function which is used</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">to check</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">passed value is date or not of specified format ,it returns
1(true) or 0(false) accordingly.</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: #002240; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #ff9d00; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> SELECT</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> ISDATE(</span><span style="color: #3ad900; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">'</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">1/08/13') </span><span style="color: #ff9d00; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">AS</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #3ad900; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">"</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">MM/DD/YY";</span><span style="color: #222222; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #002240; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> It will return 0
because passed date is not in correct format.</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> Que 5: Write a SQL
Query to print the name of distinct employee whose DOB is between 01/02/2012 to
31/12/2013.</span></b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> <b>Ans:</b></span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #002240; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #ff9d00; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> SELECT DISTINCT</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> EmpName </span><span style="color: #ff9d00; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">FROM</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> Employees </span><span style="color: #ff9d00; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">WHERE</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> DOB BETWEEN ‘</span><span style="color: #ff628c; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">01/02/2012’</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #ff9d00; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">AND</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> ‘</span><span style="color: #ff628c; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">31</span><span style="color: #ff9d00; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">/</span><span style="color: #ff628c; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">12</span><span style="color: #ff9d00; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">/</span><span style="color: #ff628c; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">2013</span><span style="color: white; font-family: Consolas; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">’;</span><span style="color: #222222; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> Que 6:Write an SQL
Query find number of employees according to gender </span></b><b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span></b><b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">whose DOB is between 01/01/1960 to 31/12/1975.</span></b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> <b>Ans</b></span><b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">:</span></b><span style="color: #222222; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #222222; font-family: "Courier New"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">SELECT
COUNT(*), sex from Employees </span><span style="color: #222222; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #222222; font-family: "Courier New"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">WHERE </span><span style="color: #222222; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #222222; font-family: "Courier New"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">DOB BETWEEN ‘01/01/1960 ' AND ‘31/12/1975’ GROUP BY sex;</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> Que 7:Write an SQL
Query to find employee whose Salary is equal or greater than 20000</span></b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">.</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> Ans</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">:</span></b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #222222; font-family: "Courier New"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">SELECT
EmpName FROM </span><span style="color: #222222; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #222222; font-family: "Courier New"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">Employees WHERE </span><span style="color: #222222; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #222222; font-family: "Courier New"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">Salary>=20000;</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> Que 8:Write an SQL
Query to find name of employee whose name Start with ‘S’</span></b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> <b>Ans: </b>SELECT * FROM
Employees WHERE EmpName like 'S%';</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #222222; font-family: Arial, sans-serif; font-size: 9pt;"><b> Que 9: find all
Employee records containing the word "</b>John<b>", regardless of whether it
was stored as JOHN, John, or john.</b></span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> <b>Ans</b></span><b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">:</span></b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #222222; font-family: "Courier New"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">SELECT </span><span style="color: #222222; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #222222; font-family: "Courier New"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">* from Employees WHERE </span><span style="color: #222222; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #222222; font-family: "Courier New"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">upper(EmpName)
like upper('john%');</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">Que 10: Write a SQL
Query to find </span></b><b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">year</span></b><b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"> from date.</span></b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";">Ans</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"> </span></b><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 9.0pt; mso-fareast-font-family: "Times New Roman";"><b>:</b> SELECT YEAR(GETDATE()) as
"Year";</span><span style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.85pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-21488880687154923912014-09-20T10:41:00.000-07:002014-09-20T10:41:25.439-07:00IMP Questions and answer in Heap and Stack Memory area in Java<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
<div class="MsoNormal">
<b><span style="font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 115%;">Question - </span></b><span style="font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 115%;">Stack Vs Heap Memory<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="font-family: 'Times New Roman', serif; font-size: 12pt;">Answer - </span></b><span style="font-family: 'Times New Roman', serif; font-size: 12pt;">Main difference between heap and stack is that
stack memory is used to store local variables and function call, while heap
memory is used to store objects in Java. No matter, where object is created in
code e.g. as member variable, local variable or class variable, they are always
created inside heap space in Java.</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; color: #444444; font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; color: #444444; font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 115%;">In a multi-threaded application, each thread will have its
own stack, but, all the different threads will share the heap. Because the
different threads share the heap in a multi-threaded application, this also
means that there has to be some coordination between the threads so that they don’t
try to access and manipulate the same piece(s) of memory in the heap at the
same time.</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="font-family: 'Times New Roman', serif; font-size: 12pt;">Question</span></b><span style="font-family: 'Times New Roman', serif; font-size: 12pt;"> - Can an object be stored on the stack
instead of the heap?</span><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="font-family: 'Times New Roman', serif; font-size: 12pt;">Answer </span></b><span style="font-family: 'Times New Roman', serif; font-size: 12pt;">- </span><b><span style="color: #444444; font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Yes</span></b><span style="color: #444444; font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">, an object can be
stored on the stack. If you create an object inside a function without </span><span style="font-family: 'Times New Roman', serif; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #444444; font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">using the “new” operator
then this will create and store the object on the stack, and not on the
heap. </span><span style="font-family: 'Times New Roman', serif; font-size: 12pt;"><o:p></o:p></span></div>
</div>
<div>
<span style="color: #444444; font-family: "Verdana","sans-serif"; font-size: 9.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Times New Roman"; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;"><br /></span></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-21725242759814764902014-09-20T10:28:00.001-07:002014-09-20T10:28:20.746-07:00Servlet<div dir="ltr" style="text-align: left;" trbidi="on">
<table border="0" cellpadding="0" cellspacing="0" style="color: #3d366f; font-family: Verdana, Arial, Georgia, serif; font-size: 10px; font-weight: bold; height: 100%px; line-height: 22px; margin: 0px; outline: 0px; padding: 0px; width: 100%px;"><tbody style="margin: 0px; outline: 0px; padding: 0px;">
<tr style="margin: 0px; outline: 0px; padding: 0px;"><td align="center" class="heading_font " colspan="2" height="21" style="color: #9900cc; font-family: Georgia, Times, serif; font-size: 11pt; margin: 0px; outline: 0px; padding: 0px;" valign="top" width="100%"><br /></td></tr>
<tr style="margin: 0px; outline: 0px; padding: 0px;"><td colspan="2" height="21" style="margin: 0px; outline: 0px; padding: 0px;" valign="top" width="100%"><div style="outline: 0px; padding: 0px;">
<span class="heading_font" style="color: #9900cc; font-family: Georgia, Times, serif; font-size: 11pt; margin: 0px; outline: 0px; padding: 0px;">Life-cycle of Servlet :</span> </div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://software-programming.appspot.com/images/servlet_lifecycle.jpeg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img align="left" border="0" src="http://software-programming.appspot.com/images/servlet_lifecycle.jpeg" style="margin-top: 0px; outline: 0px; padding: 0px;" /></a></div>
<div style="outline: 0px; padding: 0px;">
<br />
<span class="content_font" style="color: black; font-family: Georgia, Times, serif; font-size: 12pt; margin: 0px; outline: 0px; padding: 0px;"><br style="margin: 0px; outline: 0px; padding: 0px;" /></span></div>
</td></tr>
<tr style="margin: 0px; outline: 0px; padding: 0px;"><td colspan="2" height="21" style="margin: 0px; outline: 0px; padding: 0px;" valign="top" width="100%"><ins id="aswift_2_expand" style="border: none; display: inline-table; height: 15px; margin: 0px; outline: 0px; padding: 0px; position: relative; visibility: visible; width: 728px;"><ins id="aswift_2_anchor" style="border: none; display: block; height: 15px; margin: 0px; outline: 0px; padding: 0px; position: relative; visibility: visible; width: 728px;"><iframe allowfullscreen="true" allowtransparency="true" frameborder="0" height="15" hspace="0" id="aswift_2" marginheight="0" marginwidth="0" name="aswift_2" scrolling="no" style="left: 0px; margin: 0px; outline: 0px; padding: 0px; position: absolute; top: 0px;" vspace="0" width="728"></iframe></ins></ins></td></tr>
<tr style="margin: 0px; outline: 0px; padding: 0px;"><td align="left" height="21" style="margin: 0px; outline: 0px; padding: 0px;" valign="top" width="30%"><span class="heading_font" style="color: #9900cc; font-family: Georgia, Times, serif; font-size: 11pt; margin: 0px; outline: 0px; padding: 0px;">Steps in Servlet Life Cycle :</span></td><td align="left" style="margin: 0px; outline: 0px; padding: 0px;" valign="top" width="70%"><span class="content_font" style="color: black; font-family: Georgia, Times, serif; font-size: 12pt; margin: 0px; outline: 0px; padding: 0px;"><br style="margin: 0px; outline: 0px; padding: 0px;" />The life cycle of a servlet consists of the following phases:<br style="margin: 0px; outline: 0px; padding: 0px;" /><br style="margin: 0px; outline: 0px; padding: 0px;" />* Servlet class loading : For each servlet defined in the deployment descriptor of the Web application, the servlet container locates and loads a class of the type of the servlet. This can happen when the servlet engine itself is started, or later when a client request is actually delegated to the servlet.<br style="margin: 0px; outline: 0px; padding: 0px;" />* Servlet instantiation : After loading, it instantiates one or more object instances of the servlet class to service the client requests.<br style="margin: 0px; outline: 0px; padding: 0px;" />* Initialization (call the init method) : After instantiation, the container initializes a servlet before it is ready to handle client requests. The container initializes the servlet by invoking its init() method, passing an object implementing the ServletConfig interface. In the init() method, the servlet can read configuration parameters from the deployment descriptor or perform any other one-time activities, so the init() method is invoked once and only once by the servlet container.<br style="margin: 0px; outline: 0px; padding: 0px;" />* Request handling (call the service method) : After the servlet is initialized, the container may keep it ready for handling client requests. When client requests arrive, they are delegated to the servlet through the service() method, passing the request and response objects as parameters. In the case of HTTP requests, the request and response objects are implementations of HttpServletRequest and HttpServletResponse respectively. In the HttpServlet class, the service() method invokes a different handler method for each type of HTTP request, doGet() method for GET requests, doPost() method for POST requests, and so on.<br style="margin: 0px; outline: 0px; padding: 0px;" />* Removal from service (call the destroy method) : A servlet container may decide to remove a servlet from service for various reasons, such as to conserve memory resources. To do this, the servlet container calls the destroy() method on the servlet. Once the destroy() method has been called, the servlet may not service any more client requests. Now the servlet instance is eligible for garbage collection<br style="margin: 0px; outline: 0px; padding: 0px;" /><br style="margin: 0px; outline: 0px; padding: 0px;" />The life cycle of a servlet is controlled by the container in which the servlet has been deployed.</span></td></tr>
<tr style="margin: 0px; outline: 0px; padding: 0px;"><td colspan="2" height="21" style="margin: 0px; outline: 0px; padding: 0px;" width="100%"></td></tr>
<tr style="margin: 0px; outline: 0px; padding: 0px;"><td colspan="2" height="21" style="margin: 0px; outline: 0px; padding: 0px;" valign="bottom" width="100%"><ins id="aswift_3_expand" style="border: none; display: inline-table; height: 90px; margin: 0px; outline: 0px; padding: 0px; position: relative; visibility: visible; width: 728px;"><ins id="aswift_3_anchor" style="border: none; display: block; height: 90px; margin: 0px; outline: 0px; padding: 0px; position: relative; visibility: visible; width: 728px;"><iframe allowfullscreen="true" allowtransparency="true" frameborder="0" height="90" hspace="0" id="aswift_3" marginheight="0" marginwidth="0" name="aswift_3" scrolling="no" style="left: 0px; margin: 0px; outline: 0px; padding: 0px; position: absolute; top: 0px;" vspace="0" width="728"></iframe></ins></ins></td></tr>
</tbody></table>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-6615015317012746142014-09-03T21:12:00.001-07:002014-09-03T21:12:51.995-07:00Java Interview Questions for Experience and Freshers<div dir="ltr" style="text-align: left;" trbidi="on">
<table border="0" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="mso-cellspacing: 0in; mso-padding-alt: 0in 0in 0in 0in; mso-yfti-tbllook: 1184; width: 100%px;">
<tbody>
<tr style="height: 15.75pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td colspan="2" style="height: 15.75pt; padding: 0in 0in 0in 0in; width: 100.0%;" valign="top" width="100%">
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #9900cc; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"> </span></b><span style="background-color: #eeeeee; color: #9900cc; font-family: Georgia, Times, serif; font-size: 15px; font-weight: bold; text-align: -webkit-center;">General Interview Questions</span></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #9900cc; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><br /></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #9900cc; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><br /></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #9900cc; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";">Que 1 - Difference
between == and equals method ?</span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><br />
Ans : The == operator compares two objects to determine if they are the
same object in memory i.e. present in the same memory location. It is
possible for two String objects to have the same value, but located in
different areas of memory.<br />
<br />
== compares references while .equals compares contents.<br />
<!--[if !supportLineBreakNewLine]--><br />
<!--[endif]--><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"> public class EqualsTest
{<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"> public static void main(String[] args) {<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"> String s1 = ?abc?;<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"> String s2 = s1;<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"> String s5 = ?abc?;<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"> String s3 = new
String(?abc?);<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"> String s4 = new
String(?abc?);<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"> System.out.println(?==
comparison : ? + (s1 == s5));<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"> System.out.println(?==
comparison : ? + (s1 == s2));<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"> System.out.println(?Using
equals method : ? + s1.equals(s2));<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"> System.out.println(?==
comparison : ? + s3 == s4);<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"> System.out.println(?Using
equals method : ? + s3.equals(s4));<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"> }<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";">}<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";">Output<br />
== comparison : true<br />
== comparison : true<br />
Using equals method : true<br />
false<br />
Using equals method : true<o:p></o:p></span></b></div>
</td>
</tr>
<tr style="height: 15.75pt; mso-yfti-irow: 1;">
<td colspan="2" style="height: 15.75pt; padding: 0in 0in 0in 0in; width: 100.0%;" valign="top" width="100%">
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #9900cc; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>Que
2 - What is the difference between an Abstract class and Interface ?</ins></span></span></b><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins><br />
Ans :<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l2 level1 lfo1; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">1.<span style="font-size: 7pt; font-weight: normal; line-height: normal;">
</span></span></b><!--[endif]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>Abstract classes may have some
executable methods and methods left unimplemented. Interfaces contain no
implementation code.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l2 level1 lfo1; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">2.<span style="font-size: 7pt; font-weight: normal; line-height: normal;">
</span></span></b><!--[endif]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>An class can implement any number of
interfaces, but subclass at most one abstract class.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l2 level1 lfo1; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">3.<span style="font-size: 7pt; font-weight: normal; line-height: normal;">
</span></span></b><!--[endif]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>An abstract class can have non
abstract methods. All methods of an interface are abstract.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l2 level1 lfo1; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">4.<span style="font-size: 7pt; font-weight: normal; line-height: normal;">
</span></span></b><!--[endif]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>An abstract class can have instance
variables. An interface cannot.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l2 level1 lfo1; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">5.<span style="font-size: 7pt; font-weight: normal; line-height: normal;">
</span></span></b><!--[endif]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>An abstract class can define
constructor. An interface cannot.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l2 level1 lfo1; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">6.<span style="font-size: 7pt; font-weight: normal; line-height: normal;">
</span></span></b><!--[endif]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>An abstract class can have any
visibility: public, protected, private or none (package). An interface's
visibility must be public or none (package).<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l2 level1 lfo1; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">7.<span style="font-size: 7pt; font-weight: normal; line-height: normal;">
</span></span></b><!--[endif]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>An abstract class inherits from Object
and includes methods such as clone() and equals().<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins><br />
<!--[if !supportLineBreakNewLine]--><br />
<!--[endif]--><o:p></o:p></ins></span></span></b></div>
</td>
</tr>
<tr style="height: 15.75pt; mso-yfti-irow: 2;">
<td colspan="2" style="height: 15.75pt; padding: 0in 0in 0in 0in; width: 100.0%;" valign="top" width="100%">
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>14.Can
overloaded methods be override too?<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>Yes,
derived classes still can override the overloaded methods. Polymorphism can
still happen. Compiler will not binding the method calls since it is
overloaded, because it might be overridden now or in the future.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins><br />
15.Is it possible to override the main method?<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>NO,
because main is a static method. A static method can't be overridden in Java.<o:p></o:p></ins></span></span></b></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>27.What
are the differences between Interface and Abstract class?<o:p></o:p></ins></span></span></b></div>
<table border="1" cellpadding="0" cellspacing="5" class="MsoNormalTable">
<tbody>
<tr>
<td style="padding: 0in 0in 0in 0in; width: 50.0%;" width="50%">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
<b>Abstract
Class<o:p></o:p></b></div>
</td>
<td style="padding: 0in 0in 0in 0in; width: 50.0%;" width="50%">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
<b>Interfaces<o:p></o:p></b></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
An abstract
class can provide complete, default code and/or just the details that have
to be overridden.<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
An interface
cannot provide any code at all,just the signature.<o:p></o:p></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
In case of
abstract class, a class may extend only one abstract class.<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
A Class may
implement several interfaces.<o:p></o:p></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
An abstract
class can have non-abstract methods.<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
All methods
of an Interface are abstract.<o:p></o:p></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
An abstract
class can have instance variables.<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
An Interface
cannot have instance variables.<o:p></o:p></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
An abstract
class can have any visibility: public, private, protected.<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
An Interface
visibility must be public (or) none.<o:p></o:p></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
If we add a
new method to an abstract class then we have the option of providing
default implementation and therefore all the existing code might work
properly.<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
If we add a
new method to an Interface then we have to track down all the
implementations of the interface and define implementation for the new
method.<o:p></o:p></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
An abstract
class can contain constructors .<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
An Interface
cannot contain constructors .<o:p></o:p></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
Abstract
classes are fast.<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
Interfaces
are slow as it requires extra indirection to find corresponding method in
the actual class.<o:p></o:p></div>
</td>
</tr>
</tbody></table>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins><br />
28.When should I use abstract classes and when should I use interfaces?<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>Use
Interfaces when?<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l0 level1 lfo2; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><span style="color: #3d366f; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-bidi-font-weight: bold; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>You see that something in your design will change
frequently.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l0 level1 lfo2; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><span style="color: #3d366f; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-bidi-font-weight: bold; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>If various implementations only share method signatures
then it is better to use Interfaces.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l0 level1 lfo2; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><span style="color: #3d366f; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-bidi-font-weight: bold; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>you need some classes to use some methods which you don't
want to be included in the class, then you go for the interface, which makes
it easy to just implement and make use of the methods defined in the
interface.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>Use
Abstract Class when?<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l3 level1 lfo3; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><span style="color: #3d366f; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-bidi-font-weight: bold; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>If various implementations are of the same kind and use
common behavior or status then abstract class is better to use.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l3 level1 lfo3; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><span style="color: #3d366f; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-bidi-font-weight: bold; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>When you want to provide a generalized form of abstraction
and leave the implementation task with the inheriting subclass.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l3 level1 lfo3; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><span style="color: #3d366f; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-bidi-font-weight: bold; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>Abstract classes are an excellent way to create planned
inheritance hierarchies. They're also a good choice for nonleaf classes in
class hierarchies.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins><br />
29.When you declare a method as abstract, can other nonabstract methods
access it?<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>Yes,
other nonabstract methods can access a method that you declare as abstract.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins><br />
30.Can there be an abstract class with no abstract methods in it?<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>Yes,
there can be an abstract class without abstract methods.<o:p></o:p></ins></span></span></b></div>
</td>
<td style="padding: 0in 0in 0in 0in;"></td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>36.What
are the differences between Class Methods and Instance Methods?<br />
<!--[if !supportLineBreakNewLine]--><br />
<!--[endif]--><o:p></o:p></ins></span></span></b></div>
<table border="1" cellpadding="0" cellspacing="5" class="MsoNormalTable">
<tbody>
<tr>
<td style="padding: 0in 0in 0in 0in; width: 50.0%;" width="50%">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
<b>Class
Methods<o:p></o:p></b></div>
</td>
<td style="padding: 0in 0in 0in 0in; width: 50.0%;" width="50%">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
<b>Instance
Methods<o:p></o:p></b></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
Class methods
are methods which are declared as static. The method can be called without
creating an instance of the class<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
Instance
methods on the other hand require an instance of the class to exist before
they can be called, so an instance of a class needs to be created by using
the new keyword.<br />
Instance methods operate on specific instances of classes.<o:p></o:p></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
Class methods
can only operate on class members and not on instance members as class
methods are unaware of instance members.<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
Instance
methods of the class can also not be called from within a class method
unless they are being called on an instance of that class.<o:p></o:p></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
Class methods
are methods which are declared as static. The method can be called without
creating an instance of the class.<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
Instance methods
are not declared as static.<o:p></o:p></div>
</td>
</tr>
</tbody></table>
</td>
<td style="padding: 0in 0in 0in 0in;"></td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>38.What
are Access Specifiers?<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>One
of the techniques in object-oriented programming is <i>encapsulation</i>.
It concerns the hiding of data in a class and making this class available
only through methods. Java allows you to control access to classes, methods,
and fields via so-called <i>access specifiers</i>..<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins><br />
39.What are Access Specifiers available in Java?<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>Java
offers four access specifiers, listed below in decreasing accessibility:<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l1 level1 lfo4; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><span style="color: #3d366f; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-bidi-font-weight: bold; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>Public- <i>public</i> classes, methods, and
fields can be accessed from everywhere.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l1 level1 lfo4; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><span style="color: #3d366f; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-bidi-font-weight: bold; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>Protected- <i>protected</i> methods and fields
can only be accessed within the same class to which the methods and fields
belong, within its subclasses, and within classes of the same package.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l1 level1 lfo4; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><span style="color: #3d366f; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-bidi-font-weight: bold; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>Default(no specifier)- If you do not set access to
specific level, then such a class, method, or field will be accessible from
inside the same package to which the class, method, or field belongs, but not
from outside this package.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l1 level1 lfo4; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><span style="color: #3d366f; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-bidi-font-weight: bold; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>Private- <i>private</i> methods and fields can
only be accessed within the same class to which the methods and fields
belong. <i>private</i>methods and fields are not visible within
subclasses and are not inherited by subclasses.<o:p></o:p></ins></span></span></b></div>
<table border="1" cellpadding="0" cellspacing="5" class="MsoNormalTable">
<tbody>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
<b> Situation <o:p></o:p></b></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
<b> public <o:p></o:p></b></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
<b> protected <o:p></o:p></b></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
<b> default <o:p></o:p></b></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
<b> private <o:p></o:p></b></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
Accessible
to class<br />
from same package? <o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
yes<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
yes<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
yes<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
no<o:p></o:p></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
Accessible
to class<br />
from different package? <o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
yes<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
no, <i>unless
it is a subclass</i> <o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
no<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
no<o:p></o:p></div>
</td>
</tr>
</tbody></table>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins><br />
40.What is final modifier?<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>The final modifier
keyword makes that the programmer cannot change the value anymore. The actual
meaning depends on whether it is applied to a class, a variable, or a method.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l4 level1 lfo5; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><span style="color: #3d366f; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-bidi-font-weight: bold; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><b><i><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>final</ins></span></span></i></b><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins> Classes-
A final class cannot have subclasses.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l4 level1 lfo5; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><span style="color: #3d366f; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-bidi-font-weight: bold; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><b><i><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>final</ins></span></span></i></b><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins> Variables-
A final variable cannot be changed once it is initialized.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin: 0in; mso-list: l4 level1 lfo5; tab-stops: list .5in; text-indent: -.25in;">
<!--[if !supportLists]--><span style="color: #3d366f; font-family: Symbol; font-size: 10.0pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-bidi-font-weight: bold; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><b><i><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>final</ins></span></span></i></b><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins> Methods-
A final method cannot be overridden by subclasses.<o:p></o:p></ins></span></span></b></div>
</td>
<td style="padding: 0in 0in 0in 0in;"></td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>54.Difference
between ArrayList and Vector ?<o:p></o:p></ins></span></span></b></div>
<table border="1" cellpadding="0" cellspacing="5" class="MsoNormalTable">
<tbody>
<tr>
<td style="padding: 0in 0in 0in 0in; width: 50.0%;" width="50%">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
<b>ArrayList<o:p></o:p></b></div>
</td>
<td style="padding: 0in 0in 0in 0in; width: 50.0%;" width="50%">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
<b>Vector<o:p></o:p></b></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
ArrayList is <b>NOT</b> synchronized
by default.<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
Vector List
is synchronized by default.<o:p></o:p></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
ArrayList can
use only Iterator to access the elements.<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
Vector list
can use Iterator and Enumeration Interface to access the elements.<o:p></o:p></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
The ArrayList
increases its array size by 50 percent if it runs out of room.<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
A Vector
defaults to doubling the size of its array if it runs out of room<o:p></o:p></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
ArrayList has
no default size.<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
While vector
has a default size of 10.<o:p></o:p></div>
</td>
</tr>
</tbody></table>
</td>
<td style="padding: 0in 0in 0in 0in;"></td>
</tr>
<tr style="height: 15.75pt; mso-yfti-irow: 7;">
<td colspan="2" style="height: 15.75pt; padding: 0in 0in 0in 0in; width: 100.0%;" valign="bottom" width="100%"></td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>69.Difference
between HashMap and Hashtable ?<o:p></o:p></ins></span></span></b></div>
<table border="1" cellpadding="0" cellspacing="5" class="MsoNormalTable">
<tbody>
<tr>
<td style="padding: 0in 0in 0in 0in; width: 50.0%;" width="50%">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
<b>HashMap<o:p></o:p></b></div>
</td>
<td style="padding: 0in 0in 0in 0in; width: 50.0%;" width="50%">
<div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">
<b>Hashtable<o:p></o:p></b></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
HashMap lets
you have null values as well as one null key.<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
HashTable
does not allows null values as key and value.<o:p></o:p></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
The iterator
in the HashMap is fail-safe (If you change the map while iterating, you?ll
know).<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
The
enumerator for the Hashtable is not fail-safe.<o:p></o:p></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
HashMap is
unsynchronized.<o:p></o:p></div>
</td>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
Hashtable is
synchronized.<o:p></o:p></div>
</td>
</tr>
</tbody></table>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><u><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>Note</ins></span></span></u></b><b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>: Only one NULL is allowed as a key in
HashMap. HashMap does not allow multiple keys to be NULL. Nevertheless, it
can have multiple NULL values.<o:p></o:p></ins></span></span></b></div>
</td>
<td style="padding: 0in 0in 0in 0in;"></td>
</tr>
<tr style="height: 15.75pt; mso-yfti-irow: 9;">
<td colspan="2" style="height: 15.75pt; padding: 0in 0in 0in 0in;" valign="bottom"></td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in;">
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>Que
- Difference between Class.forName() and ClassLoader.loadClass() ?<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>Both
methods try to dynamically locate and load a java.lang.Class object
corresponding to a given class name. However, their behavior differs
regarding which java.lang.ClassLoader they use for class loading and whether
or not the resulting Class object is initialized.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>The
most common form of Class.forName(), the one that takes a single String
parameter, always uses the caller's classloader. This is the classloader that
loads the code executing the forName() method. By comparison,
ClassLoader.loadClass() is an instance method and requires you to select a
particular classloader, which may or may not be the loader that loads that
calling code. If picking a specific loader to load the class is important to
your design, you should use ClassLoader.loadClass() or the three-parameter
version of forName() added in Java 2 Platform, Standard Edition (J2SE):
Class.forName(String, boolean, ClassLoader).<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>Additionally,
Class.forName()'s common form initializes the loaded class. The visible
effect of this is the execution of the class's static initializers as well as
byte code corresponding to initialization expressions of all static fields
(this process occurs recursively for all the class's superclasses). This
differs from ClassLoader.loadClass() behavior, which delays initialization
until the class is used for the first time.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>You
can take advantage of the above behavioral differences. For example, if you
are about to load a class you know has a very costly static initializer, you
may choose to go ahead and load it to ensure it is found in the classpath but
delay its initialization until the first time you need to make use of a field
or method from this particular class.<o:p></o:p></ins></span></span></b></div>
<div class="MsoNormal" style="line-height: 16.5pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #3d366f; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman";"><span class="msoIns"><ins>The
three-parameter method Class.forName(String, boolean, ClassLoader) is the
most general of them all. You can delay initialization by setting the second
parameter to false and pick a given classloader using the third parameter. I
recommend always using this method for maximum flexibility.<o:p></o:p></ins></span></span></b></div>
</td>
<td style="padding: 0in 0in 0in 0in;"></td>
</tr>
</tbody></table>
<div class="MsoNormal">
<br /></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-62366385975895858002014-09-02T21:45:00.005-07:002014-09-02T21:45:55.015-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<br /><table border="0" cellpadding="0" cellspacing="0" style="color: #3d366f; font-family: Verdana, Arial, Georgia, serif; font-size: 10px; font-weight: bold; height: 100%px; line-height: 22px; margin: 0px; outline: 0px; padding: 0px; width: 100%px;"><tbody style="margin: 0px; outline: 0px; padding: 0px;">
<tr style="margin: 0px; outline: 0px; padding: 0px;"><td align="center" class="heading_font " colspan="2" height="15" style="color: #9900cc; font-family: Georgia, Times, serif; font-size: 11pt; margin: 0px; outline: 0px; padding: 0px;" valign="top" width="100%">Java Collections</td></tr>
<tr style="margin: 0px; outline: 0px; padding: 0px;"><td colspan="2" height="21" style="margin: 0px; outline: 0px; padding: 0px;" valign="top" width="100%"><div style="outline: 0px; padding: 0px;">
<span class="content_font" style="color: black; font-family: Georgia, Times, serif; font-size: 12pt; margin: 0px; outline: 0px; padding: 0px;"><span style="font-weight: normal;"><br style="margin: 0px; outline: 0px; padding: 0px;" />The Java Collections API's provide Java developers with a set of classes and interfaces that</span></span></div>
<div style="outline: 0px; padding: 0px;">
<span class="content_font" style="color: black; font-family: Georgia, Times, serif; font-size: 12pt; margin: 0px; outline: 0px; padding: 0px;"><span style="font-weight: normal;"> makes it easier to handle collections of objects. In a sense Collection's works a bit like arrays, </span></span></div>
<div style="outline: 0px; padding: 0px;">
<span class="content_font" style="margin: 0px; outline: 0px; padding: 0px;"><span style="color: black; font-family: Georgia, Times, serif; font-size: small;"><span style="font-weight: normal;">except their size can change dynamically, and they have more advanced behavior </span></span></span></div>
<div style="outline: 0px; padding: 0px;">
<span class="content_font" style="color: black; font-family: Georgia, Times, serif; font-size: 12pt; margin: 0px; outline: 0px; padding: 0px;"><span style="font-weight: normal;">than arrays.</span><img align="left" src="http://software-programming.appspot.com/images/collection1.jpeg" style="margin: 0px; outline: 0px; padding: 0px;" /></span></div>
<pre style="outline: 0px; padding: 0px;"><span class="content_font" style="color: black; font-family: Georgia, Times, serif; font-size: 12pt; margin: 0px; outline: 0px; padding: 0px;"> Map</span></pre>
<span class="content_font" style="color: black; font-family: Georgia, Times, serif; font-size: 12pt; margin: 0px; outline: 0px; padding: 0px;"><pre style="outline: 0px; padding: 0px;"><strong style="margin: 0px; outline: 0px; padding: 0px;"> |</strong></pre>
<pre style="outline: 0px; padding: 0px;"><strong style="margin: 0px; outline: 0px; padding: 0px;"> SortedMap</strong></pre>
</span><div style="outline: 0px; padding: 0px;">
</div>
</td></tr>
<tr style="margin: 0px; outline: 0px; padding: 0px;"><td colspan="2" style="margin: 0px; outline: 0px; padding: 0px;" valign="top" width="100%"><div style="outline: 0px; padding: 0px;">
<span class="heading_font" style="color: #9900cc; font-family: Georgia, Times, serif; font-size: 11pt; margin: 0px; outline: 0px; padding: 0px;">Guide to Selecting Appropriate Map/Collection in Java</span> <span class="content_font" style="color: black; font-family: Georgia, Times, serif; font-size: 12pt; margin: 0px; outline: 0px; padding: 0px;"><br style="margin: 0px; outline: 0px; padding: 0px;" /><img align="center" src="http://software-programming.appspot.com/images/java-map-collection-cheat-sheet.gif" style="margin: 0px; outline: 0px; padding: 0px;" /></span></div>
</td></tr>
<tr style="margin: 0px; outline: 0px; padding: 0px;"><td align="center" colspan="2" height="21" style="margin: 0px; outline: 0px; padding: 0px;" valign="top" width="100%"><ins id="aswift_2_expand" style="border: none; display: inline-table; height: 15px; margin: 0px; outline: 0px; padding: 0px; position: relative; visibility: visible; width: 728px;"><ins id="aswift_2_anchor" style="border: none; display: block; height: 15px; margin: 0px; outline: 0px; padding: 0px; position: relative; visibility: visible; width: 728px;"><iframe allowfullscreen="true" allowtransparency="true" frameborder="0" height="15" hspace="0" id="aswift_2" marginheight="0" marginwidth="0" name="aswift_2" scrolling="no" style="left: 0px; margin: 0px; outline: 0px; padding: 0px; position: absolute; top: 0px;" vspace="0" width="728"></iframe></ins></ins></td></tr>
<tr style="margin: 0px; outline: 0px; padding: 0px;"><td colspan="2" style="margin: 0px; outline: 0px; padding: 0px;" valign="top" width="100%"><div style="outline: 0px; padding: 0px;">
<span class="heading_font" style="color: #9900cc; font-family: Georgia, Times, serif; font-size: 11pt; margin: 0px; outline: 0px; padding: 0px;">What is the difference between Enumeration and Iterator?</span> <span class="content_font" style="color: black; font-family: Georgia, Times, serif; font-size: 12pt; margin: 0px; outline: 0px; padding: 0px;"><br style="margin: 0px; outline: 0px; padding: 0px;" /><span style="font-weight: normal;">The functionality of Enumeration interface is duplicated by the Iterator interface. Iterator </span></span></div>
<div style="outline: 0px; padding: 0px;">
<span class="content_font" style="color: black; font-family: Georgia, Times, serif; font-size: 12pt; margin: 0px; outline: 0px; padding: 0px;"><span style="font-weight: normal;">has a remove() method while Enumeration doesn't. Enumeration acts as Read-only interface,</span></span></div>
<div style="outline: 0px; padding: 0px;">
<span class="content_font" style="color: black; font-family: Georgia, Times, serif; font-size: 12pt; margin: 0px; outline: 0px; padding: 0px;"><span style="font-weight: normal;"> because it has the methods only to traverse and fetch the objects, where as using Iterator </span></span></div>
<div style="outline: 0px; padding: 0px;">
<span class="content_font" style="color: black; font-family: Georgia, Times, serif; font-size: 12pt; margin: 0px; outline: 0px; padding: 0px;"><span style="font-weight: normal;">we can manipulate the objects also like adding and removing the objects.</span><br style="margin: 0px; outline: 0px; padding: 0px;" /><span style="font-weight: normal;">So Enumeration is used when ever we want to make Collection objects as Read-only.</span></span></div>
</td></tr>
<tr style="margin: 0px; outline: 0px; padding: 0px;"><td colspan="2" style="margin: 0px; outline: 0px; padding: 0px;" valign="top" width="100%"><div style="outline: 0px; padding: 0px;">
<span class="heading_font" style="color: #9900cc; font-family: Georgia, Times, serif; font-size: 11pt; margin: 0px; outline: 0px; padding: 0px;">Difference between HashMap and HashTable? Can we make hashmap synchronized?</span> </div>
<div style="outline: 0px; padding: 0px;">
<span class="content_font" style="margin: 0px; outline: 0px; padding: 0px;"><br style="margin: 0px; outline: 0px; padding: 0px;" /><span style="font-weight: normal;"><span style="color: black; font-family: Georgia, Times, serif; font-size: small;">1. The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized </span></span></span></div>
<div style="outline: 0px; padding: 0px;">
<span class="content_font" style="margin: 0px; outline: 0px; padding: 0px;"><span style="font-weight: normal;"><span style="color: black; font-family: Georgia, Times, serif; font-size: small;">and permits nulls. (HashMap allows null values as key and value whereas Hashtable doesn?t</span></span></span></div>
<div style="outline: 0px; padding: 0px;">
<span class="content_font" style="margin: 0px; outline: 0px; padding: 0px;"><span style="font-weight: normal;"><span style="color: black; font-family: Georgia, Times, serif; font-size: small;">allow nulls).</span><br style="margin: 0px; outline: 0px; padding: 0px;" /><span style="color: black; font-family: Georgia, Times, serif; font-size: small;">2. HashMap does not guarantee that the order of the map will remain constant over time.</span><br style="margin: 0px; outline: 0px; padding: 0px;" /><span style="color: black; font-family: Georgia, Times, serif; font-size: small;">3. HashMap is non synchronized whereas Hashtable is synchronized.</span><br style="margin: 0px; outline: 0px; padding: 0px;" /><span style="color: black; font-family: Georgia, Times, serif; font-size: small;">4. Iterator in the HashMap is fail-safe while the enumerator for the Hashtable isn't.</span><br style="margin: 0px; outline: 0px; padding: 0px;" /><br style="margin: 0px; outline: 0px; padding: 0px;" /><span style="color: black; font-family: Georgia, Times, serif; font-size: small;">Note on Some Important Terms </span><br style="margin: 0px; outline: 0px; padding: 0px;" /><span style="color: black; font-family: Georgia, Times, serif; font-size: small;">1)Synchronized means only one thread can modify a hash table at one point of time. Basically, it means that any thread before performing an update on a hashtable will have to acquire a lock on the object while others will wait for lock to be released.</span><br style="margin: 0px; outline: 0px; padding: 0px;" /><br style="margin: 0px; outline: 0px; padding: 0px;" /><span style="color: black; font-family: Georgia, Times, serif; font-size: small;">2)Fail-safe is relevant from the context of iterators. If an iterator has been created on a collection object and some other thread tries to modify the collection object "structurally?, a concurrent modification exception will be thrown. It is possible for other threads though to invoke "set" method since it doesn?t modify the collection "structurally?. However, if prior to calling "set", the collection has been modified structurally,</span><br style="margin: 0px; outline: 0px; padding: 0px;" /><span style="color: black; font-family: Georgia, Times, serif; font-size: small;">"IllegalArgumentException" will be thrown.</span><br style="margin: 0px; outline: 0px; padding: 0px;" /><br style="margin: 0px; outline: 0px; padding: 0px;" /><span style="color: black; font-family: Georgia, Times, serif; font-size: small;">HashMap can be synchronized by </span><br style="margin: 0px; outline: 0px; padding: 0px;" /><span style="color: black; font-family: Georgia, Times, serif; font-size: small;">Map m = Collections.synchronizeMap(hashMap);</span><br style="margin: 0px; outline: 0px; padding: 0px;" /></span></span></div>
<h2 style="margin: 0px; outline: 0px; padding: 0px;">
<span class="content_font" style="color: black; font-family: Georgia, Times, serif; font-size: 12pt; font-weight: normal; margin: 0px; outline: 0px; padding: 0px;">Implementations</span></h2>
<span class="content_font" style="color: black; font-family: Georgia, Times, serif; font-size: 12pt; margin: 0px; outline: 0px; padding: 0px;"><div style="outline: 0px; padding: 0px;">
<span style="font-weight: normal;">This table is a good summary of commonly used collection implementation classes.</span></div>
<div style="outline: 0px; padding: 0px;">
<span style="font-weight: normal;">General-purpose Implementations:</span></div>
<table border="1" cellpadding="0" style="margin: 0px; outline: 0px; padding: 0px; width: 99%px;"><tbody style="margin: 0px; outline: 0px; padding: 0px;">
<tr style="margin: 0px; outline: 0px; padding: 0px;"><td style="margin: 0px; outline: 0px; padding: 0px;" width="14%"><strong style="margin: 0px; outline: 0px; padding: 0px;">Interfaces</strong></td><td colspan="5" style="margin: 0px; outline: 0px; padding: 0px;"><strong style="margin: 0px; outline: 0px; padding: 0px;">Implementations</strong></td></tr>
<tr style="margin: 0px; outline: 0px; padding: 0px;"><td style="margin: 0px; outline: 0px; padding: 0px;"></td><td style="margin: 0px; outline: 0px; padding: 0px;">Hash table</td><td style="margin: 0px; outline: 0px; padding: 0px;">Resizable array</td><td style="margin: 0px; outline: 0px; padding: 0px;">Tree</td><td style="margin: 0px; outline: 0px; padding: 0px;">Linked list</td><td style="margin: 0px; outline: 0px; padding: 0px;">Hash table + Linked list</td></tr>
<tr style="margin: 0px; outline: 0px; padding: 0px;"><td style="margin: 0px; outline: 0px; padding: 0px;">Set</td><td style="margin: 0px; outline: 0px; padding: 0px;">HashSet</td><td style="margin: 0px; outline: 0px; padding: 0px;"></td><td style="margin: 0px; outline: 0px; padding: 0px;">TreeSet</td><td style="margin: 0px; outline: 0px; padding: 0px;"></td><td style="margin: 0px; outline: 0px; padding: 0px;">LinkedHashSet</td></tr>
<tr style="margin: 0px; outline: 0px; padding: 0px;"><td style="margin: 0px; outline: 0px; padding: 0px;">List</td><td style="margin: 0px; outline: 0px; padding: 0px;"></td><td style="margin: 0px; outline: 0px; padding: 0px;">ArrayList</td><td style="margin: 0px; outline: 0px; padding: 0px;"></td><td style="margin: 0px; outline: 0px; padding: 0px;">LinkedList</td><td style="margin: 0px; outline: 0px; padding: 0px;"></td></tr>
<tr style="margin: 0px; outline: 0px; padding: 0px;"><td style="margin: 0px; outline: 0px; padding: 0px;">Queue</td><td style="margin: 0px; outline: 0px; padding: 0px;"></td><td style="margin: 0px; outline: 0px; padding: 0px;"></td><td style="margin: 0px; outline: 0px; padding: 0px;"></td><td style="margin: 0px; outline: 0px; padding: 0px;"></td><td style="margin: 0px; outline: 0px; padding: 0px;"></td></tr>
<tr style="margin: 0px; outline: 0px; padding: 0px;"><td style="margin: 0px; outline: 0px; padding: 0px;">Map</td><td style="margin: 0px; outline: 0px; padding: 0px;">HashMap</td><td style="margin: 0px; outline: 0px; padding: 0px;"></td><td style="margin: 0px; outline: 0px; padding: 0px;">TreeMap</td><td style="margin: 0px; outline: 0px; padding: 0px;"></td><td style="margin: 0px; outline: 0px; padding: 0px;">LinkedHashMap</td></tr>
</tbody></table>
</span></td></tr>
<tr style="margin: 0px; outline: 0px; padding: 0px;"><td colspan="2" height="21" style="margin: 0px; outline: 0px; padding: 0px;" width="100%">Collection Resources -<br style="margin: 0px; outline: 0px; padding: 0px;" /><a href="http://bighai.com/ppjava/?p=158" style="color: #0252aa; cursor: pointer; margin: 0px; outline: 0px; padding: 0px; text-decoration: none;">http://bighai.com/ppjava/?p=158</a> <br style="margin: 0px; outline: 0px; padding: 0px;" /><a href="http://www.interview-questions-java.com/java-collections.htm" style="color: #0252aa; cursor: pointer; margin: 0px; outline: 0px; padding: 0px; text-decoration: none;">http://www.interview-questions-java.com/java-collections.htm</a> <br style="margin: 0px; outline: 0px; padding: 0px;" /><a href="http://www.javafaq.nu/java-article991.html" style="color: #0252aa; cursor: pointer; margin: 0px; outline: 0px; padding: 0px; text-decoration: none;">http://www.javafaq.nu/java-article991.html</a></td></tr>
</tbody></table>
<div class="MsoNormal">
<br /></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-80417774446408821212014-08-30T02:44:00.002-07:002014-08-30T02:44:34.054-07:00Difference between Get and Load method in Hibernate Get VS Load methods in Hibernate<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Difference between Get and Load method in Hibernate Get VS Load methods in Hibernate ? </b><br />
<br />
The difference between and get and load method is one of the most frequent asked question in hibernate. This question answer lets lot of about hibernate concepts. Hibernate session(session class is not thread safe) class get and load method, both of these methods used to access data, main difference between get() and load() method is that get() hits database if object doesn't exists in Session Cache and returns a fully initialized object which may involve several database call while load method can return proxy in place and only initialize the object or hit the database if any method other than getId() is called on persistent or entity object.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<b>Difference between get and load method</b><br />
<br />
<b>1. Database : </b><br />
Get method always hit database while load() method may not always hit the database, depending upon which method is called.<br />
<br />
<b>2. Behavior of get vs load when Object not found in session cache : </b><br />
Get method of Hibernate Session class returns null if object is not found in session cache as well as on database while load() method throws ObjectNotFoundException if object is not found on cache as well as on database but never return null.<br />
<br />
<b>3. Proxy :</b><br />
Get method never returns a proxy, it either returns null or fully initialized Object, while load() method may return proxy, which is the object with ID but without initializing other properties, which is lazily initialized. If you are just using returned object for creating relationship and only need Id then load() is the way to go<br />
<br />
<b>4. Performance : </b><br />
In interview most of the time ask which method have better performance Get method will return a completely initialized object if Object is not on the cache but exists on database, which may involve multiple round-trips to database based upon object relational mappings while load() method can return a proxy which can be initialized on demand (lazy initialization) when a non identifier method is accessed. Due to above reason use of load method will result in slightly better performance, but there is a caveat that proxy object will throw ObjectNotFoundExceptionRead<br />
<br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-43862371268439465002014-08-30T01:19:00.000-07:002014-08-30T02:15:49.144-07:00Difference between start and run in Java Thread<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;"><u>Difference between<span class="apple-converted-space"> </span></u><u>start</u><span class="apple-converted-space"><u> </u></span><u>and<span class="apple-converted-space"> </span></u><u>run</u><span class="apple-converted-space"><u> </u></span><u>in Java Thread</u><br />
<!--[if !supportLineBreakNewLine]-->
<!--[endif]--></span></div>
<table border="0">
<tbody>
<tr><td valign="top"><span style="font-family: Arial, Helvetica, sans-serif;">This is one of the popular interview question and </span><span style="font-family: Arial, Helvetica, sans-serif;">important to know the difference between these </span><span style="font-family: Arial, Helvetica, sans-serif;">two for multi thread programming.</span><b style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: 9pt; line-height: 13.800000190734863px;"> Why do one call<span class="apple-converted-space"> </span></span></b><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><b><span style="font-size: 9pt; line-height: 13.800000190734863px;">start</span></b><span class="apple-converted-space"><b><span style="font-size: 9pt; line-height: 13.800000190734863px;"> </span></b></span><b><span style="font-size: 9pt; line-height: 13.800000190734863px;">method of thread if<span class="apple-converted-space"> </span></span></b><b><span style="font-size: 9pt; line-height: 13.800000190734863px;">start()</span></b><span class="apple-converted-space"><b><span style="font-size: 9pt; line-height: 13.800000190734863px;"> </span></b></span><b><span style="font-size: 9pt; line-height: 13.800000190734863px;">calls<span class="apple-converted-space"> internally to </span></span></b><b><span style="font-size: 9pt; line-height: 13.800000190734863px;">run()</span></b><span class="apple-converted-space"><b><span style="font-size: 9pt; line-height: 13.800000190734863px;"> </span></b></span><b><span style="font-size: 9pt; line-height: 13.800000190734863px;">in</span></b></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><b><span style="font-size: 9pt; line-height: 13.800000190734863px;"> method.</span></b></span></td><td><script async="" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- JS_Thread_360_280 -->
<ins class="adsbygoogle" data-ad-client="ca-pub-8007733233603859" data-ad-slot="9037754342" style="display: inline-block; height: 280px; width: 336px;"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></td></tr>
</tbody></table>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; line-height: 115%;">So what difference is between<span class="apple-converted-space"> </span></span><span style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; line-height: 115%;">start</span><span class="apple-converted-space" style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: 9pt; line-height: 115%;"> </span></span><span style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; line-height: 115%;">and<span class="apple-converted-space"> </span></span><span style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; line-height: 115%;">run
method</span><span style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; line-height: 115%;">? The main difference between there are –</span></div>
<div class="MsoNormal">
<span style="font-size: 9pt; line-height: 115%;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<ul style="margin-top: 0in;" type="disc">
<ol start="1" style="margin-top: 0in;" type="1">
<li class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: 9pt; line-height: 115%;">While
program calls<span class="apple-converted-space"> </span></span><span style="font-size: 9pt; line-height: 115%;">start</span><span style="font-size: 9pt; line-height: 115%;">()
method a<span class="apple-converted-space"> </span><b>new Thread<span class="apple-converted-space"> </span></b>is created and code inside<span class="apple-converted-space"> </span></span><span style="font-size: 9pt; line-height: 115%;">run()</span><span class="apple-converted-space"><span style="font-size: 9pt; line-height: 115%;"> </span></span><span style="font-size: 9pt; line-height: 115%;">method
is executed in <b>new Thread while</b>
if you call<span class="apple-converted-space"> </span></span><span style="font-size: 9pt; line-height: 115%;">run()</span><span class="apple-converted-space"><span style="font-size: 9pt; line-height: 115%;"> </span></span><span style="font-size: 9pt; line-height: 115%;">method
directly<span class="apple-converted-space"> </span><b>no new Thread
is created</b><span class="apple-converted-space"> </span>and code
inside<span class="apple-converted-space"> </span></span><span style="font-size: 9pt; line-height: 115%;">run()</span><span class="apple-converted-space"><span style="font-size: 9pt; line-height: 115%;"> </span></span><span style="font-size: 9pt; line-height: 115%;">will
execute on<span class="apple-converted-space"> </span><b>current
Thread</b>.</span></span></li>
<li class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: 9pt; line-height: 115%;">Another
difference is that you<span class="apple-converted-space"> </span><b>can
not call<span class="apple-converted-space"> </span></b></span><b><span style="font-size: 9pt; line-height: 115%;">start()</span></b><span class="apple-converted-space"><b><span style="font-size: 9pt; line-height: 115%;"> </span></b></span><b><span style="font-size: 9pt; line-height: 115%;">method
twice<span class="apple-converted-space"> </span></span></b><span style="font-size: 9pt; line-height: 115%;">on
thread object, once started, second call of start() will throw<span class="apple-converted-space"> </span></span><span style="font-size: 9pt; line-height: 115%;">IllegalStateException<span class="apple-converted-space"> </span></span><span style="font-size: 9pt; line-height: 115%;">in Java while
you can call<span class="apple-converted-space"> </span></span><span style="font-size: 9pt; line-height: 115%;">run()</span><span class="apple-converted-space"><span style="font-size: 9pt; line-height: 115%;"> </span></span><span style="font-size: 9pt; line-height: 115%;">method
twice.<o:p></o:p></span></span></li>
</ol>
</ul>
<div class="MsoNormal" style="margin-left: 1.0in;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; line-height: 115%;">While java
programmer implemented threading in java most the time his/her intention is to
call start() method to create new thread but here calling run() is bug or
programming mistake. This error can be detected by many static code coverage
tools like FindBugs.</span></div>
<div class="MsoNormal" style="margin-left: 1.0in;">
<div class="MsoNormal" style="margin-left: 1.0in;">
<span style="background: white; font-size: 12pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 1.0in;">
<span style="background-color: white; font-size: 12pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 1.0in;">
<span style="background-color: white; font-size: 12pt; line-height: 115%;">FindBugs is a program which uses
static analysis to look for bugs in Java code, it is free software.</span></div>
</div>
<div class="MsoNormal" style="margin-left: 1.0in;">
<br /></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-83311181030549372162014-04-07T21:23:00.000-07:002014-08-30T02:18:00.017-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span class="heading_font" style="background-color: white; color: #9900cc; font-family: Georgia, Times, serif; font-size: 11pt; width: 500px;"> </span></h2>
<table border="0" cellpadding="0" cellspacing="0" style="font-family: Verdana, Arial, Georgia, serif; height: 100%px; width: 100%px;"><tbody>
<tr><td align="center" class="heading_font_repeater " colspan="2" height="21" style="color: blue; font-family: Georgia, Times, serif; font-size: 12pt; font-weight: bold; width: 500px;" valign="top" width="100%">iPhone</td></tr>
<tr><td colspan="2" height="21" valign="top" width="100%"><span class="heading_font" style="color: #9900cc; font-family: Georgia, Times, serif; font-size: 11pt; font-weight: bold; width: 500px;">Video formats supported by iPhone :</span> <span class="content_font" style="font-family: Georgia, Times, serif; font-size: 12pt; padding: 0px;"><br />The supported formats are:<br />* H.264 video, up to 1.5 Mbps, 640 by 480 pixels, 30 frames per second, Low-Complexity version of the H.264 Baseline Profile with AAC-LC audio up to 160 Kbps, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats;<br />* H.264 video, up to 768 Kbps, 320 by 240 pixels, 30 frames per second, Baseline Profile up to Level 1.3 with AAC-LC audio up to 160 Kbps, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats;<br />* MPEG-4 video, up to 2.5 Mbps, 640 by 480 pixels, 30 frames per second, Simple Profile with AAC-LC audio up to 160 Kbps, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats. </span><br />
<span class="content_font" style="font-family: Georgia, Times, serif; font-size: 12pt; padding: 0px;"><br /></span></td></tr>
</tbody></table>
<h2 style="text-align: left;">
<span class="heading_font" style="background-color: white; color: #9900cc; font-family: Georgia, Times, serif; font-size: 11pt; width: 500px;"> </span><span class="heading_font" style="color: #9900cc; font-family: Georgia, Times, serif; font-size: 11pt; width: 500px;">What is iPhone H.264? :</span><span style="background-color: white; font-family: Verdana, Arial, Georgia, serif;"> </span></h2>
<div>
<div style="background-color: white; font-family: Verdana, Arial, Georgia, serif;">
<span class="content_font" style="font-family: Georgia, Times, serif; font-size: 12pt; padding: 0px;">H.264 is a MPEG-4 compression standard for video, which can deliver top video quality at about half the file size of MPEG-2. H.264 technology is also known as MPEG-4 Part 10 or AVC (Advanced Video Coding). </span></div>
<div style="background-color: white; font-family: Verdana, Arial, Georgia, serif;">
<span class="content_font" style="font-family: Georgia, Times, serif; font-size: 12pt; padding: 0px;"><br /></span></div>
<div style="background-color: white; font-family: Verdana, Arial, Georgia, serif;">
<span class="content_font" style="font-family: Georgia, Times, serif; font-size: 12pt; padding: 0px;"><span style="color: #9900cc; font-size: 15px; font-weight: bold;">Audio formats supported by iPhone :</span></span></div>
<div style="background-color: white; font-family: Verdana, Arial, Georgia, serif;">
<span class="content_font" style="font-family: Georgia, Times, serif; font-size: 12pt; padding: 0px;">The Apple iPhone supports the following audio formats:<br />AAC (16 to 320 Kbps)<br />AIFF<br />AAC Protected (MP4 from iTunes Store)<br />MP3 (16 to 320 Kbps)<br />MP3 VBR<br />Audible (formats 2-4)<br />Apple Lossless<br />WAV</span></div>
</div>
<div>
<br />
<br /></div>
</div>
<form action="http://feedburner.google.com/fb/a/mailverify" method="post" onsubmit="window.open('http://feedburner.google.com/fb/a/mailverify?uri=Jeet-software', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true" style="border: 1px solid #ccc; padding: 3px; text-align: center;" target="popupwindow">
Enter your email address:<br />
<input name="email" style="width: 140px;" type="text" /><br />
<input name="uri" type="hidden" value="Jeet-software" /><input name="loc" type="hidden" value="en_US" /><input type="submit" value="Subscribe" /><br />
Delivered by <a href="http://feedburner.google.com/" target="_blank">FeedBurner</a></form>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-50198761258848682922012-12-30T08:39:00.002-08:002012-12-30T08:48:17.787-08:00<div dir="ltr" style="text-align: left;" trbidi="on">
<br /><font color="GREEN" >
What is Firepond's ICS ?
</font></div>
Firepond's ICS provides the tools needed to create and maintain the product configuration data, whether it's for a robust enterprise sales system, or the Internet-enabled OnDemand application. Firepond also offers data maintenance services for companies that prefer to outsource their data work.
Firepond have developed ICS over 20 years. The company says it has evolved into the most powerful yet easiest to use product configuration data maintenance tool available. Data entry personnel do not need to be programmers, and, as the rules are easy to create and understand, there is less chance for error. And if there is an error, it is easier to locate and correct. The Product Data Tester (PDT) allows the data to be tested to ensure it produces the desired results.
"This release of ICS shows Firepond's ongoing commitment to its customers as well as a commitment to strengthening the new OnDemand product," said Firepond's VP of Engineering, Craig Christiansen. "We are excited to offer these products to companies who want to arm their salespeople with all the data needed to accurately configure, price, quote and propose products and services to prospective customers."
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1633638665839357738.post-33912627939372472782012-12-30T07:10:00.002-08:002012-12-30T07:12:43.714-08:00<div dir="ltr" style="text-align: left;" trbidi="on">
<br />My Java Programming site - <a target="_blank" href="http://www.javaprogrammings.info"> Click Here</a></div>
Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-1633638665839357738.post-19000662177748573692010-10-10T10:53:00.000-07:002014-05-01T20:49:03.517-07:00Jitendra's Portfolio<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
I am Software Engineer having 4 + years of experience in cutting edge technologies like web 2.0 ,wap,RESTful web services,JSON,AJAX etc.<br />
<br />
Having good hands in hibernate,struts,MySql etc.<br />
Experience in Frameworks like Struts 1.2 and Struts 2.0,Spring.<br />
Experience in UI development using JavaScript and AJAX.<br />
Sound knowledge of Design Patterns.<br />
<br />
2 + years development and deployment experience in Linux OS.<br />
<br />
Hands in following third party services -<br />
Payment Gateway (Paypal for web and WAP site.)<br />
SMS Gateway (Clickatell, NowSMS)<br />
Amazon S3 Services (Data storage third party). <br />
<br />
I developed web portal,wap portals (compatible in iPhone,Nokia mobiles,Blackberry).<br />
<br /></div>
<a href="http://feeds.feedburner.com/Jeet-software" rel="alternate" title="Subscribe to my feed" type="application/rss+xml"><img alt="" src="//feedburner.google.com/fb/images/pub/feed-icon32x32.png" style="border: 0;" /></a><a href="http://feeds.feedburner.com/Jeet-software" rel="alternate" title="Subscribe to my feed" type="application/rss+xml">Subscribe in a reader</a></div>
<a href="http://feedburner.google.com/fb/a/mailverify?uri=Jeet-software&loc=en_US">Subscribe to jeet-software by Email</a></div>
Unknownnoreply@blogger.com1