Вы находитесь на странице: 1из 5

Java Topics to cover in interviews

Core Java
1. Fundamentals of OOPS
2. Classes, Objects and Methods
3. Arrays, Strings and Vectors
4. Interfaces, Packages
5. Threading
6. Exception Handling
7. Applets
8. File Handling
9. Serialization
10.Collections
11.JDBC
Advanced Java
1. Generics
2. Reflection
3. Sockets
4. Design Pattern
5. JSP
6. Servlets
7. Java Beans
8. Session Management
9. RMI
10.Hibernate
11.Spring
12.Struts
13.Web Services

Java questions
1. Explain about OOPS concepts
a. What is polymorphism
The ability to define more than one function with the same name is called
Polymorphism. 2 types: overloading and overriding
What is inheritance
What is multiple inheritance and whether java supports it?
What is abstraction
What is encapsulation
What is association (is a relationship)
Performing a task by a method in one class on behalf of some
other class
g. What is aggregation (has a relationship)?
h. What is composition (has a relationship with compulsion of
object existence)

b.
c.
d.
e.
f.

2. Questions on Classes, Objects and methods

a. Different access modifiers applicable to a class, object, method


and variables?
b. Why to use synchronized keyword?
c. What is volatile keyword?
d. What is transient keyword?
e. What is strictfp modifier?
f. Explain static concept in java?
g. Why static methods cannot access non-static variables?
h. Can a static block throw an exception? Yes, only run time
exceptions
i. Difference between abstract class and an interface
j. What are different types of references in java
i. Strong reference
1. Direct reference present
ii. Soft reference
1. Variable that cannot be reached by strong
reference. Used for implementing cache
iii. Weak reference
1. Variable that cant be reached by strong and soft
references. Used to implement weak maps
iv. Phantom reference
1. Objects that have been marked for garbage
collection and have been finalized but not yet
claimed
k. How to change heap size of JVM
i. Use -Xmx and -Xms
l. Difference between instanceof (keyword) and isinstance()
(method in Class)
m. Can an abstract class can have static method?
n. Can an abstract class can have constructor?
o. How java allocates stack and heap memory?
p. What is a re-entrant method(can be accessed concurrently
without disturbing other calls) and idempotent method (calling
same method with same arguments based on some conditions)?
q. Can a private variable or method of a class can be accessed? Yes
using reflection
r. Difference between static block and init block?
s. Why inner classes can access only final variables?
t. What is static binding and dynamic binding?
u. When an object is passed as argument to a function, we can
change the variables of that object but we cannot nullify it?
Why?
3. Questions on Exception Handling
a. What is an exception
b. Difference between an exception and error (virtualMachineError
etc)
c. Parent class for all exceptions (Throwable)
d. How to create custom exceptions
e. Difference between classNotFoundException and
NoClassDefFoundException
f. Difference between throw and throws
g. Usage of try, catch, finally

h. Difference between final and finally and finalize() methods


i. How can we handle out of memory error
j. Difference between outofMemory error and stackOverflowError?
k. What are checked exceptions and unchecked exceptions
l. What is exception matching?
m. What does ducking the exception mean?
n. Can a catch block throw the exception it caught itself?
4. Questions on Collections
a. Difference between arraylist and vector
b. How we can synchronize an arraylist without using vector?
c. If an Employee class is present and its objects are added in an
arrayList. Now I want the list to be sorted on the basis of the
employeeID of Employee class. What are the steps?( Ans)
Implement Comparable interface for the Employee class and override the
compareTo(Object obj) method in which compare the employeeID, Now call

d.
e.
f.
g.
h.
i.
j.
k.
l.
m.
n.

Collections.sort() method and pass the list as an argument.


