Interview Questions and Answers for 'MIT' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

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.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'MIT' - 19 question(s) found - Order By Newest

Advanced level question. Frequently asked in High end product companies. Frequently asked in Google , Cognizant and Deloitte ( Based on 2 feedback )
  Q1. Why is String immutable in Java ?Core Java
Ans. 1. String Pool - When a string is created and if it exists in the pool, the reference of the existing string will be returned instead of creating a new object. If string is not immutable, changing the string with one reference will lead to the wrong value for the other references.

Example -

String str1 = "String1";
String str2 = "String1"; // It doesn't create a new String and rather reuses the string literal from pool

// Now both str1 and str2 pointing to same string object in pool, changing str1 will change it for str2 too

2. To Cache its Hashcode - If string is not immutable, One can change its hashcode and hence it's not fit to be cached.

3. Security - String is widely used as parameter for many java classes, e.g. network connection, opening files, etc. Making it mutable might possess threats due to interception by the other code segment.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   string   string class   immutable  immutability   advanced     Asked in 39 Companies      expert        frequent

Try 4 Question(s) Test


Frequently asked to fresh graduates and less experienced developers. Among the first few questions in many interviews.
  Q2. What are the difference between composition and inheritance in Java?Core Java
Ans. Composition - has-a relationship between objects.
Inheritance - is-a relationship between classes.

Composition - Composing object holds a reference to composed objects and hence relationship is loosely bound.
Inheritance - Derived object carries the base class definition in itself and hence its tightly bound.

Composition - Used in Dependency Injection
Inheritance - Used in Runtime Polymorphism

Composition - Single class objects can be composed within multiple classes.
Inheritance - Single class can only inherit 1 Class.

Composition - Its the relationship between objects.
Inheritance - Its the relationship between classes.

  Sample Code for inheritance

  Sample Code for composition

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   java concepts   inheritance  object oriented programming (oops)  oops concepts   composition  object oriented programming (oops)  oops concepts   inheritance  object oriented programming (oops)  inheritance vs composition  object oriented programming (oops)  oops concepts     Asked in 29 Companies      basic        frequent

Try 5 Question(s) Test


  Q3. Explain OOPs

or

Explain OOPs Principles

or

Explain OOPs Concepts

or

Explain OOPs features

or

Tell me something about OOPs
Core Java
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. Have been asked in HCL Technologies very frequently ( based on 3 feedback ). Among first few questions in many interviews.
  Q4. Differences between abstract class and interface ?Core Java
Ans. Abstract classes can have both abstract methods ( method declarations ) as well as concrete methods ( inherited to the derived classes ) whereas Interfaces can only have abstract methods ( method declarations ).

A class can extend single abstract class whereas it can implement multiple interfaces.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   classes   abstract class   interfaces   abstract class vs interface   abstract classes vs interfaces     Asked in 82 Companies      basic        frequent


Frequently asked in all types of companies especially Indian Services companies. Frequently asked in CTS (Based on 2 feedback)
  Q5. What is the use of hashcode in Java ?Core Java
Ans. Hashcode is used for bucketing in Hash implementations like HashMap, HashTable, HashSet etc. The value received from hashcode() is used as bucket number for storing elements. This bucket number is the address of the element inside the set/map. when you do contains() then it will take the hashcode of the element, then look for the bucket where hashcode points to and if more than 1 element is found in the same bucket (multiple objects can have the same hashcode) then it uses the equals() method to evaluate if object are equal, and then decide if contain() is true or false, or decide if element could be added in the set or not.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   collections   hashcode   advanced  hashtable     Asked in 33 Companies      intermediate        frequent

Try 1 Question(s) Test


Very Frequently asked to fresh graduates and less experienced. Favorite question in Walk in drives. Frequently asked in Indian Services companies.
  Q6. Difference between Overloading and Overriding ?Core Java
Ans. Overloading - Similar Signature but different definition , like function overloading.

Overriding - Overriding the Definition of base class in the derived class.

  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     java   oops   overloading   overriding   oops concepts   basic interview question   overloading vs overriding     Asked in 86 Companies      basic        frequent

Try 1 Question(s) Test


Almost sure to be asked in every company using any Dependency Injection framework ( Spring, Guice etc )
  Q7. What is Dependency Injection or IOC ( Inversion of Control ) ?Design
