How-to articles, tricks, and solutions about JAVA
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:
To break out or exit a method in Java, you can use the return statement.
To build a JAR (Java Archive) file from IntelliJ IDEA, you need to follow these steps:
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.
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.
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.
There are a few different approaches you can take to capitalize the first character of each word in 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:
To cast an Object to an int in Java, you can use the intValue() method of the Integer class.
To change the date format in a Java string, you can use the SimpleDateFormat class.
To change the font size in the Java text editor in Eclipse, follow these steps:
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).
To check if a folder exists in Java, you can use the java.nio.file.Files class and its exists method.
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.
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+".
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.
In Java, an int is a primitive data type and cannot be null.
To check if a string is equal to null in Java, you can use the == operator.
To check for internet access on Android, you can use the isReachable() method of the InetAddress class.
To check a string in the response body with MockMvc, you can use the andExpect() method of the MockMvcResultMatchers class.
To check the type of a variable in Java, you can use the instanceof operator.
To clear the console in most command-line interfaces (CLI), you can use the clear or cls command.
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.
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
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.