Interview Questions and Answers - Order By Rating Q781. 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 Q782. Can we declare interface methods as private ?
Ans. With Java 9 we can declare interface methods as private Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   interfaces   yes-no   privateAns. 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. Q784. 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) TestAns. 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) Q786. 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 Q787. 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 Q788. 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 Q789. Difference between Factory and Abstract Factory Design Pattern ? Design
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. 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   abstract factory design pattern   factory vs abstract factory expert Q790. 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 Q791. Difference between Proxy and Adapter ? Design
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. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   design pattern   proxy   adapter   proxy vs adapter expert Q792. Difference between Adapter and Facade ? Design
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. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   design pattern   adapter   facade expert Q793. 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 Q794. 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 Q795. Example of Observer Design Pattern ?
Ans. Listeners. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   design pattern   listeners   observer design pattern expert Q796. Difference between Factory and Strategy Design Pattern ? Design
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. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   design pattern   factory   strategy   creational design pattern   behavioral design pattern Asked in 1 Companies expert Q797. 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. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   design pattern   strategy design patterm expert Q798. What will happen if we make the constructor private ? Core Java
Ans. We can't create the objects directly by invoking new operator. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   constructor   access specifier   private Asked in 1 Companies basic Try 2 Question(s) Test Q799. How can we create objects if we make the constructor private ? Core Java
Ans. We can do so through a static public member method or static block. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   static   constructor   static method   static block  private Asked in 1 Companies Q800. 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. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   jvm   memory management   pointers intermediate Q801. Can we use both "this()" and "super()" in a constructor ? Core Java
Ans. No, because both this and super should be the first statement. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops  this   super   constructor Asked in 1 Companies intermediate   rare Try 2 Question(s) Test Q802. Is it necessary that each try block to be followed by catch block ? Core Java
Ans. It should be followed by either catch or finally block. Sample Code for Retry in case of exception Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   exceptions   exception handling   try   catch   finally  Oracle OCA Test Asked in 3 Companies basic   frequent Try 1 Question(s) Test Q803. Can finally block be used without catch ? Core Java
Ans. Yes but should follow "try" block then. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   exceptions   exception handling   try   catch   finally   yes-no Try 1 Question(s) Test Q804. Difference between nested and inner classes ?
Ans. Inner class is a type of nested class.
Inner classes are non static nested classes i.e the one that are associated with the instance of outer class. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   static   nested classes   inner classes   nested vs inner class basic   frequent Try 1 Question(s) Test Q805. What is an Externalizable interface ?
Ans. Externalizable interface is used to write the state of an object into a byte stream in compressed format. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   serialization   externalizable interface   interface Asked in 3 Companies Q806. Difference between serializable and externalizable interface ?
Ans. Serializable is a marker interface whereas externalizable is not. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   serialization   externalizable   interface   marker interface Q807. What is reflection ?
Ans. It is the process of examining / modifying the behaviour of an object at runtime. Sample Code for reflection Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   reflection   reflection api   ebay   mindtree Asked in 29 Companies basic   frequent Q808. Can we instantiate the object of derived class if parent constructor is protected ? Core Java
Ans. Yes, as protected constructor is accessible in sub class. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   constructor   access specifier   protected   yes-no  private constructor Q809. Can we declare an abstract method private ?
Ans. No Abstract methods can only be declared protected or public. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   abstract   oops   access specifier   private   yes-no intermediate   rare Q810. What are the design considerations while making a choice between using interface and abstract class ? Core Java
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. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   abstract classes   interfaces   advanced Asked in 3 Companies