Ans. It is a Design Pattern that facilitates loose coupling by sending the dependency information ( object references of dependent object ) while building the state of the object. Objects are designed in a manner where they receive instances of the objects from other pieces of code, instead of constructing them internally and hence provide better flexibility.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     design patterns   ioc ( Inversion of Control )  dependency injection     Asked in 83 Companies      intermediate        frequent


Very frequently asked.Usually among first few questions.
  Q8. What is MVC ? Design
Ans. MVC is a Design Pattern that facilititates loose coupling by segregating responsibilities in a Web application

1. Controller receives the requests and handles overall control of the request
2. Model holds majority of the Business logic, and
3. View comprise of the view objects and GUI component

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     j2ee   mvc   mvc design pattern   design pattern   struts   spring   web application   web frameworks   ebay     Asked in 60 Companies      basic        frequent

Try 1 Question(s) Test


 Q9. Why Java is not considered pure OOP's language ?Core Java
Ans. There are 2 reasons for it.

1. Usage of Primitive types - Though Java provides classes for the primitive data types but as the usage of primitives is permissible, its considered unpure OOP's language.

2. Usage of Static members - Static members belong to the class and not objects and hence not considered fit for pure OOP's programming.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     oops  object oriented programming  object oriented language  primitive data types     Asked in 2 Companies


 Q10. What are the benefits of using Wrapper classes over primitive types ?Core Java
Ans. With Collection classes , we cannot use primitive types. Moreover for any class using generic types, we cannot use primitive types.

They add more functionality by means of additional methods.

As their reference can be null , they offer consistent check for uninitialized state.

They facilitate caching and reuse by means of constant Pools.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     wrapper classes  benefits of wrapper classes over primitives


Usually asked to entry level software developers.
  Q11. Write a program to swap two variables without using thirdCore Java
Ans. public static void main(String[] args) {
   int num1 = 1;   
   int num2 = 2;
   num1 = num1^num2;
   num2 = num1^num2;
   num1 = num1^num2;
   System.out.print("num1 = " + num1 +", num2 = "+num2);
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     code  coding     Asked in 37 Companies      basic        frequent


 Q12. 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


 Q13. Write a Program to print factorial of a number using recursionCore Java
Ans. public class BuggyBread {
public static void main(String args[]) {
System.out.println(factorial(5));
}

private static int factorial(int number){
if(number == 1){
return 1;
} else {
return number * factorial(number - 1);
}
}
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     recursion     Asked in 25 Companies


Frequently asked in face to face interviews.
  Q14. Write a program to print fibonacci series.Core Java
Ans. int count = 15;
int[] fibonacci = new int[count];
fibonacci[0] = 0;
fibonacci[1] = 1;
for(int x=2; x < count; x++){
fibonacci[x] = fibonacci[x-1] + fibonacci[x-2];
}

for(int x=0; x< count; x++){
System.out.print(fibonacci[x] + " ");
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     ebay   fibonacci series     Asked in 66 Companies      basic        frequent


 Q15. What is the purpose of Commit and Rollback in Databases ?Database
Ans. When a DML is executed, the changes only stays in session and still not pushed to DB Tables, Commit is used to push those changes to the Tables.

In case we realize that we don't want to commit those changes and would like to ignore them, we can use rollback.

For example - You may like that for a banking transaction you would like to update the account balance only if the debit or credit record was correctly inserted, so you may like to encapsulate both DML's - insert for transaction and update for balance in a single transaction and would only commit if both succeeds else rollback.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     databases  commit  rollback     Asked in 2 Companies      Basic


 Q16. What are the different primitive data types in Java ?Core Java
Ans. boolean
byte
char
double
float
int
long
short
void

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     data types  primitive data types     Asked in 1 Companies      Basic


 Q17. What is the difference between GIT Commit and Push ?GIT
Ans. Git commit commit the changes to local repository whereas Push commits the changes to Remote repository.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     GIT  Configuration Management  commit vs push


 Q18. What is OSGI ?OSGI
Ans. OSGI is open service gateway initiative, its used as java framework for developing and deploying the modular softwares.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve          Asked in 23 Companies


 Q19. What is the difference between subscribe and emit ?Angular
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     subscribe vs emit



Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: