Category: Java


  • ConcurrentHashMap

    1. ConcurrentHashMap class The ConcurrentHashMap is very similar to the HashMap class, except that ConcurrentHashMap offers internally maintained concurrency. It means we do not need to have synchronized blocks when accessing its key-value pairs in a multithreaded application. //Initialize ConcurrentHashMap instance ConcurrentHashMap<String, Integer> m = new ConcurrentHashMap<>(); //Print all values stored in ConcurrentHashMap instance for each (Entry<String, Integer> e : m.entrySet()) { system.out.println(e.getKey()+”=”+e.getValue()); } The…

  • 1. Deadlock In Java, a deadlock is a situation where minimum two threads are holding the lock on some different resource, and both are waiting for the other’s resource to complete its task. And, none is able to leave the lock on the resource it is holding. ResolveDeadLockTest.java package thread; public class ResolveDeadLockTest { public static…

  • A Stream in Java can be defined as a sequence of elements from a source. The source of elements here refers to a Collection or Array that provides data to the Stream. Java streams are designed in such a way that most of the stream operations (called intermediate operations) return a Stream. This helps to create a chain of stream operations. This is…

  • Stream toArray(IntFunction generator) example Description Stream toArray(IntFunction<A[]> generator) returns an array containing the elements of this stream, using the provided generator function. import java.util.List; import java.time.LocalDate; import java.time.Month; import java.util.Arrays; public class Main { public static void main(String[] args) { List<Employee> persons = Employee.persons(); Employee[] men = persons.stream() .filter(p -> p.getGender() ==Gender.MALE) .toArray(Employee[]::new); for(Employee employee: men){…

  • GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement You should try different dialects likeorg.hibernate.dialect.MySQL5Dialect OR org.hibernate.dialect.MySQLMyISAMDialect OR org.hibernate.dialect.MySQLInnoDBDialect to see which one works for you. Solution 1 You should try different dialects likeorg.hibernate.dialect.MySQL5Dialect OR org.hibernate.dialect.MySQLMyISAMDialect OR org.hibernate.dialect.MySQLInnoDBDialect to see which one works for you. All in all, your current dialect is generating,type=MyISAM while it should be, ENGINE=MyISAM in create table query. mysql…