tag:blogger.com,1999:blog-89335991839036605152024-03-14T05:35:25.019-07:00Java TutorialA blog with important java concepts...Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.comBlogger22125tag:blogger.com,1999:blog-8933599183903660515.post-37012904394883347772014-12-10T07:26:00.001-08:002014-12-10T07:26:06.758-08:00Assign javascript variable to jsp variable<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
Struct with the below scenario ? ,</div>
<div>
<br /></div>
<div>
String version ="<script>document.write(get_version);</script>";</div>
<div>
out.println(version); -------> 1.0</div>
<div>
<br /></div>
<div style="text-align: justify;">
but version = "<script>document.write(get_version);</script>" still and are you unable to use the version variable in JSP and want to fix this issue.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Guys am here to help you out even in this tough situation. You should not suffer as I suffered to fix this issue. Please follow the below steps and make yourself great and fix the issue. Everything is possible in Java.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Assign javascript variable to jsp variable, or use javascript variable to jsp variable or pass hidden value to JSP page from another page where you are uploading a file with post method and still you want to pass a html element value from post form where you want the get method logic. Here below the great example. Try to understand the below scenario and your issue is fixed.</div>
<div>
<br /></div>
<div>
<b>Current JSP or HTML form page : </b></div>
<div>
<b><br /></b></div>
<div>
<b>Currentpage.jsp</b></div>
<div>
<br /></div>
<div>
document.getElementById("myForm").submit();</div>
<div>
document.myForm.action = "uploadget.jsp?hiddenVersion="+document.getElementById("version").value;</div>
<div>
alert("File Uploaded Successfully");</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<div>
<form name="myForm" enctype="multipart/form-data" method="post" onsubmit="return validateForm();" id="myForm"></div>
<div>
<input type="hidden" name="hiddenVersion" id="hiddenVersion" value=""></div>
</div>
<div>
.....</div>
<div>
<input type="text" id="version" name="version"></div>
<div>
......</div>
<div>
</form></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<b>And in your action JSP use this,</b></div>
<div>
<br /></div>
<div>
request.getParameter("hiddenVersion");</div>
<div>
<br /></div>
<div>
and thats it.</div>
</div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com1tag:blogger.com,1999:blog-8933599183903660515.post-1258874220905757292014-05-27T00:53:00.003-07:002014-05-27T00:53:40.230-07:00Features of Java<div dir="ltr" style="text-align: left;" trbidi="on">
The features of Java are,<br />
<br />
<b>Simple </b>- Java is very simple programming to learn which is based on C++. No complex terms like explicit pointers and operator overloading etc. No need to destroy objects at the end after usage because there is auto destruction of objects in java named as Garbage Collection.<br />
<b>Object Oriented </b>- Simplified software development and rules and maintenance is easier. The basic concept of oops are object, class, inheritance, polymorphism, abstraction, encapsulation, dynamic binding, message parsing.<br />
<b>Platform Independent - </b>Compile it once and run it in any platform like windows, linux, solaris, etc... Java code units are converted into byte code by the compiler. This byte code is platform independent.<br />
<b>Secured - </b>Java is secured because there are no pointers and the program runs inside the virtual machine.<br />
<b>Robust - </b>Java is strong in memory management.<br />
<b>Portability - </b>Java byte code can be run in any platform and it can be carried anywhere in any platform.<br />
<b>Interpreted</b><br />
<b>Multi threading - </b>Multiple tasks using multiple threads sharing same memory. Threads are separate program which runs concurrently.<br />
<b>High Performance - </b>Java is faster.<br />
<b>Distributed - </b>We can create distributed apps in Java.<br />
<br />
The above terms are also called as buzz words in Java.</div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0tag:blogger.com,1999:blog-8933599183903660515.post-83332629214333228972014-05-15T04:11:00.001-07:002014-05-15T04:11:00.899-07:00Genetic Algorithm Java Example<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="text-align: justify;">
Genetic algorithm is a part in evolutionary computing and it
is growing rapidly in the area of artificial intelligence. Let us discuss about this concept in the below link.<o:p></o:p></div>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<a href="http://stackoverflow.com/questions/1575061/ga-written-in-java">http://stackoverflow.com/questions/1575061/ga-written-in-java</a></div>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
Applications of GA (Genetic Algorithm) are used in engineering, computational science, physics, chemistry, mathematics, manufacturing, economics, pharmacometrics, bio informatics, phylogenetics, and in many other fields.</div>
</div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0tag:blogger.com,1999:blog-8933599183903660515.post-7444691497237193762014-04-25T12:39:00.000-07:002014-04-25T12:39:10.116-07:00Right Click JTextField cut copy paste<div dir="ltr" style="text-align: left;" trbidi="on">
In this post you can learn an example on how to implement right click option for cut, copy and paste in a JTextField in java swings. This concept is used in many swing application development.<br />
<br />
<span style="background-color: #cccccc;"> JTextField textfield;</span><br />
<span style="background-color: #cccccc;"> textfield = new JTextField(15);</span><br />
<span style="background-color: #cccccc;"> </span><br />
<span style="background-color: #cccccc;"> JPopupMenu popup = new JPopupMenu();</span><br />
<span style="background-color: #cccccc;"> JMenuItem item = new JMenuItem(new DefaultEditorKit.CutAction());</span><br />
<span style="background-color: #cccccc;"> item.setText("Cut");</span><br />
<span style="background-color: #cccccc;"> popup.add(item);</span><br />
<span style="background-color: #cccccc;"> item = new JMenuItem(new DefaultEditorKit.CopyAction());</span><br />
<span style="background-color: #cccccc;"> item.setText("Copy");</span><br />
<span style="background-color: #cccccc;"> popup.add(item);</span><br />
<span style="background-color: #cccccc;"> item = new JMenuItem(new DefaultEditorKit.PasteAction());</span><br />
<span style="background-color: #cccccc;"> item.setText("Paste");</span><br />
<span style="background-color: #cccccc;"> popup.add(item);</span><br />
<span style="background-color: #cccccc;"> textfield.setComponentPopupMenu(popup);</span></div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0tag:blogger.com,1999:blog-8933599183903660515.post-58799699154699442322014-04-25T12:28:00.002-07:002014-04-25T12:29:26.897-07:00Change value of static variable by method<div dir="ltr" style="text-align: left;" trbidi="on">
Actually we have learned that static variable does not change its value and it is not possible to change the value of a static variable. But in this post you can learn an example in java on how to change the value of a static variable by using a method in java.<br />
<br />
<b>InitializeByMethod.java</b><br />
<b><br /></b>
<span style="background-color: #cccccc;">package com.udhaya;</span><br />
<span style="background-color: #cccccc;"><br /></span>
<span style="background-color: #cccccc;">class StaticDemo {</span><br />
<span style="background-color: #cccccc;"> static String name;</span><br />
<span style="background-color: #cccccc;">public static void staticVariable() {</span><br />
<span style="background-color: #cccccc;"> name = name + " " + "kumar";</span><br />
<span style="background-color: #cccccc;"> System.out.println("Value of static variable after method calling"</span><br />
<span style="background-color: #cccccc;"> + name);</span><br />
<span style="background-color: #cccccc;"> }</span><br />
<span style="background-color: #cccccc;">}</span><br />
<span style="background-color: #cccccc;">public class InitializeByMethod {</span><br />
<span style="background-color: #cccccc;">public static void main(String[] args) {</span><br />
<span style="background-color: #cccccc;"> System.out.println("Initial value of static variable"</span><br />
<span style="background-color: #cccccc;"> + StaticDemo.name);</span><br />
<span style="background-color: #cccccc;"> StaticDemo.name = "udhaya";</span><br />
<span style="background-color: #cccccc;"> System.out.println("Value of static variable after initialization"</span><br />
<span style="background-color: #cccccc;"> + StaticDemo.name);</span><br />
<span style="background-color: #cccccc;"> StaticDemo.staticVariable();</span><br />
<span style="background-color: #cccccc;"> }</span><br />
<span style="background-color: #cccccc;">}</span></div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0tag:blogger.com,1999:blog-8933599183903660515.post-82112423935350163442013-10-11T04:18:00.000-07:002013-10-11T04:18:10.957-07:00What is the Latest Java Version<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_Pzqndmx1o1xu_E1zqNhHRMV9vmfR93Nfr0fsQDzzhFP6SazQlQLJF41PSEa-NStDnduJmcc_Kk5g2cG6CRsyNc28EaOVuJfxSJkVQl2OkNI8pyrUEz1O87wUYek4bqDHV-l2XoG7dPeK/s1600/IMAG0524.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_Pzqndmx1o1xu_E1zqNhHRMV9vmfR93Nfr0fsQDzzhFP6SazQlQLJF41PSEa-NStDnduJmcc_Kk5g2cG6CRsyNc28EaOVuJfxSJkVQl2OkNI8pyrUEz1O87wUYek4bqDHV-l2XoG7dPeK/s200/IMAG0524.jpg" width="132" /></a></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"></span> </div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">"What is the latest java version?" is an important question today in majority of the interviews. This post explains you the list of Java Versions.</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"> </span></div>
<div style="text-align: left;">
<strong><span style="font-family: Arial, Helvetica, sans-serif;">Java Version SE 7</span></strong></div>
<div style="text-align: left;">
<strong><span style="font-family: Arial, Helvetica, sans-serif;">Java Version SE 6</span></strong></div>
<div style="text-align: left;">
<strong><span style="font-family: Arial, Helvetica, sans-serif;">J2SE Version 5.0</span></strong></div>
<div style="text-align: left;">
<strong><span style="font-family: Arial, Helvetica, sans-serif;">J2SE Version 1.4</span></strong></div>
<div style="text-align: left;">
<strong><span style="font-family: Arial, Helvetica, sans-serif;">J2SE Version 1.3</span></strong></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><strong>J2SE Version 1.2</strong> </span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><strong>JDK Version 1.1</strong> </span></div>
<div style="text-align: left;">
<strong><span style="font-family: Arial, Helvetica, sans-serif;">JDK Version 1.0</span></strong></div>
<div style="text-align: left;">
<strong><span style="font-family: Arial, Helvetica, sans-serif;"></span></strong> </div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><strong>Features of Java SE 7</strong></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-family: Arial, Helvetica, sans-serif;">Automatic Null Handling</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Binary Literals and underscore in literals</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Diamond Syntax</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Java nio Package</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Multiple Exception Handling</span><br />
Strings in the Switch Statement</span><span style="font-family: Arial, Helvetica, sans-serif;">Support for the Dynamic Languages</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Type Inference for the Generic Instance Creation</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Try with Resources</span></div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0tag:blogger.com,1999:blog-8933599183903660515.post-38398291001497721922013-10-01T02:33:00.003-07:002013-10-01T02:33:40.523-07:00Java Complete Video Tutorial<div dir="ltr" style="text-align: left;" trbidi="on">
Core Java Video Tutorial<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/Wap6gRuB8Xw?feature=player_embedded' frameborder='0'></iframe></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
Java Collections Video Tutorial<br />
<br />
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/jU5ACV5MucM?feature=player_embedded' frameborder='0'></iframe><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
Restful Services in Java</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/gKBiIWY7FYw?feature=player_embedded' frameborder='0'></iframe></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
Java J2EE</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/R0dogNWjqw8?feature=player_embedded' frameborder='0'></iframe></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
Servlets</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/cyPT4DXYu8g?feature=player_embedded' frameborder='0'></iframe></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
Hibernate</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/Yv2xctJxE-w?feature=player_embedded' frameborder='0'></iframe></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
Struts 2</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/y91YILd8DGo?feature=player_embedded' frameborder='0'></iframe></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
Spring</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<object width="320" height="266" class="BLOGGER-youtube-video" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" data-thumbnail-src="http://img.youtube.com/vi/Jjp_EYEn4bc/0.jpg"><param name="movie" value="http://youtube.googleapis.com/v/Jjp_EYEn4bc&source=uds" /><param name="bgcolor" value="#FFFFFF" /><param name="allowFullScreen" value="true" /><embed width="320" height="266" src="http://youtube.googleapis.com/v/Jjp_EYEn4bc&source=uds" type="application/x-shockwave-flash" allowfullscreen="true"></embed></object></div>
</div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0tag:blogger.com,1999:blog-8933599183903660515.post-50496953151467442922013-06-03T09:19:00.001-07:002013-06-03T09:19:05.364-07:00How to get Input from User in Java<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="background-color: #fff2cc;">
import java.util.Scanner;</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
<br /></div>
<div class="MsoNormal" style="background-color: #fff2cc;">
class getuserinput</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
{</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
public static void main(String args[])</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
{</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
int a;</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
float b;</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
String c;</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
System.out.println("Enter integer");</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
a = in.nextInt();</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
System.out.println("The Value is "+a);</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
Scanner in = new Scanner(System.in);</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
System.out.println("Enter float");</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
b = in.nextFloat();</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
System.out.println("The Value is "+b); </div>
<div class="MsoNormal" style="background-color: #fff2cc;">
System.out.println("Enter string");</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
c = in.nextLine();</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
System.out.println("The Value is "+c);</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
}</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
}</div>
</div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0tag:blogger.com,1999:blog-8933599183903660515.post-6193128863115596922013-06-03T09:18:00.003-07:002013-06-03T09:18:31.331-07:00Java Code to Read Text File<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="background-color: #fff2cc;">
import java.io.*;</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
class ReadFile </div>
<div class="MsoNormal" style="background-color: #fff2cc;">
{</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
public static void main(String args[])</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
{</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
try{</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
FileInputStream fstream = new
FileInputStream("C:\\java\\<wbr></wbr>demo\\file.txt");</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
DataInputStream in = new
DataInputStream(fstream);</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
BufferedReader br = new BufferedReader(new
InputStreamReader(in));</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
String Data;</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
while ((Data = br.readLine()) != null) {</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
System.out.println (Data);</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
}</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
in.close();</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
}</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
catch (Exception e)</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
{</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
System.err.println("Error: " +
e.getMessage());</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
}</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
}</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
}</div>
</div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0tag:blogger.com,1999:blog-8933599183903660515.post-22956229379714573282013-06-03T09:17:00.004-07:002014-05-27T00:07:04.452-07:00Java Code to Send Email<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="background-color: #fff2cc;">
package Javamails;</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
<br /></div>
<div class="MsoNormal" style="background-color: #fff2cc;">
import javax.mail.*;</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
import java.util.*; </div>
<div class="MsoNormal" style="background-color: #fff2cc;">
<br /></div>
<div class="MsoNormal" style="background-color: #fff2cc;">
public class Javamail</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
{</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
public static void main(String[] args)throws
MessagingException</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
{</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
String from = "<a href="http://www.blogger.com/blogger.g?&v=b&cs=wh&to=javasundaresan@gmail.com" target="_blank">udhaya1987devtest@gmail.com</a>",</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
password = "",</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
host = "<a href="http://smtp.gmail.com/" target="_blank">smtp.gmail.com</a>",</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
port = "8000",</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
to = "<a href="http://www.blogger.com/blogger.g?&v=b&cs=wh&to=kadavul@sorgam.com" target="_blank">infy1998soft@sorgam.com</a>",</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
subject = "Hi",</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
message = "Hi Team";</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
Properties props = new Properties();</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
props.put("mail.smtp.user", from);</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
props.put("mail.smtp.host", host);</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
props.put("mail.smtp.port", port);</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
props.put("mail.smtp.starttls.<wbr></wbr>enable","true");</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
props.put("mail.smtp.auth", "true");</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
props.put("mail.smtp.<wbr></wbr>socketFactory.port",port);</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
props.put("mail.smtp.<wbr></wbr>socketFactory.class","javax.<wbr></wbr>net.ssl.SSLSocketFactory");</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
props.put("mail.smtp.<wbr></wbr>socketFactory.fallb","false");</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
SecurityManager security =
System.getSecurityManager();</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
try</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
{</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
Authenticator auth = new
SMTPAuthenticator();</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
Session session = Session.getInstance(props,
auth);</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
MimeMessage msg = new MimeMessage(session);</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
msg.setText(message);</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
msg.setSubject(subject);</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
msg.setFrom(new InternetAddress(from));</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
msg.addRecipient(<a href="http://www.google.com/url?q=http%3A%2F%2FMessage.RecipientType.TO&sa=D&sntz=1&usg=AFQjCNG5IU0_CAyfFMaeASasga5V7HN_Sg" target="_blank">Message.<wbr></wbr>RecipientType.TO</a>,new
InternetAddress(to);</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
Transport.send(msg);</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
}</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
catch(Exception mex)</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
{</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
mex.printStackTrace();</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
} </div>
<div class="MsoNormal" style="background-color: #fff2cc;">
}</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
}</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
<br /></div>
<div class="MsoNormal" style="background-color: #fff2cc;">
class SMTPAuthenticator extends
javax.mail.Authenticator</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
{</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
String from = "<a href="http://www.blogger.com/blogger.g?&v=b&cs=wh&to=sender_id@gmail.com" target="_blank">sender_id@gmail.com</a>",</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
password = "password",</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
host = "<a href="http://smtp.gmail.com/" target="_blank">smtp.gmail.com</a>",</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
port = "8000",</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
to = "<a href="http://www.blogger.com/blogger.g?&v=b&cs=wh&to=kadavul@sorgam.com" target="_blank">infy1998soft</a><a href="http://www.blogger.com/blogger.g?&v=b&cs=wh&to=kadavul@sorgam.com" target="_blank">@sorgam.com</a>",</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
subject = "Hi",</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
message = "Hi Team";</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
public PasswordAuthentication
getPasswordAuthentication()</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
{</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
return new PasswordAuthentication(from,
password);</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
}</div>
<div class="MsoNormal" style="background-color: #fff2cc;">
}</div>
</div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0tag:blogger.com,1999:blog-8933599183903660515.post-27732677961644992013-05-27T14:03:00.000-07:002013-05-27T14:03:05.924-07:00How to Declare a String Array in Java<div dir="ltr" style="text-align: left;" trbidi="on">
Strings can be declared in java using the keyword new as shown in the below example. Without using the keyword new also it can be declared as shown below. The following example illustrates how to declare a string and how to initialize it. <br />
<br />
<b>String arrays can be declared in Java by the following syntax.</b><br />
<br />
String first[] = new String[] {"gopi", "krishnamma",
"udhaya", "priya"};<br /><br />
String second[] = {"ravi", "bindhu", "ramya",
"rama"};<br />
<br />
<b>For two dimensional arrays,</b><br />
<br />
<br />
<pre class="prettyprint lang-java"><span class="typ">String</span><span class="pln"> twod</span><span class="pun">[][]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="pun">{</span><span class="str">"a"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"b"</span><span class="pun">},</span><span class="pln">
</span><span class="pun">{</span><span class="str">"c"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"d"</span><span class="pun">}</span><span class="pun">}</span><span class="pln">
</span><span class="pun">};</span><span class="pln">
</span></pre>
</div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0tag:blogger.com,1999:blog-8933599183903660515.post-9503658094457890562013-05-27T13:29:00.002-07:002013-05-27T13:29:30.432-07:00Core Java Interview Questions and Answers<div dir="ltr" style="text-align: left;" trbidi="on">
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><br />
<!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if !mso]><img src="//img2.blogblog.com/img/video_object.png" style="background-color: #b2b2b2; " class="BLOGGER-object-element tr_noresize tr_placeholder" id="ieooui" data-original-id="ieooui" />
<style>
st1\:*{behavior:url(#ieooui) }
</style>
<![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
<br />
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b><span class="il">Java</span> <span class="il">Interview</span> <span class="il">Questions</span> and Answers.</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Hi
Guys. You can see the list of important <span class="il">interview</span> <span class="il">questions</span> asked in <span class="il">Java</span>. Please have a
look. This might be useful for you for preparing your <span class="il">interviews</span>.
You can get a clear view on definitions and concepts from this page.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is <span class="il">Java</span>? Where it is used?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span class="il">Java</span> is a programming language and computing platform. It is
released by Sun Microsystems in 1995. It is used in Gaming, Web building &
Business Applications.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
are the Basic concepts of OOPS?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Object</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Class</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Data
Abstraction</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Data
Encapsulation</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Polymorphism
</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Inheritance</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Dynamic
Binding & Message Parsing</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is an Object?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
An
object is an instance of class. It can be a name, color, etc....</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is a Class?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
A
class is a blue print from which individual objects are created.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is Data Abstraction? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Data
Abstraction refers to the act of representing essential features without
considering the background details or explanations.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is Data Encapsulation? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
It
is used for hiding the properties of an object. It prevents other objects from
accessing the properties of the encapsulate object.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is Polymorphism? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Polymorphism
is the ability to have more than one form.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>Explain
the different forms of Polymorphism?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
There
are two types of polymorphism one is Compile time polymorphism and the other
one is run time polymorphism. </div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Compile
time polymorphism is method overloading. </div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Runtime
time polymorphism is done using inheritance and interface.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>How
does <span class="il">Java</span> implement polymorphism? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span class="il">Java</span> implements polymorphism by using overloading and
overriding concepts.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is Overloading?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Methods
with same name, but with different arguments.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is overriding?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
When
a method in a subclass has the same name and type signature as a method in its
super class, then the method in the subclass is said to override the method in
the super class.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
A
method named final or a method named static cannot be overridden.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>Can
a main method be overridden?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Since
the main method is static it cannot be overridden.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is super keyword? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Super
keyword is used to access the methods or member variables from the super class.
If a method hides one of the member variables in its super class, the method
can refer to the hidden variable through the use of the super keyword.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
If
a method overrides one of the methods in its super class, the method can invoke
the overridden method through the use of the super keyword.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is Inheritance? What are its types?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Inheritance
is the process by which objects of one class acquiring the properties of
objects of another class. The types are single inheritance, multiple
inheritance, multilevel inheritance and hierarchical inheritance.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>Does
<span class="il">Java</span> support multiple inheritances? If yes/no why?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
No.
<span class="il">Java</span> does not support multiple inheritances. Because when
a class inherits from more than one class, it will lead to inheritance path
ambiguity problem which is normally called as diamond problem.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>Name
the keyword used for inheritance?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Extends
keyword is used for inheritance.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is Dynamic Binding?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Dynamic
Binding refers to the linking of a procedure call to the code to be executed in
response to the call. Dynamic binding means that the code associated with a
given procedure call is not known until the time of the call at run-time. </div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
It
is associated with polymorphism and inheritance.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is an Interface? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
An
interface is a description of a set of methods that conforming implementing
classes must have.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
You
cannot mark an interface as final. Interface variables must be static. An
Interface cannot extend anything but it can extend with another interfaces.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>Is
it possible to instantiate an interface? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
It
is not possible to instantiate an interface directly, but you can instantiate a
class that implements an interface.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>Do
interfaces have member variables? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Interfaces
may have member variables, but these are implicitly public, static, and final.
In other words, interfaces can declare only constants, not instance variables
that are available to all implementations and may be used as key references for
method arguments for example.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is an abstract class? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Abstract
classes are classes that contain one or more abstract methods. An abstract
method is a method that is declared, but contains no implementation. </div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
If
even a single method is abstract, the whole class must be declared abstract.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Abstract
classes may not be instantiated, and require subclasses to provide
implementations for the abstract methods.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
An
abstract class can never be instantiated. Its purpose is to be extended (sub
classed).</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
You
cannot mark a class as both abstract and final.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
are the differences between Interface and Abstract class? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
An
abstract class can provide complete, default code and just the details that
have to be overridden. </div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
An
interface cannot provide any code at all, just the signature.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
All
the methods declared inside an interface are implicitly abstract whereas
abstract class must have at least one abstract method and others may be
concrete or abstract.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
In
abstract class, key word abstract must be used for the methods whereas
interface we need not use that keyword for the methods.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Abstract
class must have subclasses whereas interface cannot have subclasses.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>When
should I use abstract classes and when should I use interfaces? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Use
an interface if various implementations only share method signatures.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
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.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Use
Abstract Class if various implementations are of the same kind and use common
behavior or status then abstract class is better to use. Abstract classes are
an excellent way to create planned inheritance hierarchies.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>When
you declare a method as abstract, can other non abstract methods access it? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Yes,
other non abstract methods can access a method that you declare as abstract. </div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>Can
there be an abstract class with no abstract methods in it? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Yes,
there can be an abstract class without abstract methods.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is Constructor? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
A
constructor is a special method whose task is to initialize the object of its
class.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
It
is a special method because its name is the same as the class name. </div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
They
do not have any return types. They not even have void, they cannot be
inherited. A constructor is called when instantiating a object with new ().
Constructors can be overloaded.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>Can
constructor be inherited? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
No,
constructor cannot be inherited, though a derived class can call the base class
constructor.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>How
are this () and super () used with constructors? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Constructors
use this to refer to another constructor in the same class with a different
parameter list.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Constructors
use super to invoke the super class’s constructor. If a constructor uses super
it must use it in the first line. Otherwise the compiler will throw.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
are the differences between Class Methods and Instance Methods? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Class
methods are methods which are declared as static. The method can be called
without creating an instance of the class.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
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.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
are Access Specifies? What are its types?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
One
of the techniques in object-oriented programming is encapsulation. It concerns
the hiding of data in a class and making this class available only through
methods. <span class="il">Java</span> allows you to control access to classes,
methods, and fields via so-called access specifies.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Public-
public classes, methods, and fields can be accessed from everywhere.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Private-
Private Methods and fields can only be accessed within the same class to which
the methods and fields belong. Private methods and fields are not visible
within subclasses and are not inherited by subclasses.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Protected-
protected 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. </div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Default-
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.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>Name
some modifiers in <span class="il">java</span>?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Final,
Transient, abstract, public, private, etc...</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is final modifier?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
A
class declared as final cannot be sub classed.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
A
method declared as final cannot be overridden and dynamically looked up.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
A
field declared as final cannot change its value. Static final fields are
compile-time constants.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
A
variable declared as final cannot change its value.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is static block?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Static
block executes exactly once when the class is first loaded into JVM. Before
going to the main method the static block will execute.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is the difference between static and non-static variables?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
A
static variable is associated with the class as a whole rather than with
specific instances of a class. Non-static variables take on unique values with
each object instance.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is an Iterator? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
The
Iterator interface is used to step through the elements of a Collection.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Iterators
let you process each element of a Collection. </div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Iterators
are a generic way to go through all the elements of a Collection no matter how
it is organized.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Iterator
is an Interface implemented a different way for every Collection. </div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
are the advantages of Array List over arrays ? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
It
can grow dynamically</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
It
provides more powerful insertion and search mechanisms than arrays.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
are the main Implementations of the Set interface? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Hash
Set </div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Tree
Set</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Linked
Hash Set </div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Enum
Set</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>Difference
between Hash Map and Hash table ? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Hash
Map lets you have null values as well as one null key.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Hash
Table does not allows null values as key and value.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
The
iterator in the Hash Map is fail-safe.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
The
enumerator for the Hash table is not fail-safe.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Hash
Map is unsynchronized.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Hash
table is synchronized.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>Explain
different way of using thread? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
The
thread could be implemented by using runnable interface or by inheriting from
the Thread class.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
are pass by reference and passby value? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Pass
By Reference means the passing the address itself rather than passing the
value. Passby Value means passing a copy of the value to be passed. </div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is Hash Map and Map?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Map
is Interface and Hash map is class that implements that.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>Difference
between Vector and Array List?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Vector
is synchronized whereas array list is not synchronized.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>Difference
between Swing and Awt?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
AWT
are heavy-weight components. Swings are light-weight components. Swing works
faster than AWT.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is the difference between a constructor and a method? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
A
constructor is a member function of a class that is used to create objects of
that class. It has the same name as the class itself, has no return type, and
is invoked using the new operator.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
A
method is an ordinary member function of a class. It has its own name, a return
type (which may be void), and is invoked using the dot operator.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is Garbage Collection and how to call it explicitly?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
The
purpose of garbage collection is to identify and discard objects that are no
longer needed by a program so that their resources can be reclaimed and reused.
A <span class="il">Java</span> object is subject to garbage collection when it
becomes unreachable to the program in which it is used. When an object is no
longer referred to by any variable, <span class="il">java</span> automatically
reclaims memory used by that object. This is known as garbage collection.
System. gc () method may be used to call it explicitly.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is finalize () method?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Finalize
() method is used just before an object is destroyed and can be called just
prior to garbage collection.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is daemon thread and which method is used to create the daemon thread? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Daemon
thread is a low priority thread which runs intermittently in the back ground
doing the garbage collection operation for the <span class="il">java</span>
runtime system. setDaemon method is used to create a daemon thread.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
are applets?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Applets
are <span class="il">java</span> programs used for internet computing. Applet is
a dynamic and interactive program that runs inside a web page displayed by a <span class="il">java</span> capable browser.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is serialization and deserialization?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Serialization
is the process of writing the state of an object to a byte stream.
Deserialization is the reverse process of restoring these objects.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is JDBC?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
JDBC
stands for <span class="il">Java</span> Data Base Connectivity which is a set of <span class="il">Java</span> API for executing SQL statements.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
are drivers available in <span class="il">Java</span>?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
JDBC-ODBC Bridge driver </div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Native
API Partly-<span class="il">Java</span> driver</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
JDBC-Net
Pure <span class="il">Java</span> driver</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Native-Protocol
Pure <span class="il">Java</span> driver</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is a subclass? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Subclass
is a class that inherits from one or more classes. </div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is a super class or base class? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Super
class or a base class is a class from which another class inherits. </div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>Explain
Destructors in <span class="il">java</span>?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span class="il">Java</span> does not have any destructors because <span class="il">java</span>
has garbage collection.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is JVM? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
JVM
is <span class="il">Java</span> Virtual Machine which is a run time environment
for the compiled <span class="il">java</span> class files. </div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
are Instance variables? </b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Instance
variables are variables which are defined inside the class but outside the
method. They will be automatically initialized. </div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is a package?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Package
is a collection of related classes and interfaces.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>Can
a Class extend more than one Class?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
No.
A Class can extend only one class but it can implements any number of
Interfaces. </div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is a Marker Interface?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Interfaces
with no methods are known as marker interfaces. Marker interfaces are
Serializable, Clonable, Single Thread Model, Event listener. Marker Interfaces
are implemented by the classes or their super classes in order to add some
functionality.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>Explain
about transient keyword?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Transient
keyword indicates that the member variable should not be serialized.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b>What
is Synchronization?</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Synchronization
is the mechanism that ensures that only one thread is accessed the resources at
a time.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Synchronization
is a process of controlling the access of shared resources by the multiple
threads in such a manner that only one thread can access one resource at a
time.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
With
respect to multithreading, synchronization is the capability to control the
access of multiple threads to shared resources. Without synchonization, it is
possible for one thread to modify a shared variable while another thread is in
the process of using or updating same shared variable. This usually leads to
significant errors. </div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
All the best... </div>
</div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0tag:blogger.com,1999:blog-8933599183903660515.post-22437055436205570412013-05-27T13:23:00.005-07:002013-05-27T13:23:39.374-07:00Serialization in Java with Example<div dir="ltr" style="text-align: left;" trbidi="on">
Java provides a technique known as object serialization in which an
object can be represented as a "sequence of bytes" which contains the
object's data as well as the information about the object's type and the
types of data stored in the object.<br />
<br />
For more please visit,<br />
<a href="http://www.tutorialspoint.com/java/java_serialization.htm">http://www.tutorialspoint.com/java/java_serialization.htm</a> </div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0tag:blogger.com,1999:blog-8933599183903660515.post-51151997544078657042013-05-23T10:41:00.004-07:002013-05-23T10:41:45.817-07:00Important Java Questions<div dir="ltr" style="text-align: left;" trbidi="on">
<div id="hub_container">
<div id="hub_main">
<div class="modfloat full">
<div class="module moduleText color0" id="mod_19512825">
<h2 class="subtitle">
Important Java Questions</h2>
<div class="txtd" id="txtd_19512825">
<strong>Guys,</strong><br />
Here is a list of important java questions asked in majority of the
interviews. Just have a look and get prepared.<br />
<br />
What is meant by abstraction ?<br />
What is an abstract class ?<br />
What is access specifier ?<br />
What is access modifier ?<br />
What is array list ?<br />
What are applets ?<br />
What are the basic concepts of oops ?<br />
What is a class ?<br />
What is a constructor ?<br />
What are the collections in java ?<br />
What is a sub class ?<br />
What is deserialization ?<br />
What is Encapsulation ?<br />
What is finalize() ?<br />
Explain garbage collection in java ?<br />
What is hash map and what is hash table ?<br />
What is inheritance ?<br />
What is interface ?<br />
What is iterator ?<br />
What are instance variables ?<br />
Explain JVM ?<br />
What is marker interface ?<br />
What is an object ?<br />
What is overloading ?<br />
What is overriding ?<br />
What is a package ?<br />
What is polymorphism ?<br />
Explain about super keyword ?<br />
What is super() ?<br />
Explain static block ?<br />
What is serialization ?<br />
What is a base class or parent class ?<br />
What is synchronization ?<br />
What is this() ?<br />
What is transient keyword ?</div>
</div>
</div>
</div>
</div>
</div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0tag:blogger.com,1999:blog-8933599183903660515.post-69581963178719163432013-05-11T08:47:00.003-07:002013-05-11T09:02:13.646-07:00Multiple Interface in Java<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<h2>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Multiple Interface in Java</span></h2>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Multiple interface in java is an important topic in object oriented design. Please see an example of multiple interface in java below.</span></div>
<div>
<br /></div>
<div>
<span style="background-color: #ffe599; font-family: Arial, Helvetica, sans-serif;">interface a</span></div>
<span style="background-color: #ffe599; font-family: Arial, Helvetica, sans-serif;">{<br />void insurance ();<br />}<br /><br /><br />interface b<br />{<br />void trading ();<br />}<br /><br />public class multiple interface implements a, b<br />{<br />public void insurance ()<br />{<br />System.out.println ("This is an example for multiple interfaces in java");<br />}<br />public void trading ()<br />{<br />System.out.println ("This is also an example for multiple interfaces in java");<br />}<br />}</span></div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0tag:blogger.com,1999:blog-8933599183903660515.post-22448227624240840372013-05-11T07:59:00.002-07:002014-09-24T16:08:26.147-07:00Ant Colony Optimization in Java<div dir="ltr" style="text-align: left;" trbidi="on">
<h3 style="text-align: left;">
<span style="font-weight: normal;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">There are many algorithms designed on the concept of ant colony optimization which are used in electrical and electronics engineering technology and also in transmission and distribution of electrical energy and also in software technology. Here we are going to discuss about the ant colony optimization in Java.<br /><br />Ants do communicate themselves greatly. They secrete an enzyme called pheromone when they go out for searching for food and through which they communicate one after the other and they return back. If any obstacles is there in its way after getting food and returning back, then the group gets dispersed to find a shortest path. This algorithm is used in java.<br /><br /><a href="http://livehelpdesk.blogspot.in/" target="_blank">Live Chat Discussion</a><br /><br />For more in this please visit,<br /><a href="http://javapapers.com/java-gallery/ant-colony-optimization-in-java/">http://javapapers.com/java-gallery/ant-colony-optimization-in-java/</a><br />Thanks dear friends..</span></span></h3>
<div>
<span style="font-weight: normal;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><br /></span></span></div>
<div>
<span style="font-weight: normal;"><div style="text-align: justify;">
<span style="font-family: Arial, Helvetica, sans-serif;">Read Powerful Bible verses and make Prayers to Jesus using the android app below. Download the app from the store using the link below.</span></div>
<div style="text-align: justify;">
<span style="font-family: Arial, Helvetica, sans-serif;"><a href="https://play.google.com/store/apps/details?id=com.udhaya.android">https://play.google.com/store/apps/details?id=com.udhaya.android</a></span></div>
</span></div>
</div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0tag:blogger.com,1999:blog-8933599183903660515.post-64090239691596840022013-04-23T05:44:00.001-07:002013-05-11T09:01:25.381-07:00Mysql and Java<div dir="ltr" style="text-align: left;" trbidi="on">
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Mysql and Java</span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="font-weight: normal;">We can use Java JDBC to connect to a Mysql database and can retrieve values from the database. Please find the concept of Mysql and Java connection below. Similarly you can establish connection from Java to any database.</span></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Mysql and Java Example</span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="background-color: #ffe599;"><span style="font-weight: normal;"> import java.sql.*;</span><br /><span style="font-weight: normal;"> public class Mysqlandjava</span><br /><span style="font-weight: normal;"> {</span><br /><span style="font-weight: normal;"> public static void main(String[] args)</span><br /><span style="font-weight: normal;"> {</span><br /><span style="font-weight: normal;"> System.out.println("MySQL and Java Connection");</span><br /><span style="font-weight: normal;"> Connection conn = null;</span><br /><span style="font-weight: normal;"> String link = "jdbc:mysql://localhost:1111/";</span><br /><span style="font-weight: normal;"> String dbName = "mysqlandjava";</span><br /><span style="font-weight: normal;"> String driver = "com.mysql.jdbc.Driver";</span><br /><span style="font-weight: normal;"> String userName = "username";</span><br /> <span style="font-weight: normal;"> String password = "password";</span><br /><span style="font-weight: normal;"> try</span><br /><span style="font-weight: normal;"> {</span><br /><span style="font-weight: normal;"> Class.forName(driver).newInstance();</span><br /><span style="font-weight: normal;"> conn = DriverManager.getConnection(link+dbName,userName,password);</span><br /><span style="font-weight: normal;"> System.out.println("Connected Successfully!");</span><br /><span style="font-weight: normal;"> conn.close();</span><br /><span style="font-weight: normal;"> System.out.println("Connection Closed!");</span><br /><span style="font-weight: normal;"> }</span><br /><span style="font-weight: normal;"> catch (Exception e)</span><br /><span style="font-weight: normal;"> {</span><br /><span style="font-weight: normal;"> e.printStackTrace();</span><br /><span style="font-weight: normal;"> }</span><br /><span style="font-weight: normal;"> }</span><br /><span style="font-weight: normal;"> }</span></span><span style="font-weight: normal;"> </span><br /> Explanation</span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="font-weight: normal;">Connnection is an interface in java.sql package. Databases like MySQL, Oracle, etc can be connected.</span></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="font-weight: normal;">Class.forName(String driver) is a static method. This attempts to load class and return the class instance and takes string value (driver) after that matches the class with given string.</span></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="font-weight: normal;">DriverManager is a class of Java JDBC driver.</span></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="font-weight: normal;">getConnection(String link, String userName, String password) method establishes a database connectivity. 3 parameters are required namely the link, the username and the password.</span><br /><span style="font-weight: normal;"><br /></span></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="font-weight: normal;">con.close() is used to close the database connection once the values are retrieved from the database.</span></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="font-weight: normal;">printStackTrace() is used to show error message. Message is thrown if connection is failed.</span><br /><span style="font-weight: normal;">For more details just visit,</span></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="font-weight: normal;">http://www.roseindia.net/jdbc/jdbc-mysql/</span></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="font-weight: normal;">Thanks and Best Regards...</span></span></h3>
</div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0tag:blogger.com,1999:blog-8933599183903660515.post-75574571783979235442012-07-25T11:48:00.009-07:002013-05-11T08:59:38.226-07:00Hashmap And Hashtable<div dir="ltr" style="text-align: left;" trbidi="on">
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Hashmap And Hashtable</span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="background-color: white; font-weight: normal;">Guys, One of the important concepts that you should know in java is the Hashmap and the Hashtable. This is one of the important questions raised in majority of the interviews. You should know to explain them and you should know to spot the difference between Hashmap and Hashtable. You can get an idea on this concept below.</span></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="font-weight: normal;">Hashmap and Hashtable both comes under java collections. Both provide key values in order to access the data. Hashtable comes under original collection class in java whereas hashmap comes under collection framework part. We can access the data in the hashtable in synchronized manner whereas it is not possible to access data in synchronized manner in hashmap. Iterator in hashmap is fail safe. Hashmap allows NULL values and one NULL key whereas hashtable does not allow NULL values. HashMap is good for non threaded applications.</span></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Hashmap</span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="background-color: #ffe599;"><span style="font-weight: normal;">import java.util.HashMap;</span><br /><span style="font-weight: normal;">public class hashmap</span><br /><span style="font-weight: normal;">{</span><br /><span style="font-weight: normal;">public static void main (String [] args)</span><br /><span style="font-weight: normal;">{</span><br /><span style="font-weight: normal;">HashMap<Integer, String> om = new HashMap<Integer, String> ();</span><br /><span style="font-weight: normal;">om.put (new Integer (1), "insurance");</span><br /><span style="font-weight: normal;">om.put (new Integer (2), "bank");</span><br /><span style="font-weight: normal;">System.out.println ("Displaying Elements:" + om);</span><br /><span style="font-weight: normal;">}</span><br /><span style="font-weight: normal;">}</span></span>Hashtable</span></h3>
<h3 style="text-align: left;">
<span style="background-color: #ffe599; font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="font-weight: normal;">import java.util.Hashtable;</span><br /><span style="font-weight: normal;">public class Hashtable</span><br /><span style="font-weight: normal;">{</span><br /><span style="font-weight: normal;">public static void main (String [] args)</span><br /><span style="font-weight: normal;">{</span><br /><span style="font-weight: normal;">Hashtable hasht = new Hashtable ();</span><br /><span style="font-weight: normal;">hasht.put ("insurance", new Integer (1));</span><br /><span style="font-weight: normal;">hasht.put ("bank", new Integer (2));</span><br /><span style="font-weight: normal;">Object ob = hasht.get ("insurance");</span><br /><span style="font-weight: normal;">System.out.println (ob);</span><br /><span style="font-weight: normal;">}</span></span></h3>
</div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0tag:blogger.com,1999:blog-8933599183903660515.post-36051104986049836612012-07-25T11:41:00.000-07:002013-05-11T08:58:18.817-07:00Inheritance in Java<div dir="ltr" style="text-align: left;" trbidi="on">
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Inheritance in Java</span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="background-color: white; font-weight: normal;">Guys,</span></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="font-weight: normal;">Welcome you all to this page. Inheritance is one of the important concepts in java what all software professionals and all computer science students should be strong enough to code in. Inheritance in Java is also an important question asked in majority of the interviews and in exams as well. Since guys find hard and quiet confusing in this concept of object oriented programming studies, I described the easiest way on the exact concept with examples in this page. Let me share my knowledge on this with you.</span></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="font-weight: normal;">Inheritance means one class acquiring the properties from another class. A class which is derived from other class is a subclass or derived class or child class and the class from which the child class is derived is called as a super class or the base class or the parent class. Inheritance is an important concept in object oriented programming language. There are many types of inheritances in object oriented design. They are single inheritance, multiple inheritance, multilevel inheritance and hierarchical inheritance. But here we are going to discuss about two types namely the single inheritance and the multilevel inheritance. Also an important concept in java what you should know is java does not support multiple inheritance. Because, when a class inherits from more than one class, it will lead to an inheritance path ambiguity problem which is commonly called as a diamond problem. But the concept of multiple inheritances can be achieved in java by using the concept of interfaces. Interfaces are friendly and are advanced which replaces the concept of multiple inheritances in java. Two important concepts of inheritances namely single inheritance and multilevel inheritance are explained in detail below. Please have a look.</span><span style="background-color: white; font-weight: normal;"> </span></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="background-color: white; font-weight: normal;"><br /></span>Single Inheritance<span style="background-color: white;"> </span></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="font-weight: normal;">The concept of single inheritance is illustrated below. I.e. one class is derived from another class. I.e. one class acquiring the properties from another class. Here insurance is the parent class and trading is the child class. Child class extends the parent class I.e. inherits with the parent class using the keyword extends as shown in the below example.</span></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="background-color: white;">Class Class in Java Examples or Inheritance Examples</span></span></h3>
<h3 style="text-align: left;">
<span style="background-color: #ffe599; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal;">class insurance</span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="background-color: #ffe599;"><span style="font-weight: normal;">{</span><br /><span style="font-weight: normal;">int cash;</span><br /><span style="font-weight: normal;">int deposit_id;</span><br /><span style="font-weight: normal;">int substitute (int a, int b)</span><br /><span style="font-weight: normal;">{</span><br /><span style="font-weight: normal;">cash=a;</span><br /><span style="font-weight: normal;">deposit_id=b;</span><br /><span style="font-weight: normal;">return (0);</span><br /><span style="font-weight: normal;">}</span><br /><span style="font-weight: normal;">void display ()</span><br /><span style="font-weight: normal;">{</span><br /><span style="font-weight: normal;">System.out.println ("Please claim the insurance");</span><br /><span style="font-weight: normal;">}</span><br /><span style="font-weight: normal;">}</span><br /><span style="font-weight: normal;">class trading extends insurance</span><br /><span style="font-weight: normal;">{</span><br /><span style="font-weight: normal;">public static void main (String args [])</span><br /><span style="font-weight: normal;">{</span><br /><span style="font-weight: normal;">insurance ins = new insurance ();</span><br /><span style="font-weight: normal;">ins.substitute (5000,123);</span><br /><span style="font-weight: normal;">ins.display ();</span><br /><span style="font-weight: normal;">}</span><br /><span style="font-weight: normal;">void screen ()</span><br /><span style="font-weight: normal;">{</span><br /><span style="font-weight: normal;">System.out.println ("The insurance amount deposited is valid");</span><br /><span style="font-weight: normal;">}</span><br /><span style="font-weight: normal;">}</span></span></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Multilevel Inheritance</span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="font-weight: normal;">When a child class is derived from a derived class, then it is known as multilevel inheritance.</span></span></h3>
<h3 style="text-align: left;">
<span style="background-color: #ffe599; font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="font-weight: normal;">class insurance</span><br /><span style="font-weight: normal;">{</span><br /><span style="font-weight: normal;">//implementations</span><br /><span style="font-weight: normal;">}</span><br /><span style="font-weight: normal;">class trading extends insurance</span><br /><span style="font-weight: normal;">{</span><br /><span style="font-weight: normal;">//implementations</span><br /><span style="font-weight: normal;">}</span><br /><span style="font-weight: normal;">class bank extends trading</span><br /><span style="font-weight: normal;">{</span><br /><span style="font-weight: normal;">//implementations</span><br /><span style="font-weight: normal;">}</span></span></h3>
<div style="text-align: left;">
</div>
<div style="text-align: left;">
</div>
</div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com1tag:blogger.com,1999:blog-8933599183903660515.post-18563817207487518602012-07-25T11:26:00.001-07:002013-05-11T08:56:13.238-07:00Difference Abstract Class and Interface<div dir="ltr" style="text-align: left;" trbidi="on">
<b><span style="font-family: Arial, Helvetica, sans-serif;">Difference between Abstract Class and Interface</span><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;"> </span></b><br />
<b><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;"><br /></span></b>
<span style="background-color: #cfe2f3; font-family: Arial, Helvetica, sans-serif;">Guys, Difference between Abstract Class and Interface is one of the confusing topic for beginners in object oriented programming language. The difference between the two concepts are spotted simple in this page. You can have a look and make it clear.</span><br />
<span style="background-color: #cfe2f3; font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="background-color: #cfe2f3; font-family: Arial, Helvetica, sans-serif;">The main difference between <a href="http://saijava.blogspot.in/2012/07/what-is-abstract-class_25.html" target="_blank">Abstract Class</a> and <a href="http://saijava.blogspot.com/2012/07/interface-in-java.html" target="_blank">Interface</a> is, Interface do not have any implementations.</span><br />
<span style="background-color: #cfe2f3; font-family: Arial, Helvetica, sans-serif;">They contain only the method name. I.e. the signature part. The body implementation part is done in the class in which it is implemented. This is the reasons why methods of an interface are called as implicitly abstract. A class which is implementing an interface has to implement all the methods of the interface.</span><br />
<span style="background-color: #cfe2f3; font-family: Arial, Helvetica, sans-serif;">Interface is not a class. Interface is an entity.</span><br />
<span style="background-color: #cfe2f3; font-family: Arial, Helvetica, sans-serif;">Interface forms the contract between the class and the outside world.</span><br />
<span style="background-color: #cfe2f3; font-family: Arial, Helvetica, sans-serif;">Interface should be implemented in another class using the keyword implements.</span><br />
<span style="background-color: #cfe2f3; font-family: Arial, Helvetica, sans-serif;">Interface cannot be instantiated, but we can instantiate a class that implements the interface.</span><br />
<span style="background-color: #cfe2f3; font-family: Arial, Helvetica, sans-serif;">Java does not support multiple inheritances.So the concept of multiple inheritances can be achieved by using interface in java.</span><br />
<span style="background-color: #cfe2f3; font-family: Arial, Helvetica, sans-serif;">Also many interface can be implemented in a class using the keyword implements with the interface names separated with commas.</span><br />
<span style="background-color: #cfe2f3; font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="background-color: #cfe2f3; font-family: Arial, Helvetica, sans-serif;">An abstract class may contain complete methods or incomplete methods.</span><br />
<span style="background-color: #cfe2f3; font-family: Arial, Helvetica, sans-serif;">An abstract method declared in abstract class should be sure used in the class in which it is extended. A method with abstract keyword should be implemented in the class in which it is extended. All the abstract methods should be implemented in the class in which it is extended. A method without abstract keyword in abstract class should be implemented right there itself.</span><br />
<span style="background-color: #cfe2f3; font-family: Arial, Helvetica, sans-serif;">A class may inherit only one abstract class.</span><br />
<span style="background-color: #cfe2f3; font-family: Arial, Helvetica, sans-serif;">An abstract class can contain fields, constructors, etc…</span><br />
<span style="background-color: #cfe2f3; font-family: Arial, Helvetica, sans-serif;">Abstract classes should be extended with another class or abstract class using the keyword extends.</span><br />
<span style="background-color: #cfe2f3; font-family: Arial, Helvetica, sans-serif;">Abstract classes are faster than interface.</span></div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0tag:blogger.com,1999:blog-8933599183903660515.post-50062973564633154012012-07-25T11:01:00.002-07:002013-05-11T08:55:00.867-07:00What is an Abstract Class<div dir="ltr" style="text-align: left;" trbidi="on">
<h4 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">What is an Abstract Class ?</span></h4>
<h4 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-weight: normal;">Abstract Class is one of the important concepts in java what all software professionals and all computer science students should be strong enough to code in. Abstract Class in Java is also an important question asked in majority of the interviews and in exams as well. Since guys find hard and quiet confusing in this concept of object oriented programming studies, I described the easiest way on the exact concept with examples in this page. Let me share my knowledge on this with you.</span></h4>
<h4 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-weight: normal;">An abstract class may contain complete methods or incomplete methods. A method with abstract keyword should be implemented in the class in which it is extended. All the abstract methods should be implemented in the class in which it is extended. A method without abstract keyword in abstract class should be implemented right there itself as shown in the example. A class may inherit only one abstract class. An abstract class can contain fields, constructors, etc… Abstract classes should be extended with another class or abstract class using the keyword extends. Abstract classes are faster than interface. You can have a look at the example described below.</span></h4>
<h4 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Abstract class in Java with Example.</span></h4>
<h4 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-weight: normal;"><span style="background-color: #ffe599;">abstract class insurance<br />{<br />int a, b;<br />void plan (int aa, int bb)<br />{<br />//body implementations<br />}<br />abstract void trading ();<br />abstract void Citibank ();<br />}</span></span></h4>
<h4 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Note</span><span style="font-family: Arial, Helvetica, sans-serif; font-weight: normal;">: Each subclass of insurance which is not abstract such as bank and SBI must sure provide implementations for the trading and Citibank methods.</span></h4>
<h4 style="text-align: left;">
<span style="background-color: #ffe599; font-family: Arial, Helvetica, sans-serif; font-weight: normal;">class bank extends insurance</span></h4>
<h4 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-weight: normal;"><span style="background-color: #ffe599;">{<br />void trading ()<br />{<br />//body implementations<br />}<br />void Citibank()<br />{<br />//body implementations<br />}<br />//Its your choice to make use of "void plan (int aa, int bb)" method here. Since it is not abstract it may or may not be used.<br />}<br />class SBI extends insurance<br />{<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>void trading ()<br />{<br />//body implementations<br />}<br />void Citibank ()<br />{<br />//body implementations<br />}<br />}</span></span></h4>
<h4 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-weight: normal;">You should create an instance for class bank and for class SBI.</span></h4>
<h4 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Abstract Class</span></h4>
<h4 style="text-align: left;">
<span style="background-color: #ffe599; font-family: Arial, Helvetica, sans-serif; font-weight: normal;">abstract class insurance<br />{<br />abstract void Citibank ();<br />void Lifeinsurance ()<br />{<br />System.out.println ("Life Insurance plans are good always");<br />}<br />}<br />class trading extends insurance<br />{<br />void Citibank ()<br />{<br />System.out.println ("It’s better to create a Citibank account");<br />}<br />}<br />class bank<br />{<br />public static void main (String args[])<br />{<br />trading trade = new trading();<br />trade.Citibank ();<br />trade.Lifeinsurance ();<br />}<br />}<br />Abstract Class Extends Abstract Class<br /> abstract class a{<br />public abstract void insurance ();<br />public abstract void trading ();<br />}<br />abstract class b extends a<br />{<br />public void insurance ()<br />{<br />System.out.println ("Insurance is claimed");<br />}<br />}</span></h4>
</div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0tag:blogger.com,1999:blog-8933599183903660515.post-74802986043930655502012-07-25T09:17:00.000-07:002013-05-11T08:49:41.047-07:00Interface in Java<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Arial, Helvetica, sans-serif;">Interface in Java</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Interface in Java is one of the important concepts what all software professionals and all computer science students should be strong enough to code in. Interface in Java is also an important question asked in majority of the interviews and in exams as well. Since guys find hard and quiet confusing in this concept of object oriented programming studies, I described the easiest way on the exact concept with examples in this page. Let me share my knowledge on this with you.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="background-color: white;"><span style="font-family: Arial, Helvetica, sans-serif;">The main <a href="http://saijava.blogspot.in/2012/07/difference-abstract-class-and-interface_25.html" target="_blank">difference between Interface and Abstract Class</a> in Java is methods of a Java interface are implicitly <a href="http://saijava.blogspot.in/2012/07/what-is-abstract-class_25.html" target="_blank">abstract</a>. Interface don’t have any implementations. Interface contain only the signature alone without body implementation. The body implementation part is done in the class in which it is implemented. A class which is implementing an interface has to implement all the methods of the interface. Interface is not a class. Interface is an entity. Interface forms the contract between the class and the outside world. Interface should be implemented in another class using the keyword implements. Interface cannot be instantiated, but we can instantiate a class that implements the interface. Java does not support multiple inheritances. So the concept of multiple inheritances can be achieved by using interface in java. Also many interface can be implemented in a class using the keyword implements with the interface names separated with commas. It is also illustrated with an example in this page.</span></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<br />
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Interface in Java</span></h2>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><span style="background-color: #ffe599;"><span style="font-weight: normal;">interface insurance<br />{<br />public void account ();<br />}<br /><br />class bank implements insurance<br />{<br />public void account ()<br />{<br />System.out.println ("It’s easy to create a bank account");<br />}<br />}<br /><br />public class banking<br />{<br />public static void main (String [] args)<br />{<br />insurance trading=new bank ();<br />trading.account ();<br />}<br />}</span></span></span></h3>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">For multiple interface in java please visit the below link.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<a href="http://saijava.blogspot.in/2013/05/multiple-interface-in-java.html">http://saijava.blogspot.in/2013/05/multiple-interface-in-java.html</a></div>
<div>
<br /></div>
<div>
Thanks...</div>
</div>
Udhayakumar G Khttp://www.blogger.com/profile/01765142174253157711noreply@blogger.com0