Interview Questions
Interview Questions
25)What is immutable?
ans:Once we create an object we are not allowed to change the content if any person
try to modify and if there is a change with those
changes a new object will be created and if there is no changes then that
object is reused.
26)How to create immutable class?
ans: final public class Test{
private int i;
Test(int i){
this.i=i;
}
public Test modify(int i){
if(this.i==i){
return this;
}else{
return new Test(i);
}
}
27)What is the difference between fail fast and fail safe iterator?
ans:FailFast iterator does not allow any modification during iteration process if
we try try to modify it will throw
ConcurrentmodificationException.It requires less memory and hence performance
is faster then FailSafe iterator and no clone object is created
during iteration process.Example HashMap,ArrayList,vector etc
FailSafe iterator allow modification during iteration process and it will not
throw any exception.It requires more memory and hence performance
is slightly slower than failfast.A copy or cloned object will be created during
iteration process in failsafe.Example concurrentHashMap,
copyonwriteArrayList etc.
28)What is the difference between Factory and abstract factory?
ans:The main difference between factory pattern and abstract factory pattern is
that the factory pattern provides a method of creating objects
without specifying the exact class used to create it while the abstract factory
pattern provides a method to combine a group of individual
factories without specifying their concrete classes.
29)Which repository you have used in your project?
ans:JPA repository extends CrudRepository and PagingAndSorting repository. It
inherits some finders from crud repository such as findOne,
gets and removes an entity. It also provides some extra methods related to JPA
such as delete records in batch, flushing data directly to
a database base and methods related to pagination and sorting.
30)What is mean by pagination?
ans:To divide a large number of records into multiple parts, we use pagination. It
allows users to display a part of records only.
Loading all records on a single page may take time, so it is always recommended
to created pagination.
31)@componentScan?
ans:
32)Java 8 features?
ans:The main objective of java 8 is to enable functional programming and to reduce
the line of code through which we can get easyness or
concisness we will get.
Features:
1)Lambda expression:The main objective of Lambda expression is to bring benifits of
functional programming into java.
So the lambda expression is anonymous(Nameless) function
|
without return type
without modififiers
(Such type of terminology it is called as
annonymous function)
Example: If it want to return a square of num to method then,
public int SquareIt(int a){
return a*a;
}
By using lambda expression---- n->n*n
(int a)->{return a*a;}--if we want to return anything then without curly bracket we
can write the code,automatically it will be considered as return type.
(int a)->a*a;
33)MySQL joins?
ans:-There are mainly three types of join
1.Inner join:It gives you exactly matching rows:select* from table1 JOIN table2 ON
table1.columnname=table2.columnname
2:Outerjoin left join:It will return all the records left table and matched records
from right table:-select customer cid,cmane,oamunt LEFTJOIN
3.RightJoin:It will return all the record from the right table and matched recordes
from left table.
34)ConcurrentHashMap?
ans:In concurrentHashMap underlying data structure is hashtable.concurrenthashmap
concurrent read and threadsasfe update operation
To perform read operation thread wont require any lock but to perform any update
operation it requires a lock but it is the lock of particular
part of the map i.e bucketlock.Instead of assigning hole map it is divided into
small parts that is called as concurrencylevel.Hence
concurrenthashmap allows simulteniously read operation and 16
update(write)operations coz its default size is 16.
35)What is marker interface?
ans:Marker interface is an interface in which there is no method or constants i.e
empty method.An empty interface is used to mark or identify
special operations.Example clonable interface is used to mark cloning operation and
serializable interface is used to mark serialization
and deserialization of an object.
36)Factory method in project?
ans:we have 3 type of payment in your e-commerce app (Paypal+we payment + Value
api)
every one of these classes has its own pay method and some of these if you use take
discount.
36)Constructor chaining?
ans:Constructor chaining means calling the one contructor from another constructor.
we can call the constructor by two ways
1.Within the same class by using this().
2.Between a child class to parent class by using super method().
E.g: Class A{ Class B extends A{
A(){ B(){
} this(123); }
A(int x){} B(int x){Super(111);}
} }