<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Prepare 4 interview - Recent questions and answers in Java Interview Questions and Answers</title>
<link>http://prepare4interview.com/qa/java-interview-questions-and-answers</link>
<description>Powered by Question2Answer</description>
<item>
<title>Answered: What access level do you need to specify in the class declaration?</title>
<link>http://prepare4interview.com/1264/what-access-level-do-you-need-specify-the-class-declaration#a1265</link>
<description>You do not need to specify any access level, and Java will use a default package access level.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1264/what-access-level-do-you-need-specify-the-class-declaration#a1265</guid>
<pubDate>Sun, 05 Sep 2010 10:56:59 +0000</pubDate>
</item>
<item>
<title>Answered: What Java technique would you use to implement it?</title>
<link>http://prepare4interview.com/1262/what-java-technique-would-you-use-to-implement-it#a1263</link>
<description>If these classes are threads I'd consider notify() or notifyAll(). For regular classes you can use the Observer interface.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1262/what-java-technique-would-you-use-to-implement-it#a1263</guid>
<pubDate>Sun, 05 Sep 2010 10:55:31 +0000</pubDate>
</item>
<item>
<title>Answered: How can you minimize the need of garbage collection and make the memory use more effective?</title>
<link>http://prepare4interview.com/1260/minimize-need-garbage-collection-make-memory-more-effective#a1261</link>
<description>Use object pooling and weak object references.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1260/minimize-need-garbage-collection-make-memory-more-effective#a1261</guid>
<pubDate>Sun, 05 Sep 2010 10:54:12 +0000</pubDate>
</item>
<item>
<title>Answered: How would you make a copy of an entire Java object with its state?</title>
<link>http://prepare4interview.com/1258/how-would-you-make-copy-of-an-entire-java-object-with-its-state#a1259</link>
<description>Have this class implement Clone-able interface and call its method clone().</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1258/how-would-you-make-copy-of-an-entire-java-object-with-its-state#a1259</guid>
<pubDate>Sun, 05 Sep 2010 10:52:58 +0000</pubDate>
</item>
<item>
<title>Answered: Which of the two Java collections should you use: ArrayList or LinkedList?</title>
<link>http://prepare4interview.com/1256/which-the-two-java-collections-should-arraylist-linkedlist#a1257</link>
<description>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?&lt;br /&gt;
&lt;br /&gt;
Answer: ArrayList</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1256/which-the-two-java-collections-should-arraylist-linkedlist#a1257</guid>
<pubDate>Sun, 05 Sep 2010 10:52:08 +0000</pubDate>
</item>
<item>
<title>Answered: If you're overriding the method equals() of an object, which other method you might also consider?</title>
<link>http://prepare4interview.com/1254/overriding-method-equals-object-which-other-method-consider#a1255</link>
<description>If you're overriding the method equals() of an object, which other method you might also consider?&lt;br /&gt;
&lt;br /&gt;
hashCode()</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1254/overriding-method-equals-object-which-other-method-consider#a1255</guid>
<pubDate>Sun, 05 Sep 2010 10:50:41 +0000</pubDate>
</item>
<item>
<title>Answered: What comes to mind when someone mentions a shallow copy in Java?</title>
<link>http://prepare4interview.com/1252/what-comes-to-mind-when-someone-mentions-shallow-copy-in-java#a1253</link>
<description>Object cloning.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1252/what-comes-to-mind-when-someone-mentions-shallow-copy-in-java#a1253</guid>
<pubDate>Sun, 05 Sep 2010 10:49:24 +0000</pubDate>
</item>
<item>
<title>Answered: What comes to mind when you hear about a young generation in Java?</title>
<link>http://prepare4interview.com/1250/what-comes-mind-when-you-hear-about-young-generation-in-java#a1251</link>
<description>Garbage collection.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1250/what-comes-mind-when-you-hear-about-young-generation-in-java#a1251</guid>
<pubDate>Sun, 05 Sep 2010 10:48:05 +0000</pubDate>
</item>
<item>
<title>Answered: Can you use abstract classes instead of interfaces?</title>
<link>http://prepare4interview.com/1248/can-you-use-abstract-classes-instead-of-interfaces#a1249</link>
<description>Sometimes. But your class may be a descendant of another class and in this case the interface is your only option.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1248/can-you-use-abstract-classes-instead-of-interfaces#a1249</guid>
<pubDate>Sun, 05 Sep 2010 10:47:08 +0000</pubDate>
</item>
<item>
<title>Answered: What's the difference between a queue and a stack?</title>
<link>http://prepare4interview.com/1246/what-s-the-difference-between-a-queue-and-a-stack#a1247</link>
<description>Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1246/what-s-the-difference-between-a-queue-and-a-stack#a1247</guid>
<pubDate>Sun, 05 Sep 2010 10:43:12 +0000</pubDate>
</item>
<item>
<title>Answered: How can a subclass call a method or a constructor defined in a superclass?</title>
<link>http://prepare4interview.com/1244/how-can-subclass-call-method-constructor-defined-superclass#a1245</link>
<description>Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass's constructor.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1244/how-can-subclass-call-method-constructor-defined-superclass#a1245</guid>
<pubDate>Sun, 05 Sep 2010 10:41:48 +0000</pubDate>
</item>
<item>
<title>Answered: When should the method invokeLater() be used?</title>
<link>http://prepare4interview.com/1242/when-should-the-method-invokelater-be-used#a1243</link>
<description>This method is used to ensure that Swing components are updated through the event-dispatching thread.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1242/when-should-the-method-invokelater-be-used#a1243</guid>
<pubDate>Sun, 05 Sep 2010 10:40:19 +0000</pubDate>
</item>
<item>
<title>Answered: What's the main difference between a Vector and an ArrayList</title>
<link>http://prepare4interview.com/1240/what-s-the-main-difference-between-a-vector-and-an-arraylist#a1241</link>
<description>Java Vector class is internally synchronized and ArrayList is not.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1240/what-s-the-main-difference-between-a-vector-and-an-arraylist#a1241</guid>
<pubDate>Sun, 05 Sep 2010 10:39:09 +0000</pubDate>
</item>
<item>
<title>Answered: What can go wrong if you replace &amp;&amp; with &amp; in the following code: String a=null; if (a!=null &amp;&amp; a.length()&gt;10) {...}</title>
<link>http://prepare4interview.com/1238/what-wrong-replace-with-following-code-string-null-null-length#a1239</link>
<description>A single ampersand here would lead to a NullPointerException.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1238/what-wrong-replace-with-following-code-string-null-null-length#a1239</guid>
<pubDate>Sun, 05 Sep 2010 10:38:10 +0000</pubDate>
</item>
<item>
<title>Answered: Can an inner class declared inside of a method access local variables of this method?</title>
<link>http://prepare4interview.com/1236/inner-declared-inside-method-access-local-variables-method#a1237</link>
<description>It's possible if these variables are final.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1236/inner-declared-inside-method-access-local-variables-method#a1237</guid>
<pubDate>Sun, 05 Sep 2010 10:37:22 +0000</pubDate>
</item>
<item>
<title>Answered: Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?</title>
<link>http://prepare4interview.com/1234/statements-filenotfoundexception-ioexceptipon-written#a1235</link>
<description>Yes, it does. The FileNoFoundException is inherited from the IOException. Exception's subclasses have to be caught first.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1234/statements-filenotfoundexception-ioexceptipon-written#a1235</guid>
<pubDate>Sun, 05 Sep 2010 10:35:33 +0000</pubDate>
</item>
<item>
<title>Answered: What would you use to compare two String variables - the operator == or the method equals()?</title>
<link>http://prepare4interview.com/1232/what-would-compare-string-variables-operator-method-equals#a1233</link>
<description>I'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.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1232/what-would-compare-string-variables-operator-method-equals#a1233</guid>
<pubDate>Sun, 05 Sep 2010 10:28:02 +0000</pubDate>
</item>
<item>
<title>Answered: What's the difference between J2SDK 1.5 and J2SDK 5.0?</title>
<link>http://prepare4interview.com/1230/what-s-the-difference-between-j2sdk-1-5-and-j2sdk-5-0#a1231</link>
<description>There's no difference, Sun Microsystems just re-branded this version.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1230/what-s-the-difference-between-j2sdk-1-5-and-j2sdk-5-0#a1231</guid>
<pubDate>Sun, 05 Sep 2010 10:27:07 +0000</pubDate>
</item>
<item>
<title>Answered: If a class is located in a package, what do you need to change in the OS environment to be able to use it?</title>
<link>http://prepare4interview.com/1228/class-located-package-what-need-change-environment-able-use#a1229</link>
<description>You need to add a directory or a jar file &amp;nbsp;that contains the package directories to the CLASSPATH environment variable. Let's say a class Employee belongs to a package com.xyz.hr; and is located in the file c:\dev\com\xyz\hr\Employee.java. In this case, you'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:&lt;br /&gt;
&lt;br /&gt;
c:\&amp;gt;java com.xyz.hr.Employee</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1228/class-located-package-what-need-change-environment-able-use#a1229</guid>
<pubDate>Sun, 05 Sep 2010 10:26:11 +0000</pubDate>
</item>
<item>
<title>Answered: Explain the usage of Java packages.</title>
<link>http://prepare4interview.com/1226/explain-the-usage-of-java-packages#a1227</link>
<description>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.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1226/explain-the-usage-of-java-packages#a1227</guid>
<pubDate>Sun, 05 Sep 2010 10:24:46 +0000</pubDate>
</item>
<item>
<title>Answered: Can you call one constructor from another if a class has multiple constructors?</title>
<link>http://prepare4interview.com/1224/call-constructor-from-another-class-multiple-constructors#a1225</link>
<description>Yes. Use this() syntax.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1224/call-constructor-from-another-class-multiple-constructors#a1225</guid>
<pubDate>Sun, 05 Sep 2010 10:23:37 +0000</pubDate>
</item>
<item>
<title>Answered: What's the difference between constructors and other methods?</title>
<link>http://prepare4interview.com/1222/what-the-difference-between-constructors-and-other-methods#a1223</link>
<description>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.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1222/what-the-difference-between-constructors-and-other-methods#a1223</guid>
<pubDate>Sun, 05 Sep 2010 10:22:43 +0000</pubDate>
</item>
<item>
<title>Answered: Can you write a Java class that could be used both as an applet as well as an application?</title>
<link>http://prepare4interview.com/1220/write-java-class-that-could-used-both-applet-well-application#a1221</link>
<description>Yes. Add a main() method to the applet.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1220/write-java-class-that-could-used-both-applet-well-application#a1221</guid>
<pubDate>Sun, 05 Sep 2010 10:21:42 +0000</pubDate>
</item>
<item>
<title>Answered: What's the difference between the methods sleep() and wait()</title>
<link>http://prepare4interview.com/1218/what-s-the-difference-between-the-methods-sleep-and-wait#a1219</link>
<description>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.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1218/what-s-the-difference-between-the-methods-sleep-and-wait#a1219</guid>
<pubDate>Sun, 05 Sep 2010 10:20:52 +0000</pubDate>
</item>
<item>
<title>Answered: How do you know if an explicit object casting is needed?</title>
<link>http://prepare4interview.com/1216/how-do-you-know-if-an-explicit-object-casting-is-needed#a1217</link>
<description>If you assign a superclass object to a variable of a subclass's data type, you need to do explicit casting. For example:&lt;br /&gt;
&lt;br /&gt;
Object a; Customer b; b = (Customer) a;&lt;br /&gt;
&lt;br /&gt;
When you assign a subclass to a variable having a supeclass type, the casting is performed automatically.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1216/how-do-you-know-if-an-explicit-object-casting-is-needed#a1217</guid>
<pubDate>Sun, 05 Sep 2010 10:19:32 +0000</pubDate>
</item>
<item>
<title>Answered: How can you force garbage collection?</title>
<link>http://prepare4interview.com/1214/how-can-you-force-garbage-collection#a1215</link>
<description>You can't force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1214/how-can-you-force-garbage-collection#a1215</guid>
<pubDate>Sun, 05 Sep 2010 10:17:43 +0000</pubDate>
</item>
<item>
<title>Answered: Explain the usage of the keyword transient?</title>
<link>http://prepare4interview.com/1212/explain-the-usage-of-the-keyword-transient#a1213</link>
<description>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).</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1212/explain-the-usage-of-the-keyword-transient#a1213</guid>
<pubDate>Sun, 05 Sep 2010 10:16:21 +0000</pubDate>
</item>
<item>
<title>Answered: Why would you use a synchronized block vs. synchronized method?</title>
<link>http://prepare4interview.com/1210/why-would-you-use-synchronized-block-vs-synchronized-method#a1211</link>
<description>Synchronized blocks place locks for shorter periods than synchronized methods.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1210/why-would-you-use-synchronized-block-vs-synchronized-method#a1211</guid>
<pubDate>Sun, 05 Sep 2010 10:15:14 +0000</pubDate>
</item>
<item>
<title>Answered: What's the difference between an interface and an abstract class?</title>
<link>http://prepare4interview.com/1208/what-the-difference-between-an-interface-and-abstract-class#a1209</link>
<description>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.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1208/what-the-difference-between-an-interface-and-abstract-class#a1209</guid>
<pubDate>Sun, 05 Sep 2010 10:13:29 +0000</pubDate>
</item>
<item>
<title>Answered: How could Java classes direct program messages to the system console, but error messages, say to a file?</title>
<link>http://prepare4interview.com/1206/classes-direct-program-messages-system-console-error-messages#a1207</link>
<description>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:&lt;br /&gt;
&lt;br /&gt;
Stream st = new Stream(new FileOutputStream(&amp;quot;output.txt&amp;quot;));&lt;br /&gt;
System.setErr(st);&lt;br /&gt;
System.setOut(st);</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1206/classes-direct-program-messages-system-console-error-messages#a1207</guid>
<pubDate>Sun, 05 Sep 2010 10:06:46 +0000</pubDate>
</item>
<item>
<title>Answered: What is finalize() method?</title>
<link>http://prepare4interview.com/1189/what-is-finalize-method#a1190</link>
<description>finalize () method is used just before an object is destroyed and can be called just prior to garbage collection.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1189/what-is-finalize-method#a1190</guid>
<pubDate>Thu, 12 Aug 2010 07:57:22 +0000</pubDate>
</item>
<item>
<title>Answered: What if the main method is declared as private?</title>
<link>http://prepare4interview.com/1187/what-if-the-main-method-is-declared-as-private#a1188</link>
<description>The program compiles properly but at runtime it will give &amp;quot;Main method not public.&amp;quot; message.</description>
<category>Java Interview Questions and Answers</category>
<guid isPermaLink="true">http://prepare4interview.com/1187/what-if-the-main-method-is-declared-as-private#a1188</guid>
<pubDate>Thu, 12 Aug 2010 07:40:06 +0000</pubDate>
</item>
</channel>
</rss>
