Thursday, 21 May 2015

1000 Core Java Question



What do you know about Java?
What are the supported platforms by Java Programming Language?
List any five features of Java?
Why is Java Architectural Neutral?
How Java enabled High Performance?
Why Java is considered dynamic?
What is Java Virtual Machine and how it is considered in context of Java’s platform independent feature?
List two Java IDE’s?
List some Java keywords(unlike C, C++ keywords)?
What do you mean by Object?
Define class?
What kind of variables a class can consist of?
What is a Local Variable?
What is a Instance Variable?
What is a Class Variable?
What is Singleton class?
What do you mean by Constructor?
List the three steps for creating an Object for a class?
What is the default value of byte datatype in Java?
What is the default value of float and double datatype in Java?
When a byte datatype is used?
What is a static variable?
What do you mean by Access Modifier?
What is protected access modifier?
What do you mean by synchronized Non Access Modifier?
According to Java Operator precedence, which operator is considered to be with highest precedence?
Variables used in a switch statement can be used with which datatypes?
When parseInt() method can be used?
Why is String class considered immutable?
Why is StringBuffer called mutable?
What is the difference between StringBuffer and StringBuilder class?
Which package is used for pattern matching with regular expressions?
java.util.regex consists of which classes?
What is finalize() method?
What is an Exception?
What do you mean by Checked Exceptions?
Explain Runtime Exceptions?
Which are the two subclasses under Exception class?
When throws keyword is used?
When throw keyword is used?
How finally used under Exception Handling?
What things should be kept in mind while creating your own exceptions in Java?
Define Inheritance?
When super keyword is used?
What is Polymorphism?
What is Abstraction?
What is Abstract class?
When Abstract methods are used?
What is Encapsulation?
What is the primary benefit of Encapsulation?
What is an Interface?
Give some features of Interface?
Define Packages in Java?
Why Packages are used?
What do you mean by Multithreaded program?
What are the two ways in which Thread can be created?
What is an applet?
An applet extend which class?
Explain garbage collection in Java?
Define immutable object?
Explain the usage of this() with constructors?
Explain Set Interface?
Explain TreeSet?
What is Comparable Interface?
Difference between throw and throws?
Explain the following line used under Java Program:

public static void main (String args[ ])
Define JRE i.e. Java Runtime Environment?
What is JAR file?
What is a WAR file?
Define JIT compiler?
What is the difference between object oriented programming language and object based programming language?
What is the purpose of default constructor?
Can a constructor be made final?
What is static block?
Define composition?
What is function overloading?
What is function overriding?
Difference between Overloading and Overriding?
What is final class?
What is NullPointerException?
What are the ways in which a thread can enter the waiting state?
How does multi-threading take place on a computer with a single CPU?
What invokes a thread's run() method?
Does it matter in what order catch statements for FileNotFoundException and IOException are written?
What is the difference between yielding and sleeping?
Why Vector class is used?
How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?
What are Wrapper classes?
What is the difference between a Window and a Frame?
Which package has light weight components?
What is the difference between the paint() and repaint() methods?
What is the purpose of File class?
What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
Which class should you use to obtain design information about an object?
What is the difference between static and non-static variables?
What is Serialization and deserialization?
What are use cases?
Explain the use of sublass in a Java program?
How to add menushortcut to menu item?
Can you write a Java class that could be used both as an applet as well as an application?
What is the difference between Swing and AWT components?
What's the difference between constructors and other methods?
Is there any limitation of using Inheritance?
When is the ArrayStoreException thrown?
Can you call one constructor from another if a class has multiple constructors?
What's the difference between the methods sleep() and wait()?
When ArithmeticException is thrown?
What is a transient variable?
What is synchronization?
What is the Collections API?
Does garbage collection guarantee that a program will not run out of memory?
The immediate superclass of the Applet class?
Which Java operator is right associative?
What is the difference between a break statement and a continue statement?
If a variable is declared as private, where may the variable be accessed?
What is the purpose of the System class?
List primitive Java types?
What is the relationship between clipping and repainting under AWT?
Which class is the immediate superclass of the Container class?
What class of exceptions are generated by the Java run-time system?
Under what conditions is an object's finalize() method invoked by the garbage collector?
How can a dead thread be restarted?
Which arithmetic operations can result in the throwing of an ArithmeticException?
Variable of the boolean type is automatically initialized as?
Can try statements be nested?
What are ClassLoaders?
What is the difference between an Interface and an Abstract class?
What will happen if static modifier is removed from the signature of the main method?
What is the default value of an object reference declared as an instance variable?
Can a top level class be private or protected?
Why do we need wrapper classes?
What is the difference between error and an exception?
Is it necessary that each try block must be followed by a catch block?
When a thread is created and started, what is its initial state?
What is the Locale class?
What are synchronized methods and synchronized statements?
What is runtime polymorphism or dynamic method dispatch?
What is Dynamic Binding(late binding)?
Can constructor be inherited?
What are the advantages of ArrayList over arrays?
Why deletion in LinkedList is fast than ArrayList?
How do you decide when to use ArrayList and LinkedList?
What is a Values Collection View ?
What is dot operator?
Where and how can you use a private constructor?
What is type casting?
Describe life cycle of thread?
What is the difference between the >> and >>> operators?
Which method of the Component class is used to set the position and size of a component?
What is the range of the short type?
What is the immediate superclass of Menu?
Does Java allow Default Arguments?
Which number is denoted by leading zero in java?
Which number is denoted by leading 0x or 0X in java?
Break statement can be used as labels in Java?
Where import statement is used in a Java program?
Explain suspend() method under Thread class>
Explain isAlive() method under Thread class?
What is currentThread()?
Explain main thread under Thread class execution?
Life cycle of an applet includes which steps?
Why is the role of init() method under applets?
Which method is called by Applet class to load an image?
Define code as an attribute of Applet?
Define canvas?
Define Network Programming?
What is a Socket?
Advantages of Java Sockets?
Disadvantages of Java Sockets?
Which class is used by server applications to obtain a port and listen for client requests?
Which class represents the socket that both the client and server use to communicate with each other?
Why Generics are used in Java?
What environment variables do I need to set on my machine in order to be able to run Java programs?
Is there any need to import java.lang package?
What is Nested top-level class?
What is Externalizable interface?
If System.exit (0); is written at the end of the try block, will the finally block still execute?
What is daemon thread?
Which method is used to create the daemon thread?
Which method must be implemented by all threads?
What is the GregorianCalendar class?
What is the SimpleTimeZone class?
What is the difference between the size and capacity of a Vector?
Can a vector contain heterogenous objects?
What is an enumeration?
What is difference between Path and Classpath?
Can a class declared as private be accessed outside it's package?
What are the restriction imposed on a static method or a static block of code?
Can an Interface extend another Interface?
Which object oriented Concept is achieved by using overloading and overriding?
What is an object's lock and which object's have locks?
What is Downcasting?
What are order of precedence and associativity and how are they used?
If a method is declared as protected, where may the method be accessed?
What is the difference between inner class and nested class?
What restrictions are placed on method overriding?
What is constructor chaining and how is it achieved in Java?
Can a double value be cast to a byte?
How does a try statement determine which catch clause should be used to handle an exception?
What will be the default values of all the elements of an array defined as an instance variable?
buggybread
Q1. What is a cookie ?
Q2. Can we reduce the visibility of the overridden method ?
Q3. What are different types of inner classes ?
Q4. Difference between TreeMap and HashMap ?
Q5. What is the difference between List, Set and Map ?
Q6. Difference between Public, Private, Default and Protected ?
Q7. What is servlet Chaining ?
Q8. What are the Wrapper classes available for primitive types ?
Q9. What are concepts introduced with Java 5 ?
Q10. Does Constructor creates the object ?
Q11. Can static method access instance variables ?
Q12. Does Java support Multiple Inheritance ?
Q13. Difference between == and .equals() ?
Q14. Difference between Checked and Unchecked exceptions ?
Q15. What is a Final Variable ?
Q16. Which class does not override the equals() and hashCode() methods, inheriting them directly from class Object?
Q17. What is a final method ?
Q18. Which interface does java.util.Hashtable implement?
Q19. What is an Iterator?
Q20. Which interface provides the capability to store objects using a key-value pair?
Q21. Difference between HashMap and Hashtable?
Q22. Does java allow overriding static methods ?
Q23. When are static variables loaded in memory ?
Q24. Can we serialize static variables ?
Q25. What will this code print ?
String a = new String ("TEST");
String b = new String ("TEST");
if(a == b) {
System.out.println ("TRUE");
} else {
System.out.println ("FALSE");
}
Q26. There are two objects a and b with same hashcode. I am inserting these two objects inside a hashmap.
hMap.put(a,a);
hMap.put(b,b);
where a.hashCode()==b.hashCode()
Now tell me how many objects will be there inside the hashmap?
Q27. Difference between long.Class and Long.TYPE ?
Q28. Does Java provides default copy constructor ?
Q29. What are the common uses of "this" keyword in java ?
Q30. What are the difference between Threads and Processes ?
Q31. How can we run a java program without making any object?
Q32. Explain multithreading in Java ?
Q33. Can constructors be synchronized in Java ?
Q34. can we create a null as a key for a map collection ?
Q35. What is the use of hashcode in Java ?
Q36. Why java doesn't support multiple Inheritence ?
Q37. Why threads block or enters to waiting state on I/O?
Q38. What are transient variables in java?
Q39. What is the difference between yield() and sleep()?
Q40. What are wrapper classes ?
Q41. What is the difference between time slicing and preemptive scheduling ?
Q42. What is the initial state of a thread when it is created and started?
Q43. What one should take care of, while serializing the object?
Q44. What is a String Pool ?
Q45. Why is String immutable in Java ?
Q46. what is the use of cookie and session ? and What is the difference between them ?
Q47. Which are the different segments of memory ?
Q48. Which memory segment loads the java code ?
Q49. which containers use a border Layout as their default layout ?
Q50. Can a lock be acquired on a class ?
Q51. What state does a thread enter when it terminates its processing?
Q52. How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?
Q53. Does garbage collection guarantee that a program will not run out of memory?
Q54. What is an object's lock and which object's have locks?
Q55. What is casting?
Q56. What restrictions are placed on method overriding?
Q57. How does a try statement determine which catch clause should be used to handle an exception?
Q58. Describe what happens when an object is created in Java ?
Q59. What is the difference between StringBuffer and String class ?
Q60. Describe, in general, how java's garbage collector works ?
Q61. What is RMI ?
Q62. What is JDBC? Describe the steps needed to execute a SQL query using JDBC.
Q63. Are constructors inherited? Can a subclass call the parent's class constructor? When?
Q64. What is JSON ?
Q65. What is the role of JSON.stringify ?
Q66. When were Enums introduced in Java ?
Q67. Which function is used to convert a JSON text into an object ?
Q68. Which data types are supported by JSON ?
Q69. What are the benefits of JSON over XML ?
Q70. What are the methods of Object Class ?
Q71. Explain JMS ( Java Messaging Services ) ?
Q72. Explain EJB (Enterprise Java Beans) ?
Q73. Which MVC is struts2 based on ?
Q74. What is an API ( Application Programming Interface ) ?
Q75. What is URL?
Q76. Explain features of struts2 ?
Q77. What is HTTP ?
Q78. what is content negotiation?
Q79. Is tomcat an application or Web server ?
Q80. Is Apache an application or Web server
Q81. What are the default or implicitly assigned values for data types in java ?
Q82. What is difference between Encapsulation And Abstraction?
Q83. Can I import same package/class twice? Will the JVM load the package twice at runtime?
Q84. Explain static blocks in Java ?
Q85. Which access specifier can be used with Class ?
Q86. Explain Annotations ?
Q87. Give an Example of Annotations ?
Q88. What are few of the Annotations pre defined by Java?
Q89. What are meta Annotations ?
Q90. Name few meta-annotations ?
Q91. How to display and set the Class path in Unix ?
Q92. Difference between Abstract and Concrete Class ?
Q93. Difference between Overloading and Overriding ?
Q94. Difference between Vector and ArrayList ?
Q95. Different ways of implementing Threads in Java ?
Q96. What is Volatile keyword used for ?
Q97. Whatis Serialization ?
Q98. What is the use of Transient Keyword ?
Q99. What is a final variable ?
Q100. What is a Final Method ?
Q101. What is a Final Class ?
Q102. What is an Immutable Object ?
Q103. What is an immutable class ?
Q104. How to implement an immutable class ?
Q105. Does Declaring an object "final" makes it immutable ?
Q106. Difference between object instantiation and construction ?
Q107. Can we override static methods ? Why ?
Q108. Can we access instance variables within static methods ?
Q109. Can we reduce the visibility of the inherited or overridden method ?
Q110. Give an Example of checked and unchecked exception ?
Q111. Name few Java Exceptions ?
Q112. Which of the following is tightly bound ? Inheritance or Composition ?
Q113. How can we make sure that a code segment gets executed even in case of uncatched exceptions ?
Q114. Explain the use of "Native" keyword ?
Q115. What is "super" used for ?

