How-to articles, tricks, and solutions about JAVA
You can download the latest Java Runtime Environment (JRE) or Java Development Kit (JDK) as a zip file from the official website of Oracle (https://www.oracle.com/java/technologies/javase-downloads.html).
To increment a date by one day in Java, you can use the plusDays() method of the java.time.LocalDate class from the java.time package.
To initialize a static Map in Java, you can use the Map interface's of method, which was added in Java 9. The of method creates an immutable Map with a fixed set of key-value pairs.
To log SQL statements in Spring Boot, you can configure the logging level of the org.hibernate.SQL logger to DEBUG or TRACE.
To print quotes in Java, you need to use the escape character \ to indicate that the quote is part of the string and not the end of the string.
Java .class files are compiled Java bytecode, which is not easily readable by humans.
To pad a string in Java, you can use the String.format() method and specify a width for the string.
To pad an integer with zeros on the left in Java, you can use the String.format() method and specify a minimum field width for the integer. For example:
In Java 8 and later, you can use the java.time.LocalDateTime class to represent a date and time without a time zone. To parse a date and time string into a LocalDateTime object, you can use the java.time.format.DateTimeFormatter class.
To pass a parameter to a Java thread, you can use a Runnable object and pass the parameter to its constructor.
java.lang.NumberFormatException: For input string: "N/A" occurs when you try to parse a string that cannot be converted to a number, such as the string "N/A".
To compare two Integer objects in Java, you can use the equals() method.
To read a large text file line by line in Java, you can use a BufferedReader and pass it a FileReader object to read the file. Here's an example of how you can do this:
There are several ways to remove a substring from a given string in Java. Here are a few options:
java.lang.NoClassDefFoundError is an error that occurs when the Java Virtual Machine (JVM) can't find a required class definition at runtime. This can happen for a variety of reasons, including:
To sort a List alphabetically in Java, you can use the Collections.sort method and pass in your List as an argument.
To sort the values of a Map by key in Java, you can use the TreeMap class, which is a Map implementation that maintains its entries in ascending key order.
To determine whether you are running in a 64-bit JVM or a 32-bit JVM from within a Java program, you can use the sun.arch.data.model system property.
You can use the flatMap method from the Stream API to turn a List<List<T>> (a list of lists) into a List<T> in Java 8. Here's an example of how you can do this:
To upload files to a server using JSP/Servlet, you can use the following steps:
In Java, pointers are not used in the same way that they are used in other programming languages such as C or C++.
There are several tools that you can use to "decompile" Java class files and view the source code. Some popular ones include:
An unchecked cast warning in Java occurs when the compiler cannot verify that a cast is safe at compile time.
To break out of nested loops in Java, you can use the break statement. The break statement terminates the innermost loop that it is contained in, and transfers control to the statement immediately following the loop.
To call one constructor from another in Java, you can use the this keyword. Here is an example: