How-to articles, tricks, and solutions about JAVA
To parse an integer value from a char in Java, you can use the Character.getNumericValue() method.
The java.io.FileNotFoundException: the system cannot find the file specified error is usually thrown when a program tries to access a file that does not exist, or that it does not have permission to access.
The java.net.ConnectException: Connection refused exception is thrown when an application tries to connect to a remote host, but the connection is refused by the host. This can happen for several reasons, such as:
A java.net.SocketException: Connection reset is a runtime exception that is thrown when a connection is reset. This can be caused by a variety of issues, such as:
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.
The java.net.UnknownHostException: Invalid hostname for server: local exception usually indicates that a hostname or an IP address could not be resolved. This can happen for a variety of reasons, such as:
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.
To convert the format of a java.util.Date object from yyyy-MM-dd to MM-dd-yyyy, you can use the SimpleDateFormat class and its format() method.
To convert a java.util.Date object to an XMLGregorianCalendar in Java, you can use the toGregorianCalendar method of the DatatypeFactory class.
This error message indicates that you are trying to use a class name in a source code file that is not being processed by the Java compiler.
The error javac is not recognized as an internal or external command, operable program or batch file occurs when you try to run the javac command from the command prompt, but the command prompt cannot find the javac executable.
If javac is not working in the Windows command prompt, there could be several reasons for this.
In JAX-RS, you can use the Response class from the javax.ws.rs.core package to return a JSON response and an HTTP status code together. Here's an example of how to do this:
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.
To read a text file in Java, you can use the BufferedReader class from the java.io package.
To check if a key exists in a HashMap in Java, you can use the containsKey method.
The "Keystore was tampered with, or password was incorrect" error typically occurs when you try to use the keytool utility to access a keystore with an incorrect password or when the keystore has been modified in some way.
To left pad a String with zeros in Java, you can use the String.format() method and the %0Nd format specifier, where N is the total length of the padded string.
SOAP (Simple Object Access Protocol) and REST (Representational State Transfer) are two different styles of web services that can be used to expose the functionality of a web-based system over the internet.
To make a copy of an array in Java, you can use the clone() method of the Object class. The clone() method creates a shallow copy of the array, which means that it creates a new array with the same elements as the original array
To make a mocked method return an argument that was passed to it, you can use the Mockito.when method and pass it the argument that you want to return as the answer.
Math.random() is a method in the java.lang.Math class that returns a random double value between 0.0 (inclusive) and 1.0 (exclusive).
To package/install a Maven project without running the tests, you can use the maven-install-plugin and specify the skipTests property as true.
There are several possible reasons why Maven plugins might not be found in IntelliJ: