Interview Questions and Answers - Order By Rating Q1501. Does Declaring an object "final" makes it immutable ? Core Java
Ans. Only declaring variables as final makes them immutable. Making objects final means that the object handler cannot be used to target some other object but the object is still mutable. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   final   immutable  immutability   immutable  immutability object Q1502. Can we access instance variables within static methods ? Core Java
Ans. Yes.we cannot access them directly but we can access them using object reference.Static methods belong to a class and not objects whereas non static members are tied to an instance. Accessing instance variables without the instance handler would mean an ambiguity regarding which instance the method is referring to and hence its prohibited. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   static   static methods   java keywords Asked in 1 Companies Q1503. Give an Example of checked and unchecked exception ? Core Java
Ans. ClassNotFoundException is checked exception whereas NoClassDefFoundError is a unchecked exception. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   exceptions   checked exceptions   unchecked exceptions   exception handling Asked in 2 Companies Q1504. How can we make sure that a code segment gets executed even in case of uncatched exceptions ?
Ans. By putting it within finally. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   exceptions   finally   uncatched exceptions basic   frequent Q1505. What is "super" used for ?
Ans. Used to access members of the base class. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   java keywords   super   basic interview question Asked in 2 Companies basic   frequent Q1506. Difference between boolean and Boolean ? Core Java
Ans. boolean is a primitive type whereas Boolean is a class. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   wrapper classes   boolean vs Boolean basic   rare Ans. finalize() method is called just before an object is destroyed. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   finalize   garbage collection   basic interview question Asked in 1 Companies basic   frequent Try 1 Question(s) TestVery frequently asked in phone and walk in interviews. Q1508. What are Marker Interfaces ? Name few Java marker interfaces ? Core Java
Ans. An interface without any method declaration is called as marker interface. there are 3 in-built interfaces in JVM i.e. serializable, clonable, remote Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   interfaces   marker interface   serializable   clonable Asked in 21 Companies intermediate   frequent Try 1 Question(s) Test Q1509. Is runnable a Marker interface ? Core Java
Ans. No , it has run method declared. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   interfaces   marker interface   runnable   yes-noFrequently asked to fresh graduates. Ans. Process is a program in execution whereas thread is a separate path of execution in a program. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   threads   multi threading   operating system   process vs thread Asked in 24 Companies basic   frequent Frequently asked to fresh graduates. Ans. When two threads are waiting each other and cant precede the program is said to be deadlock. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   threads   multi threading   operating system   deadlock  concurrency Asked in 23 Companies basic   frequent Q1512. Difference between Serialization and Deserialization ? Core Java
Ans. Serialization is the process of writing the state of an object to a byte stream. Deserialization is the process of restoring these objects. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   serialization   deserialization   serialization vs deserialization Asked in 2 Companies basic   frequent Try 1 Question(s) TestAns. Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   java5   autoboxing   wrapper classes Asked in 2 Companies basic   frequent Q1514. What are Wrapper Classes ? What are Primitive Wrapper Classes ? Core Java
Ans. A wrapper class is any class which "wraps" or "encapsulates" the functionality of another class or component. A Wrapper Class that wraps or encapsulates the primitive data type is called Primitive Wrapper Class. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   wrapper classes   primitive wrapper classes Q1515. What Design pattern Wrapper Classes implement ? Design
Ans. Adapter. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   wrapper classes   adapter design pattern   design pattern Q1516. Different types of memory used by JVM ? Core Java
Ans. Class , Heap , Stack , Register , Native Method Stack. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   jvm   memory management   memory   advanced   architecture   technical architect Asked in 1 Companies intermediate   frequent Try 5 Question(s) Test Q1517. What is a class loader ? What are the different class loaders used by JVM ? Core Java
Ans. Part of JVM which is used to load classes and interfaces.
Bootstrap , Extension and System are the class loaders used by JVM. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   class loaders  classloaders   jvm   java memory management   advanced Asked in 3 Companies Ans. By static import , we can access the static members of a class directly without prefixing it with the class name. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   java5   static import   static   java keyword   static import Asked in 4 Companies basic   frequent Very frequently asked. Usually difference between String,StringBuffer and StringBuilder is asked in different variations. Q1519. Difference between StringBuffer and StringBuilder ? Core Java
Ans. StringBuffer is synchronized whereas StringBuilder is not. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   string   stringbuffer   string class   stringbuilder   synchronized   basic interview question   infosys technologies Asked in 17 Companies basic   frequent Try 1 Question(s) Test Q1520. Difference between Map and HashMap ? Core Java
Ans. Map is an interface where HashMap is the concrete class. Sample Code for map Sample Code for hashmap Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   hashmap   map basic   frequent Ans. The properties class is a subclass of Hashtable that can be read from or written to a stream. Sample Code for Load Properties using Property Class Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   hashtable   map   synchronization   synchronizedVery frequently asked in different variations. Frequently asked in Deloitte ( 2 feedback ) , HCL Tech ( 3 feedback ), TCS and Coginizant (CTS) Q1522. Explain the scenerios to choose between String , StringBuilder and StringBuffer ?
or
What is the difference between String , StringBuilder and StringBuffer ? Core Java
Ans. If the Object value will not change, 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 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). Sample Code for String Sample Code for StringBuffer Sample Code for StringBuilder Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   string class   string   stringbuilder   stringbuffer   String vs StringBuffer   String vs StringBuilder   String vs StringBuilder vs StringBuffer   StringBuffer vs stringBuilder Asked in 29 Companies basic   frequent Try 3 Question(s) Test Q1523. Can we have multiple servlets in a web application and How can we do that ? Java EE
Ans. Yes by making entries in web.xml Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  j2ee   servlets   servelets   web application   java   web.xml   yes-no   architecture Q1524. How can we manage Error Messages in the web application ? Solution
Ans. Within message.properties file. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  j2ee   web application   struts   spring Asked in 1 Companies Frequently asked to fresh graduates. Q1525. Is JVM, a compiler or interpretor ?
Ans. Its an interpretor. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   jvm   compiler   interpretor basic   frequent Q1526. 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. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   class loaders   jvm   advanced Q1527. 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. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   garbage collection   java memory management   finalize Try 2 Question(s) Test Q1528. Difference between Factory and Builder Design Pattern ? Design
Ans. Builder pattern is the extension of Factory pattern wherein the Builder class builds a complex object in multiple steps. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   design pattern   factory design pattern   builder design pattern Asked in 1 Companies expert Q1529. 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. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   design pattern   builder   composite   creational design pattern   structural design pattern Q1530. Example of Chain of Responsibility Design Pattern ?
Ans. Exception Handling Throw mechanism. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   design pattern   chain of responsibility expert