Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| ||||
Interview Questions and Answers - Order By Rating | ||||
| ||||
Ans. return is used within a method to return control out of the method. It may be followed by a value which is returned from the method to calling method immediately preceding the point of call. continue statement is used within a loop to start next iteration without executing the remaining statements in the loop. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  return statement  continue statement  return vs continue  for loop  control statements  loop statement | ||||
| ||||
Ans. Getting parent class object properties into child class is called Inheritance. The process of representing one form into multiple forms is called polymorphism. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  inheritance  object oriented programming (oops)  oops concepts  polymorphism  object oriented programming (oops)  oops concepts Asked in 1 Companies Basic   frequent | ||||
| ||||
Ans. Infinite loop is a programming condition wherein the control goes into an infinite loop because the loop termination condition can never be met. For example - for(int x=1;x>0;x++){ } in this loop, with each increment the condition x > 0 will remain true till infinity. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  loop  infinite loop  for loop  control statements  loop statement basic | ||||
| ||||
Ans. for, while and do while | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  loops  different type of loops  for loop  control statements  loop statement basic | ||||
| ||||
Ans. You can implement encapsulation in Java by keeping the fields (class variables) private and providing public getter and setter methods to each of them. Java Beans are examples of fully encapsulated classes. Encapsulation in Java: Restricts direct access to data members (fields) of a class. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  oops  oops example  oops concepts  oops features Asked in 2 Companies basic   frequent | ||||
| ||||
Ans. OOPs or Object Oriented Programming is a Programming model which is organized around Objects instead of processes. Instead of a process calling series of processes, this model stresses on communication between objects. Objects that all self sustained, provide security by encapsulating it's members and providing abstracted interfaces over the functions it performs. OOP's facilitate the following features 1. Inheritance for Code Reuse 2. Abstraction for modularity, maintenance and agility 3. Encapsulation for security and protection 4. Polymorphism for flexibility and interfacing | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  oops  oops features Asked in 260 Companies basic   frequent | ||||
Very frequently asked. Usually among very first few questions. | ||||
| ||||
Ans. Encapsulation is a feature of OOP's that binds the data and it's associated methods together as a single unit and facilitate protection and data hiding by providing minimal interface to outside. For example - member variables are declared private and are accessed through public methods. Moreover we have private methods that can only be used internally and hence providing minimal interface to outside class through use of public methods. | ||||
Sample Code for encapsulation | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  encapsulation  object oriented programming (oops)  oops concepts  oops  oops concepts  oops features Asked in 4 Companies Basic   frequent | ||||
| ||||
Ans. By encapsulating it within another class and declaring it private. In such a case, it will only be accessible through parent class or parent class object. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  private class   private inner class  class hiding  encapsulation  object oriented programming (oops)  oops concepts  inner classes   nested classes | ||||
| ||||
Ans. Private variables are not inherited. They are simply ignored and not made part of the derived object body. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  private variables  inheritance  object oriented programming (oops)  oops concepts | ||||
| ||||
Ans. Dynamic dispatch in java is also known as runtime polymorphism.It is a process in which a call to an overriden method is resolved at runtime. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  dynamic dispatch  runtime polymorphism  object oriented programming (oops)  oops concepts | ||||
| ||||
Ans. TakeScreenshot th = TakeScreenshot(driver); //Enable the driver object to take screenshot File src = th.getScreenShotAs(OutputType.FILE); FileUtils.copyFilesrc("locationWhereUWantToPlaceTheScreenshot.jpg"); | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  webdriver  selenium Asked in 1 Companies | ||||
| ||||
Ans. dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time. This is used to achieve runtime polymorphism in java. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  overriding  runtime polymorphism  object oriented programming (oops)  oops concepts | ||||
| ||||
Ans. Java identifies the method to be called at runtime by the object that is being referenced. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  polymorphism  object oriented programming (oops)  oops concepts  overloading  overriding basic | ||||
| ||||
Ans. runtime polymorphism or method overriding doesn't require method name and signature to be different whereas compile time polymorphism or method overloading requires method name to be same but the signature to be different. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  polymorphism  object oriented programming (oops)  oops concepts  overloading  overriding basic | ||||
| ||||
Ans. Counter controlled repetitions are the loops that are controlled with the use of counters or the loops where the number of repetitions are known in advance. for loop in java is the counter controlled repetition. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  for loop  control statements  loop statement | ||||
| ||||
Ans. I would avoid that. If we need to initialize member elements differently on the basis of some condition, I would prefer having overloaded constructors. I don't see a need to have a loop for initializing member elements unless the count of elements is huge and they all need to be initialized with common value. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  design constructor  for loop | ||||
| ||||
Ans. Generally one reducer runs for all mappers, but it can be increased as per requirements. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  Hadoop  BigData Asked in 1 Companies | ||||
| ||||
Ans. Composition and Inheritance are the different types of Associations for Classes. Composition is a has-a association between classes. Inheritance is a is-a association between classes. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  composition  object oriented programming (oops)  oops concepts  inheritance  object oriented programming (oops)  oops concepts  association  relationship between objects | ||||
| ||||
Ans. Abstraction, Encapsulation, Polymorphism , Composition and Inheritance | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  core oops concepts Asked in 65 Companies basic   frequent | ||||
| ||||
Ans. Web Framework - Spring , Struts, Play Dependency Injection frameworks - Google Guice , PicoContainer and Dagger ORM Framework - Hibernate Big Data / ETL Frameworks - Apche Hadoop , Apache Crunch, Apache Spark. View Frameworks - JSF , Apache Wicket,jtwig. Java Gui Frameworks - SWT , AWT, JavaFX Testing - Junit, Mockito, PowerMock, EasyMock, JMock, JMockit Rest Web services - Jersey , Restlet , RestX, RestEasy ,Restfulie Here is the big list for reference - http://javasearch.buggybread.com/home2.php?keyword= | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  frameworks Asked in 2 Companies intermediate   frequent | ||||
| ||||
Ans. class A { void test() { System.out.println("test() method"); } } class B { void test() { System.out.println("test() method"); } } Suppose if Java allows multiple inheritance like this, class C extends A, B { } A and B test() methods are inheriting to C class. So which test() method C class will take? As A & B class test() methods are different , So here we would Facing Ambiguity. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  multiple inheritance  object oriented programming (oops)  oops concepts  diamond problem Asked in 20 Companies basic   frequent | ||||
| ||||
Ans. 1. for loop in java is used with a counter as following for(int counter=0;counter < 50;counter++){ System.out.println(list.get(counter)); } for iterating and printing the contents of a collection whereas foreach loop can be specified directly without the use of counter for(String str:list){ System.out.println(list.get(counter)); } 2. for Each loop syntax is more clean if we have to iterate over the elements of a collection and we need not keep track of the record count 3. For is preferred when we need loops without the usage of collections or Array of objects and entirely primitives are being used 4. for loop is preferred if we need to keep track of record count and have to perform some action of the basis of that. For example - If we have to print something after every 5 records, With for each loop in such case, we will have to keep a separate counter. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  loop  for loop  control statements  loop statement  foreach loop  for vs foreach loop | ||||
| ||||
Ans. Yes, we can do that. Compiler wont complain. But using object reference we can only access methods which have been defined for object class i.e clone(), equals(), hashCode(), toString() etc. We cannot access methods defined in String class or in any class in hierarchy between String and Object. For example - we cannot do obj.append("abc") as it will now give compile time error. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  object initialization  object declaration   runtime polymorphism  object oriented programming (oops)  oops concepts | ||||
Basic and Very Frequently asked. | ||||
| ||||
Ans. Polymorphism means the condition of occurring in several different forms. Polymorphism in Java is achieved in two manners 1. Static polymorphism is the polymorphic resolution identified at compile time and is achieved through function overloading whereas 2. Dynamic polymorphism is the polymorphic resolution identified at runtime and is achieved through method overriding. | ||||
Sample Code for overloading Sample Code for overriding | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  polymorphism  object oriented programming (oops)  oops concepts  oops concepts Asked in 108 Companies Basic   frequent | ||||
Try 2 Question(s) Test | ||||
Very Frequently asked to fresh graduates and less experienced. | ||||
| ||||
Ans. Abstraction Polymorphism Inheritance Encapsulation | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  oops  oops concepts Asked in 1 Companies basic   frequent | ||||
| ||||
Ans. Combiners are used to increase the efficiency of a Map Reduce program. They are used to aggregate intermediate map output locally on individual mapper outputs. Combiners can help you reduce the amount of data that needs to be transferred across to the reducers. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  Hadoop Systems  BigData   hadoop combiners Asked in 1 Companies | ||||
| ||||
Ans. Hadoop is an open source framework , written in java by apche software foundation. This framework is used to write applications to process vast amount of data. Processing happens in parallel on large clusters which could have 1000 of computers. It processes data in a very reliable and fault tolerant manner. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  Hadoop framework  BigData | ||||
| ||||
Ans. Distributed file system and Map Reduce system. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hadoop  bigdata  hadoop system components   frequent | ||||
| ||||
Ans. Multiple Inheritance refers to the concept of a class inheriting multiple classes. Example - Class C extends Class A ,Class B. This is not allowed in Java. Multilevel Inheritance refers to the concept of Inheritance in a chain. Example - Class B extends Class A, Class C extends Class B. This is permitted in Java. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  inheritance  object oriented programming (oops)  oops concepts   multiple inheritance  object oriented programming (oops)  oops concepts   multi level inheritance  object oriented programming (oops)  oops concepts Basic   frequent | ||||
| ||||
Ans. No, If both Parent and Derived are outer classes. public class Vehicle { private static String manufacturingDate = "2016"; } public class Car extends Vehicle{ public static void main(String args[]){ System.out.println(manufacturingDate); // error - The field Vehicle.manufacturingDate is not visible } } Yes, If derived is the inner class of Parent. public class Vehicle { private static String manufacturingDate = "2016"; static public class Car extends Vehicle{ public static void main(String args[]){ System.out.println(manufacturingDate); // no problem } } } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  private members   private methods   private variables   inheritance  object oriented programming (oops)  oops concepts   members visibility   inner classes  nexted classes basic   frequent | ||||