How-to articles, tricks, and solutions about JAVA
The java.lang.UnsupportedOperationException is thrown when an operation is not supported by a class.
Java Persistence API (JPA) is a specification for object-relational mapping (ORM) in Java.
To set an environment variable from Java, you can use the System.setProperty() method.
In a JPA entity mapping, the @JoinColumn annotation is used to specify the foreign key column for a many-to-one or one-to-one relationship.
The best way to create an enum of strings in Java is to define the enum type with a String field, and then specify the possible values for the enum as string literals.
To import an existing X.509 certificate and private key into a Java keystore, you can use the keytool utility that is included with the Java Development Kit (JDK).
To check if a string is equal to null in Java, you can use the == operator.
To create a JSON array using JSONObject in Java, you can use the put() method of the JSONObject class to add elements to the array.
To use a custom class in your Java code, you will need to import it at the beginning of your source file.
To convert an int to a double, you can use the doubleValue() method of the Integer class.
You can use the @JsonFormat annotation to specify the format of date fields in a JSON payload when serializing or deserializing using Jackson.
To create a cron expression that triggers an event every day at 1:01 AM, you can use the following cron expression:
To get a list of JSON objects using the Spring RestTemplate, you can use the exchange() method to send an HTTP GET request to the server, and then use the getBody() method of the ResponseEntity object to retrieve the list of objects.
To check for internet access on Android, you can use the isReachable() method of the InetAddress class.
To print a Java object in a more readable format, you can override the toString() method in your class.
In Java, integer division always produces an integer result, even if the dividend is a floating-point number.
You can use the reduce() operation in the Java Streams API to sum the elements of a list of integers.
The ifPresent() and ifPresentOrElse() methods of the Optional class in Java 8 provide a functional style way to perform different actions depending on whether the Optional object is empty or contains a value.
To return a JSON object from a Java Servlet, you can use the following steps:
There are a few different approaches you can take to capitalize the first character of each word in a string in Java.
A java.net.ConnectException: Connection timed out error can occur when a Java application is unable to establish a network connection to the specified host.
A java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) error typically indicates that the MySQL server is unable to authenticate the user with the provided username and password.
A java.net.SocketTimeoutException: Read timed out error can occur when a connection to a server is blocked by a firewall or if the server is experiencing high load and is unable to process requests in a timely manner.
To launch an activity from another application in Android, you can use an Intent with the FLAG_ACTIVITY_NEW_TASK flag set.
To scroll up or down in a web page using Selenium WebDriver in Java, you can use the JavascriptExecutor interface and the scrollBy method.