You are on page 1of 10

Core Java

1. Collection
i. Set
ii. Linkedlist
iii. Hashset
iv. hashmap vs linkedhhashmap
v. hashmap vs hastable
vi. fail fast vs failsafe
2. when we have abstract class then why should go for interface?
3. Difference between Exception and Error.
4. Singleton class and its all implementation.
5. Executer Service.
6. why should we go for synchronization.
7. method overloading and overriding.
8. Constructor and instance method.
9. interface.
10. Interface & abstract class ?
Answer: Interface is a special type of class through which we can achive fully abstraction runtime
polymorphisim and multiple inheritance which makes our code completely loose coupled but in
abstract class also we can achive abstraction and R.P but partially..coz it contains both abstract method
as well as concret method but in abstract class u can't get multiple inheritance
11. To override all the method from super which keyword we have to use.and why
Answer : implements keyword coz class+interface== always implements

12. Why abstract class achive less abstraction why not interface.?
Answer : Cause Abstract class contain boh concrete and abstract method but it's not mandatory that
My subclass always override supperclass method so there is no guarentee to achive fully abstraction
13. What is abstraction
Answer: Hide the implementation Provide only Functionality is called abstraction
14. How to create own immutable class write code?
public class MyImmutable {
int no;
public MyImmutable(int no) {
super();
this.no = no;
}
public MyImmutable modify(int no) {
if (this.no == no) {
return this;
} else {
return new MyImmutable(no);
}
}
}
15. Why List allow duplicate why not Set with internal ?
Answer : Coz List internally follw Array Concept so no there is no restriction in array to allow duplicate
but in case of Set it internally follow Map which object u add in set it will be placed as key in That
internal Map so duplicate not allowed in Set Just explain the flow of Map ok if he ask more.....
16. What is the difference between CountDownLatch and CyclicBarrier. (Answer)
17. What is the time complexity of put() and get() operation in HashMap? (Answer)
18. Why do we need thredpool in Java Application? (Answer)
19. What is the time complexity of put() and get() operations in ConcurrentHashMap?
20. How ConcurrentHashMap works internally?
21. If Concurrency level of ConcurrentHashMap is 4, can more than four thread read simultaneously from
ConcurrentHashMap?
Answer : Yes. Any number of threads can read concurrently from ConcurrentHashMap.
22. If one thread is writing in one segment of ConcurrentHashMap, Can other thread read from that
segment?
Answer : Yes. In that case, reading thread will read last updated value as value field is volatile in
ConcurrentHashMap entry object.
23. What is the difference between synchronized keyword and ReentrantLock? Advantages of
ReentrantLock over synchronized keyword.
24. Print 1 to 20 numbers using two different threads concurrently.
Thread 1 prints 1, 3, 5, 7,…,19
Thread 2 prints 2, 4, 6, 8,…,20
25. Find the intersection of two singly linked list?
For Example,
First LinkedList : 1 -> 2 -> 3 -> 4 -> 5
Second LinkedList : 10 -> 9 -> 8 -> 7 -> 4 -> 5
LinnkedList InterSection - Wissen Infotech Interview Questions – Set 1
Answer should be 4 i.e. both the lists are same after 4.
26. Suppose, I have class Employee with three fields as below:
class Employee{
int empId;
String empName;
Address empAddress;
}
class Address{
}
– How will I make Employee as Immutable class.
– If Address is also a mutable object. How will you handle it?

27. What is deep copy? How it will be useful in Immutable objects?


28. How does HashMap work internally? tell me about hashCode() and equals() method.
29. How does TreeMap work internally? Do we need to implement hashCode() and equals()?
30. Which method should we implement in case of TreeMap?
31. Difference between HashMap and ConcurrentHashMap.
Answer :
1. HashMap is not thread-safe.
2. ConcurrentHashMap is a thread-safe.
3. For detailed understanding, please read our article Hashtable Vs SynchronizedMap Vs
ConcurrentHashMap
32. How does ConcurrentHashMap work internally?
Answer : Instead of acquireing a lock on entire Map object like SynchronizedMap, ConcurrentHashMap
devides map in different segements and each thread can aquire a lock on individual segment. so at a
time multiple threads can write in different segments but not in the same segement. Also this lock is
required only in write operation. Multiple threads can read concurrently from the same segement.
33. Tell me about ExecutorService.
34. If I am having a file of size 10GB. I want process that file, how will I do that?
35. I am having array which is increasing upto one element and then it decreses. Find the pick elements.
For example,
10 30 40 50 20 5 4 1 (Answer:50)
36. What is the difference between ArrayList and LinkedList?
37. When will ArrayList be resized? What will be the size of new ArrayList?
38. How HashMap works internally? Explain hashCode() and equals() method? (Answer)
39. How does HashMap calculate Bucket position, if returned HashCode of key is 35 and HashTable array
size is just 16?
40. Can we have multiple null values in HashMap?
Answer : Yes. HashMap can have multiple null values and one null key. for more details you can check
our article on HashMap Internals.
41. How does HashSet work internally? Which data structure it uses internally?
Answer : HashSet internally uses HashMap. Stores all the element as HashMap key and value as static
instance of class Object.For detailed understanding, please read our article
42. How is HashSet implemented internally in Java?
43. What is the difference between HashMap, ConcurrentHashMap and SynchronizedMap?
Answer : HashMap is not thread-safe.
1) SynchronizedMap is a thread-safe, but it will acquire lock on entire Map in read and write
opearations. So at a time only one thread can either read or write in Synchronized Map. Hence it is slower.
2) ConcurrentHashMap is a thread-safe. Instead of acquireing a lock on entire Map object, it
devides map in different segements and each thread can aquire a lock on individual segment. so at a time
multiple threads can write in different segments but not in the same segement. Also this lock is required
only in write operation. Multiple threads can read concurrently from the same segement.
3) HashMap and SynchronizedMap can have multiple null values and one null key whereas
ConcurrentHashMap can not have any null keys or values.
– For detailed understanding, please read our article Hashtable Vs SynchronizedMap Vs
ConcurrentHashMap
44. What is the difference between CountDownLatch and CyclicBarrier? (Answer)
45. How to create Immutable object? What you will do if one of the field in your immutable class is
mutable? (Answer)
46. Write down a program to implement your own iterator of ArrayList.
47. Find a cycle in a linked list.
48. Find a first node of that cycle.
49. Write a program to print 'Hello World' repeatadly using two threads. Thread 1 should print 'Hello' and
Thread 2 should print 'World'
50. What all things will you take care, if you are using serialization?
51. What will happen, if I will not declare SerialVersionUID in a class which implements Serializable?
52. How have you used serialization in your project?
53. What is the difference between Immutable object and Mutable Object?
54. When you will use Immutable objects in your application?
55. What is CyclicBarrier?
56. Have you ever used CyclicBarrierin your application? If Yes, what have you implemented using
CyclicBarrier?
57. Write a java function which accepts Map as input and outputs another Map.
input Map : Map<Student,Marks> ,marks>
output Map : Map<Student,Grades>
conditions for output Map :
1. Grades Calculation:
if marks > 90, then A Grade
if 80 < marks < 90, then B Grade
if 70 < marks < 80, then C Grade
if 60 < marks < 70, then D Grade
if 50 < marks < 60, then E Grade
2. Map should only contain Students having marks more than 50.
3. Map should be sorted based on Grades.

58. Object vs class level locks?


59. Concurrency API
60. Fail-safe fail-fast iterator

Spring
1. Bean Scopes
2. @Transaction
3. Advice
4. AutoWiring
5. @Qualifier
6. MVC Architechture
7. ParameterazableViewController
8. SimpleFormController
9. Security and How to configure and enable.
10. Why session open?
11. can we open multiple session and why?
12. Hbm to DDL.auto properties
13. Application context
14. @Entity use.
15. What is Dependency Injection ?
Answer : Dependency Injection is a process of inject dependency in Dependant class automatically we no
need create object and no need to map with object .it internally follow Strategy design pattern.
16. What is autoware,Type explain with sample code
Answer : Autowire is auto enable dependency Inject it is 3 type:1)byName 2)byType
3)Constructor
17. Which version of spring you have used ?
18. Write Spring-transaction configuration?
<aop:config>
<aop:pointcut expression="execution(*com.dt.service.ManageEmployeeService.*(..))"
id="manageEmpPct"/>
<aop:advisor advice-ref="manageEmployeeTxAdvice" pointcut-ref="manageEmpPct"/>
</aop:config>

<tx:advice id="manageEmployeeTxAdvice">
<tx:attributes>
<tx:method name="new*" read-only="false" propagation="REQUIRED" />
<tx:method name="*" read-only="true" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>

19. Spring-Transaction annotation details with attribute why ?


ans: @Transactional(read-only="false",Isolation="Read-Commit",Propagation="Required")
20. @Qualifier annotation use with example ?
Answer: @Qualifier annotation used to avoid ambiguity error
ex:
<bean id="a1" class="A">
<bean id="a2" class="A">
here class is same but id is different so here my IOC Container confuse due to same class found
multiple time so here bean id u want mention in @Qualifier("a1") then IOc will instantiate that
bean only
21. @RequestParm and @ModelAttribute
where we have to use..
ans:If from form page or from UI page u want to get more 2 to 3 element then use @RequestParm
ex:just assume from login page how many element u will get 2 username and pwd use
@RequestParm if incoming data will be more then bind them in one object by using
@ModelAttribute ex:Suppose u book a ticket then lot of data u have to pass as input like
movieName,Time,Location,Nearest hall...etc then choose @ModelAttribute
22. What are the scope of Spring Bean?
23. What is the default scope of Spring Bean?
24. What is prototype scope in Spring?
25. Explain Spring MVC Execution Flow.
26. Explain Spring Bean Life cycle.
27. Explain any one use case of Spring BeanPostProcessor.
28. Difference between auto wire by Type and auto wire by Name.
29. What is the use of dispatcher servlet in Spring MVC.
30. @qualifier annotation
31. Types of autowiring
32. Spring bean life cycle
33. Spring bean scope
34. How to create singleton class's object using spring?
35. Static factory method instantiation
36. Spring MVC flow?
37. Controller vs Restcontroller
38. Pathparam vs pathvariable

