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

<channel>
	<title>Technical Interview Questions &#187; JAVA Interview Questions</title>
	<atom:link href="http://www.technicalinterview.info/category/java-interview-questions/feed" rel="self" type="application/rss+xml" />
	<link>http://www.technicalinterview.info</link>
	<description>Java Interview Questions &#124; IT interview questions &#124; Software Testing Interview questions &#124; .Net Interview Questions &#124; Job Interview Questions &#38; Answers &#124; Tough Interview Questions &#124; Technology Interview Questions &#124; Tech Interview Questions &#124; Testing Interview Questions &#124; SAP Interview Questions &#124; ABAP Interview Questions &#124; Data Warehousing Interview Questions</description>
	<pubDate>Tue, 02 Sep 2008 08:33:19 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>30 Best Java Interview Questions</title>
		<link>http://www.technicalinterview.info/30-best-java-interview-questions/</link>
		<comments>http://www.technicalinterview.info/30-best-java-interview-questions/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 16:42:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JAVA Interview Questions]]></category>

		<guid isPermaLink="false">http://www.technicalinterview.info/?p=2268</guid>
		<description><![CDATA[Q1. How could Java classes direct program messages to the system console, but error messages, say to a file?
A. The class System has a variable out that represents the standard output, and the variable err that represents the standard error device. By default, they both point at the system console. This how the standard output [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Q1. How could Java classes direct program messages to the system console, but error messages, say to a file?</strong></p>
<p>A. The class System has a variable out that represents the standard output, and the variable err that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed:<br />
Stream st = new Stream(new FileOutputStream(&#8221;output.txt&#8221;)); System.setErr(st); System.setOut(st);</p>
<p><strong>Q2. What&#8217;s the difference between an interface and an abstract class?</strong></p>
<p>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.</p>
<p><strong>Q3. Why would you use a synchronized block vs. synchronized method?</strong><br />
A. Synchronized blocks place locks for shorter periods than synchronized methods.</p>
<p><strong>Q4. Explain the usage of the keyword transient?</strong></p>
<p>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).</p>
<p><strong>Q5. How can you force garbage collection?</strong></p>
<p>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.</p>
<p><strong>Q6. How do you know if an explicit object casting is needed?</strong></p>
<p>A. If you assign a superclass object to a variable of a subclass&#8217;s data type, you need to do explicit casting. For example:<br />
Object a; Customer b; b = (Customer) a;<br />
When you assign a subclass to a variable having a supeclass type, the casting is performed automatically.</p>
<p><strong>Q7. What&#8217;s the difference between the methods sleep() and wait()</strong></p>
<p>A. The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), 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.</p>
<p><strong>Q8. Can you write a Java class that could be used both as an applet as well as an application?</strong></p>
<p>A. Yes. Add a main() method to the applet.</p>
<p><strong>Q9. What&#8217;s the difference between constructors and other methods?</strong></p>
<p>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.</p>
<p><strong>Q10. Can you call one constructor from another if a class has multiple constructors</strong><br />
A. Yes. Use this() syntax.</p>
<p><strong>Q11. Explain the usage of Java packages.</strong></p>
<p>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.</p>
<p><strong>Q12. If a class is located in a package, what do you need to change in the OS environment to be able to use it?</strong></p>
<p>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<br />
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:<br />
c:\>java com.xyz.hr.Employee</p>
<p><strong>Q13. What&#8217;s the difference between J2SDK 1.5 and J2SDK 5.0?</strong></p>
<p>A.There&#8217;s no difference, Sun Microsystems just re-branded this version.</p>
<p><strong>Q14. What would you use to compare two String variables - the operator == or the method equals()?</strong></p>
<p>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.</p>
<p><strong>Q15. Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?</strong></p>
<p>A. Yes, it does. The FileNoFoundException is inherited from the IOException. Exception&#8217;s subclasses have to be caught first.</p>
<p><strong>Q16. Can an inner class declared inside of a method access local variables of this method?</strong></p>
<p>A. It&#8217;s possible if these variables are final.</p>
<p><strong>Q17. What can go wrong if you replace &#038;&#038; with &#038; in the following code:</strong><br />
String a=null; if (a!=null &#038;&#038; a.length()>10) {&#8230;}</p>
<p>A. A single ampersand here would lead to a NullPointerException.</p>
<p><strong>Q18. What&#8217;s the main difference between a Vector and an ArrayList</strong></p>
<p>A. Java Vector class is internally synchronized and ArrayList is not.</p>
<p><strong>Q19. When should the method invokeLater()be used?</strong></p>
<p>A. This method is used to ensure that Swing components are updated through the event-dispatching thread.</p>
<p><strong>Q20. How can a subclass call a method or a constructor defined in a superclass?</strong></p>
<p>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.</p>
<p>For senior-level developers:<br />
<strong>Q21. What&#8217;s the difference between a queue and a stack?</strong></p>
<p>A. Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule</p>
<p><strong>Q22. 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?</strong></p>
<p>A. Sometimes. But your class may be a descendant of another class and in this case the interface is your only option.</p>
<p><strong>Q23. What comes to mind when you hear about a young generation in Java?</strong></p>
<p>A. Garbage collection.</p>
<p><strong>Q24. What comes to mind when someone mentions a shallow copy in Java?</strong></p>
<p>A. Object cloning.</p>
<p><strong>Q25. If you&#8217;re overriding the method equals() of an object, which other method you might also consider?</strong></p>
<p>A. hashCode()</p>
<p><strong>Q26. You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use:ArrayList or LinkedList?</strong></p>
<p>A. ArrayList</p>
<p><strong>Q27. How would you make a copy of an entire Java object with its state?</strong></p>
<p>A. Have this class implement Cloneable interface and call its method clone().</p>
<p><strong>Q28. How can you minimize the need of garbage collection and make the memory use more effective?</strong></p>
<p>A. Use object pooling and weak object references.<br />
<strong><br />
Q29. 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></p>
<p>A. If these classes are threads I&#8217;d consider notify() or notifyAll(). For regular classes you can use the Observer interface.</p>
<p><strong>Q30. What access level do you need to specify in the class declaration to ensure that only classes from the same directory can access it?</strong></p>
<p>A. You do not need to specify any access level, and Java will use a default package access level.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.technicalinterview.info/30-best-java-interview-questions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>What are different types of inner classes?</title>
		<link>http://www.technicalinterview.info/what-are-different-types-of-inner-classes/</link>
		<comments>http://www.technicalinterview.info/what-are-different-types-of-inner-classes/#comments</comments>
		<pubDate>Tue, 31 Jul 2007 09:22:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JAVA Interview Questions]]></category>

		<guid isPermaLink="false">http://www.technicalinterview.info/what-are-different-types-of-inner-classes.html</guid>
		<description><![CDATA[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, [...]]]></description>
			<content:encoded><![CDATA[<p>Nested top-level classes, Member classes, Local classes, Anonymous classes<br />
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.<br />
Any class outside the declaring class accesses the nested class with the declaring class name acting similarly to a package. eg, [...]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.technicalinterview.info/what-are-different-types-of-inner-classes/feed/</wfw:commentRss>
		</item>
		<item>
		<title>What are Checked and UnChecked Exception?</title>
		<link>http://www.technicalinterview.info/what-are-checked-and-unchecked-exception/</link>
		<comments>http://www.technicalinterview.info/what-are-checked-and-unchecked-exception/#comments</comments>
		<pubDate>Tue, 31 Jul 2007 09:19:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JAVA Interview Questions]]></category>

		<guid isPermaLink="false">http://www.technicalinterview.info/what-are-checked-and-unchecked-exception.html</guid>
		<description><![CDATA[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&#8217;s read() method
Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also [...]]]></description>
			<content:encoded><![CDATA[<p>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&#8217;s read() method<br />
Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also [...]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.technicalinterview.info/what-are-checked-and-unchecked-exception/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Can I import same package/class twice? Will the JVM load the package twice at runtime?</title>
		<link>http://www.technicalinterview.info/can-i-import-same-packageclass-twice-will-the-jvm-load-the-package-twice-at-runtime/</link>
		<comments>http://www.technicalinterview.info/can-i-import-same-packageclass-twice-will-the-jvm-load-the-package-twice-at-runtime/#comments</comments>
		<pubDate>Tue, 31 Jul 2007 09:18:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JAVA Interview Questions]]></category>

		<guid isPermaLink="false">http://www.technicalinterview.info/can-i-import-same-packageclass-twice-will-the-jvm-load-the-package-twice-at-runtime.html</guid>
		<description><![CDATA[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.
]]></description>
			<content:encoded><![CDATA[<p>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>
]]></content:encoded>
			<wfw:commentRss>http://www.technicalinterview.info/can-i-import-same-packageclass-twice-will-the-jvm-load-the-package-twice-at-runtime/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Can I have multiple main methods in the same class?</title>
		<link>http://www.technicalinterview.info/can-i-have-multiple-main-methods-in-the-same-class/</link>
		<comments>http://www.technicalinterview.info/can-i-have-multiple-main-methods-in-the-same-class/#comments</comments>
		<pubDate>Tue, 31 Jul 2007 09:17:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JAVA Interview Questions]]></category>

		<guid isPermaLink="false">http://www.technicalinterview.info/can-i-have-multiple-main-methods-in-the-same-class.html</guid>
		<description><![CDATA[No the program fails to compile. The compiler says that the main method is already defined in the class.
]]></description>
			<content:encoded><![CDATA[<p>No the program fails to compile. The compiler says that the main method is already defined in the class.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.technicalinterview.info/can-i-have-multiple-main-methods-in-the-same-class/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Can an application have multiple classes having main method?</title>
		<link>http://www.technicalinterview.info/can-an-application-have-multiple-classes-having-main-method/</link>
		<comments>http://www.technicalinterview.info/can-an-application-have-multiple-classes-having-main-method/#comments</comments>
		<pubDate>Tue, 31 Jul 2007 09:16:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JAVA Interview Questions]]></category>

		<guid isPermaLink="false">http://www.technicalinterview.info/can-an-application-have-multiple-classes-having-main-method.html</guid>
		<description><![CDATA[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.
]]></description>
			<content:encoded><![CDATA[<p>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>
]]></content:encoded>
			<wfw:commentRss>http://www.technicalinterview.info/can-an-application-have-multiple-classes-having-main-method/feed/</wfw:commentRss>
		</item>
		<item>
		<title>What environment variables do I need to set on my machine in order to be able to run Java programs?</title>
		<link>http://www.technicalinterview.info/what-environment-variables-do-i-need-to-set-on-my-machine-in-order-to-be-able-to-run-java-programs/</link>
		<comments>http://www.technicalinterview.info/what-environment-variables-do-i-need-to-set-on-my-machine-in-order-to-be-able-to-run-java-programs/#comments</comments>
		<pubDate>Tue, 31 Jul 2007 09:16:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JAVA Interview Questions]]></category>

		<guid isPermaLink="false">http://www.technicalinterview.info/what-environment-variables-do-i-need-to-set-on-my-machine-in-order-to-be-able-to-run-java-programs.html</guid>
		<description><![CDATA[CLASSPATH and PATH are the two variables.
]]></description>
			<content:encoded><![CDATA[<p>CLASSPATH and PATH are the two variables.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.technicalinterview.info/what-environment-variables-do-i-need-to-set-on-my-machine-in-order-to-be-able-to-run-java-programs/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How can one prove that the array is not null but empty?</title>
		<link>http://www.technicalinterview.info/how-can-one-prove-that-the-array-is-not-null-but-empty/</link>
		<comments>http://www.technicalinterview.info/how-can-one-prove-that-the-array-is-not-null-but-empty/#comments</comments>
		<pubDate>Tue, 31 Jul 2007 09:15:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JAVA Interview Questions]]></category>

		<guid isPermaLink="false">http://www.technicalinterview.info/how-can-one-prove-that-the-array-is-not-null-but-empty.html</guid>
		<description><![CDATA[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.
]]></description>
			<content:encoded><![CDATA[<p>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>
]]></content:encoded>
			<wfw:commentRss>http://www.technicalinterview.info/how-can-one-prove-that-the-array-is-not-null-but-empty/feed/</wfw:commentRss>
		</item>
		<item>
		<title>What is the first argument of the String array in main method?</title>
		<link>http://www.technicalinterview.info/what-is-the-first-argument-of-the-string-array-in-main-method/</link>
		<comments>http://www.technicalinterview.info/what-is-the-first-argument-of-the-string-array-in-main-method/#comments</comments>
		<pubDate>Tue, 31 Jul 2007 07:38:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JAVA Interview Questions]]></category>

		<guid isPermaLink="false">http://www.technicalinterview.info/what-is-the-first-argument-of-the-string-array-in-main-method.html</guid>
		<description><![CDATA[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.
]]></description>
			<content:encoded><![CDATA[<p>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>
]]></content:encoded>
			<wfw:commentRss>http://www.technicalinterview.info/what-is-the-first-argument-of-the-string-array-in-main-method/feed/</wfw:commentRss>
		</item>
		<item>
		<title>What if I do not provide the String array as the argument to the method?</title>
		<link>http://www.technicalinterview.info/what-if-i-do-not-provide-the-string-array-as-the-argument-to-the-method/</link>
		<comments>http://www.technicalinterview.info/what-if-i-do-not-provide-the-string-array-as-the-argument-to-the-method/#comments</comments>
		<pubDate>Tue, 31 Jul 2007 07:35:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JAVA Interview Questions]]></category>

		<guid isPermaLink="false">http://www.technicalinterview.info/what-if-i-do-not-provide-the-string-array-as-the-argument-to-the-method.html</guid>
		<description><![CDATA[Program compiles but throws a runtime error &#8220;NoSuchMethodError&#8221;.
]]></description>
			<content:encoded><![CDATA[<p>Program compiles but throws a runtime error &#8220;NoSuchMethodError&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.technicalinterview.info/what-if-i-do-not-provide-the-string-array-as-the-argument-to-the-method/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
