How-to articles, tricks, and solutions about JAVA
To declare an ArrayList with values in Java, you can use the Arrays.asList method and pass it an array or a list of values.
In Java, the finalize method is called by the garbage collector when it determines that an object is no longer reachable.
If GSON is throwing a JsonSyntaxException with the message "Expected BEGIN_OBJECT but was BEGIN_ARRAY", it means that you are trying to parse a JSON array as if it were a JSON object.
To read an integer value from the standard input (keyboard) in Java, you can use the Scanner class from the java.util package.
To stop a thread in Java, you can use the interrupt() method of the Thread class.
To find the length (number of elements) of an ArrayList in Java, you can use the size() method of the ArrayList class.
The java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory exception is thrown when a Java application is unable to find the LogFactory class from the Apache Commons Logging library.
To get a JSON object from a HTTP response in Java, you can use the JSONObject class from the org.json library.
The equals() and hashCode() methods are two methods that are defined in the Object class, which is the superclass of all classes in Java.
To compare two Integer objects in Java, you can use the equals() method.
In Java, you can use the AbstractMap.SimpleEntry class from the java.util package to represent a value pair (also known as a tuple).
To convert an int array to a string in Java, you can use the Arrays.toString() method from the java.util package.
To get keyboard input in Java, you can use the Scanner class from the java.util package.
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 remove the first character of a string in Java, you can use the substring() method of the String class.
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 replace a substring in a string in Java, you can use the replace() method of the String class.
The "Content is not allowed in prolog" error typically occurs when you try to parse an XML document that contains characters before the XML prolog (the <?xml ...?> declaration).
To enter quotes in a Java string, you can use the escape character \ to indicate that the quote is part of the string, rather than the end of the string.
When overriding the equals() and hashCode() methods in Java, you should consider the following issues:
To find the index of an element in an int array in Java, you can use the indexOf() method of the Arrays class.
To read JSON from a URL in Java, you can use the readJsonFromUrl() method from the JSON simple library.
The initial size of an ArrayList in Java is 0.
To show the real SQL generated by Hibernate, you can enable the show_sql property in the Hibernate configuration file (hibernate.cfg.xml).
To convert a string to a Date object in Java, you can use the parse() method of the SimpleDateFormat class.