How-to articles, tricks, and solutions about JAVA

How to call a SOAP web service on Android

To call a SOAP web service on Android, you can use the HttpURLConnection class to send an HTTP request to the web service and receive the response.

What is @ModelAttribute in Spring MVC?

In Spring MVC, the @ModelAttribute annotation is used to bind request parameters to method arguments in controller methods.

How can I pass a parameter to a Java Thread?

To pass a parameter to a Java thread, you can use a Runnable object and pass the parameter to its constructor.

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.

What is the best way to tell if a character is a letter or number in Java without using regexes?

To tell if a character is a letter or number in Java without using regexes, you can use the Character class and its isLetter() and isDigit() methods.

Break or return from Java 8 stream forEach?

To break or return from a Java 8 Stream.forEach() operation, you can use the break or return statements as you would normally do in a loop.

Java 8: Difference between two LocalDateTime in multiple units

To find the difference between two LocalDateTime objects in multiple units, you can use the Duration class.

How to install JDK 11 under Ubuntu?

To install JDK 11 under Ubuntu, follow these steps:

How can I edit a .jar file?

A .jar file is a Java Archive file that contains compiled Java code and resources (such as images, sounds, etc.) that can be used by Java applications.

Why doesn't RecyclerView have onItemClickListener()?

RecyclerView does not have an onItemClickListener() method because it is not directly responsible for displaying a list of items.

How do I connect to a SQL Server 2008 database using JDBC?

To connect to a SQL Server database using JDBC, you will need to use the JDBC driver for SQL Server.

Run a single test method with maven

To run a single test method with Maven, you can use the surefire:test goal and specify the fully-qualified name of the test class and the method name using the test and method properties, respectively.

Get the POST request body from HttpServletRequest

To get the POST request body from an HttpServletRequest object in Java, you can use the getReader method of the ServletRequest interface to read the request body as a BufferedReader and then use the readLine method to read the data as a string.

HttpServletRequest get JSON POST data

To get JSON POST data from an HttpServletRequest object in Java, you can use the getReader method of the ServletRequest interface to read the request body as a BufferedReader and then use the readLine method to read the data as a string.

Check and extract a number from a String in Java

To check if a string contains a number and extract the number from the string in Java, you can use a combination of the matches method of the String class and the find method of the Matcher class.

Remove last character of a StringBuilder?

To remove the last character of a StringBuilder in Java, you can use the deleteCharAt method and pass in the index of the character you want to delete.

How is the default max Java heap size determined?

The default maximum heap size for the Java heap is determined by the amount of physical memory available on the system.

Only using @JsonIgnore during serialization, but not deserialization

If you want to use the @JsonIgnore annotation to ignore a field during serialization but not during deserialization, you can use the @JsonIgnoreProperties annotation and set its writeOnly property to true.

How to check if a folder exists?

To check if a folder exists in Java, you can use the java.nio.file.Files class and its exists method.

Strip Leading and Trailing Spaces From Java String

To remove leading and trailing whitespace from a string in Java, you can use the trim method of the String class.

Create a directory if it does not exist and then create the files in that directory as well

To create a directory in Java if it does not exist, you can use the java.nio.file.Files class and its createDirectory method.

How do I do a HTTP GET in Java?

To send an HTTP GET request in Java, you can use the java.net.URL and java.net.HttpURLConnection classes.

In java how to get substring from a string till a character c?

To get a substring from a string in Java up until a certain character, you can use the indexOf method to find the index of the character and then use the substring method to extract the substring.

C++ performance vs. Java/C#

C++ is generally considered to be a faster and more performant language than Java or C#.

Getting java.net.SocketTimeoutException: Connection timed out in android

The java.net.SocketTimeoutException: Connection timed out error usually occurs when a client is trying to connect to a server, but the connection request is taking too long to complete.

1 2 3 4 5