How-to articles, tricks, and solutions about JAVA
To set the default character encoding for the Java Virtual Machine (JVM), you can use the -Dfile.encoding option when starting the JVM.
If you get an error saying that several ports required by the Tomcat Server are already in use, it means that another program is using one or more of the ports that Tomcat is trying to bind to. Tomcat typically uses the following ports:
In Java, you can use the ternary operator (also known as the conditional operator) to create a short form for an if-else statement.
To create a simple HTTP server in Java using only the Java SE API, you can use the java.net package.
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.
In Java, you can use the String.repeat() method to repeat a string multiple times.
To read JSON from a URL in Java, you can use the readJsonFromUrl() method from the JSON simple library.
A "communications link failure" error when using JDBC and MySQL can be caused by several factors. Here are a few potential solutions:
To sort an array in Java, you can use the Arrays.sort() method of the java.util.Arrays class. This method sorts the elements of the array in ascending order according to their natural ordering.
To sort an ArrayList of custom objects by a property, you can use the Collections.sort method and pass it a custom Comparator.
To sort a HashMap by values in Java, you can use the Map.Entry interface and the Comparator interface to create a comparator that compares the values in the map.
To split a string in Java by new line, you can use the split method of the String class and pass it the regular expression "\n" or "\r\n", depending on the platform you are running on.
If you are seeing the error "Cannot determine embedded database driver class for database type NONE" in a Spring Boot application, it means that the application is trying to auto-configure an embedded database, but it is unable to determine which database
The error "Error creating bean with name 'dataSource' defined in class path resource" in Spring Boot typically indicates that there is a problem with the configuration of the dataSource bean.
In a Spring Boot application, you can log all requests and responses, along with exceptions, in a single place by using a combination of Spring Boot's logging framework and request/response interceptors.
To use multiple external configuration files with Spring Boot, you can use the spring.config.name property to specify the names of the configuration files.
To create a cron expression that triggers an event every day at 1:01 AM, you can use the following cron expression:
This exception is usually thrown when you are trying to access a property that does not exist in the entity class you are querying.
To select specific columns using Spring JPA, you can use the @Query annotation and specify the columns in the SELECT clause of the JPQL query.
To return a simple string as JSON in a Spring MVC Rest Controller, you can use the @ResponseBody annotation and return the string directly.
To perform a GET request with parameters using the RestTemplate in Spring, you can use the getForObject() method and pass it a URL with placeholders for the parameters, as well as a map of the parameter values.
An SSL (Secure Sockets Layer) keystore is a storage location for SSL certificates, which are used to establish secure, encrypted connections between a client and a server. The keystore is typically managed by a keystore manager, such as the Java Keytool,
The "stale element reference" error in Selenium WebDriver occurs when an element that was previously found on the webpage is no longer attached to the DOM (Document Object Model) and is therefore no longer accessible through the browser.
In Java, a static class is a class that can be accessed without an instance of the class. A static class is defined by adding the static keyword to the class declaration.
In Java, you can use the concat() method of the java.lang.String class or the + operator to concatenate (join) two or more strings.