Hibernate
1. Hibernet template
2. how to map hibernet in xml.
3. What is First Level Caching in Hibernate?
4. How you will create OneToMany relationship in Hibernate?
5. What are the different state of Hibernate POJO?
6. What is transient state?
7. What is Cascade Attribute In Hibernate?
8. I'd generators
9. Second level cache
10. Merge vs persist
11. Assosiation Mappings
12. Need of Lazy load
13. Get vs Load

Web Services
1) Difference between POST and PUT method.
2) Where have you used WebServices in your application?
3) What is swagger how you are using it.
4) How many policy are their in oauth2
5) What is JSON webtoken?
6) Which class we configure in web.xml as front controller in Jersey?

Design Pattern
1. Do you know about SOLID design principles? Explain.

Project
1) How can u achive Abstraction With Real Time Example(Project) ?
Answer : As per my project what we people are developed that will be hidden from user so for them it is
abstraction otherwise explain Hari sir Bank Atm example.
2) In your Project Where u are using oops concept..?
Answer : Ya we implement all the concept in our project and Encapsulation we used in Business Object or
Model class Inheritance and Polymorphisim we implement in Dao and Service Layer to make it loosly
coupled
3) Encapsulation u are using in ur project in which layer. ?
Answer : Ya we are using In Model layer (BO,DTO,FORM)
4) Write 5 classes which u r develope in your project with fully qualified name ?
Just mention as below
1. MODULE_NAME_DAO---------com.productOwnersortname.module.layer
2. MODULE_NAME_SERVICE
3. MODULE_NAME_CONTROLLER
4. MODULE_NAME_BO
5. MODULE_NAME_DTO
6. MODULE_NAME_MAPPER
7. MODULE_NAME_UTIL
5) What are the exception u face in ur project development and how u resolve them explain ?
1.NullPointerException:-Resolve by Remote Debugging
2.DataAccessException:-Enter the Column name properly this exception from DAO
3.ClassCastException:-Mentain Typecast or Generics properly
6) Why u are using Spring-jdbc why not hibernate ?
Answer :Coz my project is Intranet Application and it handles huge amount of data for persist and retrive
thats why we are using Spring-Jdbc.
7) Which security u are using..?
Answer :Simple Authentication by using Spring
8) Level of log(Which one u use in your project)
Answer : DEBUG,ERROR,WARN
9) What is singletone ,In your project did u use singletone ,Where write code ?
Answer :Singleton is object creation design pattern by which we can instantiate only one instance per one
class per one jvm. In my project i didn't use coz we are using Spring so every bean scope is singleton so
we no need to make explicitly singleton.
10) Which type of Injection u are using in ur project and why..
Answer : We are using both setter and constructor injection both coz some fields we need to compulsory
inject and some fields are optional for our project .
11) What are the annotation u are using in ur project ?
12) Tell me about your current Project.
13)
Answer: @Componet, @Service, @Controller, @Autowire, @Transactional, @Scope,
@ControllerAdvice,@ExceptionHandler, @RequestParm, @PathVariable, @ModelAttribute,
@PropertyResource
14) What is ur daily activity in ur working environment
ans:Sensiourly working in service and dao based on user story code testing and write junit test case and test
it 2 to 3 times participate in daily-Scrum
15) Aop , types of advices and what is programmatic vs declarative approach , how you used in your project.
16) Spring security how you used in your project?

SQL
1. What is the difference between clustered and non-clustered index?
2. What is the use of group by and having Clause?
3. Explain all types of joins in database.
4. What is SQL Injection? Which feature of JDBC can we use to prevent SQL Injection?
5. For below given SQL Table
EMP_ID EMPLOYEE_NAME MGR_ID
100 Prateek –
101 Kapil 100
102 Prakash 101
103 Jack 101
6. Write a query to fetch result as below
EMPLOYEE_NAME MANAGER_NAME
Prateek –
Kapil Prateek
Prakash Kapil
Jack Kapil
7. What all database constraint do you know?
8. Is it possible to create Composite Unique Key? Or It can be created only on one table?
9. Difference between clustered Index and Non clustered Index.

You might also like