Q116. What is "this" keyword used for ?
Q117. Difference between boolean and Boolean ?
Q118. What is a finalize method ?
Q119. What are Marker Interfaces ? Name few Java marker interfaces ?
Q120. Is runnable a Marker interface ?
Q121. Difference between Process and Thread ?
Q122. Wha is a Deadlock ?
Q123. Difference between Serialization and Deserialization ?
Q124. Explain Autoboxing ?
Q125. What is an Enum type ?
Q126. What are Wrapper Classes ? What are Primitive Wrapper Classes ?
Q127. What Design pattern Wrapper Classes implement ?
Q128. What is "Import" used for ?
Q129. Different types of memory used by JVM ?
Q130. What is a class loader ? What are the different class loaders used by JVM ?
Q131. Can we declare interface methods as private ?
Q132. What is a Static import ?
Q133. Difference between StringBuffer and StringBuilder ?
Q134. Difference between Map and HashMap ?
Q135. What is a Property class ?
Q136. Explain the scenerios to choose between String , StringBuilder and StringBuffer ?
Q137. Explain java.lang.OutOfMemoryError ?
Q138. Can we have multiple servlets in a web application and How can we do that ?
Q139. How can we manage Error Messages in the web application ?
Q140. Is JVM, a compiler or interpretor ?
Q141. Difference between implicit and explicit type casting ?
Q142. Difference between loadClass and Class.forName ?
Q143. Should we override finalize method ?
Q144. What is assert keyword used for ?
Q145. Difference between Factory and Abstract Factory Design Pattern ?
Q146. Difference between Factory and Builder Design Pattern ?
Q147. Difference between Proxy and Adapter ?
Q148. Difference between Adapter and Facade ?
Q149. Difference between Builder and Composite ?
Q150. Example of Chain of Responsibility Design Pattern ?
Q151. Example of Observer Design Pattern ?
Q152. Difference between Factory and Strategy Design Pattern ?
Q153. Shall we use abstract classes or Interfaces in Policy / Strategy Design Pattern ?
Q154. Which kind of memory is used for storing object member variables and function local variables ?
Q155. Why do member variables have default values whereas local variables don't have any default value ?


