Category Archives: JAVA

JAVA

First Level cache and second level cache in hibernate

First Level Cache
First-level cache always Associates with the Session object. Hibernate uses this cache by default. Here, it processes one transaction after another one, means wont process one transaction many times. Mainly it reduces the number of SQL queries it needs to generate within a given transaction. That is instead of updating after every modification done in the transaction, it updates the transaction only at the end of the transaction.

Second level cache
Second-level cache always associates with the Session Factory object. While running the transactions, in between it loads the objects at the Session Factory level, so that those objects will be available to the entire application, not bound to single user. Since the objects are already loaded in the cache, whenever an object is returned by the query, at that time no need to go for a database transaction. In this way the second level cache works. Here we can use query level cache also. Later we will discuss about it.

Difference between ArrayList and Vector

There are main two difference between ArrayList and Vector
1. Synchronization: ArrayList is not synchronized , but Vector is synchronized.
Because ArraList is not synchronized so it is not thread safe. Vector is thread safe.
Because Vector is thread safe, in terms of performance Vector is slower than ArrayList.

2. Data size Increament: ArrayList increase its size 50% whereas Vector increase its size as double.