Home » Java » Core Java

Core Java

Behind-the-Scenes Secrets of Jsoup V: Tips & Tricks of Optimization

We have done things right, now it’s time to do things faster. We would keep Donald Knuth‘s warning in mind, “We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil”. According to Jonathan Hedley, he uses YourKit Java Profiler to measure memory usage and find the performance hot point. Using ...

Read More »

A Simple Approach to Simulate User Input and Check Output

Recently some of my students asked me about the mechanism of unit test provided by MOOC from University of Helsinki, I checked their implementation and think it would be helpful for beginners to understand what happened actually, so this little article was posted. We will use the project “Airport” as an example, it’s the last assignment in the first week ...

Read More »

jcmd, Circa JDK 11

Nicolas Fränkel recently published a survey of command-line tools delivered with OpenJDK 11 in the blog post “OpenJDK 11, tools of the trade.” In that post, he briefly summarizes the tools jps (a JVM process status tool), jinfo (JVM configuration details), jmap (classes/objects on the heap), jstack (thread analysis), and graphical tool JConsole (monitor Java applications). All of these tools ...

Read More »

Filterer Pattern in 10 Steps

Filterer is a pattern that should be applied only in certain cases. In the original post, I presented a very simple example intended to show howto apply it. In this post, I present a much more detailed example that’s intended to also explain when and why to apply it. Introduction The post consists of the following 10 short steps. In each step, I introduce requirements of the following two types: ...

Read More »

JDK 9/JEP 280: String Concatenations Will Never Be the Same

JEP 280 (“Indify String Concatenation”) was implemented in conjunction with JDK 9 and, according to its “Summary” section, “Change[s] the static String-concatenation bytecode sequence generated by javac to use invokedynamic calls to JDK library functions.” The impact this has on string concatenation in Java is most easily seen by looking at the javap output of classes using string concatenation that ...

Read More »

Transformer Pattern

The Transformer pattern is a design pattern for Java (and potentially other OO languages with use-site variance only and invariant parameter types) that helps objects within a subtype hierarchy fluently transform themselves into objects of any type. Context I was following the OpenJDK threads (Sep 18-21, Nov 12-13, Nov 13-30, Dec 3-4) related to issue JDK-8203703 by Jim Laskey, and an idea came to my mind. Let ...

Read More »

Custom Compact Number Patterns with JDK 12 Compact Number Formatting

The post “Compact Number Formatting Comes to JDK 12” has been the subject of discussion on a java subreddit thread. Concerns expressed in that thread related to presentation of the compact number formatting deal with digits of precision displayed and the compact number patterns displayed. The digits of precision can be addressed via use of CompactNumberFormat.setMinimumFractionDigits(int) and this approach is ...

Read More »

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 »