Q156. What is a Default Constructor ?
Q157. Will Compiler creates a default no argument constructor if we specify only multi argument constructor ?
Q158. Can we overload constructors ?
Q159. What will happen if we make the constructor private ?
Q160. How can we create objects if we make the constructor private ?
Q161. What will happen if we remove the static keyword from main method ?
Q162. Why Java don't use pointers ?
Q163. Can we use both "this" and "super" in a constructor ?
Q164. Do we need to import java.lang.package ?
Q165. Is it necessary that each try block to be followed by catch block ?
Q166. Can finally block be used without catch ?
Q167. What is exception propogation ?
Q168. Difference between nested and inner classes ?
Q169. What is a nested interface ?
Q170. What is an Externalizable interface ?
Q171. Difference between serializable and externalizable interface ?
Q172. What is reflection ?
Q173. Can we instantiate the object of derived class if parent constructor is protected ?
Q174. Can we declare an abstract method private ?
Q175. What are the design considerations while making a choice between using interface and abstract class ?
Q176. What is a config Object?
Q177. What is a pageContext Object?
Q178. What is suspend() method used for ?
Q179. Difference between suspend() and stop() ?
Q180. What are the benefits of using Spring Framework ?
Q181. what is the difference between collections class vs collections interface ?
Q182. Will this code give error if i try to add two heterogeneous elements in the arraylist. ? and Why ?
List list1 = new ArrayList<>();
list1.add(5);
list1.add("5");
Q183. Difference between Java beans and Spring Beans ?
Q184. What is the difference between System.console.write and System.out.println ?
Q185. What are various types of Class loaders used by JVM ?
Q186. How are classes loaded by JVM ?
Q187. Difference between C++ and Java ?
Q188. Difference between static vs. dynamic class loading?
Q189. Tell something about BufferedWriter ? What are flush() and close() used for ?
Q190. What is Scanner class used for ? when was it introduced in Java ?
Q191. Why Struts 1 Classes are not Thread Safe whereas Struts 2 classes are thread safe ?
Q192. What are some Java related technologies used for distributed computing ?
Q193. Whats the purpose of marker interfaces ?
Q194. What is the difference between final, finally and finalize() ?
Q195. When do you get ClassCastException?
Q196. Explain Thread States ?
Q197. What are strong, soft, weak and phantom references in Java ?
Q198. Difference between yield() and sleeping()?
Q199. What is a daemon thread? Give an Example ?
Q200. What is the difference between AWT and Swing?
Q201. What is the order of method invocation in an applet?
Q202. Name few tools for probing Java Memory Leaks ?
Q203. Which memory areas does instance and static variables use ?
Q204. What is J2EE? What are J2EE components and services?
Q205. What are the components of J2EE ?
Q206. What is XML ?
Q207. Difference between SAX and DOM Parser ?
Q208. What is DTD ?
Q209. What is XSD ?
Q210. What is JAXP ?
Q211. What is JAXB ?
Q212. What is marshalling ?
Q213. What is unmarshalling ?
Q214. Which load testing tools have you used ?
Q215. What are LDAP servers used for ?
Q216. What is the difference between comparable and comparator in java.util pkg?
Q217. What are different modules of spring ?
Q218. Explain Flow of Spring MVC ?
Q219. What is Spring configuration file?

Q220. Q: What is default scope of bean in Spring framework?
Q221. What bean scopes does Spring support? Explain them.

Q222. What is bean auto wiring?
Q223. Difference between socket and servlet ?
Q224. Difference Between this() and super() ?

Q225. What are the phases of the JSP life cycle ?
Q226. Difference between the jsp scriptlet tag and jsp declaration tag?
Q227. What are JSP directives ? What are different types of directives ?
Q228. What is Java bytecode ?
Q229. What is a Listener ?
Q230. What is MVC ?
Q231. What is race condition ?
Q232. What is unicode ?
Q233. What is ThreadFactory ?
Q234. What is PermGen or Permanent Generation ?
Q235. What is metaspace ?
Q236. What is the benefit of inner / nested classes ?
Q237. Explain Static nested Classes ?
Q238. Explain Inner Classes ?
Q239. Explain Method Local Inner Classes ?
Q240. Explain about anonymous inner classes ?
Q241. What will happen if class implement two interface having common method?
Q242. What is the advantage of using arrays over variables ?
Q243. What are the disadvantages of using arrays ?
Q244. Difference between Class#getInstance() and new operator ?
Q245. Can we create an object if a Class doesn't have any constructor ( not even the default provided by constructor ) ?
Q246. What is a cloneable interface and what all methods does it contain?
Q247. When you will synchronize a piece of your code?
Q248. Are there any global variables in Java, which can be accessed by other part of your program?
Q249. What is an applet? What is the lifecycle of an applet?
Q250. What is meant by controls and what are different types of controls in AWT / SWT?
Q251. What is a stream and what are the types of Streams and classes of the Streams?
Q252. What is session tracking and how do you track a user session in servlets?
Q253. What is connection pooling?
Q254. Advantage of Collection classes over Arrays ?
Q255. What are the Disadvantages of using Collection Classes over Arrays ?
Q256. Can we call constructor explicitly ?
Q257. Does a class inherit the constructor of its super class?
Q258. What is the difference between float and double?
Q259. What is the difference between >> and >>>?
Q260. What is the difference between System.out ,System.err and System.in?
Q261. Is it possible to compile and run a Java program without writing main( ) method?
Q262. What are different ways of object creation in Java ?
Q263. What is Generalization and Specialization in terms of casting ?
Q264. Can we call the garbage collector explicitly ?

Q265. How does volatile affect code optimization by compiler?
Q266. Do you think that Java should have had pointers ?
Q267. How would you go about debugging a NullPointerException?
Q268. How does Java differ from other programming languages you've worked with?
Q269. Should good code be self-documenting, or is it the responsibility of the developer to document it?
Q270. What are points to consider in terms of access modifier when we are overriding any method?
Q271. what is covariant return type?
Q272. How compiler handles the exceptions in overriding ?
Q273. Why is Java considered Portable Language ?
Q274. Tell something about history of Java ?
Q275. How to find if JVM is 32 or 64 bit from Java program. ?
Q276. Does every class needs to have one non parameterized constructor ?
Q277. Difference between throw and throws ?
Q278. Can we use "this" within static method ? Why ?
Q279. Similarity and Difference between static block and static method ?
Q280. What are the platforms supported by Java Programming Language?
Q281. How Java provide high Performance ?
Q282. What is IDE ? List few Java IDE ?
Q283. What is an Object ?
Q284. What is a Class ?
Q285. According to Java Operator precedence, which operator is considered to be with highest precedence?
Q286. What data type Variable can be used in a switch statement ?
Q287. What are the sub classes of Exception class?
Q288. How finally used under Exception Handling?
Q289. What things should be kept in mind while creating your own exceptions in Java?
Q290. What is Comparable Interface?
Q291. Explain Set Interface?
Q292. What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
Q293. What are use cases?
Q294. Which Java operator is right associative?
Q295. What is the difference between a break statement and a continue statement?
Q296. What is the purpose of the System class?
Q297. Variable of the boolean type is automatically initialized as?
Q298. Can try statements be nested?
Q299. What will happen if static modifier is removed from the signature of the main method?
Q300. What is the Locale class?
Q301. Define Network Programming?
Q302. What are the advantages and Disadvantages of Sockets ?
Q303. What environment variables do I need to set on my machine in order to be able to run Java programs?
Q304. What is Externalizable interface?
Q305. What is the difference between the size and capacity of a Vector?
Q306. What is an enum or enumeration?
Q307. What is constructor chaining and how is it achieved in Java?

Q308. What is the best practice configuration usage for files - pom.xml or settings.xml ?
Q309. Why Java provides default constructor ?
Q310. In a case where there are no instance variables what does the default constructor initialize?
Q311. How can I change the default location of the generated jar when I command "mvn package"?
Q312. What is Maven's order of inheritance?
Q313. What is a Mojo?
Q314. How do I determine which POM contains missing transitive dependency?
Q315. Difference between Encapsulation and Data Hiding ?
Q316. Difference between Abstraction and Implementation hiding ?
Q317. What are the features of encapsulation ?
Q318. What are the examples of Abstraction in Java ?
Q319. What are different ways to create String Object? Explain.
Q320. Write a method to check if input String is Palindrome?


Q321. Write a method that will remove given character from the String?
Q322. Which String class methods are used to make string upper case or lower case?
Q323. How to convert String to byte array and vice versa?
Q324. Why Char array is preferred over String for storing password?
Q325. Why String is popular HashMap key in Java?
Q326. What ate the getter and setter methods ?
Q327. public class a {
public static void main(String args[]){
final String s1="job";
final String s2="seeker";
String s3=s1.concat(s2);
String s4="jobseeker";
System.out.println(s3==s4); // Output 1
System.out.println(s3.hashCode()==s4.hashCode()); Output 2
}
}
What will be the Output 1 and Output 2 ?
Q328. What is the use of HashCode in objects ?
Q329. Difference between Compositions and Inheritance ?
Q330. Will finally be called always if all code has been kept in try block ?
Q331. Will the static block be executed in the following code ? Why ?
class Test
{
static
{
System.out.println("Why I am not executing ");
}
public static final int param=20;
}

public class Demo
{
public static void main(String[] args)
{
System.out.println(Test.param);
}
}

Q332. Will static block for Test Class execute in the following code ?

class Test
{
static
{
System.out.println("Executing Static Block.");
}
public final int param=20;

public int getParam(){
return param;
}
}

