Saturday, August 16, 2014

JAVA interview questions

Q. What do you achieve through good class and interface design? 
A. 

  • Loosely coupled classes, objects, and components enabling your application to easily grow and adapt to changes without being rigid or fragile.
  • Less complex and reusable code that increases maintainability, extendability and testability.

Q. What are the 3 main concepts of OOP? 
A. Encapsulation, polymorphism, and inheritance are the 3 main concepts or pillars of an object oriented programming. Abstraction is another important concept that can be applied to both object oriented and non object oriented programming. [Remember: a pie ? abstraction, polymorphism, inheritance, and encapsulation.]


Q. What problem(s) does abstraction and encapsulation solve? 
A. Both abstraction and encapsulation solve same problem of complexity in different dimensions. Encapsulation exposes only the required details of an object to the caller by forbidding access to certain members, whereas an abstraction not only hides the implementation details, but also provides a basis for your application to grow and change over a period of time. For example, if you abstract out the make and model of a vehicle as class attributes as opposed to as individual classes like Toyota, ToyotaCamry, ToyotaCorolla, etc, you can easily incorporate new types of cars at runtime by creating a new car object with the relevant make and model as arguments as opposed to having to declare a new set of classes.


Source
--------------------------------------------------------

In computer sciencereflection is the ability of a computer program to examine (see type introspection) and modify the structure and behavior (specifically the values, meta-data, properties and functions) of an object at runtime.

Source

--------------------------------------------------------

--------------------------------------------------------
Good Links
http://www.techinterviews.com/java-interview-questions-2


-----
totally bombed the interview when i got on the phone call
he asked about polymorphism and even though i read it three times this morning I stumbled to answer (never been good at test).  He also asked the difference between rest and soap.  which i did a little better with but after that he changed the interview from questions to explaining what they do (not a good sign in my opinion)

http://spf13.com/post/soap-vs-rest/

Another question was method overriding vs overloaded
which of course is as follows
overriding =  allows a subclass or child class to provide a specific implementation of a method that is already provided by one of itssuperclasses or parent classes

overloading = creating several methods with the same name which differ from each other in the type of the input and the output of the function. It is simply defined as the ability of one function to perform different tasks.