Programming Articles - Page 2140 of 3363

Difference between HashTable and ConcurrentHashMap in Java

Alshifa Hasnain
Updated on 27-Jun-2025 18:11:39

8K+ Views

In this article, we will learn about the ConcurrentHashMap and HashTable in Java. First, we will know about ConcurrentHashMap, the syntax of ConcurrentHashMap, and an example after that will learn about HashTable, the syntax of HashTable, and an example. At the end, we will see a table showing the difference between ConcurrentHashMap and HashTable. What is ConcurrentHashMap in Java? ConcurrentHashMap is a class that was introduced in JDK 1.5. The ConcurrentHashMap is threadsafe as it allows multiple threads to read and write the data without locking the entire map. ConcurrentHashMap applies locks only at the bucket level, called a fragment, while ... Read More

Difference between sequence and identity in Hibernate

Himanshu shriv
Updated on 21-Jan-2020 08:04:06

11K+ Views

Hibernate or JPA support 4 different types of  primary key generator. These generators are used to generate primary key while inserting rows in the database. Below are the primary key generator   −GenerationType.AUTOGenerationType. IDENTITYGenerationType.SEQUENCE GenerationType.TABLEGenerationType. IDENTITY − In identity , database is responsible to auto generate the primary key. Insert a row without specifying a value for the ID and after inserting the row, ask the database for the last generated ID.  Oracle 11g does not support identity key generator. This feature is supported in Oracle 12c. GenerationType. SEQUENCE − In sequence, we first ask database for the next set of the sequence ... Read More

Difference between EnumMap and HashMap in Java

Alshifa Hasnain
Updated on 16-Jun-2025 16:40:48

1K+ Views

In this article, we will learn about the EnumMap and HashMap in Java. First, we will know about EnumMap, the syntax of EnumMap, and an example after that will learn about HashMap, the syntax of HashMap, and an example. At the end, we will see a table showing the difference between EnumMap and HashMap. What is EnumMap? EnumMap is introduced in JDK 5. It is designed to use an Enum as a key in the Map. It is an implementation of the Map interface. All of the keys in the EnumMap should be of the same enum type. Keys cannot be ... Read More

Difference between Collection.stream().forEach() and Collection.forEach() in Java

Himanshu shriv
Updated on 21-Jan-2020 08:02:10

986 Views

Collection.stream().forEach() and Collection.forEach() both are used to iterate over collection. Collection.forEach()  uses the collection’s iterator. Most of the collections doesn’t allow the structurally modification while iterating over them. If any element add or remove while iteration they will immediately throw concurrent modification exception. If Collection.forEach() is iterating over the synchronized collection then they will lock the segment of the collection and hold it across all the calls. Collection.stream().forEach() is also used for iterating the collection but it first convert the collection to the stream and then iterate over the stream of the collection therefore the processing order is undefined. It also throws ... Read More

Difference between save() and persist() in Hibernate

Himanshu shriv
Updated on 21-Jan-2020 07:33:48

23K+ Views

Save() and persist() both methods are used for saving object in the database. As per docs −Save()  − Persist the given transient instance, first assigning a generated identifier. (Or using the current value of the identifier property if the assigned generator is used.) This operation cascades to associated instances if the association is mapped with cascade="save-update".As per docs −persist() −  Make a transient instance persistent. This operation cascades to associated instances if the association is mapped with cascade="persist". The semantics of this method are defined by JSR-220. Sr. No.Keysave()persist()1Basic  It stores object in databaseIt also stores object in database2Return Type It return generated id and return type is ... Read More

Difference Between JDBC and Hibernate

Himanshu shriv
Updated on 14-Jul-2020 09:24:01

6K+ Views

JDBC is acronym of Java database connectivity. It is used to connect your application to the database and transactions . It is an open source Java api.  Hibernate is also used for connect your application to database and to do database related transactions but with different approach. It has a object relationship library which mapped the tables and columns of the database with the java object. It enables object oriented programming in database. Hibernate provides HQL to access the data from the database. Sr. No.KeyJDBCHibernate1Basic It is database connectivity technology It is a framework, 2Lazy Loading It does not support lazy loading Hibernate support ... Read More

Difference Between get() and load() in Hibernate

Himanshu shriv
Updated on 21-Jan-2020 07:19:37

26K+ Views

In hibernate, get() and load() are two methods which is used to fetch data for the given identifier. They both belong to Hibernate session class. Get() method return null, If no row is available in the session cache or the database for the given identifier whereas load() method throws object not found exception. Sr. No.KeyGet()Load()1Basic It  is used to fetch data from the database for the given identifier  It  is also used to fetch data from the database for the given identifier 2Null Object It object not found for the given identifier then it will return null object It will throw object not found exception 3Lazy ... Read More

How to implement IntBinaryOperator using lambda expression in Java?

raja
Updated on 14-Jul-2020 09:22:47

470 Views

IntBinaryOperator is a functional interface in Java 8 from java.util.function package. This interface expects two parameters of type int as input and produces an int type result. IntBinaryOperator can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsInt().Syntax@FunctionalInterface public interface IntBinaryOperator {  int applyAsInt(int left, int right) }Exampleimport java.util.function.*; public class IntBinaryOperatorTest {    public static void main(String[] args) {       IntBinaryOperator test1 = (a, b) -> a + b; // lambda expression       System.out.println("Addition of two parameters: " + test1.applyAsInt(10, 20));       IntFunction test2 = new IntFunction() {     ... Read More

Difference Between First level cache and Second level cache in Hibernate

Himanshu shriv
Updated on 21-Jan-2020 07:12:08

11K+ Views

Hibernate support two type of cache one is first level cache and other is second level cache. First level cache is a session level cache and it is always associated with session level object. This type of cache is used for minimizing Db interaction by caching the state of the object. 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 is session factory level cache and it is available across all sessions.While running the transactions, in between it loads the objects at the Session Factory level, ... Read More

How to implement Function interface with lambda expression in Java?

raja
Updated on 14-Jul-2020 09:16:29

3K+ Views

Function interface is a functional interface from java.util.function package. This interface expects one argument as input and produces a result. Function interface can be used as an assignment target for a lambda expression or method reference. It contains one abstract method: apply(), two default methods: andThen() and compose() and one static method: identity().Syntax@FunctionalInterface public interface Function {  R apply(T t); }Exampleimport java.util.function.Function; public class FunctionTest {    public static void main(String[] args) {       Function f1 = i -> i*4;   // lambda       System.out.println(f1.apply(3));       Function f2 = i -> i+4; // lambda   ... Read More

Advertisements