public class Demo
{
public static void main(String[] args)
{
System.out.println(new Test().param);
}
}
Q333. What does String intern() method do?
Q334. Will the following program display "Buggy Bread" ?
class Test{
static void display(){
System.out.println("Buggy Bread");
}
}

class Demo{
public static void main(String... args){
Test t = null;
t.display();
}
}
Q335. How substring() method of String class create memory leaks?
Q336. Write a program to reverse a string iteratively and recursively ?
Q337. If you have access to a function that returns a random integer from one to five, write another function which returns a random integer from one to seven.
Q338. Write a method to convert binary to a number ?
Q339. What will the following code print ?
String s1 = "Buggy Bread";
String s2 = "Buggy Bread";
if(s1 == s2)
System.out.println("equal 1");
String n1 = new String("Buggy Bread");
String n2 = new String("Buggy Bread");
if(n1 == n2)
System.out.println("equal 2");
Q340. Difference between new operator and Class.forName().newInstance() ?
Q341. What is Java bytecode ?
Q342. How to find whether a given integer is odd or even without use of modules operator in java?
Q343. Is JVM a overhead ?
Q344. Can we use Ordered Set for performing Binary Search ?
Q345. What is Byte Code ? Why Java's intermediary Code is called Byte Code ?
Q346. Difference between ArrayList and LinkedList ?
Q347. If you are given a choice to use either ArrayList and LinkedList, Which one would you use and Why ?
Q348. What are the pre-requisite for the collection to perform Binary Search ?
Q349. Can you provide some implementation of a Dictionary having large number of words ?
Q350. Difference between PATH and CLASSPATH ?

Q351. Name few access and non access Class Modifiers ?
Q352. Which Java collection class can be used to maintain the entries in the order in which they were last accessed?
Q353. Is it legal to initialize List like this ?
LinkedList l=new LinkedList();
Q354. Which of the following syntax is correct ?
import static java.lang.System.*;
or
static import java.lang.System.*;
Q355. What will be the output of following code ?
public static void main(String[] args)
{
int x = 10;
int y;
if (x < 100) y = x / 0;
if (x >= 100) y = x * 0;
System.out.println("The value of y is: " + y);
}
Q356. What will be the output of following Code ?
class BuggyBread {
public static void main(String[] args)
{
String s2 = "I am unique!";
String s5 = "I am unique!";
System.out.println(s2 == s5);
}
}
Q357. What will be the output of following code ?
class BuggyBread2 {
private static int counter = 0;
void BuggyBread2() {
counter = 5;
}
BuggyBread2(int x){
counter = x;
}
public static void main(String[] args) {
BuggyBread2 bg = new BuggyBread2();
System.out.println(counter);
}
}

