<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-17301471</id><updated>2011-12-14T18:58:14.727-08:00</updated><title type='text'>Java Queries</title><subtitle type='html'>Complete java interview questions library</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>26</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-17301471.post-5313485902395352813</id><published>2007-05-15T22:11:00.000-07:00</published><updated>2007-05-15T22:12:54.489-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold; color: rgb(204, 0, 0);" &gt;What do you understand by     Synchronization?&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#000080;"&gt;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. In non synchronized multithreaded     application, it is possible for one thread to modify a shared object while     another thread is in the process of using or updating the object's value.     Synchronization prevents such type of data corruption.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-5313485902395352813?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/5313485902395352813/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=5313485902395352813' title='40 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/5313485902395352813'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/5313485902395352813'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2007/05/what-do-you-understand-by.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>40</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-8923726272172839879</id><published>2007-03-14T23:19:00.000-07:00</published><updated>2007-03-17T07:47:06.443-07:00</updated><title type='text'></title><content type='html'>&lt;div&gt;&lt;span style=";font-family:onload;font-size:85%;"  &gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(204, 0, 0); font-family: verdana;"&gt;What is the difference between an Interface and an Abstract class?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;An abstract class can have instance methods that  implement a default behavior. An Interface can only declare constants and  instance methods, but cannot implement default behavior and all methods are  implicitly abstract. An interface has all public members and no implementation.  An abstract class is a class which may have the usual flavors of class members  (private, protected, etc.), but has some abstract  methods.&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-8923726272172839879?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/8923726272172839879/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=8923726272172839879' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/8923726272172839879'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/8923726272172839879'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2007/03/what-is-difference-between-interface.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-116595214667695078</id><published>2006-12-12T11:34:00.000-08:00</published><updated>2006-12-12T11:35:46.976-08:00</updated><title type='text'></title><content type='html'>&lt;strong&gt;&lt;span style="color: rgb(204, 0, 0);font-family:Arial;font-size:85%;"  &gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;Q: What is difference between jvm and a interpreter&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;Acronym for Java Virtual Machine. An abstract computing machine, or virtual machine, JVM is a platform-independent execution environment that converts Java bytecode into machine language and executes it.&lt;br /&gt;&lt;br /&gt;interpreter is a program that executes instructions written in a high-level language. An interpreter translates high-level instructions into an intermediate form, which it then executes. In contrast, a compiler translates high-level instructions directly into machine language. Compiled programs generally run faster than interpreted programs.&lt;br /&gt;&lt;br /&gt;So JVM is like in an interpreter&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-116595214667695078?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/116595214667695078/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=116595214667695078' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/116595214667695078'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/116595214667695078'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2006/12/q-what-is-difference-between-jvm-and.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-116321962535872058</id><published>2006-11-10T20:29:00.000-08:00</published><updated>2006-11-10T20:33:56.380-08:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold; color: rgb(204, 0, 0);"&gt;Explain different ways of creating a thread?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Threads can be used by either :&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Extending the Thread class&lt;/li&gt;&lt;li&gt;Implementing the Runnable interface.&lt;/li&gt;&lt;/ul&gt;The runnable interface is preferred, as it does not require your object to inherit a thread because when you need multiple inheritance, only interfaces can help you. In the above example we had to extend the Base class so implementing runnable interface is an obvious choice. Also note how the threads are started in each of the different cases as shown in the code sample.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-116321962535872058?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/116321962535872058/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=116321962535872058' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/116321962535872058'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/116321962535872058'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2006/11/explain-different-ways-of-creating.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-116080234039229490</id><published>2006-10-13T22:01:00.000-07:00</published><updated>2006-10-13T22:05:41.893-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold; color: rgb(204, 0, 0);"&gt;Explain the directory structure of a WEB application?&lt;/span&gt;&lt;br /&gt;The directory structure of a Web application&lt;br /&gt;consists of two parts:&lt;br /&gt;&lt;br /&gt;1.  Public resource directory (document root): The document root is where JSP pages, client-side classes and archives, and static Web resources are stored.&lt;br /&gt;&lt;br /&gt;2. A private directory called WEB-INF: which contains following files and directories:&lt;br /&gt;&lt;br /&gt; - web.xml : Web application deployment descriptor.&lt;br /&gt; -*.tld : Tag library descriptor files.&lt;br /&gt; -classes : A directory that contains server side classes like servlets, utility classes, JavaBeans etc.&lt;br /&gt; -lib : A directory where JAR (archive files of tag libraries, utility libraries used by the server side classes) files are stored.&lt;br /&gt;&lt;br /&gt;JSP resources usually reside directly or under subdirectories of the document root, which are directly accessible to the user through the URL. If you want to protect your Web resources then hiding the JSP files behind the WEB-INF directory can protect the JSP files from direct access.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-116080234039229490?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/116080234039229490/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=116080234039229490' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/116080234039229490'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/116080234039229490'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2006/10/explain-directory-structure-of-web.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-115881009932343419</id><published>2006-09-20T20:36:00.000-07:00</published><updated>2006-09-20T20:41:39.723-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;Tell me about JSP best practices?&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;Separate HTML code from the Java code: &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Combining HTML and Java code in the same source code can make the code less readable. Mixing HTML and scriplet will make the code extremely difficult to read and maintain. The display or behaviour logic can be implemented as a custom tags by the Java developers and Web designers can use these Tags as the ordinary XHTML tags.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Place data access logic in JavaBeans:&lt;/span&gt; The code within the JavaBean is readily accessible to other JSPs and Servlets.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Factor shared behaviour out of Custom Tags into common JavaBeans classes: &lt;/span&gt;The custom tags are not used outside JSPs. To avoid duplication of behaviour or business logic, move the logic into JavaBeans and get the custom tags to utilize the beans.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Choose the right “include” mechanism:&lt;/span&gt; What are the differences between static and a dynamic include? Using includes will improve code reuse and maintenance through modular design.&lt;br /&gt;&lt;br /&gt;Use style sheets (e.g. css), template mechanism (e.g. struts tiles etc) and appropriate comments (both hidden and output comments).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-115881009932343419?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/115881009932343419/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=115881009932343419' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115881009932343419'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115881009932343419'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2006/09/tell-me-about-jsp-best-practices.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-115829456305096660</id><published>2006-09-14T21:28:00.000-07:00</published><updated>2006-09-14T21:29:23.696-07:00</updated><title type='text'></title><content type='html'>&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;What is the difference between final, finally and finalize() in Java?&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;final&lt;/strong&gt; - keyword is constant declaration.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;finally&lt;/strong&gt; - handles exception. The finally block is optional and provides a mechanism to clean up regardless of what happens within the try block (except System.exit(0) call). Use the finally block to close files or to release other system resources like database connections, statements etc.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;finalize()&lt;/strong&gt; - method helps in garbage collection. A method that is invoked before an object is discarded by the garbage collector, allowing it to clean up its state. Should not be used to release non-memory resources like file handles, sockets, database connections etc because Java has only a finite number of these resources and you do not know when the garbage collection is going to kick in to release these non-memory resources through the finalize() method.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-115829456305096660?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/115829456305096660/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=115829456305096660' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115829456305096660'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115829456305096660'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2006/09/what-is-difference-between-final.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-115799534997564798</id><published>2006-09-11T10:21:00.000-07:00</published><updated>2006-09-11T10:22:30.440-07:00</updated><title type='text'></title><content type='html'>&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;What is the difference between an instance variable and a static variable? Give an example where you might use a static variable?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Class variables&lt;/strong&gt; are called static variables. There is only one&lt;br /&gt;occurrence of a class variable per JVM per class loader.&lt;br /&gt;When a class is loaded the class variables (aka static&lt;br /&gt;variables) are initialised.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Instance variables&lt;/strong&gt; are non-static and there is one&lt;br /&gt;occurrence of an instance variable in each class instance&lt;br /&gt;(i.e. each object).&lt;br /&gt;&lt;br /&gt;A static variable is used in the singleton pattern.A static variable is used with a final&lt;br /&gt;modifier to define constants.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-115799534997564798?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/115799534997564798/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=115799534997564798' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115799534997564798'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115799534997564798'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2006/09/what-is-difference-between-instance.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-115773910037205443</id><published>2006-09-08T11:07:00.000-07:00</published><updated>2006-09-08T11:11:40.910-07:00</updated><title type='text'></title><content type='html'>&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;When is a method said to be overloaded and when is a method said to be overridden?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Method Overloading :&lt;/strong&gt;&lt;br /&gt;1. Overloading deals with multiple methods in the same class with the same name but different method signatures.&lt;br /&gt;2. Overloading lets us define the same operation in different ways for different data.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Method Overriding : &lt;/strong&gt;&lt;br /&gt;1.&lt;strong&gt; &lt;/strong&gt;Overriding deals with two methods, one in the parent class and the other one in the child class and has the same name and signatures.&lt;br /&gt;&lt;br /&gt;2. Overriding lets you define the same operation in different ways for different object types.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-115773910037205443?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/115773910037205443/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=115773910037205443' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115773910037205443'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115773910037205443'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2006/09/when-is-method-said-to-be-overloaded.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-115726261540893909</id><published>2006-09-02T22:47:00.000-07:00</published><updated>2006-09-02T22:50:15.613-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;What is the main difference between a String and a StringBuffer class?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;String is immutable:&lt;/span&gt; you can’t modify a string&lt;br /&gt;object but can replace it by creating a new&lt;br /&gt;instance. Creating a new instance is rather&lt;br /&gt;expensive.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;StringBuffer is mutable:&lt;/span&gt; use StringBuffer or StringBuilder when you want to&lt;br /&gt;modify the contents. StringBuilder was added in Java 5 and it is identical in&lt;br /&gt;all respects to StringBuffer except that it is not synchronised, which makes&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-115726261540893909?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/115726261540893909/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=115726261540893909' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115726261540893909'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115726261540893909'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2006/09/what-is-main-difference-between-string.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-115579141710947824</id><published>2006-08-16T22:05:00.000-07:00</published><updated>2006-08-16T22:10:17.463-07:00</updated><title type='text'></title><content type='html'>&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;What is serialization? How would you exclude a field of a class from serialization or what is a transient variable?What is the common use?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Serialization is a process of reading or writing an object. It is a process of saving an object’s state to a sequence of bytes, as well as a process of rebuilding those bytes back into a live object at some future time. An object is marked serializable by implementing the java.io.Serializable interface, which is only a marker interface -- it simply allows the serialization mechanism to verify that the class can be persisted, typically to a file.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Transient&lt;/strong&gt; variables cannot be serialized. The fields marked transient in a serializable object will not be transmitted in the byte stream. An example would be a file handle or a database connection. Such objects are only meaningful locally. So they should be marked as transient in a serializable class.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Serialization can adversely affect performance since it:&lt;br /&gt;1. Depends on reflection.&lt;br /&gt;2. Has an incredibly verbose data format.&lt;br /&gt;3. Is very easy to send surplus data.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;When to use serialization?&lt;/strong&gt; Do not use serialization if you do not have to. A common use of serialization is to use it to send an object over the network or if the state of an object needs to be persisted to a flat file or a database. Deep cloning or copy can be achieved through serialization. This may be fast to code but will have performance implications&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The objects stored in an HTTP session should be serializable to support in-memory replication of sessions to achieve scalability. Objects are passed in RMI (Remote Method Invocation)&lt;br /&gt;across network using serialization.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-115579141710947824?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/115579141710947824/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=115579141710947824' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115579141710947824'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115579141710947824'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2006/08/what-is-serialization-how-would-you.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-115571468567552346</id><published>2006-08-16T00:46:00.000-07:00</published><updated>2006-08-16T00:51:25.870-07:00</updated><title type='text'></title><content type='html'>&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;What do you mean by polymorphism, inheritance, encapsulation, and dynamic binding?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Polymorphism :&lt;/strong&gt;  means the ability of a single variable of a given type to be used to reference objects of different types, and automatically call the method that is specific to the type of object the variable references. In a nutshell, polymorphism is a bottom-up method call. The benefit of polymorphism is that it is very easy to add new classes of derived objects without breaking the calling code that uses the polymorphic classes or interfaces. When you send a message to an object even though you don’t know what specific type it is, and the right thing happens, that’s called polymorphism.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:#3366ff;"&gt;The process used by objectoriented programming languages to implement polymorphism is called dynamic binding.&lt;/span&gt; &lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Inheritance&lt;/strong&gt; :  is the inclusion of behaviour (i.e. methods) and state (i.e. variables) of a base class in a derived class so that they are accessible in that derived class. The key benefit of Inheritance is that it provides the formal mechanism for code reuse. Any shared piece of business logic can be moved from the derived class into the base class as part of refactoring process to improve maintainability of your code by avoiding code duplication. The existing class is called the superclass and the derived class is called the subclass. Inheritance can also be defined as the process whereby one object acquires characteristics from one or more other objects the same way children acquire characteristics from their parents.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Encapsulation&lt;/strong&gt; :  refers to keeping all the related members (variables and methods) together in an object. Specifying members as private can hide the variables and methods. Objects should hide their inner workings from the outside view. Good encapsulation improves code modularity by preventing objects interacting with each other in an unexpected way, which in turn makes future development and refactoring efforts easy.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-115571468567552346?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/115571468567552346/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=115571468567552346' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115571468567552346'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115571468567552346'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2006/08/what-do-you-mean-by-polymorphism.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-115527846127597122</id><published>2006-08-10T23:40:00.000-07:00</published><updated>2006-08-10T23:41:02.196-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;What are some of the best practices relating to Java collection?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1. Use ArrayLists, HashMap etc as opposed to Vector, Hashtable etc, where possible to avoid&lt;br /&gt;   any synchronization overhead. Even better is to use just arrays where possible. If multiple&lt;br /&gt;   threads concurrently access a collection and at least one of the threads either adds or deletes&lt;br /&gt;   an entry into the collection, then the collection must be externally synchronized. This is&lt;br /&gt;   achieved by:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 102, 255);"&gt;    Map myMap = Collections.synchronizedMap (myMap);&lt;br /&gt;   List myList = Collections.synchronizedList (myList);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;2. Set the initial capacity of a collection appropriately (e.g. ArrayList, HashMap etc). This is     because collection classes like ArrayList, HashMap etc must grow periodically to accommodate new elements. But if you have a very large array, and you know the size in advance then you can speed things up by setting the initial size appropriately.&lt;br /&gt;&lt;br /&gt;3. Program in terms of interface not implementation&lt;br /&gt;&lt;br /&gt;4. Avoid storing unrelated or different types of objects into same collection&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 102, 255);"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-115527846127597122?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/115527846127597122/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=115527846127597122' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115527846127597122'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115527846127597122'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2006/08/what-are-some-of-best-practices.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-115495088344745437</id><published>2006-08-07T04:39:00.000-07:00</published><updated>2006-08-07T04:41:24.800-07:00</updated><title type='text'></title><content type='html'>&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;Where and how can you use a private constructor?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Private constructor is used if you do not want other classes to instantiate the object. The instantiation is done by a public static method within the same class.&lt;br /&gt;1. Used in the singleton pattern. (Refer Q45 in Java section).&lt;br /&gt;2. Used in the factory method pattern (Refer Q46 in Java section).&lt;br /&gt;3. Used in utility classes e.g. StringUtils etc.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-115495088344745437?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/115495088344745437/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=115495088344745437' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115495088344745437'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115495088344745437'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2006/08/where-and-how-can-you-use-private.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-115488629940838640</id><published>2006-08-06T10:42:00.000-07:00</published><updated>2006-08-06T10:44:59.793-07:00</updated><title type='text'></title><content type='html'>&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;What are the advantages of Object Oriented Programming Languages ?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The Object Oriented Programming Languages directly represent the real life objects like Car, Jeep, Account,Customer etc. The features of the OO programming languages like polymorphism, inheritance and encapsulation make it powerful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-115488629940838640?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/115488629940838640/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=115488629940838640' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115488629940838640'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115488629940838640'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2006/08/what-are-advantages-of-object-oriented.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-115483742011080681</id><published>2006-08-05T20:57:00.000-07:00</published><updated>2006-08-05T21:10:20.853-07:00</updated><title type='text'></title><content type='html'>&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;Why there are some interfaces with no defined methods (i.e. marker interfaces) in Java?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;The interfaces with no defined methods act like markers. They just tell the compiler that the objects of the classes implementing the interfaces with no defined methods need to be treated differently. Example Serializable, Cloneable etc&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-115483742011080681?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/115483742011080681/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=115483742011080681' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115483742011080681'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115483742011080681'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2006/08/why-there-are-some-interfaces-with-no.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-115469528590174430</id><published>2006-08-04T05:39:00.000-07:00</published><updated>2006-08-04T05:44:49.170-07:00</updated><title type='text'></title><content type='html'>&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;What is the difference between C++ and Java?&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;1. Java does not support pointers. Pointers are inherently tricky to use and troublesome.&lt;br /&gt;&lt;br /&gt;2. Java does not support multiple inheritances because it causes more problems than it solves. Instead Java supports multiple interface inheritance, which allows an object to inherit many method signatures from different interfaces with the condition that the inheriting object must implement those inherited methods. The multiple interface inheritance also allows an object to behave polymorphically on those methods.&lt;br /&gt;&lt;br /&gt;3. Java does not support destructors but rather adds a finalize() method. Finalize methods are invoked by the garbage collector prior to reclaiming the memory occupied by the object, which has the finalize() method. This means you do not know when the objects are going to be inalized. Avoid using finalize() method to release non-memory resources like file handles, sockets, database connections etc because Java has only a finite number of these resources and you do not know when the garbage collection is going to kick in to release these resources through the finalize() method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;4. Java does not include structures or unions because the traditional data structures are implemented as an object oriented framework.&lt;br /&gt;&lt;br /&gt;5. All the code in Java program is encapsulated within classes therefore Java does not have global variables or&lt;br /&gt;functions.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;6. C++ requires explicit memory management, while Java includes automatic garbage collection.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-115469528590174430?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/115469528590174430/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=115469528590174430' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115469528590174430'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/115469528590174430'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2006/08/what-is-difference-between-c-and-java.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-112922277173827176</id><published>2005-10-13T09:57:00.000-07:00</published><updated>2005-10-13T09:59:31.736-07:00</updated><title type='text'></title><content type='html'>&lt;span style="color:#cc0000;"&gt;&lt;strong&gt;Q. DriverManager is a Class or an Interface&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;strong&gt;Ans. &lt;/strong&gt;Driver Manager is a class&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-112922277173827176?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/112922277173827176/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=112922277173827176' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/112922277173827176'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/112922277173827176'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2005/10/q.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-112922234903484775</id><published>2005-10-13T09:48:00.000-07:00</published><updated>2005-10-13T09:52:29.040-07:00</updated><title type='text'></title><content type='html'>&lt;span style="color:#cc0000;"&gt;&lt;strong&gt;What is the output  of the following code?&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;public class StringExample{&lt;br /&gt;&lt;br /&gt; public static void main(String  []args){&lt;br /&gt;  String s="New";&lt;br /&gt;  String s1=s; &lt;br /&gt;  String s2="D"; &lt;br /&gt;  String s3="New";&lt;br /&gt;&lt;br /&gt;  System.out.println(s==s1); &lt;br /&gt;  System.out.println(s3==s2); &lt;br /&gt;  System.out.println(s3==s1);&lt;br /&gt;&lt;br /&gt;  System.out.println(s1.equals(s1)); &lt;br /&gt;  System.out.println(s3.equals(s2)); &lt;br /&gt;  System.out.println(s3.equals(s1));&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;Ans :&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;true&lt;/span&gt;&lt;br /&gt;false&lt;br /&gt;true&lt;br /&gt;&lt;br /&gt;true&lt;br /&gt;false&lt;br /&gt;true&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-112922234903484775?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/112922234903484775/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=112922234903484775' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/112922234903484775'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/112922234903484775'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2005/10/what-is-output-of-following-code.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-112908180553167687</id><published>2005-10-11T18:48:00.000-07:00</published><updated>2005-10-11T18:50:05.536-07:00</updated><title type='text'></title><content type='html'>&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;What is JDO?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;JDO provides for the transparent persistence of data in a data store agnostic manner, supporting object, hierarchical, as well as relational stores.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-112908180553167687?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/112908180553167687/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=112908180553167687' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/112908180553167687'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/112908180553167687'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2005/10/what-is-jdo-jdo-provides-for.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-112892569338334182</id><published>2005-10-09T23:25:00.000-07:00</published><updated>2005-10-09T23:28:13.390-07:00</updated><title type='text'></title><content type='html'>&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;Ways to connect to a Database&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A Java application can have multiple connections to multiple data sources at the same time using multiple Connection objects. A Connection object can be obtained by a Java application in two ways: through a &lt;strong&gt;DriverManager&lt;/strong&gt; class or through an implementation of the &lt;strong&gt;DataSource&lt;/strong&gt; interface.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-112892569338334182?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/112892569338334182/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=112892569338334182' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/112892569338334182'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/112892569338334182'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2005/10/ways-to-connect-to-database-java.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-112891425415116104</id><published>2005-10-09T20:16:00.000-07:00</published><updated>2005-10-09T20:17:34.156-07:00</updated><title type='text'></title><content type='html'>&lt;span style="color:#cc0000;"&gt;&lt;strong&gt;Question No:&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;Given:&lt;br /&gt;1. public class test (&lt;br /&gt;2. public static void main (String args[]) {&lt;br /&gt;3. int i = 0xFFFFFFF1;&lt;br /&gt;4. int j = ~i;&lt;br /&gt;5.&lt;br /&gt;6. }&lt;br /&gt;7. )&lt;br /&gt;What is the decimal value of j at line 5?&lt;br /&gt;A. 0&lt;br /&gt;B. 1&lt;br /&gt;C. 14&lt;br /&gt;D. –15&lt;br /&gt;E. An error at line 3 causes compilation to fail.&lt;br /&gt;F. An error at line 4 causes compilation to fail.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Answer: C&lt;br /&gt;&lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-112891425415116104?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/112891425415116104/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=112891425415116104' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/112891425415116104'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/112891425415116104'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2005/10/question-no-given-1.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-112882936889522094</id><published>2005-10-08T20:38:00.000-07:00</published><updated>2005-10-08T20:42:48.896-07:00</updated><title type='text'></title><content type='html'>&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;Web Servers vs. App Servers&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;These are two quite different pieces of software.&lt;br /&gt;There are few Web servers in common use: Apache takes the lion's share, while Microsoft Internet Information Server (IIS) and iPlanet Web Server are among the others. Application servers jumped into the limelight only about two years ago and there is a proliferation of products from companies such as BEA, iPlanet, Oracle, SilverStream, HP (Bluestone), and IBM.&lt;br /&gt;&lt;br /&gt;Speaking of functionality, in differentiating the two servers we have to say "in general" because there are customized versions of both Web and application servers that have crossover functionality. The Web server, in general, sends Web pages to browsers as its primary function.  Most Web servers also process input from users, format data, provide security, and perform other tasks. The majority of a Web server's work is to execute HTML or scripting such as Perl, JavaScript, or VBScript.&lt;br /&gt;&lt;br /&gt;In general, an application server prepares material for the Web server -- for example, gathering data from databases, applying business rules, processing security clearances, or storing the state of a user's session. In some respects the term application server is misleading since the functionality isn't limited to applications. Its role is more as an aggregator and manager for data and processes used by anything running on a Web server.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-112882936889522094?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/112882936889522094/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=112882936889522094' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/112882936889522094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/112882936889522094'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2005/10/web-servers-vs.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-112866193550532863</id><published>2005-10-06T22:06:00.000-07:00</published><updated>2005-10-06T22:17:11.290-07:00</updated><title type='text'></title><content type='html'>&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;Interfaces vs Abstact Classes &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#cc0000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;em&gt;&lt;strong&gt;1. multiple inheritance :&lt;br /&gt;&lt;/strong&gt;&lt;/em&gt;A class may implement several interfaces whereas a class may extend only one abstract class.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;2. default implementation :&lt;/em&gt;&lt;br /&gt;&lt;/strong&gt;An interface cannot provide any code at all, much less default code.&lt;br /&gt;An abstract class can provide complete code, default code, and/or just stubs that have to be overridden.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;3. constants:&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;Static final constants only, can use them without qualification in classes that implement the interface. On the other paw, these unqualified names pollute the namespace. You can use them and it is not obvious where they are coming from since the qualification is optional.&lt;br /&gt;&lt;br /&gt;Both instance and static constants are possible. Both static and instance intialiser code are also possible to compute the constants.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;4. Third party convenience :&lt;br /&gt;&lt;/em&gt;&lt;/strong&gt;An interface implementation may be added to any existing third party class.&lt;br /&gt;A third party class must be rewritten to extend only from the abstract class.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;5. plug-in :&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;You can write a new replacement module for an interface that contains not one stick of code in common with the existing implementations. When you implement the inteface, you start from scratch without any default implementation. You have to obtain your tools from other classes; nothing comes with the interface other than a few constants. This gives you freedom to implement a radically different internal design.&lt;br /&gt;You must use the abstract class as-is for the code base, with all its attendant baggage, good or bad. The abstract class author has imposed structure on you. Depending on the cleverness of the author of the abstract class, this may be good or bad.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;6. homogeneity :&lt;br /&gt;&lt;/em&gt;&lt;/strong&gt;If all the various implementaions share is the method signatures, then an interface works best.&lt;br /&gt;If the various implementations are all of a kind and share a common status and behaviour, usually an abstract class works best. Another issue that's important is what I call "heterogeneous vs. homogeneous." If implementors/subclasses are homogeneous, tend towards an abstract base class. If they are heterogeneous, use an interface. (Now all I have to do is come up with a good definition of hetero/homo-geneous in this context.) If the various objects are all of-a-kind, and share a common state and behavior, then tend towards a common base class. If all they share is a set of method signatures, then tend towards an interface.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;7. speed :&lt;br /&gt;&lt;/em&gt;&lt;/strong&gt;Slow, requires extra indirection to find the corresponding method in the actual class. Modern JVMs are discovering ways to reduce this speed penalty.&lt;br /&gt;abstract classes are fast&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-112866193550532863?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/112866193550532863/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=112866193550532863' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/112866193550532863'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/112866193550532863'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2005/10/interfaces-vs-abstact-classes-1.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-112822343898815715</id><published>2005-10-01T20:17:00.000-07:00</published><updated>2005-10-01T20:26:02.760-07:00</updated><title type='text'></title><content type='html'>&lt;strong&gt;Java Basics&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;1.The Java interpreter is used for the execution of the source code.&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;True&lt;br /&gt;False&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Ans: a.&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#cc0000;"&gt;&lt;strong&gt;2) On successful compilation a file with the class extension is created.&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;a) True&lt;br /&gt;b) False&lt;br /&gt;&lt;br /&gt;Ans: a.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;3) The Java source code can be created in a Notepad editor.&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;a) True&lt;br /&gt;b) False&lt;br /&gt;&lt;br /&gt;Ans: a.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;4) The Java Program is enclosed in a class definition.&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;a) True&lt;br /&gt;b) False&lt;br /&gt;&lt;br /&gt;Ans: a.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#cc0000;"&gt;&lt;strong&gt;5) What declarations are required for every Java application?&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Ans: A class and the main( ) method declarations.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;6) What are the two parts in executing a Java program and their purposes?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Ans: Two parts in executing a Java program are:&lt;br /&gt;Java Compiler and Java Interpreter.&lt;br /&gt;The Java Compiler is used for compilation and the Java Interpreter is used for execution of the application.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;7) What are the three OOPs principles and define them?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Ans : Encapsulation, Inheritance and Polymorphism are the three OOPs&lt;br /&gt;Principles.&lt;br /&gt;Encapsulation:&lt;br /&gt;Is the Mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse.&lt;br /&gt;Inheritance:&lt;br /&gt;Is the process by which one object acquires the properties of another object.&lt;br /&gt;Polymorphism:&lt;br /&gt;Is a feature that allows one interface to be used for a general class of actions.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;8) What is a compilation unit?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Ans : Java source code file.&lt;br /&gt;9) What output is displayed as the result of executing the following statement?&lt;br /&gt;System.out.println("// Looks like a comment.");&lt;br /&gt;// Looks like a comment&lt;br /&gt;The statement results in a compilation error&lt;br /&gt;Looks like a comment&lt;br /&gt;No output is displayed&lt;br /&gt;&lt;br /&gt;Ans : a.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;10) In order for a source code file, containing the public class Test, to successfully compile, which of the following must be true?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;It must have a package statement&lt;br /&gt;It must be named Test.java&lt;br /&gt;It must import java.lang&lt;br /&gt;It must declare a public class named Test&lt;br /&gt;&lt;br /&gt;Ans : b&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;11) What are identifiers and what is naming convention?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Ans : Identifiers are used for class names, method names and variable names. An identifier may be any descriptive sequence of upper case &amp;amp; lower case letters,numbers or underscore or dollar sign and must not begin with numbers.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;12) What is the return type of program’s main( ) method?&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;Ans : void&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;13) What is the argument type of program’s main( ) method?&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;Ans : string array.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;14) Which characters are as first characters of an identifier?&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;Ans : A – Z, a – z, _ ,$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;15) What are different comments?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Ans :&lt;br /&gt;1) // -- single line comment&lt;br /&gt;2) /* --&lt;br /&gt;*/ multiple line comment&lt;br /&gt;3) /** -- */ documentation&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;16) What is the difference between constructor method and method?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;Ans : Constructor will be automatically invoked when an object is created. Whereas method has to be call explicitly.&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;17) What is the use of bin and lib in JDK?&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;Ans : Bin contains all tools such as javac, applet viewer, awt tool etc., whereas Lib&lt;br /&gt;contains all packages and variables.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-112822343898815715?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/112822343898815715/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=112822343898815715' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/112822343898815715'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/112822343898815715'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2005/10/java-basics-1.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17301471.post-112808874859467838</id><published>2005-09-30T06:51:00.000-07:00</published><updated>2005-09-30T06:59:08.610-07:00</updated><title type='text'></title><content type='html'>&lt;strong&gt;Q. The code in a finally clause will never fail to execute, right? &lt;/strong&gt;&lt;br /&gt;Well, hardly ever. But here's an example where the finally code will not execute, regardless of the value of the boolean choice:&lt;br /&gt;&lt;br /&gt;try {&lt;br /&gt;if (choice) {&lt;br /&gt;while (true) ;&lt;br /&gt;} else {&lt;br /&gt;System.exit(1);&lt;br /&gt;}&lt;br /&gt;} finally {&lt;br /&gt;code.to.cleanup();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Q. Within a method m in a class C, isn't this.getClass() always C? &lt;/strong&gt;&lt;br /&gt;No. It's possible that for some object x that is an instance of some subclass C1 of C either there is no C1.m() method, or some method on x called super.m(). In either case, this.getClass() is C1, not C within the body of C.m(). If C is final, then you're ok.&lt;br /&gt;&lt;br /&gt;&lt;a name="equals"&gt;&lt;strong&gt;Q:&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; I defined an equals method, but Hashtable ignores it. Why?&lt;/strong&gt;&lt;br /&gt;equals methods are surprisngly hard to get right. Here are the places to look first for a problem:&lt;br /&gt;You defined the wrong equals method. For example, you wrote:&lt;br /&gt;public class C {&lt;br /&gt;public boolean equals(C that) { return id(this) == id(that); }&lt;br /&gt;}&lt;br /&gt;But in order for table.get(c) to work you need to make the equals method take an Object as the argument, not a C:&lt;br /&gt;public class C {&lt;br /&gt;public boolean equals(Object that) {&lt;br /&gt;return (that instanceof C) &amp;&amp;amp; id(this) == id((C)that);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;Why? The code for Hashtable.get looks something like this:&lt;br /&gt;public class Hashtable {&lt;br /&gt;public Object get(Object key) {&lt;br /&gt;Object entry;&lt;br /&gt;...&lt;br /&gt;if (entry.equals(key)) ...&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;Now the method invoked by entry.equals(key) depends upon the actual run-time type of the object referenced by entry, and the declared, compile-time type of the variable key. So when you as a user call table.get(new C(...)), this looks in class C for the equals method with argument of type Object. If you happen to have defined an equals method with argument of type C, that's irrelevent. It ignores that method, and looks for a method with signature equals(Object), eventually finding Object.equals(Object). If you want to over-ride a method, you need to match argument types exactly. In some cases, you may want to have two methods, so that you don't pay the overhead of casting when you know you have an object of the right class:&lt;br /&gt;public class C {&lt;br /&gt;public boolean equals(Object that) {&lt;br /&gt;return (this == that)&lt;br /&gt; ((that instanceof C) &amp;&amp;amp; this.equals((C)that));&lt;br /&gt;}&lt;br /&gt;public boolean equals(C that) {&lt;br /&gt;return id(this) == id(that); // Or whatever is appropriate for class C&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;You didn't properly implement equals as an equality predicate: equals must be symmetric, transitive, and reflexive. Symmetric means a.equals(b) must have the same value as b.equals(a). (This is the one most people mess up.) Transitive means that if a.equals(b) and b.equals(c) then a.equals(c) must be true. Reflexive means that a.equals(a) must be true, and is the reason for the (this == that) test above (it's also often good practice to include this because of efficiency reasons: testing for == is faster than looking at all the slots of an object, and to partially break the recursion problem on objects that might have circular pointer chains).&lt;br /&gt;You forgot the hashCode method. Anytime you define a equals method, you should also define a hashCode method. You must make sure that two equal objects have the same hashCode, and if you want better hashtable performance, you should try to make most non-equal objects have different hashCodes. Some classes cache the hash code in a private slot of an object, so that it need be computed only once. If that is the case then you will probably save time in equals if you include a line that says if (this.hashSlot != that.hashSlot) return false.&lt;br /&gt;You didn't handle inheritance properly. First of all, consider if two objects of different class can be equal. Before you say "NO! Of course not!" consider a class Rectangle with width and height fields, and a Box class, which has the above two fields plus depth. Is a Box with depth == 0 equal to the equivalent Rectangle? You might want to say yes. If you are dealing with a non-final class, then it is possible that your class might be subclassed, and you will want to be a good citizen with respect to your subclass. In particular, you will want to allow an extender of your class C to use your C.equals method using super as follows:&lt;br /&gt;public class C2 extends C {&lt;br /&gt;int newField = 0;&lt;br /&gt;public boolean equals(Object that) {&lt;br /&gt;if (this == that) return true;&lt;br /&gt;else if (!(that instanceof C2)) return false;&lt;br /&gt;else return this.newField == ((C2)that).newField) &amp;&amp;amp; super.equals(that);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;To allow this to work, you have to be careful about how you treat classes in your definition of C.equals. For example, check for that instanceof C rather than that.getClass() == C.class. See the previous IAQ question to learn why. Use this.getClass() == that.getClass() if you are sure that two objects must be of the same class to be considered equals.&lt;br /&gt;You didn't handle circular references properly. Consider:&lt;br /&gt;public class LinkedList {&lt;br /&gt;Object contents;&lt;br /&gt;LinkedList next = null;&lt;br /&gt;public boolean equals(Object that) {&lt;br /&gt;return (this == that)&lt;br /&gt; ((that instanceof LinkedList) &amp;&amp;amp; this.equals((LinkedList)that));&lt;br /&gt;}&lt;br /&gt;public boolean equals(LinkedList that) { // Buggy!&lt;br /&gt;return Util.equals(this.contents, that.contents) &amp;&amp;amp;&lt;br /&gt;Util.equals(this.next, that.next);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;Here I have assumed there is a Util class with:&lt;br /&gt;public static boolean equals(Object x, Object y) {&lt;br /&gt;return (x == y)  (x != null &amp;&amp;amp; x.equals(y));&lt;br /&gt;}&lt;br /&gt;I wish this method were in Object; without it you always have to throw in tests against null. Anyway, the LinkedList.equals method will never return if asked to compare two LinkedLists with circular references in them (a pointer from one element of the linked list back to another element). See the description of the Common Lisp function &lt;a href="http://www.harlequin.com/support/books/HyperSpec/Body/fun_list-length.html#list-length"&gt;list-length&lt;/a&gt; for an explanation of how to handle this problem in linear time with only two words of extra storge. (I don't give the answer here in case you want to try to figure it out for yourself first.)&lt;br /&gt;&lt;br /&gt;&lt;a name="super"&gt;&lt;strong&gt;Q:&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; I tried to forward a method to super, but it occasionally doesn't work. Why?&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;This is the code in question, simplified for this example:&lt;br /&gt;/** A version of Hashtable that lets you do&lt;br /&gt;* table.put("dog", "canine");, and then have&lt;br /&gt;* table.get("dogs") return "canine". **/&lt;br /&gt;public class HashtableWithPlurals extends Hashtable {&lt;br /&gt;/** Make the table map both key and key + "s" to value. **/&lt;br /&gt;public Object put(Object key, Object value) {&lt;br /&gt;super.put(key + "s", value);&lt;br /&gt;return super.put(key, value);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;You need to be careful when passing to super that you fully understand what the super method does. In this case, the contract for Hashtable.put is that it will record a mapping between the key and the value in the table. However, if the hashtable gets too full, then Hashtable.put will allocate a larger array for the table, copy all the old objects over, and then recursively re-call table.put(key, value). Now, because Java resolves methods based on the runtime type of the target, in our example this recursive call within the code for Hashtable will go to HashtableWithPlurals.put(key, value), and the net result is that occasionally (when the size of the table overflows at just the wrong time), you will get an entry for "dogss" as well as for "dogs" and "dog". Now, does it state anywhere in the documentation for put that doing this recursive call is a possibility? No. In cases like this, it sure helps to have source code access to the JDK.&lt;br /&gt;&lt;br /&gt;&lt;a name="prop"&gt;&lt;strong&gt;Q:&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; Why does my Properties object ignore the defaults when I do a get?&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;You shouldn't do a get on a Properties object; you should do a getProperty instead. Many people assume that the only difference is that getProperty has a declared return type of String, while get is declared to return an Object. But actually there is a bigger difference: getProperty looks at the defaults. get is inherited from Hashtable, and it ignores the default, thereby doing exactly what is documented in the Hashtable class, but probably not what you expect. Other methods that are inherited from Hashtable (like isEmpty and toString) will also ignore defaults. Example code:&lt;br /&gt;Properties defaults = new Properties();&lt;br /&gt;defaults.put("color", "black");&lt;br /&gt;Properties props = new Properties(defaults);&lt;br /&gt;System.out.println(props.get("color") + ", " +&lt;br /&gt;props.getProperty(color));&lt;br /&gt;// This prints "null, black"&lt;br /&gt;Is this justified by the documentation? Maybe. The documentation in Hashtable talks about entries in the table, and the behavior of Properties is consistent if you assume that defauls are not entries in the table. If for some reason you thought defaults were entries (as you might be led to believe by the behavior of getProperty) then you will be confused.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="del"&gt;&lt;strong&gt;Q:&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;Inheritance seems error-prone. How can I guard against these errors?&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;The previous two questions show that a programmer neeeds to be very careful when extending a class, and sometimes just in using a class that extends another class. Problems like these two lead John Ousterhout to say "Implementation inheritance causes the same intertwining and brittleness that have been observed when goto statements are overused. As a result, OO systems often suffer from complexity and lack of reuse." (Scripting, IEEE Computer, March 1998) and Edsger Dijkstra to allegedly say "Object-oriented programming is an exceptionally bad idea which could only have originated in California." (from a collection of signature files). I don't think there's a general way to insure being safe, but there are a few things to be aware of:&lt;br /&gt;Extending a class that you don't have source code for is always risky; the documentation may be incomplete in ways you can't foresee.&lt;br /&gt;Calling super tends to make these unforeseen problems jump out.&lt;br /&gt;You need to pay as much attention to the methods that you don't over-ride as the methods that you do. This is one of the big fallacies of Object-Oriented design using inheritance. It is true that inheritance lets you write less code. But you still have to think about the code you don't write.&lt;br /&gt;You're especially looking for trouble if the subclass changes the contract of any of the methods, or of the class as a whole. It is difficult to tell when a contract is changed, since contracts are informal (there is a formal part in the type signature, but the rest appears only in comments). In the Properties example, it is not clear if a contract is being broken, because it is not clear if the defaults are to be considered "entries" in the table or not.&lt;br /&gt;&lt;br /&gt;&lt;a name="del2"&gt;&lt;strong&gt;Q:&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;What are some alternatives to inheritance?&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn't force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass).&lt;br /&gt;For the HashtableWithPlurals example, delegation would give you this (note: as of JDK 1.2, Dictionary is considered obsolete; use Map instead):&lt;br /&gt;/** A version of Hashtable that lets you do&lt;br /&gt;* table.put("dog", "canine");, and then have&lt;br /&gt;* table.get("dogs") return "canine". **/&lt;br /&gt;public class HashtableWithPlurals extends Dictionary {&lt;br /&gt;Hashtable table = new Hashtable();&lt;br /&gt;/** Make the table map both key and key + "s" to value. **/&lt;br /&gt;public Object put(Object key, Object value) {&lt;br /&gt;table.put(key + "s", value);&lt;br /&gt;return table.put(key, value);&lt;br /&gt;}&lt;br /&gt;... // Need to implement other methods as well&lt;br /&gt;}&lt;br /&gt;The Properties example, if you wanted to enforce the interpretation that default values are entries, would be better done with delegation. Why was it done with inheritance, then? Because the Java implementation team was rushed, and took the course that required writing less code.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="global"&gt;&lt;strong&gt;Q:&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; Why are there no global variables in Java?Global variables are considered bad form for a variety of reasons:&lt;br /&gt;&lt;/strong&gt;Adding state variables breaks referential transparency (you no longer can understand a statement or expression on its own: you need to understand it in the context of the settings of the global variables).&lt;br /&gt;State variables lessen the cohesion of a program: you need to know more to understand how something works. A major point of Object-Oriented programming is to break up global state into more easily understood collections of local state.&lt;br /&gt;When you add one variable, you limit the use of your program to one instance. What you thought was global, someone else might think of as local: they may want to run two copies of your program at once. For these reasons, Java decided to ban global variables.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="global2"&gt;&lt;strong&gt;Q:&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; I still miss global variables. What can I do instead?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;That depends on what you want to do. In each case, you need to decide two things: how many copies of this so-called global variable do I need? And where would be a convenient place to put it? Here are some common solutions:&lt;br /&gt;If you really want only one copy per each time a user invokes Java by starting up a Java virtual machine, then you probably want a static instance variable. For example, you have a MainWindow class in your application, and you want to count the number of windows that the user has opened, and initiate the "Really quit?" dialog when the user has closed the last one. For that, you want:&lt;br /&gt;// One variable per class (per JVM)&lt;br /&gt;public Class MainWindow {&lt;br /&gt;static int numWindows = 0;&lt;br /&gt;...&lt;br /&gt;// when opening: MainWindow.numWindows++;&lt;br /&gt;// when closing: MainWindow.numWindows--;&lt;br /&gt;}&lt;br /&gt;In many cases, you really want a class instance variable. For example, suppose you wrote a web browser and wanted to have the history list as a global variable. In Java, it would make more sense to have the history list be an instance variable in the Browser class. Then a user could run two copies of the browser at once, in the same JVM, without having them step on each other.&lt;br /&gt;// One variable per instance&lt;br /&gt;public class Browser {&lt;br /&gt;HistoryList history = new HistoryList();&lt;br /&gt;...&lt;br /&gt;// Make entries in this.history&lt;br /&gt;}&lt;br /&gt;Now suppose that you have completed the design and most of the implementation of your browser, and you discover that, deep down in the details of, say, the Cookie class, inside the Http class, you want to display an error message. But you don't know where to display the message. You could easily add an instance variable to the Browser class to hold the display stream or frame, but you haven't passed the current instance of the browser down into the methods in the Cookie class. You don't want to change the signatures of many methods to pass the browser along. You can't use a static variable, because there might be multiple browsers running. However, if you can guarantee that there will be only one browser running per thread (even if each browser may have multiple threads) then there is a good solution: store a table of thread-to-browser mappings as a static variable in the Browser class, and look up the right browser (and hence display) to use via the current thread:&lt;br /&gt;// One "variable" per thread&lt;br /&gt;public class Browser {&lt;br /&gt;static Hashtable browsers = new Hashtable();&lt;br /&gt;public Browser() { // Constructor&lt;br /&gt;browsers.put(Thread.currentThread(), this);&lt;br /&gt;}&lt;br /&gt;...&lt;br /&gt;public void reportError(String message) {&lt;br /&gt;Thread t = Thread.currentThread();&lt;br /&gt;((Browser)Browser.browsers.get(t))&lt;br /&gt;.show(message)&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;Finally, suppose you want the value of a global variable to persist between invocations of the JVM, or to be shared among multiple JVMs in a network of machines. Then you probably should use a database which you access through JDBC, or you should serialize data and write it to a file.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="math"&gt;&lt;strong&gt;Q: Can I write sin(x) instead of Math.sin(x)?&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Short answer: no. Get used to writing the class name to access static methods from outside the class. However, if you insist on a longer answer ...&lt;br /&gt;If you only want a few methods, you can put in calls to them within your own class:&lt;br /&gt;public static double sin(double x) { return Math.sin(x); }&lt;br /&gt;public static double cos(double x) { return Math.cos(x); }&lt;br /&gt;...&lt;br /&gt;sin(x)&lt;br /&gt;Static methods take a target (thing to the left of the dot) that is either a class name, or is an object whose value is ignored, but must be declared to be of the right class. So you could save three characters per call by doing:&lt;br /&gt;// Can't instantiate Math, so it must be null.&lt;br /&gt;Math m = null;&lt;br /&gt;...&lt;br /&gt;m.sin(x)&lt;br /&gt;java.lang.Math is a final class, so you can't inherit from it, but if you have your own set of static methods that you would like to share among many of your own classes, then you can package them up and inherit them:&lt;br /&gt;public abstract class MyStaticMethods {&lt;br /&gt;public static double mysin(double x) { ... }&lt;br /&gt;}&lt;br /&gt;public class MyClass1 extends MyStaticMethods {&lt;br /&gt;...&lt;br /&gt;mysin(x)&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;a href="http://www.best.com/~pvdl/"&gt;Peter van der Linden&lt;/a&gt;, author of Just Java, recommends against both of the last two practices in his &lt;a href="http://www.best.com/~pvdl/javafaq.html"&gt;FAQ&lt;/a&gt;. I agree with him that Math m = null is a bad idea in most cases, but I'm not convinced that the MyStaticMethods demonstrates "very poor OOP style to use inheritance to obtain a trivial name abbreviation (rather than to express a type hierarchy)." First of all, trivial is in the eye of the beholder; the abbreviation may be substantial. (See &lt;a href="http://www.norvig.com/jscheme-design.html"&gt;an example&lt;/a&gt; of how I used this approach to what I thought was good effect.) Second, it is rather presumptuous to say that this is very bad OOP style. You could make a case that it is bad Java style, but in languages with multiple inheritance, this idiom would be more acceptable.&lt;br /&gt;Another way of looking at it is that features of Java (and any language) necessarily involve trade-offs, and conflate many issues. I agree it is bad to use inheritance in such a way that you mislead the user into thinking that MyClass1 is inheriting behavior from MyStaticMethods, and it is bad to prohibit MyClass1 from extending whatever other class it really wants to extend. But in Java the class is also the unit of encapsulation, compilation (mostly), and name scope. The MyStaticMethod approach scores negative points on the type hierarchy front, but positive points on the name scope front. If you say that the type hierarchy view is more important, I won't argue with you. But I will argue if you think of a class as doing only one thing, rather than many things at once, and if you think of style guides as absolute rather than as trade-offs.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="null"&gt;&lt;strong&gt;Q:&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; Is null an Object?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Absolutely not. By that, I mean (null instanceof Object) is false. Some other things you should know about null:&lt;br /&gt;You can't call a method on null: x.m() is an error when x is null and m is a non-static method. (When m is a static method it is fine, because it is the class of x that matters; the value is ignored.)&lt;br /&gt;There is only one null, not one for each class. Thus, ((String) null == (Hashtable) null), for example.&lt;br /&gt;It is ok to pass null as an argument to a method, as long as the method is expecting it. Some methods do; some do not. So, for example, System.out.println(null) is ok, but string.compareTo(null) is not. For methods you write, your javadoc comments should say whether null is ok, unless it is obvious.&lt;br /&gt;In JDK 1.1 to 1.1.5, passing null as the literal argument to a constructor of an anonymous inner class (e.g., new SomeClass(null) { ...} caused a compiler error. It's ok to pass an expression whose value is null, or to pass a coerced null, like new SomeClass((String) null) { ...}&lt;br /&gt;There are at least three different meanings that null is commonly used to express:&lt;br /&gt;Uninitialized. A variable or slot that hasn't yet been assigned its real value.&lt;br /&gt;Non-existant/not applicable. For example, terminal nodes in a binary tree might be represented by a regular node with null child pointers.&lt;br /&gt;Empty. For example, you might use null to represent the empty tree. Note that this is subtly different from the previous case, although some people make the mistake of confusing the two cases. The difference is whether null is an acceptable tree node, or whether it is a signal to not treat the value as a tree node. Compare the following three implementations of binary tree nodes with an in-order print method:&lt;br /&gt;// null means not applicable&lt;br /&gt;// There is no empty tree.&lt;br /&gt;class Node {&lt;br /&gt;Object data;&lt;br /&gt;Node left, right;&lt;br /&gt;void print() {&lt;br /&gt;if (left != null)&lt;br /&gt;left.print();&lt;br /&gt;System.out.println(data);&lt;br /&gt;if (right != null)&lt;br /&gt;right.print();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;// null means empty tree&lt;br /&gt;// Note static, non-static methods&lt;br /&gt;class Node {&lt;br /&gt;Object data;&lt;br /&gt;Node left, right;&lt;br /&gt;void static print(Node node) {&lt;br /&gt;if (node != null) node.print();&lt;br /&gt;}&lt;br /&gt;void print() {&lt;br /&gt;print(left);&lt;br /&gt;System.out.println(data);&lt;br /&gt;print(right);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;// Separate class for Empty&lt;br /&gt;// null is never used&lt;br /&gt;interface Node { void print(); }&lt;br /&gt;class DataNode implements Node{&lt;br /&gt;Object data;&lt;br /&gt;Node left, right;&lt;br /&gt;void print() {&lt;br /&gt;left.print();&lt;br /&gt;System.out.println(data);&lt;br /&gt;right.print();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;class EmptyNode implements Node {&lt;br /&gt;void print() { }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17301471-112808874859467838?l=java-queries.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-queries.blogspot.com/feeds/112808874859467838/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17301471&amp;postID=112808874859467838' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/112808874859467838'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17301471/posts/default/112808874859467838'/><link rel='alternate' type='text/html' href='http://java-queries.blogspot.com/2005/09/q.html' title=''/><author><name>Ashish</name><uri>http://www.blogger.com/profile/07384064689857978340</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