What is the difference between hashmap and hastable
What is fail-safe and fail-fast in terms of collections
Explain arraylist, vector, LinkedList, sortedset, treeset, hashset,
When to use arraylist and when to use linked list
Advantage of using iterator in collections
Advantage of using List interface instead of ArrayList while
creating collection variables
Difference between iterator access and index access
How to sort list in reverse order? Using
Collections.reverseOrder() and then Collections.sort()
Can a null element can be added to treeset(no) and hashset (yes
because it is based on hashmap)?
How to make a collection unmodifiable?
Collections.unmodifiablexxx(xxx)
What is concurrent hashmap? (uses bucket level locking instead
of object level mapping)
Which is faster to iterate? Linkedhasset or linskedlist? (linkedlist)
Which datastructure does hashset uses internally?

o.
p.
q.
5. Questions on Threads
a. Difference between thread and process
b. Two types of creating thread
c. Thread life cycle
d. Synchronized use
e. Difference when synchronized is applied on static and non-static
methods
f. Diff between yield and sleep
g. Diff between wait and sleep
h. Diff between notify and notifyall
i. If we dont call start method but called run directly what
happens?
j. Diff between active thread and daemon thread
k. Can a variable can be synchronized? (no)
l. Can static methods can be synchronized? Yes

m. Can two threads call two different static synchronized methods


of a same class?
n. When deadlock occur and how to avoid it?
o. Can start method thread can be overriden? If yes, why it is not
recommended?
p. What is thread starvation
q. What is threadLocal? It is a class
r.
6. Questions on inner class
a. Types of inner classes (static and inner(member, anonymous,
local))
b. How to access inner class from outer class
c. If we compile a class containing inner class, how many class files
are created and how they are named?
d. Can a method local inner class can access methods local
variables? No
e. Which modifiers can be applied to method local inner class? Only
abstract or final
f.
7. Questions in Serialization
a. What is serialization
b. Why serialization is required
c. Other than serialization, other approaches to achive
serialization? Externalizable and your own way
d. What happens if an object to be serialized includes other
references to serializable objects?
e. What happens if an object to be serialized includes no serialized
object references?
f. Can static variables be saved as part of serialization
g. What is the value of transient variables in serialized file?
h. How to customize serialize process? readObject(), writeObject()
overriding
i.
8. Questions on immutable class
a. How to create immutable classes
i. Create final class
ii. Set the values of properties using constructor only
iii. Make the properties of class private and final
iv. Do not provide any setters
v. If the instance fields include references to mutable
objects, dont allow those objects to change like this , dont
provide methods that modify mutable objects, sont share
references of mutable objects, if necessary create copies
of these objects and then use them if you want to return
them
b. Are immutable classes thread safe?
c. Which classes in java are immutable?
9. Questions on Cloning
a. What is shallow copy
b. What is deep copy
10.Questions on Garbage Collection

a. Which part of memory is involved in garbage collection? Stack or


heap?
b. Is garbage collector a daemon thread? Yes
c. When an object becomes eligible for garbage collection? And
how to make it eligible for garbage collection?
d. What is island of isolation? Is it eligible for garbage collection?
e. Can gc can be forced?
f. How gc can be requested? Runtime.gc() and system.gc()
g. What happens when finalize method throws an uncaught
exception? Whether gc continues in this case?
h. How to enable or disable the call of finalize method?
RunTime.getRunTime().runFinalizersOnExit(boolean value)
decides this.
11.Questions on JSP
a. What do you understand by the terms jsp translation phase or
compilation phase?
b. Life cycle of jsp
i. Pre-translated
ii. Translated
iii. Initialized
iv. Servicing
v. Out of service
c. Different types of scripting elements
i. Declaration elements <%! Hhh %>
ii. Expression element <%= %>
iii. Scriptlet Elements <% %>
iv. Action Elements
v. Directive Elements
1. Page
2. Include
3. taglib
vi.
d. Is jsp variable declaration thread safe?
e. Explain jsp url mapping? what is URL hiding or protecting a jsp
page?
12.Questions on Strings
a. Why strings are immutable
b. Difference between abc.equals(unknown string) and unknown
string.equals(abc)? It is safe from null pointer exception
c. What is tag interface in java ? (marker interface)
d. What happens when we override static method? No compilation
error but will be hidden
e.
13.

Вам также может понравиться