How-to articles, tricks, and solutions about JAVA

How to solve javax.net.ssl.SSLHandshakeException Error?

The javax.net.ssl.SSLHandshakeException error is usually caused by a problem with the SSL/TLS certificate of the server you are trying to connect to.

How to solve the “failed to lazily initialize a collection of role” Hibernate exception

The "failed to lazily initialize a collection of role" exception in Hibernate is thrown when you try to access an uninitialized collection from a Hibernate entity when the entity is in a detached state.

How to sort a HashMap in Java

To sort a HashMap in Java, you can use the TreeMap class, which is a Map implementation that maintains its entries in ascending order, sorted according to the keys.

How to sort a List/ArrayList?

To sort a List or ArrayList in Java, you can use the sort method of the Collections class from the java.util package. The sort method takes a List and sorts it in ascending order according to the natural ordering of its elements.

How to sort a Map<Key, Value> by values in Java

To sort a Map&lt;Key, Value&gt; by values in Java, you can create a custom comparator that compares the values and pass it to the sort() method of the Map.Entry class.

How to sort an ArrayList in Java

To sort an ArrayList in Java, you can use the Collections.sort method.

How to split a String by space

In Java, you can split a string by space using the split() method of the String class. This method takes a regular expression as an argument and returns an array of substrings split by the regular expression.

How to Split a String in Java

Learn the ways to split a string in Java. The most common way is using the String.split () method, also see how to use StringTokenizer and Pattern.compile ().

How to split a string with any whitespace chars as delimiters

In Java, you can use the split() method of the String class to split a string based on a regular expression.

How to subtract X day from a Date object in Java?

To subtract a certain number of days from a Date object in Java, you can use the Calendar class.

How to sum a list of integers with java streams?

You can use the reduce() operation in the Java Streams API to sum the elements of a list of integers.

How to switch to the new browser window, which opens after click on the button?

To switch to a new browser window in Selenium, you can use the switchTo() method with the WindowHandle of the new window.

How to tell Jackson to ignore a field during serialization if its value is null?

There are a few ways to tell Jackson to ignore a field during serialization if its value is null. One way is to use the @JsonInclude annotation with the Include.NON_NULL value on the field or class level.

How to test that no exception is thrown?

To test that no exception is thrown in a Java method, you can use the assertDoesNotThrow method from the org.junit.jupiter.api.Assertions class (part of the JUnit 5 library).

How to update a value, given a key in a hashmap?

To update the value associated with a key in a HashMap in Java, you can use the put() method.

How to upload a file and JSON data in Postman?

To upload a file and JSON data in Postman, you can follow these steps:

How to use a Java8 lambda to sort a stream in reverse order?

To use a Java 8 lambda to sort a stream in reverse order, you can use the sorted() method of the Stream interface and pass a lambda function that compares the elements in reverse order.

How to use Class<T> in Java?

In Java, the Class<T> class represents the class or interface type of a class at runtime.

How to use Comparator in Java to sort

To use a Comparator in Java to sort a list of objects, you can use the Collections.sort method and pass it a List and a Comparator.

How to use Jackson to deserialise an array of objects

Jackson is a powerful Java library for processing JSON data. You can use Jackson to deserialize an array of objects by following these steps:

How to use java.net.URLConnection to fire and handle HTTP requests

You can use the java.net.URLConnection class to fire and handle HTTP requests in Java. Here's an example of how you can use the URLConnection class to send a GET request and read the response:

How to use java.String.format in Scala?

In Scala, you can use the format method of the String class to format strings in a way similar to the printf function in C.

How to verify that a specific method was not called using Mockito?

To verify that a specific method was not called using Mockito, you can use the verifyZeroInteractions method.

How to write logs in text file when using java.util.logging.Logger

To write logs to a text file using java.util.logging.Logger, you will need to do the following:

Http 415 Unsupported Media type error with JSON

A HTTP 415 Unsupported Media Type error means that the server is unable to process the request because the request entity has a media type that the server does not support. In the context of a JSON request, this means that the server is unable to process