-->

Core Java Interview Q/A’s

C vs Java

1) C is Procedural language where as Java Object Oriented language?
Ans: True
2) Java supports pointers?
Ans: False
3) C is a high level language?
Ans: False, C is low level language and Java is high level language
4) Java doesn’t support multi overloading?
Ans: False
5) C and Java both provides automatic garbage collection?
Ans: False , only Java supports automatic garbage collection

C++ vs Java:

1) Both C++ and Java are platform independent?
Ans: Flase , only Java is platform independent.
2) Java supports virtual keyword?
Ans: False
3) What is virtual keyword?
Ans: Virtual keyword is used to modify property, method, event declaration  and allowing it to override in derived classes.
4) Java supports both “call by value” and “call by reference”?
Ans: False, Java only supports “call by value”
5) Java is memory safe where as C++ is not?
Ans: True

Serialization

1) What is need of Serialization? Ans: Serialization concept is used to

  1. send state of object/objects over a network
  2. Persist data into Objects or files etc…

2) Is Serializable is marker interface?
Ans: Yes, Serializable is marker interface and it doesn’t have any methods.
3) When NotSerializableException is thrown?
Ans: If you try to serialize an object of a class which implements serializable, but the object includes a reference to an non-
serializable class.
4) What kind of variables don’t save as part of serializable?
Ans: Static & Transient.
5) Will serialization & de-serialization occurs automatically during java runtime system?
Ans: Yes
6) What is an interface for control over serialization and deserialization?
Ans:Externalization.

Collections

1) Is Arraylist is Dynamic Array?
Ans: Yes
2) Is Array is Dyanamic Array?
Ans: No
3) ArrayList is Synchronized, True/False?
Ans: False
4) Iterator can be used in List , set and queue, True/False?
Ans: True
5) Is iteration is fail-fast?
Ans: True
6) what is fail-fast?
Ans: An iteration which throws ConcurrentModificationException is fail-fast Iterator whereas fail-safe iterator never throws
ConcurrentModificationException.
7) Which of the following set maintains Order? TreeSet or HasSet
Ans: TreeSet
8) Is set and map both contains both key and values?
Ans: set contains only values , map contains both key and value.
9) Is Collections extend clonable and serializable interfaces?
Ans: No
10)Is Map is part of Collections?
Ans:No , Map is not Collection and collections are not related to Map.
11)How many ways you can iterate over a List?
Ans: By using for each and iterator.
12)Is key object in Map is duplicatable?
Ans: No , key is unique
13)Can we use iterator in HashMap?
Ans: Yes you can use entrySet(), Ex: Iterator iterator = hashMap.entrySet().iterator() .

Hibernate

1)What is Hibernate Framework?
Ans: Hibernate ORM is a framework used to map Java Application Objects to Relational database and vice verse.It is java based ORM framework and will implement Java Persistence interface.

2) What is Java Persistence API?
Ans: Java Persistence is kind of specification to persist, access or manage data between Java Object and database.
3) What are Advantages of Hibernate then JDBC?
Ans: 1) In Hibernate we don’t need SQL language, i.e we don’t write SQL Queries
2) It supports Transaction management(It avoids in consistent data)
3) Creates tables automatically if needed
4) Fast development of application.
4)What are diff ORM’s present in Java?
Ans:Enterprise JavaBeans Entity Beans
Java Data Objects
Castor
TopLink
Spring DAO
Hibernate
5) What are the elements in Hibernate?
Ans: Configuration File(hibernate.cfg.xml)
Session Factory
Session
Transaction
Transaction factory
Connection provider

6) Is hibernate supports Transaction management?
Ans: Yes
7) How many configuration files need to create for each hibernate project?
Ans: 1
8) Is Session factory created from Configuration Object?
Ans: Yes
9) Is Session factory is Thread safe?
Ans: Yes, but it is expensive
10) How many times we need to create Session factory in hibernate project?
Ans: Since it is expensive only one time.
11) Is Session created from Session factory?
Ans: Yes
12) Is Session is Thread safe?
Ans: No, we need to close this connection once need is done.
13) How many session objects we need to create in hibernate project?
Ans: depends up on number of objects.