How-to articles, tricks, and solutions about JAVA
A good hash function for strings should have the following properties:
To compare two lists in Java, you can use the equals() method of the List interface.
To change the color of a Floating Action Button (FAB) in Android, you can use the setBackgroundTintList() method and pass it a color state list.
To get the number of lines in a file in Java, you can use the BufferedReader class and read the file line by line until the end of the file is reached.
In Java, objects are automatically eligible for garbage collection when they are no longer reachable.
In the main() method in Java, String args[] is an array of strings that holds the command-line arguments passed to the program.
In Java, interface variables are static and final by default because that is how they are defined in the Java Language Specification (JLS).
To get the row count using a ResultSet object in Java, you can use the last() method to move the cursor to the last row, and then use the getRow() method to get the row number:
If you see the error "Port 8080 already in use" when starting the Tomcat server, it means that another process is already using port 8080 on your machine.
To perform HTTPS client certificate authentication in Java, you can use the HttpsURLConnection class and the SSLSocketFactory class.
To install Java 7 on Ubuntu, you can follow these steps:
To make a POST request with the RestTemplate in JSON, you can use the postForObject() method and pass it the URL of the request, the request body, the response type, and the HttpEntity object that represents the request headers and body.
In Java, List is an interface that defines a list data structure, while ArrayList is a class that implements the List interface.
To remotely debug a Java application, you need to start the application with the java command and the -agentlib:jdwp option.
To concatenate two strings in Java, you can use the + operator.
In Java 8, the :: (double colon) operator is used to refer to a method or a constructor.
In Java 8, you can use a lambda expression to create a functional interface that throws an exception.
The @Autowired annotation in Spring is used to inject dependencies into a Java object.
To count the occurrences of a character in a string in Java, you can use the charAt() method of the String class to iterate over the characters in the string and check if each character is equal to the target character.
To convert an integer to an array of digits in Java, you can use the toCharArray() method of the String class to convert the integer to a string, and then use the toCharArray() method to convert the string to an array of characters.
To parse command line arguments in Java, you can use the main() method of your application's entry point class.
To check a string in the response body with MockMvc, you can use the andExpect() method of the MockMvcResultMatchers class.
In Java, a data access object (DAO) is a design pattern that provides an abstract interface for accessing data from a database.
To parse a date in Java, you can use the SimpleDateFormat class.
To run a Unix shell script from Java code, you can use the Runtime.getRuntime().exec() method to execute the script.