Q358. What will be the output of following code ?
class BuggyBread1 {
public String method() {
return "Base Class - BuggyBread1";
}
}
class BuggyBread2 extends BuggyBread1{
private static int counter = 0;
public String method(int x) {
return "Derived Class - BuggyBread2";
}
public static void main(String[] args) {
BuggyBread1 bg = new BuggyBread2();
System.out.println(bg.method());
}
}
Q359. What are RESTful Web Services ?
Q360. Which markup languages can be used in restful web services ?
Q361. Difference between Inner and Outer Join ?
Q362. What is a Cursor ?
Q363. What is database deadlock ? How can we avoid them?
Q364. What are temp tables ?
365. Why Web services use HTTP as the communication protocol ?
Q366. what will be the output of this code ?
public static void main(String[] args)
{
StringBuffer s1=new StringBuffer("Buggy");
test(s1);
System.out.println(s1);
}
private static void test(StringBuffer s){
s.append("Bread");
}
Q367. what will be the output of this code ?
public static void main(String[] args)
{
String s1=new String("Buggy");
test(s1);
System.out.println(s1);
}
private static void test(StringBuffer s){
s.append("Bread");
}
Q368. what will be the output of this code ?
public static void main(String[] args)
{
StringBuffer s1=new StringBuffer("Buggy");

test(s1);
System.out.println(s1);
}
private static void test(StringBuffer s){
s=new StringBuffer("Bread");
}
Q369. what will be the output ?
class Animal {
public void eat() throws Exception {
}
}
class Dog2 extends Animal {
public void eat(){}
public static void main(){
Animal an = new Dog2();
an.eat();
}
}
Q370. What are advantages of using Servlets over CGI ?
Q371. gfdddddddddddddddddddddddd
Q372. Does SQL allow null values ? Can we use it within Where clause ?
Q373. Can we add duplicate keys in a HashMap ? What will happen if we attempt to add duplicate values ?
Q374. What is the use of HTTPSession in relation to http protocol ?
Q375. Why using cookie to store session info is a better idea than just using session info in the request ?
Q376. What are different types of cookies ?
Q377. http protocol is by default ... ?
Q378. Can finally block throw an exception ?
Q379. Can we have try and catch blocks within finally ?
Q380. Which of the following is a canonical path ?
1. C:\directory\..\directory\file.txt
2. C:\directory\subDirectory1\directory\file.txt
3. \directory\file.txt
Q381. What will the following code print when executed on Windows ?
public static void main(String[] args){
String parent = null;
File file = new File("/file.txt");
System.out.println(file.getPath());
System.out.println(file.getAbsolutePath());
try {
System.out.println(file.getCanonicalPath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Q382. What will be the output of following code ?
public static void main(String[] args){
String name = null;
File file = new File("/folder", name);
System.out.print(file.exists());
}
Q383. What will be the output of following code ?
public static void main(String[] args){
String parent = null;
File file = new File(parent, "myfile.txt");
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Q384. What will be the output of following code ?
public static void main(String[] args){
String child = null;
File file = new File("/folder", child);
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Q385. What will be the output of following code, assuming that currently we are in c:\Project ?
public static void main(String[] args){
String child = null;
File file = new File("../file.txt");
System.out.println(file.getPath());
System.out.println(file.getAbsolutePath());
try {
System.out.println(file.getCanonicalPath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Q386. Which is the abstract parent class of FileWriter ?
Q387. Which class is used to read streams of characters from a file?
Q388. Which class is used to read streams of raw bytes from a file?
Q389. Which is the Parent class of FileInputStream ?
Q390. Which of the following code is correct ?

FileWriter fileWriter = new FileWriter("../file.txt");
File file = new File(fileWriter );
BufferedWriter bufferedOutputWriter = new BufferedWriter(fileWriter);
b.
BufferedWriter bufferedOutputWriter = new BufferedWriter("../file.txt");
File file = new File(bufferedOutputWriter );
FileWriter fileWriter = new FileWriter(file);


c.

File file = new File("../file.txt");
FileWriter fileWriter = new FileWriter(file);
BufferedWriter bufferedOutputWriter = new BufferedWriter(fileWriter);

d.

File file = new File("../file.txt");
BufferedWriter bufferedOutputWriter = new BufferedWriter(file);
FileWriter fileWriter = new FileWriter(bufferedOutputWriter );

Q391. Which exception should be handled in the following code ?
File file = new File("../file.txt");
FileWriter fileWriter = new FileWriter(file);
Q392. Which exceptions should be handled with the following code ?
FileOutputStream fileOutputStream = new FileOutputStream(new File("newFile.txt"));
Q393. Will this code compile fine ?
ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(new File("newFile.txt")));
Q394. What is the problem with this code ?
class BuggyBread1 {
private BuggyBread2 buggybread2;
public static void main(String[] args){
try {
BuggyBread1 buggybread1 = new BuggyBread1();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(new File("newFile.txt")));
objectOutputStream.writeObject(buggybread1);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Q395. Will this code run fine if BuggyBread2 doesn't implement Serializable interface ?
class BuggyBread1 implements Serializable{
private BuggyBread2 buggybread2 = new BuggyBread2();
public static void main(String[] args){
try {
BuggyBread1 buggybread1 = new BuggyBread1();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(new File("newFile.txt")));
objectOutputStream.writeObject(buggybread1);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Q396. Will this code work fine if BuggyBread2 doesn't implement Serializable ?
class BuggyBread1 extends BuggyBread2 implements Serializable{
private int x = 5;
public static void main(String[] args){
try {
BuggyBread1 buggybread1 = new BuggyBread1();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(new File("newFile.txt")));
objectOutputStream.writeObject(buggybread1);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}
Q397. Can we compose the Parent Class object like this ?
class BuggyBread1 extends BuggyBread2 {
private BuggyBread2 buggybread2;
public static void main(String[] args){
buggybread2 = new BuggyBread2();
}
}
Q398. Will this code Work ? If not , Why ?
java.util.Calendar c = new java.util.Calendar();
Q399. Is java.util.Date an abstract Class ? Is java.util.Calendar an abstract Class ?
Q400. What will the following code print ?
java.util.Calendar c = java.util.Calendar.getInstance();
c.add(Calendar.MONTH, 5);
System.out.println(c.getTime());
Q401. Which of the following code is correct ?
a. DateFormat df = DateFormat.getInstance();
b. DateFormat df = DateFormat.getDateInstance();
c. DateFormat df = DateFormat.getInstance(DateFormat.FULL);
d. DateFormat df = DateFormat.getDateInstance(DateFormat.FULL);
Q402. What is the use of parse method in DateFormat ?
Q403. Which of the following is not a valid java.util.Locale initialization ?
a. new Locale ()
b. new Locale ( String language )
c. new Locale ( String language , String country )
Q404. Which of the following is not a valid NumberFormat initialization ?
a. NumberFormat.getInstance()
b. NumberFormat.getDateInstance()
c. NumberFormat.getCurrencyInstance()
d. NumberFormat.getNumberInstance()
Q405. What will the following code print ?
public static void main(String[] args){
Integer i1 = new Integer("1");
Integer i2 = new Integer("2");
Integer i3 = Integer.valueOf("3");
int i4 = i1 + i2 + i3;
System.out.println(i4);
}
Q406. Which of the following syntax are correct ?
a. LinkedList l=new LinkedList();
b. List l=new LinkedList();
c. LinkedList l=new LinkedList();
d. List l = new LinkedList();
Q407. Which of the following code is correct ?
a. Date date = DateFormat.newInstance(DateFormat.LONG, Locale.US).parse(str);
b. Date date = DateFormat.newInstance(DateFormat.LONG, Locale.US).format(str);
c. Date date = DateFormat.getDateInstance(DateFormat.LONG, Locale.US).parse(str);
Q408. What's wrong with this code ?
public static void main(String[] args) {
String regex = "(\\w+)*";
String s = "Java is a programming language.";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(s);
while (matcher.next()) {
System.out.println("The e-mail id is: " + matcher.group());
}
}

Q409. Which methods of the Pattern class have equivalent methods in the String class?
Q410. Can we compare Integers by using equals() in Java ?
Q411. What is comparator interface used for ?
Q412. Which are the sorted collections ?
Q413. What is rule regarding overriding equals and hasCode method ?
Q414. What is the difference between Collection and Collections ?
Q415. Is Java a statically typed or dynamically typed language ?
Q416. What do you mean by "Java is a statically typed language" ?
Q417. How can we reverse the order in the TreeMap ?
Q418. TreeMap orders the elements on which field ?
Q419. How TreeMap orders the elements if the Key is a String ?
Q420. Can we add heterogeneous elements into TreeMap ?
Q421. Will it create any problem if We add elements with key as user defined object into the TreeMap ?
Q422. Can we null keys in TreeMap ?
Q423. Can value be null in TreeMap ?
Q424. Which interface TreeMap implements ?
Q425. Do we have form beans in Struts 2 ?
Q426. What is a ConcurrentHashMap ?
Q427. What is the use of double checked locking in createInstance() of Singleton class?
Double checked locking code:
public static Singleton createInstance() {
if(singleton == null){
synchronized(Singleton.class) {
if(singleton == null) {
singleton = new Singleton();
}
}
}
return singleton;}
Single checked locking code:
public static Singleton createInstance() {
synchronized(Singleton.class) {
if(singleton == null) {
singleton = new Singleton();
}
}
return singleton;
}
What advantage does the first code offer compared to the second ?
Q428. Why are Getter and Setter better than directly changing and retrieving fields ?
Q429. Can we overload main method in Java ?
Q430. What the Bean scopes provided by Spring ?
Q431. What are the various Auto Wiring types in Spring ?
Q432. Difference between first level and second level cache in hibernate ?
Q433. What are the the methods to clear cache in Hibernate ?
Q434. What are different types of second level cache ?
Q435. Can we disable first level cache ? What should one do if we don't want an object to be cached ?
Q436. How to configure second level cache in Hibernate ?
Q437. What is Hibernate ?
Q38. What are the advantages of Hibernate ?
Q439. What are the different types of inheritance in Hibernate ?
Q440. What is the purpose of dialect configured in Hibernate configuration file ?
Q441. Please specify in what sequence the objects of following classes will be created ?
Session , SessionFactory, Query , Configuration

Q442. What are different types of associations in Hibernate ?
Q443. What are the configuration files in Hibernate ?
Q444. What are the contents of Hibernate configuration file ( hibernate.cfg.xml ) ?
Q445. What are the Core Interfaces of Hibernate Framework ?
Q446. What are collection types in Hibernate ?
Q447. Difference between load and get ?
Q448. What is lazy fetching in Hibernate ?
Q449. Different types of Hibernate Instance States ?
Q450. Is It Good to use Reflection in an application ? Why ?
Q451. Why is Reflection slower ?
Q452. When should we use prototype scope and singleton scope for beans ?
Q453. Difference between Assert and Verify ?
Q454. What is the difference between ArrayList and LinkedList ?
Q455. Which class elements are not persisted ?
Q456. Which annotations are used in Hibernate ?
Q457. What entries we make in the hibernate config file if we are not using hbm files but Annotations ?
Q458. How many SessionFactory and Session objects are created ?
Q459. What is the way to rollback transaction if something goes wrong using hibernate API ?
Q460. What is the use of hbm2ddl Configuration in Hibernate ?
Q461. What is the difference between these 2 annotations ?

@Entity

@Entity ( name="EMPLOYEES" )

Q462. "What is the difference between these 2 annotations ?

@Entity ( name ="EMPLOYEES")

@Entity
@Table ( name=""EMPLOYEES"" )

@Entity ( name="EMP")
@Table ( name="EMPLPYEES" )

Q463. What are the different ID generating strategies using @GeneratedValue annotation ?
Q464. How to do Eager loading in Hibernate ?
Q465. What is Lazy Initialization in Hibernate ?
Q466. What are the ways to avoid LazyInitializationException ?
Q467. What is cascade ?
Q468. What are the different Cascade types ?
Q469. Which type of associated Entities are Eagerly loaded by Default ?
Q470. After which Hibernate version , related Entities are initialized lazily ?
Q471. Can we declare Entity class as final ?
Q472. What are the restrictions for the entity classes ?
Q473. What is the difference between int[] x; and int x[]; ?
Q474. What are the annotations used in Junit with Junit4 ?
Q475. What is asynchronous I/O ?
Q476. If there is a conflict between Base Class Method definition and Interface Default method definition, Which definition is Picked ?
Q477. What are new features introduced with Java 8 ?
Q478. Can we have a default method without a Body ?
Q479. Does java allow implementation of multiple interfaces having Default methods with Same name and Signature ?
Q480. What are Default Methods ?
Q481. Can we have a default method definition in the interface without specifying the keyword "default" ?
Q482. Can a class implement two Interfaces having default method with same name and signature ?
public interface DefaultMethodInterface {
default public void defaultMethod(){
System.out.println("DefaultMethodInterface");
}
}
public interface DefaultMethodInterface2 {
default public void defaultMethod(){
System.out.println("DefaultMethodInterface2");
}
}
public class HelloJava8 implements DefaultMethodInterface,DefaultMethodInterface2 {
public static void main(String[] args){
DefaultMethodInterface defMethIn = new HelloJava8();
defMethIn.defaultMethod();
}
}
Q483. What If we make the method as abstract in another Interface ?
public interface DefaultMethodInterface {
default public void defaultMethod(){
System.out.println("DefaultMethodInterface");
}
}
public interface DefaultMethodInterface2 {
public void defaultMethod(){
System.out.println("DefaultMethodInterface2");
}
}
public class HelloJava8 implements DefaultMethodInterface,DefaultMethodInterface2 {
public static void main(String[] args){
DefaultMethodInterface defMethIn = new HelloJava8();
defMethIn.defaultMethod();
}
}
Q484. What if we override the conflicting method in the Class ?
public interface DefaultMethodInterface {
default public void defaultMethod(){
System.out.println("DefaultMethodInterface");
}
}
public interface DefaultMethodInterface2 {
default public void defaultMethod(){
System.out.println("DefaultMethodInterface2");
}
}
public class HelloJava8 implements DefaultMethodInterface,DefaultMethodInterface2 {
public static void main(String[] args){
DefaultMethodInterface defMethIn = new HelloJava8();
defMethIn.defaultMethod();
}
public void defaultMethod(){
System.out.println("HelloJava8");
}
}
Q485. What will happen if there is a default method conflict as mentioned above and we have specified the same signature method in the base class instead of overriding in the existing class ?

Q486. If a method definition has been specified in Class , its Base Class , and the interface which the class is implementing, Which definition will be picked if we try to access it using Interface Reference and Class object ?
Q487. If a method definition has been specified in the Base Class and the interface which the class is implementing, Which definition will be picked if we try to access it using Interface Reference and Class object ?
Q488. Can we use static method definitions in Interfaces ?
Q489. Can we access Interface static method using Interface references ?
Q490. Can we have default method with same name and signature in the derived Interface as the static method in base Interface and vice versa ?
Q491. What is a Lambda Expression ? What's its use ?
Q492. Difference between Predicate, Supplier and Consumer ?
Q493. What does the following lambda expression means ?
helloJava8 ( x-> x%2 )
Q494. What is the difference between namenode and datanode in Hadoop?
Q495. Write a program to see if the number is prefect number or not ?
Q496. Difference between a Pointer and a Reference ?
Q497. Difference between TCP and UDP ?
Q498. What things you would care about to improve the performance of Application if its identified that its DB communication that needs to be improved ?
Q499. Explain Singleton Design Pattern ?






















1. Java OOPS Concepts ?
Ans. Abstraction , Encapsulation , Inheritance and Polymorphism.
2. Difference between Abstract and Concrete Class ?
Ans. Abstract classes are only meant to be sub classed and not meant to be instantiated whereas concrete classes are meant to be instantiated.
3. Difference between Overloading and Overriding ?
Ans.
Overloading - Similar Signature but different definition , like function overloading.
Overriding - Overriding the Definition of base class in the derived class.
4. Types of Inner classes ?
Ans. Simple Inner Class, Local Inner Class, Anonymous Inner Class , Static Nested Inner Class.
5. Difference between TreeMap and HashMap ?
Ans. They are different the way they are stored in memory. TreeMap stores the Keys in order whereas HashMap stores the key value pairs randomly.
6. Difference between List , Sets and Maps ?
Ans. Lists - Members are stored in sequence in memory and can be accessed through index. Sets - There is no relevance of sequence and index. Sets doesn't contain duplicates whereas multiset can have duplicates. Maps - Contains Key , Value pairs.
7. Difference between Private , Public and Protected ?
Ans. Private - Not accessible outside object scope. Public - Accessible from anywhere. Protected - Accessible from anywhere within same package.
8. What is role of Synchronization in Java ?
Ans. Managing exclusive access of the code block to single thread at a time to maintain its integrity.
9. What is Default Access ?
Ans. Accessible only by the objects in the same package.
10. Difference between Vector and ArrayList ?
Ans. Vectors are synchronized whereas Array lists are not.
11. Difference between class and objects ?
Ans. Class is a template using which objects are created in memory.
12. Describe Garbage Collection in Java ?
Ans. Mechanism by which Java reclaims the memory inaccessible by the application.
13. What are the types of Polymorphism in Java ?
Ans. Static ( function overloading ) and Run time ( Virtual functions )
14. Different ways of using threads ?
Ans. Extending Thread class and implementing runnable interface.
15. Difference between Composition and Inheritence ?
Ans. Has a relationship vs Is a relationship.
16. What are Static variables ?
Ans. Correspond to class and not objects. All objects share that variable.
17. Difference between Interfaces and Abstract classes ?
Ans. Abstract classes have a body ( member elements ) where as Interfaces just have methods and static member declarations.
18. Explain Constructor ?
Ans. Its an operation that initializes the object.
19. What is Dynamic Binding ?
Ans. Association of function call to function definition during run time.
20. What is the use of Volatile Keyword ?
Ans. Volatile is a declaration that a variable can be accessed by multiple threads and hence shouldn't be cached
21. Explain Serialization ?
Ans. Storing the state of an object in a file or other medium.
22. What is the use of Transient Keyword ?
Ans. keyword in Java is used to indicate that a field should not be serialized.
23. What are Static Methods ?
Ans. Can only operates on static variables.
25. What is a Final variable ?
Ans. Variable constant. Variable value can't be changed after instantiation.
26. What is a Final Method ?
Ans. Can't be overridden
27. What is a Final Class ?
Ans. Can't be sub classed.
28 What is an Immutable Object ?
Ans. Object that can't be changed after instantiation.
29. Difference between checked and unchecked exceptions ?
Ans. For checked exceptions compiler throws a errors if they are not checked whereas unchecked exceptions and caught during runtime only and hence can't be checked.
30 Give an Example of checked and unchecked exception ?
Ans. ClassNotFoundException is checked exception whereas NoClassDefFoundError is a unchecked exception.
31. What is a Singleton Class ?
Ans. Using which only 1 object can be created.
32. Name few Java exceptions ?
Ans. IndexOutofBound , NoClassDefFound , OutOfMemory , IllegalArgument.
33. Name few Design Patterns used for designing Java applications ?
Ans. Singleton , Factory , Abstract Factory , Proxy , Command , Builder.
34. Give an example of Runtime Polymorphism ?
Ans. Action Mapping in a web application , Generics.
35. Which of the following is tightly bound ? Inheritance or Composition ?
Ans. Inheritence.
36. Give an Example of Generics in Java 5 ?
Ans. List<number> aList = new ArrayList <number>
37. How can we make sure that a code segment gets executed even in case of uncatched exceptions ?
Ans. By putting it within finally.
38. Can a class extend an interface ?
Ans. No Class implement the interface. An interface can extend another interface.
39. Does Java support multiple inheritence ?
Ans. No. We can't extend multiple classes but can implement multiple interfaces.\
40. Can we use an interface reference for referring to an object ?
Ans Yes we can do it for object implementing that interface.
41. What do you mean by return type Void  ?
Ans. Returns Nothing.
42. Is Java Compiled or an Interpreted language ?
Ans Both
43. What is a class file ?
Ans. Compiled Java files.
44. Why Java is a called a platform independent language ?
Ans. Java creates the pre compiled files ( class files ) which can then be interpreted on multiple platforms.
45. Explain the use of "Native" keyword ?
Ans. Used in method declarations to specify that the method is not implemented in the same Java source file, but rather in another language
46. What is "super" used for ?
Ans. Used to access members of the base class.
47. What is "this" keyword used for ?
Ans. Used to represent an instance of the class in which it appears.

48. What is the default value of local variable ?
Ans. The local variables are not initialized to any default value.
49. What will happen if we declare a class abstract as well as final ?
Ans. Compile time error.
50 Encapsulation ?
Ans. Encapsulation is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse
Subscribe to Java News and Posts.
Get latest updates and posts on Java from Buggybread.com
Enter your email address
Delivered by FeedBurner
51. Explain Inheritence ?
Ans. Inheritance is the process by which one object acquires the properties of another object.
52. Explain Polymorphism ?
Ans. Polymorphism is the feature that allows one interface to be used for general class actions
53. Difference between assignment and initialization ?
Ans. Assignment can be done anytime but initialization can be done only once during object instantiation.
54. Difference between boolean and Boolean ?
Ans. boolean is a primitive type whereas Boolean is a class.
55. What is an Immutable object ?
Ans. Objects that can't be changed after initialization.
56. Give an example of immutable class ?
Ans. String
57. What is Casting ?
Ans. Process to convert one data type to another.
58. Explain Finalize () ?
Ans. finalize() method is used just before an object is destroyed.
59. What are Marker Interfaces ?
Ans. These are the interfaces which have no declared methods.
60. Name few Java marker interfaces ?
Ans. Serializable and cloneable.
61. Is runnable a Marker interface ?
Ans. No , it has run method declared.
62. Difference between String and StringBuffer ?
Ans. String is an immutable class where StringBuffer is not.
63. Difference between Process and Thread ?
Ans. Process is a program in execution whereas thread is a separate path of execution in a program.
64. Explain Thread states ?
Ans. ready, running, waiting and dead.
65. What is a Deadlock ?
Ans. When two threads are waiting each other and can’t precede the program is said to be deadlock.
66. Difference between Serialization and Deserialization ?
Ans. Serialization is the process of writing the state of an object to a byte stream. Deserialization is the process of restoring these objects.
67. Difference between Java 1.4 and Java 5 ?

Ans. Generics , Autoboxing , Enum and Static Imports.
68. Explain Autoboxing ?
Ans. Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes
69. What is an Enum type ?
Ans. An enum type is a special data type that enables for a variable to be a set of predefined constants
70. What are Wrapper Classes ?
Ans. A wrapper class is any class which "wraps" or "encapsulates" the functionality of another class or component.
71. What are Primitive Wrapper Classes ?
Ans. A Wrapper Class that wraps or encapsulates the primitive data type.
72. Wat is automatic conversion of primitive data type to its Wrapper class called ?
Ans. Autoboxing.
73. What Design pattern Wrapper Classes implement ?
Ans. Adapter.
74. What is "Import" used for ?
Ans. Enables the programmer to abbreviate the names of classes defined in a package.
75. Explain Servlet Chaining ?
Ans. Servlet chaining is a technique in which two or more servlets can cooperate in servicing a single request.
76. What is the difference between set and list?
Ans. Set stores elements in an unordered way but does not contain duplicate elements, whereas list stores elements in an ordered way but may contain duplicate elements. List can also holds null elements while Set can't.
77. Difference between HashMap and HashTable ?
Ans. The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.
78. What is an Iterator ?
Ans. Some of the collection classes provide traversal of their contents via a java.util.Iterator interface. This interface allows you to walk through a collection of objects, operating on each object in turn.
79. What is JVM ?
Ans. Java Virtual Machine or JVM is an abstract which provides the runtime environment for the Java byte code to run.
80. What is JDK ?
Ans. Java Development Kit or JDK is physical entity that comprises of JRE and Development Tools.
81. What is JRE ?
Ans. Java Run Time Environment is the implementation of JVM.
82. Different types of memory used by JVM ?
Ans. Class , Heap , Stack , Register , Native Method Stack.
83. What is a Class Loader ?
Ans. Part of JVM which is used to load classes and interfaces.
84. Does Static Public Void instead of Public static Void gives compilation error ?Ans. No
85. Does constructor returns any value ?
Ans. Yes , the current instance or object of the class.
86. Can we make constructor final ?Ans. No
87. Why main method is static ?
Ans. Object needs to be created for calling non static methods.
88. What is a Static Block ?
Ans. It is executed before main method at the time of class loading.
89. Can we execute program without mail method ?
Ans. Yes , one way is through static block.
90. What is Cloning ?
Ans. Keyword to create the exact copy of the object.
91. Can we overload main method ?Ans. Yes.
92. Can we declare main method as final ?Ans. Yes.
93. What is Static binding ?
Ans. Associating function call and its definition during compile time.
94. What is Dynamic Binding ?
Ans. Associating function call and its definition during runtime.
95. Can we declare an interface method static ?Ans. No
96. Can an interface be final ?Ans. No
97. Can we declare interface methods as private ?Ans. No, they are implicitely public.
98. What is a Static import ?
Ans. By static import , we can access the static members of a class directly without prefixing it with the class name.
99. Base class for Error and Exceptions ?Ans. Throwable
100. Difference between StringBuffer and StringBuilder ?
Subscribe to Java News and Posts.
Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
Ans. StringBuffer is synchronized whereas String Builder is not.
101. Default Package for Collection classes ?Ans. Java.Util
102. Difference between List and Queue ?
Ans. In queue access can only happen at the ends whereas we can access any element of the list.
103. Difference between Vector and ArrayList ?
Ans. Vectors are synchronized whereas ArrayList are not.
104. Which is the base interface for all collection classes ?
Ans. Collection interface.
105. How can we make HashMap synchronized ?
Ans. Map m = Collections.synchronizedMap(hashMap);
106. Difference between Map and HashMap ?
Ans. Map is an interface where HashMap is the concrete class.
107. Property Class ?
Ans. The properties class is a subclass of Hashtable that can be read from or written to a stream.
108 Why Java is a preferred technology for Web Applications ?
Ans. Web application involves dealing with multiple requests and thread and hence deals with lot of memory allocation and de allocation. Hence Java with its intrinsic capability of Garbage collection offer a perfect platform.

109. What are concepts introduced with Java 5 ?
Ans. Generics , Enums , Autoboxing , Annotations and Static Import.
110. Difference between get and post ?
Ans. Request parameters in get are passed within url whereas with post these are passed within post body as object.
111. Difference between C++ and Java ?
Ans. We have pointers in C++ , We have garbage collection in Java.
112. Name few Design Patterns ?
Ans. Singleton , Adapter , Factory , Abstract Factory , Builder , Facade , Observer , Proxy , Prototype.
113. Give an Example of Factory Design Pattern ?
Ans. Action Mapping within Web Application.
114. Give an example of Adapter design pattern ?
Ans. Wrapper Classes.
115. Can we override static methods ?Ans. No
116. What precaution should be used while dealing with static variables ?
Ans. Static variables are shared by all objects of the class and hence each instance may update it with its local value.
117. Can we override main method ?Ans. No
118. Difference between server side and client side validation ?
Ans. Client side validation is done using scripting technologies like javascript before the form is submitted to server whereas server side validation is done after the form is submitted to server.
119. Difference between sleep and wait ?
Ans. Sleep puts thread aside for exactly the time specified. Wait causes a wait of up to time specified. A thread could stop waiting earlier if it receives the notify() or notifyAll() call.
120. Name Wrapper classes available for primitive types ?
Ans.
boolean  - java.lang.Boolean
byte - java.lang.Byte
char - java.lang.Character
double - java.lang.Double
float - java.lang.Float
int - java.lang.Integer
long - java.lang.Long
short - java.lang.Short
void - java.lang.Void
121. Explain System.out.println ?
Ans. System is the class having static variable out that defaults to system console and println is the overloaded method.
122. Explain public static void main() ?
Ans. public means it has public access, static means that the method can be invoked without instantiating the object, void means it returns nothing.
123. What is Java Byte Code ?
Ans. Java bytecode is the form of instructions that the Java virtual machine executes.
124. What is the relation between class file and byte code ?
Ans. Class files holds the instructions in byte code.
125. How can we make the object immutable ?

Ans. By making it a final class and making all members as private with those being initialized through constructor.
126. What is the purpose of making an object immutable ?
Ans. Since they cannot change state, they cannot be corrupted by thread interference or observed in an inconsistent state.
127. Explain the scenerios to choose between String , StringBuilder and StringBuffer ?
Ans.
    If the Object value will not change in a scenario use String Class because a String object is immutable.
    If the Object value can change and will only be modified from a single thread, use a StringBuilder because StringBuilder is unsynchronized(means faster).
    If the Object value may change, and can be modified by multiple threads, use a StringBuffer because StringBuffer is thread safe(synchronized).
128. Explain java.lang.OutOfMemoryError ?
Ans. This Error is thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.
129. Difference between arraylist and linkedlist ?
Ans. Array list maintains indices like array whereas Linked List maintain pointers to the next element.
130. Difference between hashtable and hashmap ?
Ans. Hashtable are synchronized whereas hashmaps are not. Hashtable doesn't allow null values whereas HashMaps allows null values.
131. Can we have multiple servlets in a web application and How can we do that ?
Ans. Yes by making entries in web.xml
132. Are static members serialized ?
Ans. Static members don't belong to a object and hence are not serialized.
133. How can we manage Error Messages in the web application ?
Ans. Within message.properties file.
134. What is the use of Marker interface if they don't hold anything ?
Ans. As the name suggest , They just mark a class and just indicate something to compiler and JVM.
135. Is JVM, a compiler or interpretor ?Ans. Its an interpretor.
136. Is Synchronization an overhead ?
Ans. Synchronization has relevance only if a code segment can be accessed by multiple threads and hence may result in ambiguity. Yes Its an overhead if simultaneous access doesn't pose any problem.
137. Difference between implicit and explicit type casting ?
Ans. An explicit conversion is where you use some syntax to tell the program to do a conversion whereas in case of implicit type casting you need not provide the data type.
138. Can we have an abstract class without abstract methods ?Ans. Yes
139. Can we have abstract methods in a class which is not Abstract ?Ans. No
140. Are list , Map and Set Classes or Interfaces ? Ans. These are interfaces.
141. Difference between .equals and == ?
Ans. .equals is the method of object class and is used to match the content of object whereas == matches the objects itself. So == looks to see if they are same object.
142. What are the methods of Object class ?
Ans. toString , clone , finalize , hashcode , equals.
143. What are the class loaders ?
Ans. JVM loads the classes through class loaders.

144. What are the different class loaders used by JVM ? Ans. Bootstrap , Extension and System.
145. difference between loadClass and Class.forName ?
Ans. loadClass only loads the class but doesn't initialize the object whereas Class.forName initialize the object after loading it.
146. How do we load the DB drivers ?Ans. Using Class.forName
147. Have you ever destroyed objects yourself ?
Ans. Java by its mechanism of Garbage collection does this itself.
148. Should we override finalize method ?
Ans. Finalize is used by Java for Garbage collection. It should not be done as we should leave the Garbage Collection to Java itself.
149. Will finally be executed for handled or unhandled exceptions ?
Ans. Both.
150. Difference between protected and default Modifier ?
Ans. With protected member is accessible in subclass whereas with Default Member is not accessible in subclass.
151. Can we overload methods on a single parameter with data types as int and long. For example - int calculate(int x) and int calculate(long x)  ?Ans. Yes
152. What will happen if we call such method using a number lets say calculate(5) ?
Ans. It will call first method with int argument.
153. Then whats the use of second method. Will that ever be called ?
Ans. we can call by having argument as 5L.
154. What is servlet Chaining ?
Ans. Multiple servlets serving the request in chain.
155. In the following code
String str1 = new String("abc");
String str2 = new String("abc");
Which of the following will be true.
str == str2
str.equal(str2)
Ans. str.equal(str2) will be true but str==str2 will be false
156. In the following code
String str1 = new String("abc");
String str2 = new String("xyz");
str1=str2;
Which of the following will be true.
str == str2
str.equal(str2)
Ans. both str.equal(str2) and str==str2 will be true
157. What is keyword instanceOf used for ?
Ans.  It is used to see if an object is an instance of a specific class.
158. If we obj is an object of Class A and Class A extends Class B , What will obj instanceof B will return ?
Ans. True
159. What is assert keyword used for ?

Ans. The assert keyword is used to make an assertion—a statement which the programmer believes is always true at that point in the program. This keyword is intended to aid in testing and debugging.
160. Any example of Serialization in your application ?
Ans. Properties Class.
161. Difference between Factory and Abstract Factory Design Pattern ?
Ans. Factory Pattern deals with creation of objects delegated to a separate factory class whereas Abstract Factory patterns works around a super-factory which creates other factories.
162. Difference between Factory and Builder Design Pattern ?
Ans. Builder pattern is the extension of Factory pattern wherein the Builder class builds a complex object in multiple steps.
163. Difference between Proxy and Adapter ?
Ans. Adapter object has a different input than the real subject whereas Proxy object has the same input as the real subject. Proxy object is such that it should be placed as it is in place of the real subject.
164. Difference between Adapter and Facade ?
Ans. The Difference between these patterns in only the intent. Adapter is used because the objects in current form cannot communicate where as in Facade , though the objects can communicate , A Facade object is placed between the client and subject to simplify the interface.
165. Difference between Builder and Composite ?
Ans. Builder is a creational Design Pattern whereas Composite is a structural design pattern. Composite creates Parent - Child relations between your objects while Builder is used to create group of objects of predefined types.
166. Example of Chain of Responsibility Design Pattern ?
Ans. Exception Handling Throw mechanism.
167. Example of Observer Design Pattern ?
Ans. Listeners.
168. Difference between Factory and Strategy Design Pattern ?
Ans. Factory is a creational design pattern whereas Strategy is behavioral design pattern. Factory revolves around the creation of object at runtime whereas Strategy or Policy revolves around the decision at runtime.
169. Shall we use abstract classes or Interfaces in Policy / Strategy Design Pattern ?
Ans. Strategy deals only with decision making at runtime so Interfaces should be used.
170. Which kind of memory is used for storing object member variables and function local variables ?
Ans. Local variables are stored in stack whereas object variables are stored in heap.
171. Why do member variables have default values whereas local variables don't have any default value ?
Ans. member variable are loaded into heap, so they are initialized with default values when an instance of a class is created. In case of local variables, they are stored in stack until they are being used.
172. What is the default value for Object Reference in Java ?Ans. Null
173. What is a Default Constructor ?
Ans. The no argument constructor provided by Java Compiler if no constructor is specified.
174. Will Compiler creates a default no argument constructor if we specify only multi argument constructor ?
Ans. No, Compiler will create default constructor only if we don't specify any constructor.
175.  Can we overload constructors ?Ans. Yes.
176. What will happen if we make the constructor private ?
Ans. We can't create the objects directly by invoking new operator.
177. How can we create objects if we make the constructor private ?
Ans. We can do so through a static public member method.
178. Is that the only way to initialize the object in that case ?
Ans. We can also do so using static block.
179. Is constructor inherited ?Ans. No
180. What will happen if we remove the static keyword from main method ?
Ans. Program will compile but will give a "NoSuchMethodError" during runtime.
181. Which is the super class of all classes in java ?
Ans. Object Class
182. Why Java don't use pointers ?
Ans. Pointers are vulnerable and slight carelessness in their use may result in memory problems and hence Java intrinsically manage their use.
183. Can we use both "this" and "super" in a constructor ?
Ans. No, because both this and super should be the first statement.
184. Can we achieve runtime polymorphism by data members ?Ans. No
185. Do we need to import java.lang.package ?Ans. No, It is loaded by default by the JVM.
186. Can i import same package / class twice ?
Ans. Compiler doesn't give any error if we try to import same package or class twice but internally JVM will load the class only once.
187. Is it necessary that each try block to be followed by catch block ?Ans. It should be followed by either catch or finally block.
188. Can finally block be used without catch ?Ans. Yes but should follow "try" block then.
189. Can an exception be rethrown ?Ans. Yes
190. What is exception propogation ?
Ans. Passing the exception object to the calling method.
191. What is the use of toString method ?
Ans. It provides the string representation of an object.
192. Difference between nested and inner classes ?
Ans. Inner classes are non static nested classes.
193. What is a nested interface ?
Ans. Any interface declared inside a class or an interface. It is static by default.
194. Can an unreferenced object be referenced again ?
Ans. Yes.
195. What kind of thread is garbage collector thread ?
Ans. Dameon Thread.
196. What is an Externalizable interface ?
Ans. Externalizable interface is used to write the state of an object into a byte stream in compressed format.
197. Difference between serializable and externalizable interface ?
Ans. Serializable is a marker interface whereas externalizable  is not.
198. What is reflection ?
Ans. It is the process of examining / modifying the runtime behaviour of an object at runtime.
199. What is the purpose of System Class ?
Ans. To provide access to the system resources.
200. What is Locale ?
Ans. A Locale object represents a specific geographical, political, or cultural region. 
201. Situations where "this" keyword can be used ?
Ans.
a. While accessing the member variable having same name as local variable.
b. constructor chaining
c. pass the current object as a parameter to another method.
202. Can we declare interface method's private ?
Ans. No
203. What is the problem with following code ?
if(x == null && x.getMethod() == true)
Ans. It will throw NPE in case x is null.
204. Can we instantiate the object of derived class if parent constructor is protected ?
Ans. Yes.
206. Can we declare an abstract method private ?
Ans. No Abstract methods can only be declared protected or public.
207. Can Abstract methods in parent class have a body ?Ans. No.
208. Can we declare a class static ?
Ans. We cab only declare the inner class as static but not the top level class.
209. Can we reduce the visibility of the overridden method ?Ans. No.
210. Can we make an object final i.e immutable using final keyword ?
Ans. No, only object reference can be made final. This means that the reference cannot be reassigned.
211. What are the design considerations while making a choice between using interface and abstract class ?
Ans. Keep it as a Abstract Class if its a "Is a" Relationsship and should do subset/all of the functionality. Keep it as Interface if its a "Should Do" relationship.
Read Full