14. What is the difference between Relational-database and Non-Relational-Database?

Java Threads

8. how to use Lock class instead of Synchronized? Lock Reentrance?
Locks in Java

9. How to use wait() and notify()?
Java - Interthread Communication

JDBC

JDBC详解

1. What is JDBC ?
JDBC(Java Data Base Connectivity) is an abstraction layer that allows users to choose between databases. JDBC enables developers to write database applications in Java, without having to concern themselves with the underlying details of a particular database.

2. Explain the role of Driver in JDBC.
The JDBC Driver provides vendor-specific implementations of the abstract classes provided by the JDBC API. Each driver must provide implementations for the following classes of the java.sql package:Connection, Statement, PreparedStatement, CallableStatement, ResultSet and Driver.

3. What is the purpose Class.forName method ?
This method is used to load the driver that will establish a connection to the database. For example: Class.forName("com.mysql.jdbc.Driver");

4. What is the advantage of PreparedStatement over Statement ?

  • PreparedStatements are precompiled and thus, their performance is much better.
  • PreparedStatement objects can be reused with different input values to their queries.
  • PreparedStatement can prevent SQL injection

5. What is the use of CallableStatement ? Name the method, which is used to prepare a CallableStatement.
A CallableStatement is used to execute stored procedures. Stored procedures are stored and offered by a database. Stored procedures may take input values from the user and may return a result. The usage of stored procedures is highly encouraged, because it offers security and modularity.The method that prepares a CallableStatement is the following: CallableStament.prepareCall();

6. What does Connection pooling mean ?
The interaction with a database can be costly, regarding the opening and closing of database connections. Especially, when the number of database clients increases, this cost is very high and a large number of resources is consumed.A pool of database connections is obtained at start up by the application server and is maintained in a pool. A request for a connection is served by a connection residing in the pool. In the end of the connection, the request is returned to the pool and can be used to satisfy future requests.

Java Collections

8. What is the tradeoff between using an unordered array versus an ordered array ?

  • The major advantage of an ordered array is that the search times have time complexity of O(log n), compared to that of an unordered array, which is O (n).
  • The disadvantage of an ordered array is that the insertion operation has a time complexity of O(n), because the elements with higher values must be moved to make room for the new element. Instead, the insertion operation for an unordered array takes constant time of O(1).

9. What is the importance of hashCode() and equals() methods ?
The hashCode method is used in order to determine where the specified key will be stored. Since different keys may produce the same hash value, the equals method is used, in order to determine whether the specified key actually exists in the collection or not. Therefore, the implementation of both methods is crucial to the accuracy and efficiency of the HashMap.

Exception Handling

1. What are the two types of Exceptions in Java ? Which are the differences between them ?
Checked and unchecked exceptions in java with examples
Checked exceptions are checked at compile-time. It means if a method is throwing a checked exception then it should handle the exception using try-catch block or it should declare the exception using throws keyword, otherwise the program will give a compilation error. It is named as checked exception because these exceptions are checked at Compile time.
Unchecked exceptions are not checked at compile time. It means if your program is throwing an unchecked exception and even if you didn’t handle/declare that exception, the program won’t give a compilation error. Most of the times these exception occurs due to the bad data provided by user

2. What is the difference between Exception and Error in java ?

  • Both Error and Exception are derived from java.lang.Throwable in Java
  • But Error represent errors which are generally can not be handled and usually refer catastrophic failure e.g. running out of System resources.
  • The Exception class is used for exceptional conditions that a user’s program should catch.

3. What is the difference between throw and throws ?

  • The throw keyword is used to explicitly raise a exception within the program.
  • On the contrary, the throws clause is used to indicate those exceptions that are not handled by a method.

Reference

Java Interview Questions and Answers
Java Interview Questions and Answers - Part 1
Java Multhithreading Interview Questions
Java Threads Tutorial
敏捷开发 (Agile software development)