How-to articles, tricks, and solutions about JAVA

How to assert that a certain exception is thrown in JUnit tests?

To assert that a certain exception is thrown in a JUnit test, you can use the @Test annotation's expected attribute. Here's an example:

How to break out or exit a method in Java?

To break out or exit a method in Java, you can use the return statement.

How to build JARs from IntelliJ properly?

To build a JAR (Java Archive) file from IntelliJ IDEA, you need to follow these steps:

How to calculate the running time of my program?

To calculate the running time of a program in Java, you can use the System.currentTimeMillis() method to get the current time in milliseconds before and after the program runs.

How to call a method after a delay in Android

To call a method after a delay in Android, you can use the Handler class and the postDelayed() method. The postDelayed() method takes a Runnable and a delay in milliseconds as arguments, and it runs the Runnable after the specified delay.

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.

How to capitalize the first character of each word in a string

There are a few different approaches you can take to capitalize the first character of each word in a string in Java.

How to capitalize the first letter of a String in Java?

To capitalize the first letter of a string in Java, you can use the toUpperCase method of the java.lang.String class. Here's an example of how you can do this:

How to cast an Object to an int

To cast an Object to an int in Java, you can use the intValue() method of the Integer class.

How to change date format in a Java string?

To change the date format in a Java string, you can use the SimpleDateFormat class.

How to change font size in Eclipse for Java text editors?

To change the font size in the Java text editor in Eclipse, follow these steps:

How to check certificate name and alias in keystore files?

To check the certificate name and alias in a keystore file, you can use the keytool utility that comes with the Java Development Kit (JDK).

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.

How to check if a String contains another String in a case insensitive manner in Java?

To check if a String contains another String in a case-insensitive manner in Java, you can use the toLowerCase() method of the String class and the contains() method.

How to check if a string contains only digits in Java

To check if a string contains only digits in Java, you can use the matches() method of the String class in combination with the regular expression "\\d+".

How to check if a String is numeric in Java

To check if a String is numeric in Java, you can use the isNumeric method of the StringUtils class from the org.apache.commons.lang3 library.

How to check if an int is a null

In Java, an int is a primitive data type and cannot be null.

How to check if my string is equal to null?

To check if a string is equal to null in Java, you can use the == operator.

How to check internet access on Android? InetAddress never times out

To check for internet access on Android, you can use the isReachable() method of the InetAddress class.

How to check String in response body with mockMvc

To check a string in the response body with MockMvc, you can use the andExpect() method of the MockMvcResultMatchers class.

How to check type of variable in Java?

To check the type of a variable in Java, you can use the instanceof operator.

How to clear the console?

To clear the console in most command-line interfaces (CLI), you can use the clear or cls command.

How to clone ArrayList and also clone its contents?

To clone an ArrayList and also clone its contents, you can use the clone method of the ArrayList class, which creates a shallow copy of the list.

How to compare dates in Java?

You can compare dates in Java by using the compareTo() method of the java.util.Date class. This method compares the date object on which it is called with the date object passed as an argument to the method

How to Compare Strings in Java

The comparison of strings is one of the mostly used Java operations. If you’re looking for different ways to compare two strings in Java, you’re at the right place.