Q. What are the difference between @Controller and @RestController?
Ans: 1. The @Controller is a common annotation that is used to mark a class as Spring MVC Controller while @RestController is a special controller used in RESTFul web services and the equivalent of @Controller + @ResponseBody.
Q. What are the use of @PathVariable?
Ans: @PathVariable is used to bind method parameter to the value of URI template variable
ex: @RequestMapping(value="login/{id}",method=RequestMethod.post)
Q. What are difference between Abstract class and Interface in java?
Ans: 1. Abstract classes have partial implementation whereas Interface have only methods declaration/signature.
2. Abstract classes are used when parent classes need to provide some default behavior(method) and child classes need to provide some specialized behavior(method) whereas Interfaces are used in design phase when multiple behaviors from a subsystem are expected. OR I use interfaces when I see that any subsystem of my design will change frequently for example if my application need to support multiple databases then I will define interfaces and write implementation classes for each database.
Q. What are differences between String and StringBuffer classess?
Ans: 1. String is immutable whereas StringBuffer is mutable.
Q. What are differences between StringBuffer and StringBuilder classess?
Ans: 1. StringBuffer is synchronized whereas StringBuilder is not synchronized.
Q. Does Serializable interface have any method?
Ans: No, It is a marker interfaces.
Q. What is transient variable?
Ans: Attributes defines as transietn will not be serialized.
Q. What type of Variables are declared as transient?
Ans: Calculated filed, memory point and database pointer objects like ResultSet.
Q. Does cloneable interface have any method?
Ans: No, It is a marker interfaces.
Q. What are the difference between Overloading and Overriding?
And: Overloading vs Overriding in Java
-----------------------------------------------------------------------------------
Overloading | Overriding |
1. More than one method with same name, different prototype in name scope is called method overloading | 1. More than one method with same name, same prototype in different scope is called method overriding |
2. In case of method overloading, parameter must be different. | 2. In case of method overriding, parameter must be same. |
3. Method overloading is performed within class | 3. Method overriding occurs in two classes. |
4. In case of method overloading, return type can be same or different. | 4. In case of method overriding, return type must be same. |
Method Overloading:- If a class has multiple method having same name but different in parameter list, it is known as method overloading.
Method Overriding:- If child class have same method as declared in parent class, it is known as method overriding in java
Q. What is immutable object?
Ans: When object values can be initialized once and can never be changed, It is called immutable object.