Convert Exception Stack Trace to String in Java
Convert an exception stack trace to string in Java with StringWriter and PrintWriter, read causes and suppressed lines, and store or log it safely.
“Core Java” is Sun’s term, used to refer to Java SE, the standard edition and a set of related technologies, like the Java VM, CORBA, etc. This is mostly to differentiate from others like Java ME or Java EE. “Core Java” is Oracle’s definition and refers to subset of Java SE technologies.
The Core Java technologies and application programming interfaces (APIs) are the foundation of the Java Platform, Standard Edition (Java SE). They are used in all classes of Java programming, from desktop applications to Java EE applications.
Convert an exception stack trace to string in Java with StringWriter and PrintWriter, read causes and suppressed lines, and store or log it safely.
Fix InvalidKeyException Parameters missing by passing the IV to Cipher.init(), with AES-GCM IV storage and InvalidAlgorithmParameterException causes.
Java AES encryption and decryption with AES-256-GCM, random IVs, key storage, PBKDF2 and HKDF keys, file encryption, tamper detection and common mistakes.
Right pad a string in Java with spaces, zeros or any character using String.format(), repeat(), StringUtils.rightPad() and Guava, plus truncation.
Left pad a string in Java with spaces or leading zeros using String.format(), repeat(), StringUtils.leftPad() and Guava, with negative numbers and nulls.
Learn the Java StringJoiner class with add(), setEmptyValue(), merge() and length() examples, and compare it with String.join() and Collectors.joining().
Java remove extra spaces between words with replaceAll() and strip(), normalizeSpace(), split and join, plus non-breaking spaces and line breaks.
Java remove leading and trailing whitespace with strip(), stripLeading(), stripTrailing() and trim(), plus Unicode spaces, non-breaking spaces and null.
Learn to check if an array contains a value in Java with Arrays.asList(), anyMatch(), binarySearch() and HashSet, and why asList() fails on int[].
Convert int to String in Java with Integer.toString(), String.valueOf() and format(), plus null Integer, locale digits, hex and long to String.
Java wrapper classes explained with autoboxing and unboxing, valueOf() vs parseInt(), the Integer cache, == and null pitfalls, and examples on Java 25.
Convert a string to title case in Java with Character.toTitleCase(), a regex, split() or WordUtils, and keep small words such as of and the lowercase.
Check if a node or attribute exists with XPath in Java using boolean(), NODESET, NODE or count(), and tell missing elements from empty ones.
Use XPath to find nodes by attribute value in Java. Equality, numbers, contains, starts-with, missing attributes, any-case matches and safe variables.
Java convert XML Document to String with Transformer, pretty print without blank lines, drop the declaration and write an XML file with the right encoding.
Java convert String to XML Document with DocumentBuilder and InputSource. Secure parsing, malformed input, prolog errors, encodings and reuse explained.
Java unescape HTML examples with Commons Text unescapeHtml4(), Spring HtmlUtils and jsoup, plus a plain Java method and a fix for double-escaped text.
Java escape HTML examples with OWASP Java Encoder, Commons Text escapeHtml4() and Spring HtmlUtils, plus a plain Java method and how quotes differ.
Convert XML to properties in Java with loadFromXML() and store(), and back with storeToXML(), plus encoding, escaping, key order and flattening any XML.
Learn the Java StAX parser with XMLStreamReader and XMLEventReader examples, cursor vs iterator, XXE-safe factory settings and XMLStreamWriter on Java 25.
Learn to copy an array in Java with clone(), Arrays.copyOf() and System.arraycopy(), and how to make deep copies of object arrays and 2D arrays.
Sort a String alphabetically in Java with toCharArray() and Arrays.sort(), streams, case-insensitive order, emoji-safe codePoints() and a Collator.
Sort by multiple fields in Java with Comparator thenComparing(). Covers all six overloads, Collator names, map entries, 2D arrays and stable sorts.
Java Collections.sort() sorts a List in place. Learn natural order, Comparator and reverseOrder(), stability, List.sort() and the exceptions it throws.
Sort array in Java with Arrays.sort() and parallelSort(), including ranges, comparators, primitive arrays in descending order and 2D arrays by column.
Convert String to String array in Java with split(), handle regex delimiters, empty strings and emoji, and build a single-element array.
Learn to create a subarray in Java with Arrays.copyOfRange(), copyOf(), System.arraycopy(), range streams and ArrayUtils, plus index rules and pitfalls.
Java DateTimeFormatter examples for formatting and parsing LocalDate, LocalDateTime and ZonedDateTime with ofPattern() letters, ISO constants, FormatStyle and Locale, plus DateTimeParseException handling and the yyyy vs YYYY mistake.
Convert LocalDate to java.sql.Date and LocalTime to java.sql.Time, or skip both with JDBC 4.2 setObject() and getObject(), JPA and Hibernate.
Convert Date to LocalDate in Java with LocalDate.ofInstant() and back with Date.from(), pick the right time zone and avoid the one-day-off bug.
Convert LocalDateTime to Date in Java with atZone() and Date.from(), and back with ofInstant(), including DST gaps, overlaps and lost nanoseconds.
Convert LocalDateTime to ZonedDateTime in Java with atZone(), ofLocal() and ofStrict(), see how DST gaps and overlaps resolve, and convert back safely.
Convert date and time between time zones in Java with withZoneSameInstant(), from Instant, OffsetDateTime or LocalDateTime, with DST-safe examples.
Learn to add days to a date in Java with plusDays(), plusMonths() and plusYears(), with month-end rules, leap years, DST and java.util.Date conversion.
Format LocalDateTime in Java with format() and DateTimeFormatter. ISO and custom patterns, AM/PM, millis, locales, zones and pattern mistakes to avoid.
Measure elapsed time in Java with System.nanoTime() and Duration, avoid wall-clock errors, time any task with a helper, and use JMH for benchmarks.
Get the current timestamp in Java with Instant.now() and currentTimeMillis(), convert to epoch millis or seconds, format it, and save it with JDBC.
Compare two dates in Java with isBefore(), isAfter(), isEqual() and compareTo(), with or without time, across time zones, in ranges and for legacy Date.
Convert date and time to EST in Java with America/New_York, which switches between EST and EDT. Compare EST5EDT and EST and print the right zone label.
Create a Java list with a single element using List.of(), Collections.singletonList(), Arrays.asList() or ArrayList. Mutability and null rules compared.
Java append to file examples with StandardOpenOption.APPEND, BufferedWriter, FileWriter and FileOutputStream, plus new lines, missing files and threads.
Java write to file examples with Files.writeString, Files.write, BufferedWriter, PrintWriter and streams, plus append options, UTF-8 and atomic writes.
Java var keyword explained with Java 25 examples. See where local variable type inference works, which javac errors it causes, and common mistakes.
Java comments explained with single-line, multi-line and Javadoc examples, Markdown doc comments from Java 23, javadoc tags, shortcuts and good practice.
Java variables explained with examples of local, instance and static variables, default values, scope, var, final and naming rules in Java 25.
Learn the difference between JDK, JRE and JVM in Java 25, what each one contains, how class loaders and the JIT work and why Oracle ships no JRE.
SSLHandshakeException means the Java client and the server could not agree on a TLS connection. Fix TLS version mismatches with jdk.tls.client.protocols, untrusted certificates with keytool, and find the rest with javax.net.debug.
Sort a Map by values in Java with Map.Entry.comparingByValue() and a LinkedHashMap, in ascending and descending order, with ties, top N and null values.
Sort a Map by keys in Java with a TreeMap or a stream and a LinkedHashMap, in both orders, with case-insensitive, numeric and null keys.
Build a Java chatbot with AIML and Program AB on Java 25, see the library status today, and add an LLM chatbot with HttpClient for many model providers.
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.