<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Java Interview Questions</title>
	<atom:link href="http://javafaq.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://javafaq.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Thu, 08 Feb 2007 10:45:33 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='javafaq.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/5e4dc178bfa1ab3b73c2c815116e908c?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Java Interview Questions</title>
		<link>http://javafaq.wordpress.com</link>
	</image>
			<item>
		<title>Some Interview Questions on String.</title>
		<link>http://javafaq.wordpress.com/2007/01/24/some-interview-questions-on-string/</link>
		<comments>http://javafaq.wordpress.com/2007/01/24/some-interview-questions-on-string/#comments</comments>
		<pubDate>Wed, 24 Jan 2007 05:23:19 +0000</pubDate>
		<dc:creator>vcoder</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://javafaq.wordpress.com/2007/01/24/some-interview-questions-on-string/</guid>
		<description><![CDATA[Que:-1 Difference Between String and String Buffer?
Ans:- String is a Collection or array of Characters.when u create a string object u r creating a string that can&#8217;t be changed. this approach is used becoz fixed, immutable strings can be implemented more efficiently then the muttable (Changeable Ones ) strings.
StringBuffer &#8211; StringBuffer Represents growable and writeable [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&blog=586052&post=15&subd=javafaq&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Que:-1 Difference Between String and String Buffer?</p>
<p>Ans:- String is a Collection or array of Characters.when u create a string object u r creating a string that can&#8217;t be changed. this approach is used becoz fixed, immutable strings can be implemented more efficiently then the muttable (Changeable Ones ) strings.</p>
<p>StringBuffer &#8211; StringBuffer Represents growable and writeable character sequences.StringBuffer may have characters and substrings inserted in the middle or append to end.</p>
<p>StringBuffer allocates room for 16 additional Characters when no specific buffer length is requested, becoz reallocation is a costly process in terms of time.</p>
<p>Que:-2  difference between verses (==) and .equals().</p>
<p>Ans.  .equals() is used for comparing values of a string objects and verses ( ==) is used to compare there memory reference.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/javafaq.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/javafaq.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/javafaq.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/javafaq.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/javafaq.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/javafaq.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/javafaq.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/javafaq.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/javafaq.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/javafaq.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/javafaq.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/javafaq.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&blog=586052&post=15&subd=javafaq&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://javafaq.wordpress.com/2007/01/24/some-interview-questions-on-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f23d189363d45b9dd3f4c41382224ec?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Sachin</media:title>
		</media:content>
	</item>
		<item>
		<title>Core Java Interview Questions</title>
		<link>http://javafaq.wordpress.com/2006/12/02/hello-world/</link>
		<comments>http://javafaq.wordpress.com/2006/12/02/hello-world/#comments</comments>
		<pubDate>Sat, 02 Dec 2006 05:22:11 +0000</pubDate>
		<dc:creator>vcoder</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[This site is developed for all IT people who work in the field of Java.
This site covers all Core Java, J2EE and Sql’s Frequently Asked Questions that are asked in most technical interviews.

Core Java Interview Questions:

What is a class? A class is a blueprint, or prototype, that defines the variables and the methods common to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&blog=586052&post=1&subd=javafaq&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p CLASS="MsoNormal"><span STYLE="font-family: Verdana">This site is developed for all IT people who work in the field of Java.</span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana">This site covers all Core Java, J2EE and Sql’s Frequently Asked Questions that are asked in most technical interviews.</span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Core Java Interview Questions:</span></strong></p>
<ol>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is a class?</span></strong><span STYLE="font-family: Verdana"> A class is a blueprint, or prototype, that defines the variables and the methods common to all objects of a certain kind. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is an object? </span></strong><span STYLE="font-family: Verdana">An object is a software bundle of variables and related methods. An instance of a class depicting the state and behavior at that particular time in real world. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is a method? </span></strong><span STYLE="font-family: Verdana">Encapsulation of a functionality which can be called to perform specific tasks. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is encapsulation? Explain with an example.</span></strong><span STYLE="font-family: Verdana"> Encapsulation is the term given to the process of hiding the implementation details of the object. Once an object is encapsulated, its implementation details are not immediately accessible any more. Instead they are packaged and are only indirectly accessible via the interface of the object </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is inheritance? Explain with an example.</span></strong><span STYLE="font-family: Verdana"> Inheritance in object oriented programming means that a class of objects can inherit properties and methods from another class of objects. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is polymorphism? Explain with an example. </span></strong><span STYLE="font-family: Verdana">In object-oriented programming, polymorphism refers to a programming language’s ability to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes. For example, given a base class shape, polymorphism enables the programmer to define different area methods for any number of derived classes, such as circles, rectangles and triangles. No matter what shape an object is, applying the area method to it will return the correct results. Polymorphism is considered to be a requirement of any true object-oriented programming language </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Is multiple inheritances allowed in Java? </span></strong><span STYLE="font-family: Verdana">No, multiple inheritance is not allowed in Java. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is interpreter and compiler? </span></strong><span STYLE="font-family: Verdana">Java interpreter converts the high level language code into a intermediate form in Java called as byte code, and then executes it, where as a compiler converts the high level language code to machine language making it very hardware specific </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is JVM?</span></strong><span STYLE="font-family: Verdana"> The Java interpreter along with the runtime environment required to run the Java application in called as Java virtual machine(JVM) </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What are the different types of modifiers? </span></strong><span STYLE="font-family: Verdana">There are access modifiers and there are other identifiers. Access modifiers are public, protected and private. Other is final and static. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What are the access modifiers in Java? </span></strong><span STYLE="font-family: Verdana">There are 3 access modifiers. Public, protected and private, and the default one if no identifier is specified is called friendly, but programmer cannot specify the friendly identifier explicitly. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is a wrapper class?</span></strong><span STYLE="font-family: Verdana"> They are classes that wrap a primitive data type so it can be used as a object </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is a static variable and static method? What’s the difference between two?</span></strong><span STYLE="font-family: Verdana"> The modifier static can be used with a variable and method. When declared as static variable, there is only one variable no matter how instances are created, this variable is initialized when the class is loaded. Static method do not need a class to be instantiated to be called, also a non static method cannot be called from static method. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is garbage collection?</span></strong><span STYLE="font-family: Verdana"> Garbage Collection is a thread that runs to reclaim the memory by destroying the objects that cannot be referenced anymore. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is abstract class?</span></strong><span STYLE="font-family: Verdana"> Abstract class is a class that needs to be extended and its methods implemented, aclass has to be declared abstract if it has one or more abstract methods. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is meant by final class, methods and variables? </span></strong><span STYLE="font-family: Verdana">This modifier can be applied to class method and variable. When declared as final class the class cannot be extended. When declared as final variable, its value cannot be changed if is primitive value, if it is a reference to the object it will always refer to the same object, internal attributes of the object can be changed. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is interface?</span></strong><span STYLE="font-family: Verdana"> Interface is a contact that can be implemented by a class, it has method that need implementation. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is method overloading?</span></strong><span STYLE="font-family: Verdana"> Overloading is declaring multiple method with the same name, but with different argument list. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is method overriding?</span></strong><span STYLE="font-family: Verdana"> Overriding has same method name, identical arguments used in subclass. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is singleton class?</span></strong><span STYLE="font-family: Verdana"> Singleton class means that any given time only one instance of the class is present, in one JVM. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the difference between an array and a vector?</span></strong><span STYLE="font-family: Verdana"> Number of elements in an array are fixed at the construction time, whereas the number of elements in vector can grow dynamically. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is a constructor?</span></strong><span STYLE="font-family: Verdana"> In Java, the class designer can guarantee initialization of every object by providing a special method called a constructor. If a class has a constructor, Java automatically calls that constructor when an object is created, before users can even get their hands on it. So initialization is guaranteed. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is casting?</span></strong><span STYLE="font-family: Verdana"> Conversion of one type of data to another when appropriate. Casting makes explicitly converting of data. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the difference between final, finally and finalize?</span></strong><span STYLE="font-family: Verdana"> The modifier final is used on class variable and methods to specify certain behavior explained above. And finally is used as one of the loop in the try catch blocks, It is used to hold code that needs to be executed whether or not the exception occurs in the try catch block. Java provides a method called finalize( ) that can be defined in the class. When the garbage collector is ready to release the storage ed for your object, it will first call finalize( ), and only on the next garbage-collection pass will it reclaim the objects memory. So finalize( ), gives you the ability to perform some important cleanup at the time of garbage collection. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What are are packages?</span></strong><span STYLE="font-family: Verdana"> A package is a collection of related classes and interfaces providing access protection and namespace management. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is a super class and how can you call a super class?</span></strong><span STYLE="font-family: Verdana"> When a class is extended that is derived from another class there is a relationship is created, the parent class is referred to as the super class by the derived class that is the child. The derived class can make a call to the super class using the keyword super. If used in the constructor of the derived class it has to be the first statement. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is meant by a Thread?</span></strong><span STYLE="font-family: Verdana"> Thread is defined as an instantiated parallel process of a given program. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is multi-threading?</span></strong><span STYLE="font-family: Verdana"> Multi-threading as the name suggest is the scenario where more than one threads are running. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What are two ways of creating a thread? Which is the best way and why?</span></strong><span STYLE="font-family: Verdana"> Two ways of creating threads are, one can extend from the Java.lang.Thread and can implement the rum method or the run method of a different class can be called which implements the interface Runnable, and the then implement the run() method. The latter one is mostly used as first due to Java rule of only one class inheritance, with implementing the Runnable interface that problem is sorted out. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is deadlock?</span></strong><span STYLE="font-family: Verdana"> Deadlock is a situation when two threads are waiting on each other to release a resource. Each thread waiting for a resource which is held by the other waiting thread. In Java, this resource is usually the object lock obtained by the synchronized keyword. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What are the three types of priority?</span></strong><span STYLE="font-family: Verdana"> MAX_PRIORITY which is 10, MIN_PRIORITY which is 1, NORM_PRIORITY which is 5. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the use of synchronizations?</span></strong><span STYLE="font-family: Verdana"> Every object has a lock, when a synchronized keyword is used on a piece of code the, lock must be obtained by the thread first to execute that code, other threads will not be allowed to execute that piece of code till this lock is released. </span></li>
</ol>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana"></span></strong></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">33. How could Java classes direct program messages to the system console, but error messages, say to a file?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p STYLE="margin-bottom: 12pt" CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. The class System has a variable <em>out</em> that represents the standard output, and the variable <em>err</em> that represent the standard error device. By default, they both point at the system console. This how the standard output could be re-directed:</span></p>
<p CLASS="MsoNormal"><span CLASS="code"><span STYLE="font-family: Verdana">Stream st = new Stream(new FileOutputStream(&#8220;output.txt&#8221;)); System.setErr(st); System.setOut(st);</span></span><span STYLE="font-family: Verdana"> </span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana"><br />
34. What&#8217;s the difference between an interface and an abstract class?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.</span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana"><br />
35. Why would you use a synchronized block vs. synchronized method?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. Synchronized blocks place locks for shorter periods than synchronized methods.</span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana"><br />
36<strong><span STYLE="font-family: Verdana">. Explain the usage of the keyword transient?</span></strong></span></strong><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. This keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers).</span></p>
<p><strong>37. How can you force garbage collection?</strong></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. You can&#8217;t force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.</span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana"><br />
38. How do you know if an explicit object casting is needed?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p STYLE="margin-bottom: 12pt" CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. If you assign a super class object to a variable of a subclass&#8217;s data type, you need to do explicit casting. For example:</span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana">Object a; Customer b; b = (Customer) a;</span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
When you assign a subclass to a variable having a sup class type, the casting is performed automatically. </span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana"><br />
39. What&#8217;s the difference between the methods sleep() and wait()</span></strong><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. The code <span CLASS="code">sleep(1000); </span>puts thread aside for exactly one second. The code <span CLASS="code">wait(1000), </span>causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.</span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana"><br />
40. Can you write a Java class that could be used both as an applet as well as an application?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. Yes. Add a main() method to the applet.</span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana"><br />
41. What&#8217;s the difference between constructors and other methods?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times.</span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana"><br />
42. Can you call one constructor from another if a class has multiple constructors?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. Yes. Use this() syntax.</span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana"><br />
43. Explain the usage of Java packages.</span></strong><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. This is a way to organize files when a project consists of multiple modules. It also helps resolve naming conflicts when different packages have classes with the same names. Packages access level also allows you to protect data from being used by the non-authorized classes.</span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana"><br />
44. If a class is located in a package, what do you need to change in the OS environment to be able to use it?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p STYLE="margin-bottom: 12pt" CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. You need to add a directory or a jar file that contains the package directories to the CLASSPATH environment variable. Let&#8217;s say a class Employee belongs to a package com.xyz.hr; and is located in the file c:\dev\com\xyz\hr\Employee.java. In this case, you&#8217;d need to add c:\dev to the variable CLASSPATH. If this class contains the method main(), you could test it from a command prompt window as follows:</span></p>
<p CLASS="MsoNormal"><span CLASS="code"><span STYLE="font-family: Verdana">c:\&gt;java com.xyz.hr.Employee</span></span><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><strong><br />
45. What&#8217;s the difference between J2SDK 1.5 and J2SDK 5.0?</strong></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. There’s no difference, Sun Microsystems just re-branded this version.</span></p>
<p><strong><span STYLE="font-family: Verdana">46. What would you use to compare two String variables &#8211; the operator == or the method equals()?</span></strong></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. I&#8217;d use the method equals() to compare the values of the Strings and the == to check if two variables point at the same instance of a String object.</span></p>
<p><strong><span STYLE="font-family: Verdana">47. Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?</span></strong></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. Yes, it does. The FileNoFoundException is inherited from the IOException. Exception&#8217;s subclasses have to be caught first.</span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana"><br />
48. Can an inner class declared inside of a method access local variables of this method?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. It&#8217;s possible if these variables are final.</span></p>
<p STYLE="margin-bottom: 12pt" CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana"><br />
49. What can go wrong if you replace &amp;&amp; with &amp; in the following code:</span></strong></p>
<p STYLE="margin-bottom: 12pt" CLASS="MsoNormal"><span CLASS="code"><strong><span STYLE="font-family: Verdana">String a=null; if (a!=null &amp;&amp; a.length()&gt;10) {&#8230;}</span></strong></span><strong><span STYLE="font-family: Verdana"></span></strong></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana">A. A single ampersand here would lead to a NullPointerException.</span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
<strong><span STYLE="font-family: Verdana">50. What&#8217;s the main difference between a Vector and an ArrayList</span></strong></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. Java Vector class is internally synchronized and ArrayList is not.</span></p>
<p><strong>51. When should the method invokeLater()be used?</strong></p>
<p STYLE="margin-bottom: 12pt" CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. This method is used to ensure that Swing components are updated through the event-dispatching thread.</span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">52<span> </span>. How can a subclass call a method or a constructor defined in a super class?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass&#8217;s constructor.</span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">53. What&#8217;s the difference between a queue and a stack?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule</span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">54. You can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces?</span></strong><span STYLE="font-family: Verdana"> </span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. Sometimes. But your class may be a descendent of another class and in this case the interface is your only option.</span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">55. What comes to mind when you hear about a young generation in Java?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. Garbage collection.</span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">56. What comes to mind when someone mentions a shallow copy in Java?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. Object cloning.</span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">57. If you&#8217;re overriding the method equals() of an object, which other method you might also consider?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. hashCode()</span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">58. You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use:<br />
ArrayList or LinkedList?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. ArrayList</span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">59. How would you make a copy of an entire Java object with its state?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. Have this class implement Cloneable interface and call its method clone().</span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">60. How can you minimize the need of garbage collection and make the memory use more effective?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. Use object pooling and weak object references.</span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><strong>61. There are two classes: A and B. The class B need to inform a class A when some important event has happened. What Java technique would you use to implement it?</strong></span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. If these classes are threads I&#8217;d consider notify() or notifyAll(). For regular classes you can use the Observer interface.</span></p>
<p CLASS="MsoNormal"><span STYLE="font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">62. What access level do you need to specify in the class declaration to ensure that only classes from the same directory can access it?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p STYLE="margin-bottom: 12pt" CLASS="MsoNormal"><span STYLE="font-family: Verdana"><br />
A. You do not need to specify any access level, and Java will use a default package access level.</span></p>
<p STYLE="margin-bottom: 12pt" CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Some Basic to Advance Core Java Questions</span></strong></p>
<ol>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Can there be an abstract class with no abstract methods in it?</span></strong><span STYLE="font-family: Verdana"> &#8211; Yes </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Can an Interface be final?</span></strong><span STYLE="font-family: Verdana"> &#8211; No </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Can an Interface have an inner class?</span></strong><span STYLE="font-family: Verdana"> &#8211; Yes. </span></li>
</ol>
<pre><span STYLE="font-size: 12pt; font-family: Verdana"><span>  </span>public interface abc</span></pre>
<pre><span STYLE="font-size: 12pt; font-family: Verdana"><span>  </span>{</span></pre>
<pre><span STYLE="font-size: 12pt; font-family: Verdana"><span> 	</span>static int i=0; void dd();</span></pre>
<pre><span STYLE="font-size: 12pt; font-family: Verdana"><span> 	</span>class a1</span></pre>
<pre><span STYLE="font-size: 12pt; font-family: Verdana">	{</span></pre>
<pre><span STYLE="font-size: 12pt; font-family: Verdana">		a1()</span></pre>
<pre><span STYLE="font-size: 12pt; font-family: Verdana"><span> 		</span>{</span></pre>
<pre><span STYLE="font-size: 12pt; font-family: Verdana">			int j;</span></pre>
<pre><span STYLE="font-size: 12pt; font-family: Verdana">			System.out.println("inside");</span></pre>
<pre><span STYLE="font-size: 12pt; font-family: Verdana">		};</span></pre>
<pre><span STYLE="font-size: 12pt; font-family: Verdana">	public static void main(String a1[])</span></pre>
<pre><span STYLE="font-size: 12pt; font-family: Verdana">	{</span></pre>
<pre><span STYLE="font-size: 12pt; font-family: Verdana">		System.out.println("in interfia");</span></pre>
<pre><span STYLE="font-size: 12pt; font-family: Verdana">	}</span></pre>
<pre><span STYLE="font-size: 12pt; font-family: Verdana">	}</span></pre>
<pre><span STYLE="font-size: 12pt; font-family: Verdana">}</span></pre>
<ol>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Can we define private and protected modifiers for variables in interfaces?</span></strong><span STYLE="font-family: Verdana"> &#8211; No </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is Externalizable?</span></strong><span STYLE="font-family: Verdana"> &#8211; Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in) </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What modifiers are allowed for methods in an Interface?</span></strong><span STYLE="font-family: Verdana"> &#8211; Only public and abstract modifiers are allowed for methods in interfaces. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is a local, member and a class variable?</span></strong><span STYLE="font-family: Verdana"> &#8211; Variables declared within a method are “local” variables. Variables declared within the class i.e not within any methods are “member” variables (global variables). Variables declared within the class i.e not within any methods and are defined as “static” are class variables </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What are the different identifier states of a Thread?</span></strong><span STYLE="font-family: Verdana"> &#8211; The different identifiers of a Thread are: R &#8211; Running or runnable thread, S &#8211; Suspended thread, CW &#8211; Thread waiting on a condition variable, MW &#8211; Thread waiting on a monitor lock, MS &#8211; Thread suspended waiting on a monitor lock </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What are some alternatives to inheritance?</span></strong><span STYLE="font-family: Verdana"> &#8211; 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). </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Why isn’t there operator overloading?</span></strong><span STYLE="font-family: Verdana"> &#8211; Because C++ has proven by example that operator overloading makes code almost impossible to maintain. In fact there very nearly wasn’t even method overloading in Java, but it was thought that this was too useful for some very basic methods like print(). Note that some of the classes like DataOutputStream have unoverloaded methods like writeInt() and writeByte(). </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What does it mean that a method or field is “static”?</span></strong><span STYLE="font-family: Verdana"> &#8211; Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class. Static methods can be referenced with the name of the class rather than the name of a particular object of the class (though that works too). That’s how library methods like System.out.println() work. out is a static field in the java.lang.System class. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">How do I convert a numeric IP address like 192.18.97.39 into a hostname like java.sun.com?</span></strong><span STYLE="font-family: Verdana"> </span></li>
</ol>
<pre><span STYLE="font-size: 12pt; font-family: Verdana"><span><span></span></span></span><span STYLE="font-size: 12pt; font-family: Verdana"><span></span>String hostname = InetAddress.getByName("192.18.97.39").getHostName();</span></pre>
<ol>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Difference between JRE/JVM/JDK?</span></strong><span STYLE="font-family: Verdana"> </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Why do threads block on I/O?</span></strong><span STYLE="font-family: Verdana"> &#8211; Threads block on i/o (that is enters the waiting state) so that other threads may execute while the I/O operation is performed. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is synchronization and why is it important?</span></strong><span STYLE="font-family: Verdana"> &#8211; With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object’s value. This often leads to significant errors. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Is null a keyword?</span></strong><span STYLE="font-family: Verdana"> &#8211; The null value is not a keyword. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Which characters may be used as the second character of an identifier, but not as the first character of an identifier?</span></strong><span STYLE="font-family: Verdana"> &#8211; The digits 0 through 9 may not be used as the first character of an identifier but they may be used after the first character of an identifier. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What modifiers may be used with an inner class that is a member of an outer class?</span></strong><span STYLE="font-family: Verdana"> &#8211; A (non-local) inner class may be declared as public, protected, private, static, final, or abstract. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?</span></strong><span STYLE="font-family: Verdana"> &#8211; Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What are wrapped classes?</span></strong><span STYLE="font-family: Verdana"> &#8211; Wrapped classes are classes that allow primitive types to be accessed as objects. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What restrictions are placed on the location of a package statement within a source code file?</span></strong><span STYLE="font-family: Verdana"> &#8211; A package statement must appear as the first line in a source code file (excluding blank lines and comments). </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the difference between preemptive scheduling and time slicing?</span></strong><span STYLE="font-family: Verdana"> &#8211; Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is a native method?</span></strong><span STYLE="font-family: Verdana"> &#8211; A native method is a method that is implemented in a language other than Java. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What are order of precedence and associativity, and how are they used?</span></strong><span STYLE="font-family: Verdana"> &#8211; Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the catch or declare rule for method declarations?</span></strong><span STYLE="font-family: Verdana"> &#8211; If a checked exception may be thrown within the body of a method, the method must either catch the exception or declare it in its throws clause. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Can an anonymous class be declared as implementing an interface and extending a class?</span></strong><span STYLE="font-family: Verdana"> &#8211; An anonymous class may implement an interface or extend a superclass, but may not be declared to do both. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the range of the char type?</span></strong><span STYLE="font-family: Verdana"> &#8211; The range of the char type is 0 to 2^16 &#8211; 1. </span></li>
</ol>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Basic Java Interview Questions:</span></strong></p>
<p><strong><span STYLE="font-family: Verdana">1. Why do you prefer Java?</span></strong><span STYLE="font-family: Verdana"> </span></p>
<p><span STYLE="font-family: Verdana">Answer: write once ,run anywhere.</span></p>
<p><strong><span STYLE="font-family: Verdana">2. Name some of the classes which provide the functionality of collation?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p><span STYLE="font-family: Verdana">Answer: collator, rulebased collator, collationkey, collationelement iterator.</span></p>
<p><strong><span STYLE="font-family: Verdana">3. Awt stands for? and what is it?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p><span STYLE="font-family: Verdana">Answer: AWT stands for Abstract window tool kit. It is a is a package that provides an integrated set of classes to manage user interface components. </span></p>
<p><strong><span STYLE="font-family: Verdana">4. why a java program can not directly communicate with an ODBC driver?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p><span STYLE="font-family: Verdana">Answer: Since ODBC API is written in C language and makes use of pointers which Java can not support.</span></p>
<p><strong><span STYLE="font-family: Verdana">5. Are servlets platform independent? If so Why? Also what is the most common application of servlets?</span></strong><span STYLE="font-family: Verdana"></span></p>
<p STYLE="border-top-color: #000000; border-left-color: #000000; border-right-color: #000000; border-bottom-color: #000000; border-top-width: medium; border-left-width: medium; border-right-width: medium; border-bottom-width: medium; border-top-style: none; border-left-style: none; border-right-style: none; border-bottom-style: none; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0"><span STYLE="font-family: Verdana">Answer: Yes, Because they are written in Java. The most common application of servlet is to access database and dynamically construct HTTP response</span></p>
<ol>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is garbage collection? What is the process that is responsible for doing that in java?</span></strong><span STYLE="font-family: Verdana"> &#8211; Reclaiming the unused memory by the invalid objects. Garbage collector is responsible for this process</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What kind of thread is the Garbage collector thread?</span></strong><span STYLE="font-family: Verdana"> &#8211; It is a daemon thread.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is a daemon thread?</span></strong><span STYLE="font-family: Verdana"> &#8211; These are the threads which can run without user intervention. The JVM can exit when there are daemon thread by killing them abruptly.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">How will you invoke any external process in Java?</span></strong><span STYLE="font-family: Verdana"> &#8211; Runtime.getRuntime().exec(….)</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the finalize method do?</span></strong><span STYLE="font-family: Verdana"> &#8211; Before the invalid objects get garbage collected, the JVM give the user a chance to clean up some resources before it got garbage collected.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is mutable object and immutable object?</span></strong><span STYLE="font-family: Verdana"> &#8211; If a object value is changeable then we can call it as Mutable object. (Ex., StringBuffer, …) If you are not allowed to change the value of an object, it is immutable object. (Ex., String, Integer, Float, …)</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the basic difference between string and stringbuffer object?</span></strong><span STYLE="font-family: Verdana"> &#8211; String is an immutable object. StringBuffer is a mutable object.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the purpose of Void class?</span></strong><span STYLE="font-family: Verdana"> &#8211; The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is reflection?</span></strong><span STYLE="font-family: Verdana"> &#8211; Reflection allows programmatic access to information about the fields, methods and constructors of loaded classes, and the use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the base class for Error and Exception?</span></strong><span STYLE="font-family: Verdana"> &#8211; Throwable</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the byte range?</span></strong><span STYLE="font-family: Verdana"> -128 to 127</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the implementation of destroy method in java.. is it native or java code?</span></strong><span STYLE="font-family: Verdana"> &#8211; This method is not implemented.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is a package?</span></strong><span STYLE="font-family: Verdana"> &#8211; To group set of classes into a single unit is known as packaging. Packages provides wide namespace ability.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What are the approaches that you will follow for making a program very efficient?</span></strong><span STYLE="font-family: Verdana"> &#8211; By avoiding too much of static methods avoiding the excessive and unnecessary use of synchronized methods Selection of related classes based on the application (meaning synchronized classes for multiuser and non-synchronized classes for single user) Usage of appropriate design patterns Using cache methodologies for remote invocations Avoiding creation of variables within a loop and lot more.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is a DatabaseMetaData?</span></strong><span STYLE="font-family: Verdana"> &#8211; Comprehensive information about the database as a whole. </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is Locale?</span></strong><span STYLE="font-family: Verdana"> &#8211; A Locale object represents a specific geographical, political, or cultural region</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">How will you load a specific locale?</span></strong><span STYLE="font-family: Verdana"> &#8211; Using ResourceBundle.getBundle(…);</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is JIT and its use?</span></strong><span STYLE="font-family: Verdana"> &#8211; Really, just a very fast compiler… In this incarnation, pretty much a one-pass compiler — no offline computations. So you can’t look at the whole method, rank the expressions according to which ones are re-used the most, and then generate code. In theory terms, it’s an on-line problem.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Is JVM a compiler or an interpreter?</span></strong><span STYLE="font-family: Verdana"> &#8211; Interpreter</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">When you think about optimization, what is the best way to findout the time/memory consuming process?</span></strong><span STYLE="font-family: Verdana"> &#8211; Using profiler</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the purpose of assert keyword used in JDK1.4.x?</span></strong><span STYLE="font-family: Verdana"> &#8211; In order to validate certain expressions. It effectively replaces the if block and automatically throws the AssertionError on failure. This keyword should be used for the critical arguments. Meaning, without that the method does nothing.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">How will you get the platform dependent values like line separator, path separator, etc., ?</span></strong><span STYLE="font-family: Verdana"> &#8211; Using Sytem.getProperty(…) (line.separator, path.separator, …)</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is skeleton and stub? what is the purpose of those?</span></strong><span STYLE="font-family: Verdana"> &#8211; Stub is a client side representation of the server, which takes care of communicating with the remote server. Skeleton is the server side representation. But that is no more in use… it is deprecated long before in JDK.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the final keyword denotes?</span></strong><span STYLE="font-family: Verdana"> &#8211; final keyword denotes that it is the final implementation for that method or variable or class. You can’t override that method/variable/class any more.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the significance of ListIterator?</span></strong><span STYLE="font-family: Verdana"> &#8211; You can iterate back and forth.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the major difference between LinkedList and ArrayList?</span></strong><span STYLE="font-family: Verdana"> &#8211; LinkedList are meant for sequential accessing. ArrayList are meant for random accessing.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is nested class?</span></strong><span STYLE="font-family: Verdana"> &#8211; If all the methods of a inner class is static then it is a nested class.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is inner class?</span></strong><span STYLE="font-family: Verdana"> &#8211; If the methods of the inner class can only be accessed via the instance of the inner class, then it is called inner class.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is composition?</span></strong><span STYLE="font-family: Verdana"> &#8211; Holding the reference of the other class within some other class is known as composition.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is aggregation?</span></strong><span STYLE="font-family: Verdana"> &#8211; It is a special type of composition. If you expose all the methods of a composite class and route the method call to the composite method through its reference, then it is called aggregation.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What are the methods in Object?</span></strong><span STYLE="font-family: Verdana"> &#8211; clone, equals, wait, finalize, getClass, hashCode, notify, notifyAll, toString</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Can you instantiate the Math class?</span></strong><span STYLE="font-family: Verdana"> &#8211; You can’t instantiate the math class. All the methods in this class are static. And the constructor is not public.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is singleton?</span></strong><span STYLE="font-family: Verdana"> &#8211; It is one of the design pattern. This falls in the creational pattern of the design pattern. There will be only one instance for that entire JVM. You can achieve this by having the private constructor in the class. For eg., public class Singleton { private static final Singleton s = new Singleton(); private Singleton() { } public static Singleton getInstance() { return s; } // all non static methods … } </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is DriverManager?</span></strong><span STYLE="font-family: Verdana"> &#8211; The basic service to manage set of JDBC drivers.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is Class.forName() does and how it is useful?</span></strong><span STYLE="font-family: Verdana"> &#8211; It loads the class into the ClassLoader. It returns the Class. Using that you can get the instance ( “class-instance”.newInstance() ).</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Inq</span></strong><span STYLE="font-family: Verdana"> adds a question: Expain the reason for each keyword of</span></li>
</ol>
<p STYLE="margin-left: 0.50in" CLASS="MsoNormal"><span STYLE="font-family: Verdana">public static void main(String args[])</span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">2.</span></strong></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana"></span></strong></p>
<ol>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is a Marker Interface?</span></strong><span STYLE="font-family: Verdana"> &#8211; An interface with no methods. Example: Serializable, Remote, Cloneable</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What interface do you implement to do the sorting?</span></strong><span STYLE="font-family: Verdana"> &#8211; Comparable</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the eligibility for a object to get cloned?</span></strong><span STYLE="font-family: Verdana"> &#8211; It must implement the Cloneable interface</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the purpose of abstract class? </span></strong><span STYLE="font-family: Verdana">- It is not an instantiable class. It provides the concrete implementation for some/all the methods. So that they can reuse the concrete functionality by inheriting the abstract class.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the difference between interface and abstract class?</span></strong><span STYLE="font-family: Verdana"> &#8211; Abstract class defined with methods. Interface will declare only the methods. Abstract classes are very much useful when there is a some functionality across various classes. Interfaces are well suited for the classes which varies in functionality but with the same method signatures.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What do you mean by RMI and how it is useful?</span></strong><span STYLE="font-family: Verdana"> &#8211; RMI is a remote method invocation. Using RMI, you can work with remote object. The function calls are as though you are invoking a local variable. So it gives you a impression that you are working really with a object that resides within your own JVM though it is somewhere.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the protocol used by RMI?</span></strong><span STYLE="font-family: Verdana"> &#8211; RMI-IIOP</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is a hashCode?</span></strong><span STYLE="font-family: Verdana"> &#8211; hash code value for this object which is unique for every object.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is a thread?</span></strong><span STYLE="font-family: Verdana"> &#8211; Thread is a block of code which can execute concurrently with other threads in the JVM.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the algorithm used in Thread scheduling?</span></strong><span STYLE="font-family: Verdana"> &#8211; Fixed priority scheduling.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is hash-collision in Hashtable and how it is handled in Java?</span></strong><span STYLE="font-family: Verdana"> &#8211; Two different keys with the same hash value. Two different entries will be kept in a single hash bucket to avoid the collision.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What are the different driver types available in JDBC?</span></strong><span STYLE="font-family: Verdana"> &#8211; 1. A JDBC-ODBC bridge 2. A native-API partly Java technology-enabled driver 3. A net-protocol fully Java technology-enabled driver 4. A native-protocol fully Java technology-enabled driver For more information: Driver Description</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Is JDBC-ODBC bridge multi-threaded?</span></strong><span STYLE="font-family: Verdana"> &#8211; No</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Does the </span></strong><strong><span STYLE="font-family: Verdana">JDBC-ODBC</span></strong><strong><span STYLE="font-family: Verdana"> </span></strong><strong><span STYLE="font-family: Verdana">Bridge</span></strong><strong><span STYLE="font-family: Verdana"> support multiple concurrent open statements per connection?</span></strong><span STYLE="font-family: Verdana"> &#8211; No</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the use of serializable?</span></strong><span STYLE="font-family: Verdana"> &#8211; To persist the state of an object into any perminant storage device.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the use of transient?</span></strong><span STYLE="font-family: Verdana"> &#8211; It is an indicator to the JVM that those variables should not be persisted. It is the users responsibility to initialize the value when read back from the storage.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What are the different level lockings using the synchronization keyword?</span></strong><span STYLE="font-family: Verdana"> &#8211; Class level lock Object level lock Method level lock Block level lock</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the use of preparedstatement?</span></strong><span STYLE="font-family: Verdana"> &#8211; Preparedstatements are precompiled statements. It is mainly used to speed up the process of inserting/updating/deleting especially when there is a bulk processing.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is callable statement? Tell me the way to get the callable statement?</span></strong><span STYLE="font-family: Verdana"> &#8211; Callablestatements are used to invoke the stored procedures. You can obtain the callablestatement from Connection using the following methods prepareCall(String sql) prepareCall(String sql, int resultSetType, int resultSetConcurrency) </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">In a statement, I am executing a batch. What is the result of the execution?</span></strong><span STYLE="font-family: Verdana"> &#8211; It returns the int array. The array contains the affected row count in the corresponding index of the SQL.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Can a abstract method have the static qualifier?</span></strong><span STYLE="font-family: Verdana"> &#8211; No</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What are the different types of qualifier and what is the default qualifier?</span></strong><span STYLE="font-family: Verdana"> &#8211; public, protected, private, package (default)</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the super class of Hashtable?</span></strong><span STYLE="font-family: Verdana"> &#8211; Dictionary</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is a lightweight component?</span></strong><span STYLE="font-family: Verdana"> &#8211; Lightweight components are the one which doesn’t go with the native call to obtain the graphical units. They share their parent component graphical units to render them. Example, Swing components</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is a heavyweight component?</span></strong><span STYLE="font-family: Verdana"> &#8211; For every paint call, there will be a native call to get the graphical units. Example, AWT.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is an applet?</span></strong><span STYLE="font-family: Verdana"> &#8211; Applet is a program which can get downloaded into a client environment and start executing there.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What do you mean by a Classloader?</span></strong><span STYLE="font-family: Verdana"> &#8211; Classloader is the one which loads the classes into the JVM.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What are the implicit packages that need not get imported into a class file?</span></strong><span STYLE="font-family: Verdana"> &#8211; java.lang</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the difference between lightweight and heavyweight component?</span></strong><span STYLE="font-family: Verdana"> &#8211; Lightweight components reuses its parents graphical units. Heavyweight components goes with the native graphical unit for every component. Lightweight components are faster than the heavyweight components.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What are the ways in which you can instantiate a thread?</span></strong><span STYLE="font-family: Verdana"> &#8211; Using Thread class By implementing the Runnable interface and giving that handle to the Thread class.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What are the states of a thread?</span></strong><span STYLE="font-family: Verdana"> &#8211; 1. New 2. Runnable 3. Not Runnable 4. Dead </span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is a socket?</span></strong><span STYLE="font-family: Verdana"> &#8211; A socket is an endpoint for communication between two machines.</span></li>
</ol>
<p><span STYLE="font-family: Verdana">33.</span><span STYLE="font-family: Verdana"> How will you establish the connection between the servlet and an  applet?</span> -<br />
<span STYLE="font-family: Verdana">Using the URL, I will create the connection URL. Then by openConnection method of the URL, I will establish the connection, through which I can be able to exchange data.</span></p>
<p>34.<strong><span STYLE="font-family: Verdana">What are the threads will start, when you start the java program?</span></strong><span STYLE="font-family: Verdana"> &#8211; Finalizer, Main, Reference Handler, Signal Dispatcher.</span></p>
<p><span STYLE="font-size: 12pt; font-family: Verdana"></span></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Simple Java Questions</span></strong></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana"></span></strong></p>
<ol>
<li CLASS="MsoNormal"><span STYLE="font-family: Verdana">Meaning &#8211; Abstract classes, abstract methods</span></li>
<li CLASS="MsoNormal"><span STYLE="font-family: Verdana">Difference &#8211; Java,C++</span></li>
<li CLASS="MsoNormal"><span STYLE="font-family: Verdana">Difference between == and equals method</span></li>
<li CLASS="MsoNormal"><span STYLE="font-family: Verdana">Explain Java security model</span></li>
<li CLASS="MsoNormal"><span STYLE="font-family: Verdana">Explain working of Java Virtual Machine (JVM)</span></li>
<li CLASS="MsoNormal"><span STYLE="font-family: Verdana">Difference: Java Beans, Servlets</span></li>
<li CLASS="MsoNormal"><span STYLE="font-family: Verdana">Difference: AWT, Swing</span></li>
<li CLASS="MsoNormal"><span STYLE="font-family: Verdana">Disadvantages of Java</span></li>
<li CLASS="MsoNormal"><span STYLE="font-family: Verdana">What is BYTE Code ?</span></li>
<li CLASS="MsoNormal"><span STYLE="font-family: Verdana">What gives java it’s “write once and run anywhere” nature?</span></li>
<li CLASS="MsoNormal"><span STYLE="font-family: Verdana">Does Java have “goto”?</span></li>
<li CLASS="MsoNormal"><span STYLE="font-family: Verdana">What is the meaning of “final” keyword?</span></li>
<li CLASS="MsoNormal"><span STYLE="font-family: Verdana">Can I create final executable from Java?</span></li>
<li CLASS="MsoNormal"><span STYLE="font-family: Verdana">Explain Garbage collection mechanism in Java</span></li>
<li CLASS="MsoNormal"><span STYLE="font-family: Verdana">Why Java is not 100% pure object oriented language?</span></li>
<li CLASS="MsoNormal"><span STYLE="font-family: Verdana">What are interfaces? or How to support multiple inhertance in Java?</span></li>
<li CLASS="MsoNormal"><span STYLE="font-family: Verdana">How to use C++ code in Java Program?</span></li>
<li CLASS="MsoNormal"><span STYLE="font-family: Verdana">Differnece between &#8220;Applet&#8221; and &#8220;Application&#8221;?</span></li>
</ol>
<p><strong>Something New in Core Java Questions</strong></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Good Java Questions</span></strong></p>
<p CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana"></span></strong></p>
<ol>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Is “abc” a primitive value?</span></strong><span STYLE="font-family: Verdana"> &#8211; The String literal “abc” is not a primitive value. It is a String object.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What restrictions are placed on the values of each case of a switch statement?</span></strong><span STYLE="font-family: Verdana"> &#8211; During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What modifiers may be used with an interface declaration?</span></strong><span STYLE="font-family: Verdana"> &#8211; An interface may be declared as public or abstract.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Is a class a subclass of itself?</span></strong><span STYLE="font-family: Verdana"> &#8211; A class is a subclass of itself.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the difference between a while statement and a do statement?</span></strong><span STYLE="font-family: Verdana"> &#8211; A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What modifiers can be used with a local inner class?</span></strong><span STYLE="font-family: Verdana"> &#8211; A local inner class may be final or abstract.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the purpose of the File class?</span></strong><span STYLE="font-family: Verdana"> &#8211; The File class is used to create objects that provide access to the files and directories of a local file system.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Can an exception be rethrown?</span></strong><span STYLE="font-family: Verdana"> &#8211; Yes, an exception can be rethrown.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">When does the compiler supply a default constructor for a class?</span></strong><span STYLE="font-family: Verdana"> &#8211; The compiler supplies a default constructor for a class if no other constructors are provided.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">If a method is declared as protected, where may the method be accessed?</span></strong><span STYLE="font-family: Verdana"> &#8211; A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Which non-Unicode letter characters may be used as the first character of an identifier?</span></strong><span STYLE="font-family: Verdana"> &#8211; The non-Unicode letter characters $ and _ may appear as the first character of an identifier</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What restrictions are placed on method overloading?</span></strong><span STYLE="font-family: Verdana"> &#8211; Two methods may not have the same name and argument list but different return types.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is casting?</span></strong><span STYLE="font-family: Verdana"> &#8211; There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the return type of a program’s main() method?</span></strong><span STYLE="font-family: Verdana"> &#8211; A program’s main() method has a void return type.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What class of exceptions are generated by the Java run-time system?</span></strong><span STYLE="font-family: Verdana"> &#8211; The Java runtime system generates RuntimeException and Error exceptions.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What class allows you to read objects directly from a stream?</span></strong><span STYLE="font-family: Verdana"> &#8211; The ObjectInputStream class supports the reading of objects from input streams.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the difference between a field variable and a local variable?</span></strong><span STYLE="font-family: Verdana"> &#8211; A field variable is a variable that is declared as a member of a class. A local variable is a variable that is declared local to a method.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">How are this() and super() used with constructors?</span></strong><span STYLE="font-family: Verdana"> &#8211; this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the relationship between a method’s throws clause and the exceptions that can be thrown during the method’s execution?</span></strong><span STYLE="font-family: Verdana"> &#8211; A method’s throws clause must declare any checked exceptions that are not caught within the body of the method.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Why are the methods of the Math class static?</span></strong><span STYLE="font-family: Verdana"> &#8211; So they can be invoked as if they are a mathematical code library.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What are the legal operands of the instanceof operator?</span></strong><span STYLE="font-family: Verdana"> &#8211; The left operand is an object reference or null value and the right operand is a class, interface, or array type.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What an I/O filter?</span></strong><span STYLE="font-family: Verdana"> &#8211; An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">If an object is garbage collected, can it become reachable again?</span></strong><span STYLE="font-family: Verdana"> &#8211; Once an object is garbage collected, it ceases to exist. It can no longer become reachable again.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What are E and PI?</span></strong><span STYLE="font-family: Verdana"> &#8211; E is the base of the natural logarithm and PI is mathematical value pi.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Are true and false keywords?</span></strong><span STYLE="font-family: Verdana"> &#8211; The values true and false are not keywords.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the difference between the File and RandomAccessFile classes?</span></strong><span STYLE="font-family: Verdana"> &#8211; The File class encapsulates the files and directories of the local file system. The RandomAccessFile class provides the methods needed to directly access data contained in any part of a file.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What happens when you add a double value to a String?</span></strong><span STYLE="font-family: Verdana"> &#8211; The result is a String object.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is your platform’s default character encoding?</span></strong><span STYLE="font-family: Verdana"> &#8211; If you are running Java on English Windows platforms, it is probably Cp1252. If you are running Java on English Solaris platforms, it is most likely 8859_1.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Which package is always imported by default?</span></strong><span STYLE="font-family: Verdana"> &#8211; The java.lang package is always imported by default.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What interface must an object implement before it can be written to a stream as an object?</span></strong><span STYLE="font-family: Verdana"> &#8211; An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">How can my application get to know when a HttpSession is removed?</span></strong><span STYLE="font-family: Verdana"> &#8211; Define a Class HttpSessionNotifier which implements HttpSessionBindingListener and implement the functionality what you need in valueUnbound() method. Create an instance of that class and put that instance in HttpSession.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Whats the difference between notify() and notifyAll()?</span></strong><span STYLE="font-family: Verdana"> &#8211; notify() is used to unblock one waiting thread; notifyAll() is used to unblock all of them. Using notify() is preferable (for efficiency) when only one blocked thread can benefit from the change (for example, when freeing a buffer back into a pool). notifyAll() is necessary (for correctness) if multiple threads should resume (for example, when releasing a “writer” lock on a file might permit all “readers” to resume).</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Why can’t I say just abs() or sin() instead of Math.abs() and Math.sin()?</span></strong><span STYLE="font-family: Verdana"> &#8211; The import statement does not bring methods into your local name space. It lets you abbreviate class names, but not get rid of them altogether. That’s just the way it works, you’ll get used to it. It’s really a lot safer this way.<br />
However, there is actually a little trick you can use in some cases that gets you what you want. If your top-level class doesn’t need to inherit from anything else, make it inherit from java.lang.Math. That *does* bring all the methods into your local name space. But you can’t use this trick in an applet, because you have to inherit from java.awt.Applet. And actually, you can’t use it on java.lang.Math at all, because Math is a “final” class which means it can’t be extended.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Why are there no global variables in Java?</span></strong><span STYLE="font-family: Verdana"> &#8211; Global variables are considered bad form for a variety of reasons: 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), 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, 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.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What does it mean that a class or member is final?</span></strong><span STYLE="font-family: Verdana"> &#8211; A final class can no longer be subclassed. Mostly this is done for security reasons with basic classes like String and Integer. It also allows the compiler to make some optimizations, and makes thread safety a little easier to achieve. Methods may be declared final as well. This means they may not be overridden in a subclass. Fields can be declared final, too. However, this has a completely different meaning. A final field cannot be changed after it’s initialized, and it must include an initializer statement where it’s declared. For example, public final double c = 2.998; It’s also possible to make a static field final to get the effect of C++’s const statement or some uses of C’s #define, e.g. public static final double c = 2.998;</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What does it mean that a method or class is abstract?</span></strong><span STYLE="font-family: Verdana"> &#8211; An abstract class cannot be instantiated. Only its subclasses can be instantiated. You indicate that a class is abstract with the abstract keyword like this: </span></li>
</ol>
<pre><span STYLE="font-family: Verdana">37.public abstract class Container extends Component {</span></pre>
<p STYLE="margin-left: 0.50in"><span STYLE="font-family: Verdana">Abstract classes may contain abstract methods. A method declared abstract is not actually implemented in the current class. It exists only to be overridden in subclasses. It has no body. For example, </span></p>
<pre><span STYLE="font-family: Verdana">public abstract float price();</span></pre>
<p STYLE="margin-left: 0.50in"><span STYLE="font-family: Verdana">Abstract methods may only be included in abstract classes. However, an abstract class is not required to have any abstract methods, though most of them do. Each subclass of an abstract class must override the abstract methods of its superclasses or itself be declared abstract. </span></p>
<ol>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is a transient variable?</span></strong><span STYLE="font-family: Verdana"> &#8211; transient variable is a variable that may not be serialized.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">How are Observer and Observable used?</span></strong><span STYLE="font-family: Verdana"> &#8211; Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Can a lock be acquired on a class?</span></strong><span STYLE="font-family: Verdana"> &#8211; Yes, a lock can be acquired on a class. This lock is acquired on the class’s Class object.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What state does a thread enter when it terminates its processing?</span></strong><span STYLE="font-family: Verdana"> &#8211; When a thread terminates its processing, it enters the dead state.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">How does Java handle integer overflows and underflows?</span></strong><span STYLE="font-family: Verdana"> &#8211; It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the difference between the &gt;&gt; and &gt;&gt;&gt; operators?</span></strong><span STYLE="font-family: Verdana"> &#8211; The &gt;&gt; operator carries the sign bit when shifting right. The &gt;&gt;&gt; zero-fills bits that have been shifted out.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Is sizeof a keyword?</span></strong><span STYLE="font-family: Verdana"> &#8211; The sizeof operator is not a keyword.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Does garbage collection guarantee that a program will not run out of memory?</span></strong><span STYLE="font-family: Verdana"> &#8211; Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Can an object’s finalize() method be invoked while it is reachable?</span></strong><span STYLE="font-family: Verdana"> &#8211; An object’s finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object’s finalize() method may be invoked by other objects.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What value does readLine() return when it has reached the end of a file?</span></strong><span STYLE="font-family: Verdana"> &#8211; The readLine() method returns null when it has reached the end of a file.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Can a for statement loop indefinitely?</span></strong><span STYLE="font-family: Verdana"> &#8211; Yes, a for statement can loop indefinitely. For example, consider the following: for(;;) ;</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">To what value is a variable of the String type automatically initialized?</span></strong><span STYLE="font-family: Verdana"> &#8211; The default value of an String type is null.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is a task’s priority and how is it used in scheduling?</span></strong><span STYLE="font-family: Verdana"> &#8211; A task’s priority is an integer value that identifies the relative order in which it should be executed with respect to other tasks. The scheduler attempts to schedule higher priority tasks before lower priority tasks.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the range of the short type?</span></strong><span STYLE="font-family: Verdana"> &#8211; The range of the short type is -(2^15) to 2^15 &#8211; 1.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the purpose of garbage collection?</span></strong><span STYLE="font-family: Verdana"> &#8211; The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources may be reclaimed and reused.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What do you understand by private, protected and public?</span></strong><span STYLE="font-family: Verdana"> &#8211; These are accessibility modifiers. Private is the most restrictive, while public is the least restrictive. There is no real difference between protected and the default type (also known as package protected) within the context of the same package, however the protected keyword allows visibility to a derived class in a different package.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is Downcasting ?</span></strong><span STYLE="font-family: Verdana"> &#8211; Downcasting is the casting from a general to a more specific type, i.e. casting down the hierarchy</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Can a method be overloaded based on different return type but same argument type ?</span></strong><span STYLE="font-family: Verdana"> &#8211; No, because the methods can be called without using their return type in which case there is ambiquity for the compiler</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What happens to a static var that is defined within a method of a class ?</span></strong><span STYLE="font-family: Verdana"> &#8211; Can’t do it. You’ll get a compilation error</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">How many static init can you have ?</span></strong><span STYLE="font-family: Verdana"> &#8211; As many as you want, but the static initializers and class variable initializers are executed in textual order and may not refer to class variables declared in the class whose declarations appear textually after the use, even though these class variables are in scope.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the difference amongst JVM Spec, JVM Implementation, JVM Runtime ?</span></strong><span STYLE="font-family: Verdana"> &#8211; The JVM spec is the blueprint for the JVM generated and owned by Sun. The JVM implementation is the actual implementation of the spec by a vendor and the JVM runtime is the actual running instance of a JVM implementation</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">Describe what happens when an object is created in Java?</span></strong><span STYLE="font-family: Verdana"> &#8211; Several things happen in a particular order to ensure the object is constructed properly: Memory is allocated from heap to hold all instance variables and implementation-specific data of the object and its superclasses. Implemenation-specific data includes pointers to class and method data. The instance variables of the objects are initialized to their default values. The constructor for the most derived class is invoked. The first thing a constructor does is call the consctructor for its superclasses. This process continues until the constrcutor for java.lang.Object is called, as java.lang.Object is the base class for all objects in java. Before the body of the constructor is executed, all instance variable initializers and initialization blocks are executed. Then the body of the constructor is executed. Thus, the constructor for the base class completes first and constructor for the most derived class completes last.</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What does the “final” keyword mean in front of a variable? A method? A class?</span></strong><span STYLE="font-family: Verdana"> &#8211; FINAL for a variable: value is constant. FINAL for a method: cannot be overridden. FINAL for a class: cannot be derived</span></li>
<li CLASS="MsoNormal"><strong><span STYLE="font-family: Verdana">What is the difference between instanceof and isInstance?</span></strong><span STYLE="font-family: Verdana"> &#8211; instanceof is used to check to see if an object can be cast into a specified type without throwing a cast class exception. isInstance() Determines if the specified Object is assignment-compatible with the object represented by this Class. This method is the dynamic equivalent of the Java language instanceof operator. The method returns true if the specified Object argument is non-null and can be cast to the reference type represented by this Class object without raising a ClassCastException. It returns false otherwise.</span></li>
</ol>
<p><strong><span STYLE="font-size: 12pt; font-family: Verdana">.Why does it take so much time to access an Applet having Swing Components the first time?</span></strong>-<br />
<span STYLE="font-family: Verdana">Because behind every swing component are many Java objects and resources. This takes time to create them in memory. JDK 1.3 from Sun has some improvements which may lead to faster execution of Swing applications.</span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/javafaq.wordpress.com/1/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/javafaq.wordpress.com/1/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/javafaq.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/javafaq.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/javafaq.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/javafaq.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/javafaq.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/javafaq.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/javafaq.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/javafaq.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/javafaq.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/javafaq.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&blog=586052&post=1&subd=javafaq&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://javafaq.wordpress.com/2006/12/02/hello-world/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f23d189363d45b9dd3f4c41382224ec?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Sachin</media:title>
		</media:content>
	</item>
	</channel>
</rss>