<?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/"
	>

<channel>
	<title>Java Interview Questions &#187; Basic Java Interview Questions</title>
	<atom:link href="http://www.bestjavainterviewquestions.com/category/java-interview-questions/basic-java-interview-questions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bestjavainterviewquestions.com</link>
	<description>Java Interview Questions &#124; Core Java Interview Questions &#124; Advanced Java Interview Questions &#124; EJB Interview Questions &#124; J2EE Interview Questions &#124; Hibernate Interview Questions</description>
	<lastBuildDate>Fri, 03 Feb 2012 10:23:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Define Static Keyword</title>
		<link>http://www.bestjavainterviewquestions.com/define-static-keyword/</link>
		<comments>http://www.bestjavainterviewquestions.com/define-static-keyword/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 07:32:24 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Define static keyword]]></category>
		<category><![CDATA[corejava]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[static]]></category>
		<category><![CDATA[static in java]]></category>
		<category><![CDATA[static keyword in java]]></category>
		<category><![CDATA[static member in java]]></category>
		<category><![CDATA[static members]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=495</guid>
		<description><![CDATA[static is a keyword and means &#8216; can be accessed without the help of an object &#8216;. static is used an access modifier with members ( variables and methods ) of class. A static member belongs to the whole class. That is, all the objects of the class share ( or access ) the same [...]]]></description>
			<content:encoded><![CDATA[<p><strong>static is a keyword </strong>and means <strong>&#8216; can be accessed without the help of an object &#8216;.</strong></p>
<p><strong>static </strong>is used an access modifier with members ( variables and methods ) of class. A static member belongs to the whole class. That is, all the objects of the class share ( or access ) the same static variable. Or to say, a static variable is common to all the objects of the class. static variables do not have &#8220;this&#8221; reference. <strong>&#8216; this &#8216; </strong>is a keyword used to refer to a particular current object. This is quite contrast with instance variables where each variable keeps a separate copy of data when called with an object. The static variables like instance variables are given default values ( like zero for int ), if not assiganed any values.</p>
<p><strong>Declaring static members : </strong></p>
<p><strong>static </strong>int count ;</p>
<p><strong>static </strong>int min( int a, int b)</p>
<p><em>{</em></p>
<p><em>//body</em></p>
<p><em>}</em></p>
<p><strong>Example :</strong></p>
<p><em>public class StaticDemo {<br />
static int salary = 5000;<br />
public static void display()<br />
{<br />
System.out.println(&#8220;Hello&#8221;);<br />
}<br />
public static void main(String args[])<br />
{<br />
System.out.println(salary);</em></p>
<p><em>//called directly without object<br />
StaticDemo sd= new StaticDemo();</em></p>
<p><em>//called with object<br />
System.out.println(sd.salary);</em></p>
<p><em>//called with class name<br />
System.out.println(StaticDemo.salary);</em></p>
<p><em>//all the below display calls prints Hello</em></p>
<p><em>display();<br />
sd.display();<br />
StaticDemo.display();<br />
}<br />
}</em></p>
<p><strong>Output :</strong></p>
<p><em>double d =10.5 ;<br />
int x=d;<br />
int y=(int)d ;<br />
System.out.println(y);</em></p>
<p>In the above, casting is done explicitly by us as we are assigning d of datatype double ( 8 bytes ) to x of datatype int ( 4 bytes ).</p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li>December 16, 2008 -- <a href="http://www.bestjavainterviewquestions.com/explain-interfacedefine/" title="Explain Interface?Define ">Explain Interface?Define </a> (0)</li><li>July 30, 2010 -- <a href="http://www.bestjavainterviewquestions.com/stored-procedures-for-beginners/" title="Stored Procedures for Beginners">Stored Procedures for Beginners</a> (0)</li><li>April 7, 2009 -- <a href="http://www.bestjavainterviewquestions.com/overview-of-servlets/" title="OVERVIEW OF SERVLETS">OVERVIEW OF SERVLETS</a> (0)</li><li>April 5, 2009 -- <a href="http://www.bestjavainterviewquestions.com/how-to-get-a-leap-year/" title="How to get a Leap Year">How to get a Leap Year</a> (0)</li><li>March 29, 2009 -- <a href="http://www.bestjavainterviewquestions.com/j2ee-interview-questions/" title="J2EE Interview Questions">J2EE Interview Questions</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/define-static-keyword/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Garbage Collections</title>
		<link>http://www.bestjavainterviewquestions.com/java-garbage-collections/</link>
		<comments>http://www.bestjavainterviewquestions.com/java-garbage-collections/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 15:17:25 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Basic Java Interview Questions]]></category>
		<category><![CDATA[garbage collection questions]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=33</guid>
		<description><![CDATA[JAVA GARBAGE COLLECTION INTERVIEW QUESTIONS AND ANSWERS Q) Explain Garbage collection in Java? A) In Java, Garbage Collection is automatic. Garbage Collector Thread runs as a low     priority daemon thread freeing memory. Q) When does the Garbage Collection happen? A) When there is not enough memory. Or when the daemon GC thread gets a chance      [...]]]></description>
			<content:encoded><![CDATA[<p><strong>JAVA GARBAGE COLLECTION INTERVIEW QUESTIONS AND ANSWERS </strong></p>
<p><strong>Q) Explain Garbage collection in Java?<br />
A)</strong> In Java, Garbage Collection is automatic. Garbage Collector Thread runs as a low     priority daemon thread freeing memory.</p>
<p><strong>Q) When does the Garbage Collection happen?<br />
A)</strong> When there is not enough memory. Or when the daemon GC thread gets a chance      to run.</p>
<p><strong>Q) When is an Object eligible for Garbage collection?<br />
A)</strong> An Object is eligble for GC, when there are no references to the object.<br />
<strong><br />
Q) What are two steps in Garbage Collection?<br />
A)</strong><br />
1. Detection of garbage collectible objects and marking them for garbage        collection.<br />
2. Freeing the memory of objects marked for GC.</p>
<p><strong>Q) What is the purpose of finalization?<br />
A)</strong> The purpose of finalization is to give an unreachable object the opportunity to      perform any cleanup processing before the object is garbage collected.</p>
<p><strong>Q) Can GC be forced in Java?<br />
A)</strong> No. GC can&#8217;t be forced.</p>
<p><strong>Q) What does System.gc() and Runtime.gc() methods do?<br />
A) </strong> These methods inform the JVM to run GC but this is only a request to the JVM      but it is up to the JVM to run GC immediately or run it when it gets time.<br />
<strong><br />
Q) When is the finalize() called?<br />
A)</strong> finalize() method is called by the GC just before releasing the object&#8217;s memory. It      is normally advised to release resources held by the object in finalize() method.</p>
<p><strong>Q) Can an object be resurrected after it is marked for garbage collection?<br />
A)</strong> Yes. It can be done in finalize() method of the object but it is not advisable to do      so.</p>
<p><strong>Q) Will the finalize() method run on the resurrected object?<br />
A)</strong> No. finalize() method will run only once for an object. The resurrected object&#8217;s will      not be cleared till the JVM cease to exist.</p>
<p><strong>Q) GC is single threaded or multi threaded?<br />
A)</strong> Garbage Collection is multi threaded from JDK1.3 onwards.<br />
<strong><br />
Q) What are the good programming practices for better memory management?<br />
A)</strong><br />
a. We shouldn&#8217;t declare unwanted variables and objects.<br />
b. We should avoid declaring variables or instantiating objects inside loops.<br />
c. When an object is not required, its reference should be nullified.<br />
d. We should minimize the usage of String object and SOP&#8217;s.</p>
<p><strong>Q) When is the Exception object in the Exception block eligible for GC?<br />
A)</strong> Immediately after Exception block is executed.</p>
<p><strong>Q) When are the local variables eligible for GC?<br />
A) </strong> Immediately after method&#8217;s execution is completed.<br />
<strong><br />
Q) If an object reference is set to null, Will GC immediately free the memory held by      that    object?<br />
A) </strong>No. It will be garbage collected only in the next GC cycle.</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>July 21, 2010 -- <a href="http://www.bestjavainterviewquestions.com/using-serialization/" title="Using Serialization ">Using Serialization </a> (0)</li><li>April 4, 2009 -- <a href="http://www.bestjavainterviewquestions.com/java-interview-questions/" title="Java Interview Questions">Java Interview Questions</a> (0)</li><li>August 10, 2008 -- <a href="http://www.bestjavainterviewquestions.com/can-we-call-destroy-method-on-servlets-from-service-method/" title="Can we call destroy() method on servlets from service method">Can we call destroy() method on servlets from service method</a> (0)</li><li>July 21, 2008 -- <a href="http://www.bestjavainterviewquestions.com/java-swings-interview-questions/" title="Java Swings Interview Questions">Java Swings Interview Questions</a> (0)</li><li>August 24, 2008 -- <a href="http://www.bestjavainterviewquestions.com/difference-between-a-break-statement-and-a-continue-statement/" title="Difference between a break statement and a continue statement">Difference between a break statement and a continue statement</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/java-garbage-collections/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Java Multi-Thread Questions</title>
		<link>http://www.bestjavainterviewquestions.com/java-multi-thread-questions/</link>
		<comments>http://www.bestjavainterviewquestions.com/java-multi-thread-questions/#comments</comments>
		<pubDate>Tue, 01 Jul 2008 15:10:59 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Basic Java Interview Questions]]></category>
		<category><![CDATA[multi-thread questions]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=32</guid>
		<description><![CDATA[Multi-threaded design questions Q) Do I need to use synchronized on setValue(int)? A) It depends whether the method affects method local variables, class static or instance variables. If only method local variables are changed, the value is said to be confined by the method and is not prone to threading issues. Q) Do I need [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal"><strong><span style="color: fuchsia;">Multi-threaded design questions</span></strong></p>
<p><strong>Q) Do I need to use synchronized on setValue(int)?<br />
A)</strong> It depends whether the method affects method local variables, class static or instance variables. If only method local variables are changed, the value is said to be confined by the method and is not prone to threading issues. <strong></p>
<p>Q) Do I need to use synchronized on setValue(int)?<br />
A) </strong> It depends whether the method affects method local variables, class static or instance variables. If only method local variables are changed, the value is said to be confined by the method and is not prone to threading issues.<br />
<strong><br />
Q) What is the SwingUtilities.invokeLater(Runnable) method for?<br />
A) </strong> The static utility method invokeLater(Runnable) is intended to execute a new runnable thread from a Swing application without disturbing the normal sequence of event dispatching from the Graphical User Interface (GUI). The method places the runnable object in the queue of Abstract Windowing Toolkit (AWT) events that are due to be processed and returns immediately. The runnable object&#8217;s run() method is only called when it reaches the front of the queue.<br />
The deferred effect of the invokeLater(Runnable) method ensures that any necessary updates to the user interface can occur immediately, and the runnable work will begin as soon as those high priority events are dealt with. The invoke later method might be used to start work in response to a button click that also requires a significant change to the user interface, perhaps to restrict other activities, while the runnable thread executes.</p>
<p><strong>Q) What is the volatile modifier for?<br />
A)</strong> The volatile modifier is used to identify variables whose values should not be optimized by the Java Virtual Machine, by caching the value for example. The volatile modifier is typically used for variables that may be accessed or modified by numerous independent threads and signifies that the value may change without synchronization.</p>
<p><strong>Q) Which class is the wait() method defined in?<br />
A)</strong> The wait() method is defined in the Object class, which is the ultimate superclass of all others. So the Thread class and any Runnable implementation inherit this method from Object. The wait() method is normally called on an object in a multi-threaded program to allow other threads to run. The method should should only be called by a thread that has ownership of the object&#8217;s monitor, which usually means it is in a synchronized method or statement block.<br />
Premium Content: Follow this link for subscription information More details available to subscribers:<br />
<strong><br />
Q) Which class is the wait() method defined in?<br />
I get &#8220;incompatible return type&#8221; for my thread&#8217;s getState( ) method!<br />
A)</strong> It sounds like your application was built for a Java software development kit before Java 1.5. The Java API Thread class method getState() was introduced in version 1.5. Your thread method has the same name but different return type. The compiler assumes your application code is attempting to override the API method with a different return type, which is not allowed, hence the compilation error.</p>
<p class="MsoNormal"><strong><span style="color: fuchsia;"> Multi-threaded design patterns</span></strong><span style="color: fuchsia;"></span></p>
<p><strong>Q) What is a working thread?<br />
A)</strong> A working thread, more commonly known as a worker thread is the key part of a design pattern that allocates one thread to execute one task. When the task is complete, the thread may return to a thread pool for later use. In this scheme a thread may execute arbitrary tasks, which are passed in the form of a Runnable method argument, typically execute(Runnable). The runnable tasks are usually stored in a queue until a thread host is available to run them.<br />
The worker thread design pattern is usually used to handle many concurrent tasks where it is not important which finishes first and no single task needs to be coordinated with another. The task queue controls how many threads run concurrently to improve the overall performance of the system. However, a worker thread framework requires relatively complex programming to set up, so should not be used where simpler threading techniques can achieve similar results.</p>
<p class="MsoNormal"><strong><span style="color: fuchsia;"> Thread programming jargon</span></strong></p>
<p><strong>Q) What is a green thread?<br />
A)</strong> A green thread refers to a mode of operation for the Java Virtual Machine (JVM) in which all code is executed in a single operating system thread. If the Java program has any concurrent threads, the JVM manages multi-threading internally rather than using other operating system threads.<br />
There is a significant processing overhead for the JVM to keep track of thread states and swap between them, so green thread mode has been deprecated and removed from more recent Java implementations. Current JVM implementations make more efficient use of native operating system threads.</p>
<p><strong>Q) What are native operating system threads?<br />
A) </strong>Native operating system threads are those provided by the computer operating system that plays host to a Java application, be it Windows, Mac or GNU/Linux. Operating system threads enable computers to run many programs simultaneously on the same central processing unit (CPU) without clashing over the use of system resources or spending lots of time running one program at the expense of another. Operating system thread management is usually optimised to specific microprocessor architecture and features so that it operates much faster than Java green thread processing.</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>December 17, 2008 -- <a href="http://www.bestjavainterviewquestions.com/explain-stream-tokenizer/" title="Explain Stream Tokenizer">Explain Stream Tokenizer</a> (0)</li><li>August 24, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-nullpointerexception/" title="Define NullPointerException">Define NullPointerException</a> (0)</li><li>October 5, 2008 -- <a href="http://www.bestjavainterviewquestions.com/goto-statement-in-java/" title="GoTo statement in Java">GoTo statement in Java</a> (0)</li><li>August 24, 2008 -- <a href="http://www.bestjavainterviewquestions.com/difference-between-string-and-stringbuffer/" title="Difference between String and StringBuffer">Difference between String and StringBuffer</a> (0)</li><li>October 4, 2008 -- <a href="http://www.bestjavainterviewquestions.com/how-application-creates-a-connection/" title="How application creates a connection">How application creates a connection</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/java-multi-thread-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Thread Questions</title>
		<link>http://www.bestjavainterviewquestions.com/java-thread-questions/</link>
		<comments>http://www.bestjavainterviewquestions.com/java-thread-questions/#comments</comments>
		<pubDate>Tue, 01 Jul 2008 03:08:37 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Basic Java Interview Questions]]></category>
		<category><![CDATA[thread questions]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=31</guid>
		<description><![CDATA[THREADS INTERVIEW QUESTIONS AND ANSWERS JAVA Q) What is threaded programming and when is it used? A) Threaded programming is normally used when a program is required to do more than one task at the same time. Threading is often used in applications with graphical user interfaces; a new thread may be created to do [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal"><strong><span style="font-size: 10pt; color: fuchsia;">THREADS INTERVIEW QUESTIONS AND ANSWERS JAVA</span></strong></p>
<p class="MsoNormal"><strong>Q) What is threaded programming and when is it used?<br />
A)</strong> Threaded programming is normally used when a program is required to do more than one task at the same time. Threading is often used in applications with graphical user interfaces; a new thread may be created to do some processor-intensive work while the main thread keeps the interface responsive to human interaction.<br />
The Java programming language has threaded programming facilities built in, so it is relatively easy to create threaded programs. However, multi-threaded programs introduce a degree of complexity that is not justified for most simple command line applications.</p>
<p class="MsoNormal"><strong>Q) Why not override Thread to make a Runnable?<br />
A) </strong>There is little difference in the work required to override the Thread class compared with implementing the Runnable interface, both require the body of the run() method. However, it is much simpler to make an existing class hierarchy runnable because any class can be adapted to implement the run() method. A subclass of Thread cannot extend any other type, so application-specific code would have to be added to it rather than inherited.<br />
Separating the Thread class from the Runnable implementation also avoids potential synchronization problems between the thread and the run() method. A separate Runnable generally gives greater flexibility in the way that runnable code is referenced and executed.</p>
<p><strong>Q) What&#8217;s the difference between a thread&#8217;s start() and run() methods?<br />
A)</strong> The separate start() and run() methods in the Thread class provide two ways to create threaded programs. The start() method starts the execution of the new thread and calls the run() method. The start() method returns immediately and the new thread normally continues until the run() method returns.<br />
The Thread class&#8217; run() method does nothing, so sub-classes should override the method with code to execute in the second thread. If a Thread is instantiated with a Runnable argument, the thread&#8217;s run() method executes the run() method of the Runnable object in the new thread instead.<br />
Depending on the nature of your threaded program, calling the Thread run() method directly can give the same output as calling via the start() method, but in the latter case the code is actually executed in a new thread.</p>
<p><strong>Q) Can I implement my own start() method?<br />
A) </strong>The Thread start() method is not marked final, but should not be overridden. This method contains the code that creates a new executable thread and is very specialised. Your threaded application should either pass a Runnable type to a new Thread, or extend Thread and override the run() method.</p>
<p class="MsoNormal"><strong>Q) What&#8217;s the difference between Thread and Runnable types?<br />
A)</strong> A Java Thread controls the main path of execution in an application. When you invoke the Java Virtual Machine with the java command, it creates an implicit thread in which to execute the main method. The Thread class provides a mechanism for the first thread to start-up other threads to run in parallel with it.</p>
<p>The Runnable interface defines a type of class that can be run by a thread. The only method it requires is run, which makes the interface very easy to to fulfil by extending existing classes. A runnable class may have custom constructors and any number of other methods for configuration and manipulation.</p>
<p><strong>Q) How does the run() method in Runnable work?<br />
A)</strong> It may help to think of the run method like the main method in standard single threaded applications. The run method is a standard entry point to run or execute a class. The run method is normally only executed in the context of an independent Thread, but is a normal method in all other respects.</p>
<p><strong>Q) What is a deadlock?<br />
A)</strong> A condition that occurs when two processes are waiting for each other to       complete before proceeding. The result is that both processes wait endlessly.</p>
<p><strong>Q) What are all the methods used for Inter Thread communication and what is the       class in which these methods are defined?<br />
A) </strong> a. wait(),notify() &amp; notifyall()<br />
b. Object class</p>
<p><strong>Q) What is the mechanisam defind in java for a code segment be used by only one      Thread at a time?<br />
A)</strong> Synchronisation</p>
<p><strong>Q) What is the procedure to own the moniter by many threads?<br />
A)</strong> Its not possible. A monitor can be held by only one thread at a time.</p>
<p><strong>Q) What is the unit for 500 in the statement, obj.sleep(500);?<br />
A)</strong> 500 is the no of milliseconds and the data type is long.</p>
<p><strong>Q) What are the values of the following thread priority constants?<br />
A) </strong>MAX_PRIORITY,MIN_PRIORITY and NORMAL_PRIORITY<br />
10,1,5</p>
<p><strong>Q) What is the default thread at the time of starting a java application?<br />
A)</strong> main thread</p>
<p><strong>Q) The word synchronized can be used with only a method. True/ False?<br />
A)</strong> False. A block of code can also be synchronised.<br />
<strong><br />
Q) What is a Monitor?<br />
A)</strong> A monitor is an object which contains some synchronized code in it.<br />
<strong><br />
Q) What are all the methods defined in the Runnable Interface?<br />
A)</strong> only run() method is defined the Runnable interface.</p>
<p><strong>Q) How can i start a dead thread?<br />
A)</strong> A dead Thread cannot be started again.</p>
<p><strong>Q) When does a Thread die?<br />
A)</strong> A Thread dies after completion of run() method.<br />
<strong><br />
Q) What does the yield() method do?<br />
A)</strong> The yield() method puts currently running thread in to ready state.<br />
<strong><br />
Q) What exception does the wait() method throw?<br />
A)</strong> The java.lang.Object class wait() method throws &#8220;InterruptedException&#8221;.<br />
<strong><br />
Q) What does notifyAll() method do?<br />
A) </strong> notifyAll() method moves all waiting threads from the waiting pool to ready state.<br />
<strong><br />
Q) What does wait() method do?<br />
A)</strong> wait() method releases CPU, releases objects lock, the thread enters into pool of      waiting threads.</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>August 25, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-servletoutputstream/" title="Define ServletOutputStream">Define ServletOutputStream</a> (0)</li><li>September 20, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-session-hijacking-2/" title="Define Session Hijacking">Define Session Hijacking</a> (0)</li><li>September 20, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-session-hijacking-3/" title="Define Session Hijacking">Define Session Hijacking</a> (0)</li><li>September 17, 2008 -- <a href="http://www.bestjavainterviewquestions.com/example-of-hibernate/" title="Example of Hibernate">Example of Hibernate</a> (0)</li><li>October 5, 2008 -- <a href="http://www.bestjavainterviewquestions.com/thread-safety-of-the-servlet/" title="Thread safety of the servlet">Thread safety of the servlet</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/java-thread-questions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Java Thread Interview Questions</title>
		<link>http://www.bestjavainterviewquestions.com/java-thread-interview-questions/</link>
		<comments>http://www.bestjavainterviewquestions.com/java-thread-interview-questions/#comments</comments>
		<pubDate>Tue, 01 Jul 2008 02:57:33 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Basic Java Interview Questions]]></category>
		<category><![CDATA[thread interview questions]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=30</guid>
		<description><![CDATA[THREADS INTERVIEW QUESTIONS AND ANSWERS JAVA Q) What are the two types of multitasking ? A) a. Process-based. b. Thread-based. Q) What is a Thread ? A)  A thread is a single sequential flow of control within a program. Q) What are the two ways to create a new thread? A) a.Extend the Thread class [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal"><strong><span style="font-size: 10pt; color: fuchsia;">THREADS INTERVIEW QUESTIONS AND ANSWERS JAVA</span></strong></p>
<p><strong>Q) What are the two types of multitasking ?<br />
A)</strong> a. Process-based.<br />
b. Thread-based.</p>
<p>Q) What is a Thread ?<br />
A)  A thread is a single sequential flow of control within a program.</p>
<p><strong>Q) What are the two ways to create a new thread?<br />
A) </strong>a.Extend the Thread class and override the run() method.<br />
b.Implement the Runnable interface and implement the run() method.<br />
<strong><br />
Q) If you have ABC class that must subclass XYZ class, which option will you use to      create a thread?<br />
A)</strong> I will make ABC implement the Runnable interface to create a new thread,     because ABC class will not be able to extend both XYZ class and Thread class.<br />
<strong><br />
Q) Which package contains Thread class and Runnable Interface?<br />
A)</strong> java.lang package</p>
<p><strong>Q) What is the signature of the run() mehod in the Thread class?<br />
A)</strong> public void run()<br />
<strong><br />
Q) Which methods calls the run() method?<br />
A)</strong> start() method.<br />
<strong><br />
Q) Which interface does the Thread class implement?<br />
A)</strong> Runnable interface</p>
<p><strong>Q) What are the states of a Thread ?<br />
A)</strong> Ready,Running,Waiting and Dead.</p>
<p><strong>Q) Where does the support for threading lie?<br />
A)</strong> The thread support lies in java.lang.Thread, java.lang.Object and JVM.<br />
<strong><br />
Q) In which class would you find the methods sleep() and yield()?<br />
A)</strong> Thread class</p>
<p><strong>Q) In which class would you find the methods notify(),notifyAll() and wait()?<br />
A) </strong>Object class</p>
<p><strong>Q) What will notify() method do?<br />
A) </strong> notify() method moves a thread out of the waiting pool to ready state, but there is no guaranty which    thread will be moved out of the pool.</p>
<p><strong>Q) Can you notify a particular thread?<br />
A)</strong> No.<br />
<strong><br />
Q) What is the difference between sleep() and yield()?<br />
A)</strong> When a Thread calls the sleep() method, it will return to its waiting state. When a Thread calls the yield()  method, it returns to the ready state.<br />
<strong><br />
Q) What is a Daemon Thread?<br />
A) </strong> Daemon is a low priority thread which runs in the backgrouund.</p>
<p><strong>Q) How to make a normal thread as daemon thread?<br />
A) </strong> We should call setDaemon(true) method on the thread object to make a thread as       daemon thread.</p>
<p><strong>Q) What is the difference between normal thread and daemon thread?<br />
A)</strong> Normal threads do mainstream activity, whereas daemon threads are used low       priority work. Hence daemon threads are also stopped when there are no normal       threads.</p>
<p><strong>Q) Give one good example of a daemon thread?<br />
A)</strong> Garbage Collector is a low priority daemon thread.</p>
<p><strong>Q) What does the start() method of Thread do?<br />
A)</strong> The thread&#8217;s start() method puts the thread in ready state and makes the thread      eligible to run. start() method automatically calls the run () method.<br />
<strong><br />
Q) What are the two ways that a code can be synchronised?<br />
A)</strong> a. Method can be declared as synchronised.<br />
b. A block of code be sychronised.</p>
<p><strong>Q) Can you declare a static method as synchronized?<br />
A)</strong> Yes, we can declare static method as synchronized. But the calling thread should      acquire lock on the class that owns the method.<br />
<strong><br />
Q) Can a thread execute another objects run() method?<br />
A)</strong> A thread can execute it&#8217;s own run() method or another objects run() method.<br />
<strong><br />
Q) What is the default priority of a Thread?<br />
A) </strong> NORM_PRIORITY</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>September 2, 2008 -- <a href="http://www.bestjavainterviewquestions.com/difference-between-stateful-and-stateless-session-bean/" title="Difference Between StateFul and Stateless Session Bean">Difference Between StateFul and Stateless Session Bean</a> (0)</li><li>September 30, 2008 -- <a href="http://www.bestjavainterviewquestions.com/what-are-the-elements-of-jsp/" title="What are the elements of JSP">What are the elements of JSP</a> (0)</li><li>December 17, 2008 -- <a href="http://www.bestjavainterviewquestions.com/when-the-port-number-is-changed/" title="When the port number is changed">When the port number is changed</a> (0)</li><li>February 9, 2009 -- <a href="http://www.bestjavainterviewquestions.com/uploading-excel-file-using-jsp/" title="Uploading Excel File  Using Jsp">Uploading Excel File  Using Jsp</a> (0)</li><li>August 9, 2008 -- <a href="http://www.bestjavainterviewquestions.com/some-important-methos-in-applets/" title="Some important methos in Applets">Some important methos in Applets</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/java-thread-interview-questions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Java Exception Handling Questions</title>
		<link>http://www.bestjavainterviewquestions.com/java-exception-handling-questions/</link>
		<comments>http://www.bestjavainterviewquestions.com/java-exception-handling-questions/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 17:50:12 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Basic Java Interview Questions]]></category>
		<category><![CDATA[exception handling questions]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=29</guid>
		<description><![CDATA[JAVA EXCEPTION HANDLING INTERVIEW QUESTIONS AND ANSWERS Q) What package contains exception handling related classes? A) java.lang Q) what ar the two types of Exceptions? A) Checked Exceptions and Unchecked Exceptions Q) What is the base class of all Exceptions? A) java.lang.Throwable. Q) What is difference between an Exception and Error in java? A) Exception [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal">
<p class="MsoNormal">
<p class="MsoNormal"><span style="font-size: 10pt; color: fuchsia;"><strong>JAVA EXCEPTION HANDLING INTERVIEW QUESTIONS AND ANSWERS</strong></span></p>
<p><strong>Q) What package contains exception handling related classes?</strong><br />
<strong>A)</strong> java.lang</p>
<p><strong>Q) what ar the two types of Exceptions?<br />
A)</strong> Checked Exceptions and Unchecked Exceptions</p>
<p><strong>Q) What is the base class of all Exceptions?<br />
A)</strong> java.lang.Throwable.</p>
<p><strong>Q) What is difference between an Exception and Error in java?<br />
A)</strong> Exception and Error are the subclasses of the Throwable class. Exception class is used for exceptional conditions that user program should catch. Error defines exceptions that are not excepted to be caught by the user program. Example is Stack Overflow.<br />
( or )<br />
Exception defines an abnormal termination of the program which can be handled at compile time using try catch finally mechanisum or by using the throws option<br />
where as Error will be seen at runtime which cannot be handled.</p>
<p><strong>Q) What is the difference between throw and throws?<br />
A)</strong> throw is used to explicitly raise a exception within the program, the statement would be throw new Exception(); throws clause is used to indicate the exceptions that are not handled by the method. It must specify this behavior so the callers of the method can guard against the exceptions. throws is specified in the method signature. If multiple exceptions are not handled, then they are separated by a comma. the statement would be as follows: public void doSomething() throws IOException</p>
<p><strong>Q) What is the difference between Exception and Error in java?<br />
A)</strong> Exception and Error are the subclasses,MyException{}</p>
<p><strong>Q) Differentiate between Checked Exceptions and Unchecked Exceptions?<br />
A)</strong> Checked Exceptions are those exceptions which should be explicitly handled by the calling method. Unhandled checked exceptions results in compilation error.<br />
Unchecked Exceptions are those which occur at runtime and need not be explicitly handled. RuntimeException and it&#8217;s subclasses, Error and it&#8217;s subclasses fall under unchecked exceptions.</p>
<p><strong>Q) What are User defined Exceptions?<br />
A)</strong> Apart from the exceptions already defined in Java package libraries, user can define his own exception classes by extending Exception class.</p>
<p><strong>Q) What is the importance of finally block in exception handling?<br />
A)</strong> Finally block will be executed whether or not an exception is thrown. If an exception is thrown, the finally block will execute even if no catch statement match the exception. Any time a method is about to return to the caller from inside try/catch block, via an uncaught exception or an explicit return statement, the finally block will be executed. Finally is used to free up resources like database connections, IO handles, etc.<br />
<strong><br />
Q) Can a catch block exist without a try block?<br />
A)</strong> No. A catch block should always go with a try block.</p>
<p><strong>Q) Can a finally block exist with a try block but without a catch?<br />
A)</strong> Yes. The following are the combinations try/catch or try/catch/finally or try/finally.<br />
<strong><br />
Q) What will happen to the Exception object after exception handling?<br />
A) </strong> Exception object will be garbage collected.</p>
<p><strong>Q) The subclass exception should precede the base class exception when used within the catch clause. True/False?<br />
A)</strong> True.</p>
<p><strong>Q) Exceptions can be caught or rethrown to a calling method. True/False?<br />
A)</strong> True.</p>
<p><strong>Q) The statements following the throw keyword in a program are not executed. True/False?<br />
A) </strong>True.<br />
<strong><br />
Q) How does finally block differ from finalize() method?<br />
A)</strong> Finally block will be executed whether or not an exception is thrown. So it is used to free resoources. finalize() is a protected method in the Object class which is called by the JVM just before an object is garbage collected.</p>
<p><strong>Q) What are the constraints imposed by overriding on exception handling?<br />
A) </strong> An overriding method in a subclass may only throw exceptions declared in the parent class or children of the exceptions declared in the parent class.</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>July 21, 2008 -- <a href="http://www.bestjavainterviewquestions.com/java-swings-interview-questions/" title="Java Swings Interview Questions">Java Swings Interview Questions</a> (0)</li><li>August 24, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-servletoutputstream-object-in-jsp/" title="Define ServletOutputStream object in Jsp">Define ServletOutputStream object in Jsp</a> (0)</li><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/java-lang-package-interview-questions/" title="Java lang package interview questions">Java lang package interview questions</a> (2)</li><li>April 6, 2009 -- <a href="http://www.bestjavainterviewquestions.com/exception-handling-and-their-uses/" title="Exception Handling and their uses">Exception Handling and their uses</a> (2)</li><li>October 27, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-connection-pooling/" title="Define Connection Pooling">Define Connection Pooling</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/java-exception-handling-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Basic Questions</title>
		<link>http://www.bestjavainterviewquestions.com/19/</link>
		<comments>http://www.bestjavainterviewquestions.com/19/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 17:06:12 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Basic Java Interview Questions]]></category>
		<category><![CDATA[abstract class]]></category>
		<category><![CDATA[advance java]]></category>
		<category><![CDATA[arraylist]]></category>
		<category><![CDATA[core java]]></category>
		<category><![CDATA[Enumeration]]></category>
		<category><![CDATA[HashMap]]></category>
		<category><![CDATA[HashSet]]></category>
		<category><![CDATA[HashTable]]></category>
		<category><![CDATA[inner classes]]></category>
		<category><![CDATA[interfaces]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[java basics]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[overload]]></category>
		<category><![CDATA[overriding]]></category>
		<category><![CDATA[polymorphism]]></category>
		<category><![CDATA[servlet config]]></category>
		<category><![CDATA[servlet context]]></category>
		<category><![CDATA[servlets]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[set]]></category>
		<category><![CDATA[springs]]></category>
		<category><![CDATA[struts]]></category>
		<category><![CDATA[Vector]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=19</guid>
		<description><![CDATA[Q. Can you help me debug my program? A. If the problem you are having is not directly related to our software, we suggest that you use a Java development tool that helps you with debugging, and that you invest in some books or training to help you learn Java. There are many ways to [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Q. Can you help me debug my program? </strong></p>
<p><strong></strong>A. If the problem you are having is not directly related to our software, we suggest that you use a Java development tool that helps you with debugging, and that you invest in some books or training to help you learn Java. There are many ways to build debugging into your program, and getting good training in Java programming is a good start to understanding how to do this.</p>
<p><strong>Q. Where can I get help learning Java?</strong></p>
<p>A. There are a lot of books and online references to Java. A good starting place is at the JavaSoft website documentation index, which has links to white papers and the Java Tutorial. You can find books on Java at any of the major online book shopping sites.</p>
<p><strong>Q. Where do I get the JDK?</strong></p>
<p>A. WebLogic 6.1 bundles JDK131. See our Platform support page for information about specific JDKs that we have tested and certified for use with WebLogic software.<br />
Once you determine which version of the JDK you will be using, go to the JavaSoft website. Many platform vendors provide an optimized version of the JDK for their computers.</p>
<p><strong>Q. How do I set up my CLASSPATH? </strong></p>
<p>A. Setting up your CLASSPATH correctly depends on what you are trying to do. The most common tasks are described below:<br />
-&gt; Starting WebLogic Server. See Setting the Classpath Option in the Starting and Stopping WebLogic Servers section of the Administration Guide. In addition, your WebLogic distribution includes shell scripts that you can use to start the server. These scripts, which are located in the domain directories under the config directory of your WebLogic Server distribution, automatically set up the CLASSPATH variable in the shell before starting the server.<br />
-&gt; Compiling Application Classes or Using WebLogic Server Utilities. See Setting the Classpath for Compiling in the Developing WebLogic Server Components section of Developing WebLogic Server Applications.<br />
-&gt; Working With WebLogic Server Code Examples. See the WebLogic Server Examples Guide located at samples/examples/examples.html in your WebLogic Server distribution.</p>
<p><strong>Q. Why won&#8217;t the examples work?</strong></p>
<p>A. Usually problems with examples are related to your environment. Here are some troubleshooting hints:<br />
1. If you are using a database, make sure you have run the utility utils.dbping to verify that your JDBC driver is correctly installed and configured.<br />
2. Run the setEnv script to make sure your CLASSPATH is correctly set in the shell or DOS window in which you are running the examples. For more information, see Setting your development environment.<br />
3. Check the instructions for the examples to make sure you have changed any user-specific variables in the code before compiling.<br />
4. Verify that you are compiling with the -d option to direct the class files into the proper directory, as defined in the example instructions.<br />
If the example is an applet, check the CODE and CODEBASE, and make sure WebLogic Server is running.</p>
<p><strong>Q. Where can I get help with Java error messages?</strong></p>
<p>A. Many questions we receive at BEA are related to generic Java error messages and are not specific to WebLogic Server. Here are some links that contain helpful information about Java error messages.<br />
Source Description<br />
Sun&#8217;s Java Developer Connection:-<br />
This forum includes Questions and Answers on a wide variety of Java topics, including error messages. Use the Search box for fast results. For example, type &#8220;classpath error&#8221; in the Search box.<br />
Compiler Error Messages:-<br />
An extensive list of compiler error messages, including the infamous NoClassDefFoundError.<br />
Sun&#8217;s Java APIs:-<br />
Check the Java API to see if there is an exception description for the class you are using.</p>
<p><strong>Q. Why did a client-server message generate a StackOverflowException? </strong></p>
<p>A. If you are sending a particularly large data structure using java.io.Serialization, you may exceed the per-thread size limit for either the Java or native stack. You can increase the stack size by using the following command line options:<br />
-ss Stacksize to increase the native stack size or<br />
-oss Stacksize to increase the Java stack size,<br />
where Stacksize is expressed as an integer followed by &#8220;k&#8221; or &#8220;m&#8221; for kbytes or mbytes. For example,<br />
$java -ss156k (native)<br />
$java -oss600k (Java)<br />
The default native stack size is 128k, with a minimum value of 1000 bytes. The default java stack size is 400k, with a minimum value of 1000 bytes.</p>
<p><strong>Q. Will a JIT make my Java application run faster? </strong></p>
<p>A. A Just-In-Time compiler will make some Java applications run faster. A JIT works by storing generated machine code in memory and reusing it when possible. For example, if you execute the same operation 1000 times in a loop, a JIT will improve performance of this operation since the code will only be generated once. Applications with a lot of native methods will not see as much performance improvement as pure-Java applications.<br />
If you use a JIT, you may want to turn off the JIT during debugging to facilitate stacktracing. If you are doing performance testing with a JIT, make sure that you execute the same test several times in the same invocation and then throw away the first result to get an idea of how long the transaction will take when your application is running in a steady state. The first time the code is executed, your test will take longer (the &#8220;code generation hit&#8221;).</p>
<p><strong>Q. Can I redistribute the JDK that is bundled with WebLogic Server?</strong></p>
<p>A. BEA Systems has the non-exclusive right to grant a third party, such as an independent software vendor (ISV), the right to redistribute the JDK that is bundled with WebLogic Server without any modifications of any kind. The following are caveats to this general statement:<br />
-&gt; The ISV cannot remove or alter any proprietary legends or notices contained in the JDK. The ISV shall not decompile, disassemble, decrypt, extract, or otherwise reverse engineer or modify the JDK. The JDK may not be leased or assigned in whole or in part.<br />
-&gt; The ISV must enter into a signed agreement with its distributors on terms substantially similar to those contained here in this redistribution policy explanation.<br />
-&gt; The ISV requires an end user license agreement with the product within which it embeds WebLogic Server.</p>
<p>-&gt; The embedding of the JDK in ISV products does not include maintenance and support of the JDK by the JDK Provider. BEA Systems shall be solely responsible for providing maintenance and support for its ISVs and distributors. The ISV shall be solely responsible for providing maintenance and support for the end users of its products.<br />
-&gt; If an ISV wants to ship a JDK that is different from the JDK that BEA ships with WebLogic Server, that ISV needs to get those bundling rights directly from Sun or HP. For example:<br />
Assume that BEA ships WebLogic Server 6.0 with JDK 1.3 only, that BEA ships WebLogic Server 5.1 with JDK 1.1 only, and that an ISV wants to ship JDK 1.1 with WebLogic Server 6.0 in an integrated product offered by that ISV. Unless BEA, for BEA business reasons, elects to make WebLogic Server 6.0 with JDK 1.1 generally available, the ISV couldn&#8217;t ship JDK 1.1 with WebLogic Server 6.0 in an integrated product offered by that ISV under BEA&#8217;s agreement with that ISV or under BEA&#8217;s agreement with Sun. The ISV could, however, obtain its own binary distribution agreement for the JDK from Sun and under that agreement bundle JDK 1.1 with its value added software solution consisting of the ISV applications and WebLogic Server 6.0 integrated.</p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/basic-java-interview-question/" title="Basic Java Interview Question">Basic Java Interview Question</a> (1)</li><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/core-java-interview-questions/" title="Core Java Interview Questions">Core Java Interview Questions</a> (1)</li><li>June 23, 2008 -- <a href="http://www.bestjavainterviewquestions.com/java-util-package-2/" title="JAVA UTIL PACKAGE">JAVA UTIL PACKAGE</a> (0)</li><li>August 17, 2010 -- <a href="http://www.bestjavainterviewquestions.com/define-hashtablehashmap-and-hashset/" title="Define Hashtable,HashMap and HashSet">Define Hashtable,HashMap and HashSet</a> (1)</li><li>March 24, 2009 -- <a href="http://www.bestjavainterviewquestions.com/define-hashset-class/" title="Define HashSet Class">Define HashSet Class</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/19/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Core Java Inteview Questions</title>
		<link>http://www.bestjavainterviewquestions.com/core-java-inteview-questions/</link>
		<comments>http://www.bestjavainterviewquestions.com/core-java-inteview-questions/#comments</comments>
		<pubDate>Thu, 22 May 2008 18:46:30 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Basic Java Interview Questions]]></category>
		<category><![CDATA[basic core java interview questions]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=10</guid>
		<description><![CDATA[Q:What are Checked and UnChecked Exception? A: A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses. Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. eg, IOException thrown by java.io.FileInputStream’s read() method• Unchecked exceptions are RuntimeException and any [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Q:What are Checked and UnChecked Exception?</strong></p>
<p><strong>A</strong>: A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses.<br />
Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. eg, IOException thrown by java.io.FileInputStream’s read() method•<br />
Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn’t force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String’s charAt() method• Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be.</p>
<p><strong>Q:What is Overriding?</strong></p>
<p><strong></strong><strong>A:</strong> When a class defines a method using the same name, return type, and arguments as a method in its superclass, the method in the class overrides the method in the superclass.<br />
When the method is invoked for an object of the class, it is the new definition of the method that is called, and not the method definition from superclass. Methods may be overridden to be more public, not more private.</p>
<p><strong>Q:What are different types of inner classes?</strong></p>
<p><strong>A:</strong> Nested top-level classes, Member classes, Local classes, Anonymous classes Nested top-level classes- If you declare a class within a class and specify the static modifier, the compiler treats the class just like any other top-level class. Any class outside the declaring class accesses the nested class with the declaring class name acting similarly to a package. eg, outer.inner. Top-level inner classes implicitly have access only to static variables.There can also be inner interfaces. All of these are of the nested top-level variety.</p>
<p><strong>Member classes</strong> &#8211; Member inner classes are just like other member methods and member variables and access to the member class is restricted, just like methods and variables. This means a public member class acts similarly to a nested top-level class. The primary difference between member classes and nested top-level classes is that member classes have access to the specific instance of the enclosing class.</p>
<p><strong>Local classes</strong> &#8211; Local classes are like local variables, specific to a block of code. Their visibility is only within the block of their declaration. In order for the class to be useful beyond the declaration block, it would need to implement a more publicly available interface.Because local classes are not members, the modifiers public, protected, private, and static are not usable.</p>
<p><strong>Anonymous classes</strong> &#8211; Anonymous inner classes extend local inner classes one level further. As anonymous classes have no name, you cannot provide a constructor.</p>
<p><strong>Q:Are the imports checked for validity at compile time? e.g. will the code containing an import such as java.lang.ABCD compile?</strong></p>
<p><strong></strong><strong>A:</strong> Yes the imports are checked for the semantic validity at compile time. The code containing above line of import will not compile. It will throw an error saying,can not resolve symbol<br />
symbol : class ABCD<br />
location: package io<br />
import java.io.ABCD;</p>
<p><strong>Q:Does importing a package imports the subpackages as well? e.g. Does importing com.MyTest.* also import com.MyTest.UnitTests.*?</strong></p>
<p><strong></strong><strong>A:</strong> No you will have to import the subpackages explicitly. Importing com.MyTest.* will import classes in the package MyTest only. It will not import any class in any of it’s subpackage.</p>
<p><strong>Q:What is the difference between declaring a variable and defining a variable?</strong></p>
<p><strong></strong><strong>A:</strong> In declaration we just mention the type of the variable and it’s name. We do not initialize it. But defining means declaration + initialization.<br />
e.g String s; is just a declaration while String s = new String (”abcd”); Or String s = “abcd”; are both definitions.</p>
<p><strong>Q:What is the default value of an object reference declared as an instance variable?</strong></p>
<p><strong></strong><strong>A:</strong> null unless we define it explicitly.</p>
<p><strong>Q:Can a top level class be private or protected?</strong></p>
<p><strong></strong><strong>A:</strong> No. A top level class can not be private or protected. It can have either “public” or no modifier. If it does not have a modifier it is supposed to have a default access.If a top level class is declared as private the compiler will complain that the “modifier private is not allowed here”. This means that a top level class can not be private. Same is the case with protected.</p>
<p><strong>Q:What type of parameter passing does Java support?</strong></p>
<p><strong></strong><strong>A:</strong>In Java the arguments are always passed by value .</p>
<p><strong>Q:Primitive data types are passed by reference or pass by value?</strong></p>
<p><strong></strong><strong>A:</strong> Primitive data types are passed by value.</p>
<p><strong>Q:Objects are passed by value or by reference?</strong></p>
<p><strong></strong><strong>A: </strong>Java only supports pass by value. With objects, the object reference itself is passed by value and so both the original reference and parameter copy both refer to the same object .</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>June 23, 2008 -- <a href="http://www.bestjavainterviewquestions.com/19/" title="Java Basic Questions">Java Basic Questions</a> (1)</li><li>February 15, 2009 -- <a href="http://www.bestjavainterviewquestions.com/define-ejb-frame-work/" title="Define EJB frame work">Define EJB frame work</a> (1)</li><li>September 2, 2008 -- <a href="http://www.bestjavainterviewquestions.com/difference-between-getcurrentsession-and-opensession/" title="Difference between getCurrentSession() and openSession()">Difference between getCurrentSession() and openSession()</a> (0)</li><li>August 24, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-servletoutputstream-object-in-jsp/" title="Define ServletOutputStream object in Jsp">Define ServletOutputStream object in Jsp</a> (0)</li><li>March 20, 2009 -- <a href="http://www.bestjavainterviewquestions.com/life-cycle-of-stateless-session-bean/" title="Life Cycle of stateless session bean">Life Cycle of stateless session bean</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/core-java-inteview-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Core Java Interview Questions</title>
		<link>http://www.bestjavainterviewquestions.com/core-java-interview-questions/</link>
		<comments>http://www.bestjavainterviewquestions.com/core-java-interview-questions/#comments</comments>
		<pubDate>Thu, 22 May 2008 18:44:08 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Basic Java Interview Questions]]></category>
		<category><![CDATA[abstract class]]></category>
		<category><![CDATA[advance java]]></category>
		<category><![CDATA[arraylist]]></category>
		<category><![CDATA[core java]]></category>
		<category><![CDATA[Enumeration]]></category>
		<category><![CDATA[HashMap]]></category>
		<category><![CDATA[HashSet]]></category>
		<category><![CDATA[HashTable]]></category>
		<category><![CDATA[inner classes]]></category>
		<category><![CDATA[interfaces]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[overload]]></category>
		<category><![CDATA[overriding]]></category>
		<category><![CDATA[polymorphism]]></category>
		<category><![CDATA[servlet config]]></category>
		<category><![CDATA[servlet context]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[set]]></category>
		<category><![CDATA[Vector]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=9</guid>
		<description><![CDATA[Q:What is final? A:A final class can’t be extended ie., final class may not be subclassed. A final method can’t be overridden when its class is inherited. You can’t change value of a final variable (is a constant). Q:What if the main method is declared as private? A:The program compiles properly but at runtime it [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Q:What is final?</strong><br />
A:A final class can’t be extended ie., final class may not be subclassed. A final method can’t be overridden when its class is inherited. You can’t change value of a final variable (is a constant).</p>
<p><strong>Q:What if the main method is declared as private?</strong><br />
A:The program compiles properly but at runtime it will give “Main method not public.” message.</p>
<p><strong>Q:What if the static modifier is removed from the signature of the main method?</strong><br />
A:Program compiles. But at runtime throws an error “NoSuchMethodError”.</p>
<p><strong>Q:What if I write static public void instead of public static void?</strong><br />
A:Program compiles and runs properly.</p>
<p><strong>Q: What if I do not provide the String array as the argument to the method?</strong><br />
A: Program compiles but throws a runtime error “NoSuchMethodError”.</p>
<p><strong>Q: What is the first argument of the String array in main method?</strong><br />
A:The String array is empty. It does not have any element. This is unlike C/C++ where the first element by default is the program name.</p>
<p><strong>Q:If I do not provide any arguments on the command line, then the String array of Main method will be empty of null?</strong><br />
A:It is empty. But not null.</p>
<p><strong>QHow can one prove that the array is not null but empty?</strong><br />
A:Print args.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a NullPointerException on attempting to print args.length.</p>
<p><strong>Q: What environment variables do I need to set on my machine in order to be able to run Java programs?</strong><br />
A: CLASSPATH and PATH are the two variables.</p>
<p><strong>Q:Can an application have multiple classes having main method?</strong><br />
A:Yes it is possible. While starting the application we mention the class name to be run. The JVM will look for the Main method only in the class whose name you have mentioned. Hence there is not conflict amongst the multiple classes having main method.</p>
<p><strong>Q:Can I have multiple main methods in the same class?</strong><br />
A:No the program fails to compile. The compiler says that the main method is already defined in the class.</p>
<p><strong>Q:Do I need to import java.lang package any time? Why ?</strong><br />
A:No. It is by default loaded internally by the JVM.</p>
<p><strong>Q:Can I import same package/class twice? Will the JVM load the package twice at runtime?</strong><br />
A:One can import the same package or same class multiple times. Neither compiler nor JVM complains abt it. And the JVM will internally load the class only once no matter how many times you import the same class.</p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li>June 23, 2008 -- <a href="http://www.bestjavainterviewquestions.com/19/" title="Java Basic Questions">Java Basic Questions</a> (1)</li><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/basic-java-interview-question/" title="Basic Java Interview Question">Basic Java Interview Question</a> (1)</li><li>June 23, 2008 -- <a href="http://www.bestjavainterviewquestions.com/java-util-package-2/" title="JAVA UTIL PACKAGE">JAVA UTIL PACKAGE</a> (0)</li><li>August 17, 2010 -- <a href="http://www.bestjavainterviewquestions.com/define-hashtablehashmap-and-hashset/" title="Define Hashtable,HashMap and HashSet">Define Hashtable,HashMap and HashSet</a> (1)</li><li>March 24, 2009 -- <a href="http://www.bestjavainterviewquestions.com/define-hashset-class/" title="Define HashSet Class">Define HashSet Class</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/core-java-interview-questions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Basic Java Interview Question</title>
		<link>http://www.bestjavainterviewquestions.com/basic-java-interview-question/</link>
		<comments>http://www.bestjavainterviewquestions.com/basic-java-interview-question/#comments</comments>
		<pubDate>Thu, 22 May 2008 18:40:16 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Basic Java Interview Questions]]></category>
		<category><![CDATA[abstract class]]></category>
		<category><![CDATA[advance java]]></category>
		<category><![CDATA[arraylist]]></category>
		<category><![CDATA[core java]]></category>
		<category><![CDATA[Enumeration]]></category>
		<category><![CDATA[HashMap]]></category>
		<category><![CDATA[HashSet]]></category>
		<category><![CDATA[HashTable]]></category>
		<category><![CDATA[inner classes]]></category>
		<category><![CDATA[interfaces]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[overload]]></category>
		<category><![CDATA[overriding]]></category>
		<category><![CDATA[polymorphism]]></category>
		<category><![CDATA[servlet config]]></category>
		<category><![CDATA[servlet context]]></category>
		<category><![CDATA[servlets]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[set]]></category>
		<category><![CDATA[springs]]></category>
		<category><![CDATA[struts]]></category>
		<category><![CDATA[Vector]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=8</guid>
		<description><![CDATA[java.lang package is automatically imported into all programs. True False Ans : a What are the interfaces defined by java.lang? Ans : Cloneable, Comparable and Runnable. What are the constants defined by both Flaot and Double classes? Ans : MAX_VALUE, MIN_VALUE, NaN, POSITIVE_INFINITY, NEGATIVE_INFINITY and TYPE. What are the constants defined by Byte, Short, Integer [...]]]></description>
			<content:encoded><![CDATA[<p><strong>java.lang package is automatically imported into all programs.</strong><br />
True<br />
False<br />
Ans : a</p>
<p><strong>What are the interfaces defined by java.lang? </strong><br />
Ans : Cloneable, Comparable and Runnable.<br />
What are the constants defined by both Flaot and Double classes?<br />
Ans : MAX_VALUE,<br />
MIN_VALUE,<br />
NaN,<br />
POSITIVE_INFINITY,<br />
NEGATIVE_INFINITY and<br />
TYPE.</p>
<p><strong>What are the constants defined by Byte, Short, Integer and Long? </strong><br />
Ans : MAX_VALUE,MIN_VALUE and TYPE.</p>
<p><strong>What are the constants defined by both Float and Double classes? </strong><br />
Ans : MAX_RADIX,MIN_RADIX,MAX_VALUE,MIN_VALUE and TYPE.</p>
<p><strong>What is the purpose of the Runtime class? </strong><br />
Ans : The purpose of the Runtime class is to provide access to the Java runtime system.</p>
<p><strong>What is the purpose of the System class? </strong><br />
Ans : The purpose of the System class is to provide access to system resources.</p>
<p><strong>Which class is extended by all other classes? </strong><br />
Ans : Object class is extended by all other classes.</p>
<p><strong>Which class can be used to obtain design information about an object?</strong><br />
Ans : The Class class can be used to obtain information about an object’s design.</p>
<p><strong>Which method is used to calculate the absolute value of a number?</strong><br />
Ans : abs( ) method.</p>
<p><strong>What are E and PI? </strong><br />
Ans : E is the base of the natural logarithm and PI is the mathematical value pi.</p>
<p><strong>Which of the following classes is used to perform basic console I/O?<br />
System </strong><br />
SecurityManager<br />
Math<br />
Runtime<br />
Ans : a.<br />
<strong><br />
Which of the following are true?</strong><br />
The Class class is the superclass of the Object class.<br />
The Object class is final.<br />
The Class class can be used to load other classes.<br />
The ClassLoader class can be used to load other classes.<br />
Ans : c and d.</p>
<p><strong>Which of the following methods are methods of the Math class?</strong><br />
absolute( )<br />
log( )<br />
cosine( )<br />
sine( )<br />
Ans : b.</p>
<p><strong>Which of the following are true about the Error and Exception classes?</strong><br />
Both classes extend Throwable.<br />
The Error class is final and the Exception class is not.<br />
The Exception class is final and the Error is not.<br />
Both classes implement Throwable.<br />
Ans : a.</p>
<p><strong>Which of the following are true?</strong><br />
The Void class extends the Class class.<br />
The Float class extends the Double class.<br />
The System class extends the Runtime class.<br />
The Integer class extends the Number class.<br />
Ans : d.</p>
<p><strong>Which of the following will output -4.0 </strong><br />
System.out.println(Math.floor(-4.7));<br />
System.out.println(Math.round(-4.7));<br />
System.out.println(Math.ceil(-4.7));<br />
d) System.out.println(Math.Min(-4.7));<br />
Ans : c.</p>
<p><strong>Which of the following are valid statements </strong><br />
a) public class MyCalc extends Math<br />
b) Math.max(s);<br />
c) Math.round(9.99,1);<br />
d) Math.mod(4,10);<br />
e) None of the above.<br />
Ans : e.</p>
<p><strong>What will happen if you attempt to compile and run the following code? </strong><br />
Integer ten=new Integer(10);</p>
<p>Long nine=new Long (9);</p>
<p>System.out.println(ten + nine);</p>
<p>int i=1;</p>
<p>System.out.println(i + ten);<br />
19 followed by 20<br />
19 followed by 11<br />
Error: Can’t convert java lang Integer<br />
d) 10 followed by 1<br />
Ans : c.</p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li>June 23, 2008 -- <a href="http://www.bestjavainterviewquestions.com/19/" title="Java Basic Questions">Java Basic Questions</a> (1)</li><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/core-java-interview-questions/" title="Core Java Interview Questions">Core Java Interview Questions</a> (1)</li><li>June 23, 2008 -- <a href="http://www.bestjavainterviewquestions.com/java-util-package-2/" title="JAVA UTIL PACKAGE">JAVA UTIL PACKAGE</a> (0)</li><li>August 17, 2010 -- <a href="http://www.bestjavainterviewquestions.com/define-hashtablehashmap-and-hashset/" title="Define Hashtable,HashMap and HashSet">Define Hashtable,HashMap and HashSet</a> (1)</li><li>March 24, 2009 -- <a href="http://www.bestjavainterviewquestions.com/define-hashset-class/" title="Define HashSet Class">Define HashSet Class</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/basic-java-interview-question/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

