-
Parsing String to Int in Java
Converting a string number to int in java can be done using several ways. We can use the java Integer class pasrseInt and valueOf methods. We can create of util method to do this with exception handling. Integer num = Integer.valueOf(input);// orint num = Integer.parseInt(input);There is a slight difference between these methods: valueOf returns a…
-
Best ways to create ArrayList from Array in Java
Many times we need to create an ArrayList from arrays of objects in java. There are several ways to do this using core Java APIs or third-party open-source libs like guava. The easiest way to do this is by using the JDK Arrays class. Using JDK to convert array to ArrayList But the above one…
-
Convert InputStream to String in Java
While writting Java programs much time we need to convert an InputStream object to a String. There are many ways to do this, we can use core Java classes or we can use some really good java libraries to convert InputStreams to String. Apart from JDK, Apache Commons IO, and Guava provides classes to convert/read…
-
Which Java Collection Class to Implement LRU Cache?
A cache is a method to store some data temporarily which can be accessed faster to improve software performance. There can be different types of cache but in general, we use LRU (Least recently used entry will evict first in case of cache size full) and cache with TTL (Time to live, entries will be…
-
Differences of HashMap, LinkedHashMap, TreeMap, and HashTable
Java provides a rich library of different data structures to store and perform operations on those data. Java collection framework classes HashMap, LinkedHashMap, TreeMap, and HashTable provides an implementation of Map interface. All these are used as key and value store data structures. The map is the most used collection class after arrays and lists.…
-
In-Memory Local Cache Option for Java
In Java, an in-memory cache can be implemented using ConcurrentMap very efficiently, but it has only the problem that objects can not be evicted automatically after a certain time or limit, we need to remove entries manually. In many situations, the in-memory cache can be very useful to increase speed, but obviously, it will also…
-
Java Disable HTTPS Certificate Validation
While working with HTTP clients in java, many times we get a certificate validation exception as given below. Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target The above exception can be caused due to a self-signed certificate or expired certificate as the client is unable to…
-
How to Write MySql Junit Tests?
MySql is the most used open-source RDBMS in the world with different application development stacks. As nowadays most of the development of the system is TDD based, so for writing test cases for the MySql database will require running DB or we can use H2 database with MySql mode or we can even use Embedded…
-
Postgres JDBC and Hibernate Using JSONB Type
While working with Postgres JSONB type and Java, if we assign the value of type UUID as a string then we will get the following exception. To assigning value incorrect way is given below, if you are using PreparedStatement. First, in the query, you need to write input param par as given below for the…
-
Postgres JDBC and Hibernate Using UUID Types
While working with Postgres UUID type and Java, if we assign the value of type UUID as a string then we will get the following exception. To assigning value incorrect way is given below, if you are using PreparedStatement. If the value of UUID is a string type, then first you need to convert it…