Home » Java » Core Java (page 20)

Core Java

JDK 13: What AggressiveOpts?

The Java VM flag -XX:+AggressiveOpts was deprecated in JDK 11 [see JDK-8199777 and JDK-8199778] “because its behavior is ill-defined.” The “Problem” section of JDK-8199778 further explains (I added the emphasis): AggressiveOpts has been used as a catch-all method of enabling various experimental performance features, mostly targeted to improve score on very specific benchmarks. Most things it affected has been removed ...

Read More »

Running JAXB xjc Compiler with OpenJDK 11

As described in the post “APIs To Be Removed from Java 11,” a JAXB implementation is no longer included with JDK 11. In this post, I look at using the xjc compiler provided with the JAXB (Java Architecture for XML Binding) reference implementation in conjunction with OpenJDK 11 to compile XML schema files into Java classes. Prior to Java SE ...

Read More »

How much faster is Java 11?

Java 11 was released some time ago, although the majority of developers stay on Java 8. Let’s see which one of them is faster for OptaPlanner. The best way to find out is of course running OptaPlanner benchmarks. This article is a follow up on our similar article for Java 8. Benchmark methodology To run the benchmark we used: A stable machine without ...

Read More »

Using Minimum Fractional Digits with JDK 12 Compact Number Formatting

The post “Compact Number Formatting Comes to JDK 12” demonstrated the support added to NumberFormat in JDK 12 to support compact number formatting. The examples shown in that post only used the instances of NumberFormat returned by invocations of NumberFormat‘s new overloaded getCompactNumberInstance(-) methods and so therefore did not specify characteristics such as minimum fractional digits and maximum fractional digits. ...

Read More »

Different States of Java Threads

Introduction In Java, threads can have States. The Thread.State enum defines the different states that a Java thread can have. This enum defines the following values – NEWRUNNABLEBLOCKEDWAITINGTIMED_WAITINGTERMINATED In the subsequent sections, I provide a brief overview of these states along with possible transitions between them. States of a Java Thread NEW This is the default state a thread gets ...

Read More »

Java 11: Converting a Collection to an Array

In Java 11, a new default method, toArray(IntFunction), has been added to the java.util.Collection interface, which allows the collection’s elements to be transferred to a newly created array of a desired runtime type. For example: // Java 11 List<String> list = Arrays.asList("foo","bar","baz"); String[] array = list.toArray(String[]::new); // The above is equivalent to: String[] array2 = list.toArray(new String[0]); Published on Java ...

Read More »

Parsing Value from StreamCorruptedException: invalid stream header Message

It is a relatively common occurrence to see StreamCorruptedExceptions thrown with a “reason” that states, “invalid stream header” and then provides the first part of that invalid stream header. Frequently, a helpful clue for identifying the cause of that exception is to understand what the invalid stream header is because that explains what is unexpected and causing the issue. The ...

Read More »

Restarting Java’s Raw String Literals Discussion

It was announced in December 2018 that raw string literals would be dropped from JDK 12. Now, in the new year, discussion related to the design of raw string literals in Java has begun again. In the post “Raw string literals — restarting the discussion” on the amber-spec-experts OpenJDK mailing list, Brian Goetz references the explanation for dropping raw string literals preview feature from JDK ...

Read More »

Compact Number Formatting Comes to JDK 12

JDK 12 Early Access Build 24 introduces support for Compact Number Formatting. The JDK-8188147 (Compact Number Formatting support) CSR‘s “Summary” is the simple sentence, “Adding support for the compact/short number formatting in JDK.” That same CSR also provides a detailed “Solution” section that provides background on providing numbers in multiple compact forms for each Locale and the constructs/APIs added to the JDK to support this ...

Read More »