How-to articles, tricks, and solutions about JAVA
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.
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.
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.
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.
To sort a Map<Key, Value> 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.
To sort an ArrayList in Java, you can use the Collections.sort method.
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.
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 ().
In Java, you can use the split() method of the String class to split a string based on a regular expression.
To subtract a certain number of days from a Date object in Java, you can use the Calendar class.
You can use the reduce() operation in the Java Streams API to sum the elements of a list of integers.
To switch to a new browser window in Selenium, you can use the switchTo() method with the WindowHandle of the new window.
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.
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).
To update the value associated with a key in a HashMap in Java, you can use the put() method.
To upload a file and JSON data in Postman, you can follow these steps:
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.
In Java, the Class<T> class represents the class or interface type of a class at runtime.
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.
Jackson is a powerful Java library for processing JSON data. You can use Jackson to deserialize an array of objects by following these steps:
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:
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.
To verify that a specific method was not called using Mockito, you can use the verifyZeroInteractions method.
To write logs to a text file using java.util.logging.Logger, you will need to do the following:
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