How-to articles, tricks, and solutions about JAVA
To decompile a JAR file, you can use a Java decompiler such as JD-GUI.
To get an OutputStream into a String, you can use a ByteArrayOutputStream as the OutputStream and then use the toString() method of the ByteArrayOutputStream to get the contents of the stream as a string.
To convert an int to a long in Java, you can simply use the typecast operator (long) and place it in front of the value you want to convert.
To get input from the System.console() in Java, you can use the readLine() method of the Console class.
The "failed to lazily initialize a collection of role" exception in Hibernate is thrown when you try to access an uninitialized collection from a Hibernate entity when the entity is in a detached state.
The error org.xml.sax.SAXParseException: Content is not allowed in prolog usually indicates that there is some content before the XML prolog in the file you are trying to parse.
To change the font size in the Java text editor in Eclipse, follow these steps:
In Scala, you can use the format method of the String class to format strings in a way similar to the printf function in C.
To calculate the number of days between two dates in Java, you can use the Period class from the java.time package introduced in Java 8.
To implement a recursive Fibonacci sequence in Java, you can define a recursive method that returns the nth number in the sequence.
To get the milliseconds from a LocalDateTime object in Java 8, you can use the toInstant method and the toEpochMilli method.
To check if a ResultSet object contains any results in Java, you can use the next method of the ResultSet class.
To shuffle an array randomly in Java, you can use the Collections.shuffle method.
In Java, a daemon thread is a thread that runs in the background and does not prevent the program from exiting.
To display the current time in 12-hour format with AM/PM in Java, you can use the SimpleDateFormat class and the Calendar class.
To convert a JSON string to a Java object, you can use the fromJson method of the Gson class.
To append a single character to a string or char array in Java, you can use the + operator or the concat method for strings, or you can use the Arrays.copyOf method for char arrays.
In Java, the three dots (...) next to a parameter type indicate that the parameter is a varargs parameter.
To build a Gradle project without running the tests, you can use the assemble task instead of the build task.
If you are trying to download the Java Development Kit (JDK) on Linux using wget and you are being shown the license page instead of the JDK download, it is likely because the download page has changed since the wget command was written.
If you want to remove elements from a collection while iterating over it using a for-each loop in Java, you must use an iterator instead of the looping construct.
To break out or exit a method in Java, you can use the return statement.
To get the values and keys from a HashMap in Java, you can use the values and keySet methods.
To sort a List alphabetically in Java, you can use the Collections.sort method and pass in your List as an argument.