Java tips and tricks
Cascading OpenJDK builds (June 20, 2019)
Build OpenJDK 8 to 14 using the previous build as the boot JDK...
Build OpenJDK 8 to 14 using the previous build as the boot JDK...
Quickly find worst GC pauses in G1 and Parallel GC logs (December 20, 2018)
Linux command line for finding worst GC pauses in garbage collector logs (using JDK8)...
Linux command line for finding worst GC pauses in garbage collector logs (using JDK8)...
Identify the Java Thread taking the most CPU (December 20, 2018)
Linux command line for finding which Java Thread is using the most CPU...
Linux command line for finding which Java Thread is using the most CPU...
Run an IBM J9 VM in a docker container (March 19, 2017)
How to execute a Java program on the J9 VM and get a JIT log...
How to execute a Java program on the J9 VM and get a JIT log...
DemoFX Part 3 (November 9, 2016)
A JavaFX Demoscene production with 2D, 3D, chroma-keying, sprite effects, starfields, scrollers, and more!...
A JavaFX Demoscene production with 2D, 3D, chroma-keying, sprite effects, starfields, scrollers, and more!...
More Bytecode Geekery with JarScan (April 10, 2016)
So I saw this tweet and had some thoughts about bytecode size distribution :)...
So I saw this tweet and had some thoughts about bytecode size distribution :)...
DemoFX Part 2 (April 18, 2015)
Second release of DemoFX - an open-source Demoscene engine written in JavaFX...
Second release of DemoFX - an open-source Demoscene engine written in JavaFX...
OpenJFX Nightly Builds for Linux amd64 and armv6hf for Raspberry Pi (March 31, 2015)
Build server producing nightly builds of OpenJFX. Add JavaFX support to Zulu JDK and JDK 8u33 for ARM...
Build server producing nightly builds of OpenJFX. Add JavaFX support to Zulu JDK and JDK 8u33 for ARM...
Add JavaFX support to Azul Systems' Zulu JDK using OpenJFX (February 12, 2015)
Instructions for compiling OpenJFX and installing into Zulu JDK...
Instructions for compiling OpenJFX and installing into Zulu JDK...
JarScan comparison between 8u31 and 8u40 rt.jar (February 10, 2015)
Comparison of the methods above the 325 FreqInlineSize inlining limit between the two latest Oracle Java releases...
Comparison of the methods above the 325 FreqInlineSize inlining limit between the two latest Oracle Java releases...
CPU pinning Java threads with jstack and taskset (October 17, 2014)
How to discover the native PID of a Java thread and pin it to a CPU using taskset...
How to discover the native PID of a Java thread and pin it to a CPU using taskset...
The power of JIT inlining (September 9, 2014)
A contrived example to show the impact of disabling method inlining in the HotSpot JVM using a Scala method call vs a tailrec...
A contrived example to show the impact of disabling method inlining in the HotSpot JVM using a Scala method call vs a tailrec...
Building OpenJDK 9 and OpenJFX from source on Debian (September 2, 2014)
How to build a JavaFX-enabled Java 9 from OpenJDK sources...
How to build a JavaFX-enabled Java 9 from OpenJDK sources...
Building hsdis-amd64.dylib on Mac OSX (May 12, 2014)
How to build the hotspot disassembler binary on Mac OS OSX amd64...
How to build the hotspot disassembler binary on Mac OS OSX amd64...
Java 7 and Java 8 core methods above the default hot method inlining threshold (April 13, 2014)
A list of the methods in rt.jar from Java 7 and Java 8 that are too big to be inlined...
A list of the methods in rt.jar from Java 7 and Java 8 that are too big to be inlined...
Can splitting Java core class methods increase performance? (February 20, 2014)
An experiment to see if splitting hot methods that are too big to inline can increase performance...
An experiment to see if splitting hot methods that are too big to inline can increase performance...
Java acronyms (January 30, 2014)
By getting involved in the Java community, I've come across a new set of acronyms like JSR, JEP, FFI, JCP that I needed to learn...
By getting involved in the Java community, I've come across a new set of acronyms like JSR, JEP, FFI, JCP that I needed to learn...
Location of Java applet log on Windows XP (January 30, 2014)
How to access the applet's log if the console does not show or closes too quickly...
How to access the applet's log if the console does not show or closes too quickly...
Examination of PerformanceTools using JITWatch (October 29, 2013)
Analysis of why using an Exception outperforms an array bounds check in Francesco Illuminati's TryCatchVsCheckPerformanceTest...
Analysis of why using an Exception outperforms an array bounds check in Francesco Illuminati's TryCatchVsCheckPerformanceTest...
Building hsdis on Linux amd64 on Debian (October 29, 2013)
How to build the hotspot disassembler binary on Linux amd64...
How to build the hotspot disassembler binary on Linux amd64...
Update Java plugin used by OSX (October 18, 2013)
Installing 7u45 did not update the plugin used in Firefox. Here is the fix...
Installing 7u45 did not update the plugin used in Firefox. Here is the fix...
Understanding HotSpot logs (August 27, 2013)
Slides from a session I convened at the JCrete Java Specialists Symposium...
Slides from a session I convened at the JCrete Java Specialists Symposium...
Raspberry Pi TFT hack and video glasses, wearable Pi project (August 12, 2013)
Hack a 12V TFT to run on 5V...
Hack a 12V TFT to run on 5V...
Maven setup (August 6, 2013)
After the initial horror and sheer wtf factor, here are a few hints to getting the Maven build tool up and running...
After the initial horror and sheer wtf factor, here are a few hints to getting the Maven build tool up and running...
Compiling JDK8 lambdas on Eclipse Luna using Ant (July 29, 2013)
Want to try out JDK8 lambdas using Eclipse? Use an Ant script to invoke the JDK javac compiler instead of using the built in Eclipse ECJ compiler...
Want to try out JDK8 lambdas using Eclipse? Use an Ant script to invoke the JDK javac compiler instead of using the built in Eclipse ECJ compiler...
Reading and writing bytes between Java and Obj-C (July 13, 2013)
Just squashed a tricky bug that was showing up intermittently when decoding certain values written in Java and read in Obj-C...
Just squashed a tricky bug that was showing up intermittently when decoding certain values written in Java and read in Obj-C...
Reference manual index, Java, PHP, JavaScript (June 18, 2013)
URLs for programming language reference documents...
URLs for programming language reference documents...
Java JIT analysis and code coverage (June 12, 2013)
I am building a tool to visualise how much of a program's code is JIT compiled at runtime...
I am building a tool to visualise how much of a program's code is JIT compiled at runtime...
Builder Pattern (June 4, 2013)
The builder design pattern lets you construct objects with many or optional parameters without having to write multiple overloaded constructors....
The builder design pattern lets you construct objects with many or optional parameters without having to write multiple overloaded constructors....
Refactoring old style Java synchronized code with CopyOnWriteArrayList and Collections.unmodifiableList (May 29, 2013)
While refactoring some old core code I've learnt a better way to make read-only List copies using java.util.concurrent...
While refactoring some old core code I've learnt a better way to make read-only List copies using java.util.concurrent...
JavaScript prototype idiom for OO design (May 15, 2013)
A programming idiom to simulate OO design in JavaScript...
A programming idiom to simulate OO design in JavaScript...
Cross platform SWT dispatch loop idiom (May 1, 2013)
Solution to Exception Display must be created on main thread due to Cocoa restrictions...
Solution to Exception Display must be created on main thread due to Cocoa restrictions...
[SOLVED] Java 7 update 21 mixed code warning dialog with signed applet (April 17, 2013)
New security feature in 7u21 causes warnings on Java<-->JavaScript communication...
New security feature in 7u21 causes warnings on Java<-->JavaScript communication...
Clear Linux buffers, cache when benchmarking filesystem (March 12, 2013)
If you are trying to optimise a filesystem operation, remember to clear Linux buffers and cache between benchmarks or some of the file reads will be served from memory!...
If you are trying to optimise a filesystem operation, remember to clear Linux buffers and cache between benchmarks or some of the file reads will be served from memory!...
JavaFX MediaPlayer crash (Debian amd64) playing mp3 and displaying graphics (February 18, 2013)
JRE 7.0_13-b20 crashes randomly playing any mp3 when also rendering graphics...
JRE 7.0_13-b20 crashes randomly playing any mp3 when also rendering graphics...
Java on Mac OSX 10.8 Safari broken by XProtect.meta.plist whitelist update (January 31, 2013)
Apple have updated the Safari plugins whitelist with an incorrect version of Java...
Apple have updated the Safari plugins whitelist with an incorrect version of Java...
Updated Tutorial for JDK8 early access on Raspberry Pi (January 29, 2013)
How to install Oracle JDK8 early access on the Pi...
How to install Oracle JDK8 early access on the Pi...
Using Java jarsigner to check a jar signature (January 17, 2013)
How do you check the signature of a Java jar?...
How do you check the signature of a Java jar?...
Eclipse can't find import javafx (January 16, 2013)
Trying to get the JavaFX samples running under Eclipse with the latest JDK 1.7.11...
Trying to get the JavaFX samples running under Eclipse with the latest JDK 1.7.11...
JavaFX Ensemble sample won't run from Eclipse due to bad server config (January 16, 2013)
Running the main method in the JavaFX sample src/Ensemble/Ensemble2.java gives the following error...
Running the main method in the JavaFX sample src/Ensemble/Ensemble2.java gives the following error...
Java applet deployment using deployJava.js (January 16, 2013)
A list of problems and workarounds for detecting Java and launching your applet in the browser...
A list of problems and workarounds for detecting Java and launching your applet in the browser...
deployJava.js fails to install Java when Java not present (January 15, 2013)
More problems with Oracle's deployJava.js script...
More problems with Oracle's deployJava.js script...
jusched.exe still running after Java uninstalled (January 15, 2013)
The Java uninstaller is not cleaning up the Java update scheduler...
The Java uninstaller is not cleaning up the Java update scheduler...
High performance modulo operation (January 9, 2013)
If you are using modulo to select a processor for an input then this clever trick can give you a performance boost...
If you are using modulo to select a processor for an input then this clever trick can give you a performance boost...
Applet graphics corruption in Java 7 update 10, 11, 13 on Mac OSX (December 21, 2012)
A change in Java 7 update 10 on the Mac OSX operating system means that some applets are now showing graphics corruption...
A change in Java 7 update 10 on the Mac OSX operating system means that some applets are now showing graphics corruption...
ncurses type applications in Java on Raspberry Pi (Lanterna Console) (December 12, 2012)
Headless Java console applications using Google Code's Lanterna...
Headless Java console applications using Google Code's Lanterna...
OpenJDK IcedTea plugin java debugging (December 12, 2012)
How to get Java debug output when using OpenJDK IcedTea plugin...
How to get Java debug output when using OpenJDK IcedTea plugin...
Raspberry Pi Java Applets - Iceweasel OpenJDK IcedTea plugin (HardFloat) (November 19, 2012)
How do you get Java applets working on the Raspberry Pi?...
How do you get Java applets working on the Raspberry Pi?...
[SOLVED] Debian ./java: No such file or directory (November 13, 2012)
Can't get java to run on Debian even though permissions look correct?...
Can't get java to run on Debian even though permissions look correct?...
Java cheat sheet for angle plotting in degrees, radians, and Pi radians (July 16, 2012)
Quick cheat sheet for plotting angles in Java...
Quick cheat sheet for plotting angles in Java...
[SOLVED] Eclipse Java autocomplete not working (July 10, 2012)
After upgrading Eclipse my Java autocomplete suggestions (Ctrl-Space) stopped working. Here is how to fix it...
After upgrading Eclipse my Java autocomplete suggestions (Ctrl-Space) stopped working. Here is how to fix it...
Java trace memory leaks with hprof and verbose:gc (July 3, 2012)
How to use hprof and GC logging to track down a memory leak in a large Java application....
How to use hprof and GC logging to track down a memory leak in a large Java application....
Java Unsupported major minor version 51.0 (July 2, 2012)
Got this Java error when running a class compiled with a JDK7 javac?...
Got this Java error when running a class compiled with a JDK7 javac?...
Java AWT Graphics2D anti-aliasing in a Java 1.1 compatible way using reflection (June 13, 2012)
Here is how to enable anti-aliasing in AWT using reflection in a way that is compatible with Java 1.1 AWT...
Here is how to enable anti-aliasing in AWT using reflection in a way that is compatible with Java 1.1 AWT...
Getting started with Java on Raspberry Pi (June 10, 2012)
Quick HelloWorld compile and run example...
Quick HelloWorld compile and run example...
Using the Java 1.5 ScheduledExecutorService for scheduling repeating tasks (April 10, 2012)
How to use the java.util.concurrent Executor classes as a replacement for Timer and TimerTask...
How to use the java.util.concurrent Executor classes as a replacement for Timer and TimerTask...
Java wrapper around an external process (April 5, 2012)
How to invoke an external process from Java and collect the standard error output. This example converts a PDF using a Java wrapper around the Linux program pdftotext...
How to invoke an external process from Java and collect the standard error output. This example converts a PDF using a Java wrapper around the Linux program pdftotext...
Map JDBC types to Java primitive and Object types (March 29, 2012)
Table of mappings between Java and JDBC types...
Table of mappings between Java and JDBC types...
java.io.IOException: Too many open files (March 20, 2012)
If your Java program throws this exception then you have run out of file handles / pipes / domain sockets (depending on how your OS represents files). Here is how to debug the error on Linux...
If your Java program throws this exception then you have run out of file handles / pipes / domain sockets (depending on how your OS represents files). Here is how to debug the error on Linux...
Low latency Java tips (March 6, 2012)
When building a Java trading application there are several steps you can take to reduce delays (latency) at the network and transaction processing level...
When building a Java trading application there are several steps you can take to reduce delays (latency) at the network and transaction processing level...
Select correct SWT jar for your OS and JVM at runtime (February 10, 2012)
Here is a method to dynamically classload the correct SWT jar depending on your operating system and whether it is 32 or 64 bit. It relies on a little code smell (hack) using reflection but this is mu...
Here is a method to dynamically classload the correct SWT jar depending on your operating system and whether it is 32 or 64 bit. It relies on a little code smell (hack) using reflection but this is mu...
Java can an int fit inside a float or a double without loss of precision? (January 11, 2012)
I've recently upgraded our FIX trading software to support fractional quantities and needed to know if using double as the underlying storage for quantity could ever cause a loss of precision when sto...
I've recently upgraded our FIX trading software to support fractional quantities and needed to know if using double as the underlying storage for quantity could ever cause a loss of precision when sto...
Java concatenate null String with += (January 10, 2012)
Here's a stupid mistake I made concatenating a null (reference) String in Java so you don't have to make it!...
Here's a stupid mistake I made concatenating a null (reference) String in Java so you don't have to make it!...
Use 64 bit Sun Java plugin in Firefox on Ubuntu (December 23, 2011)
How do I use the Sun Java plugin instead of the OpenJDK IcedTea plugin in Ubuntu...
How do I use the Sun Java plugin instead of the OpenJDK IcedTea plugin in Ubuntu...
openSSL convert PEM certificate and import to Java keystore (December 13, 2011)
Need to convert an x509 secure certificate so that it can be imported into a Java keystore? Here is how to do it using an intermediate DER format certificate....
Need to convert an x509 secure certificate so that it can be imported into a Java keystore? Here is how to do it using an intermediate DER format certificate....
Java short form array iteration using for-loop (November 18, 2011)
The new Java 1.5 for loop can also be used to transverse an array...
The new Java 1.5 for loop can also be used to transverse an array...
Java for loop syntax to replace Iterator (November 14, 2011)
One of the new features introduced in Java 1.5 was a for-loop syntax similar to PHP's foreach loop to replace the use of java.util.Iterator...
One of the new features introduced in Java 1.5 was a for-loop syntax similar to PHP's foreach loop to replace the use of java.util.Iterator...
Java String.split include empty trailing strings (November 10, 2011)
How do I split a Java String at a delimiter but keep empty trailing strings?...
How do I split a Java String at a delimiter but keep empty trailing strings?...
Java variable scope in switch statement (November 4, 2011)
Variable scope inside the case clauses of a Java switch statement is not always obvious. This example will help understand how it works....
Variable scope inside the case clauses of a Java switch statement is not always obvious. This example will help understand how it works....
Java defensive programming - compare variable with constant (October 16, 2011)
Here's an easy way to eliminate NullPointerException when you compare a variable against a constant...
Here's an easy way to eliminate NullPointerException when you compare a variable against a constant...
SWT Canvas plot centred text (October 13, 2011)
How do you plot centre-aligned text on an SWT Canvas object?...
How do you plot centre-aligned text on an SWT Canvas object?...
FATAL: sorry, too many clients already (PostgreSQL) (September 26, 2011)
Getting a 'too many clients already' error from your database driver when opening a connection? Use this Java design template to ensure you are not leaking resources....
Getting a 'too many clients already' error from your database driver when opening a connection? Use this Java design template to ensure you are not leaking resources....
Java numerical overflow (September 26, 2011)
How Java handles numerical overflow (result of an operation is too large to be represented in the result variable)...
How Java handles numerical overflow (result of an operation is too large to be represented in the result variable)...
Business Insider's UBS Quant puzzle solution (September 21, 2011)
An interviewee at UBS for a math-heavy quant job was asked one of the toughest Wall Street interview questions we've seen yet....
An interviewee at UBS for a math-heavy quant job was asked one of the toughest Wall Street interview questions we've seen yet....
Java return code in Linux shell script (September 13, 2011)
How do you get the return code from a Java program in a Linux shell script?...
How do you get the return code from a Java program in a Linux shell script?...
Java primitives in size order (September 12, 2011)
How many bytes do Java primitive types (boolean, byte, char, short, int, float, double, long) take up?...
How many bytes do Java primitive types (boolean, byte, char, short, int, float, double, long) take up?...
SWT literal ampersand instead of keyboard hotkey (September 9, 2011)
If you call setText() on SWT components with a String containing an ampersand then the ampersand will be converted into a keyboard hotkey on the next character. Here is how to use a literal ampersand ...
If you call setText() on SWT components with a String containing an ampersand then the ampersand will be converted into a keyboard hotkey on the next character. Here is how to use a literal ampersand ...
Elegant use of Java's Math.max() to prevent negative numbers (September 9, 2011)
Here's a neat trick when scrolling / dragging to prevent negative coordinates...
Here's a neat trick when scrolling / dragging to prevent negative coordinates...
Java remove non alphanumeric characters from String (August 25, 2011)
Need to sanitise a Java String containing user input? This simple regular expressions will clean it for you...
Need to sanitise a Java String containing user input? This simple regular expressions will clean it for you...
SWT best practice - single Display multiple Shells (August 19, 2011)
Here is a design pattern for an SWT single document interface (SDI) with one Display dispatch loop handling for multiple windows (Shells)...
Here is a design pattern for an SWT single document interface (SDI) with one Display dispatch loop handling for multiple windows (Shells)...
Ubuntu remove OpenJDK and use Sun Java as default (March 3, 2011)
Now that Sun Java is in the Maverick partner's repositories you can use Sun's JDK and JRE easily in Ubuntu....
Now that Sun Java is in the Maverick partner's repositories you can use Sun's JDK and JRE easily in Ubuntu....
Java can't delete directory (August 31, 2010)
Java can't delete a directory if it is not empty. The following code uses recursion to delete the directory tree....
Java can't delete a directory if it is not empty. The following code uses recursion to delete the directory tree....
Deadlock when 2 threads write to the same HashMap (May 4, 2010)
If 2 or more threads are writing to the same java.util.HashMap then take the following advice to avoid deadlock....
If 2 or more threads are writing to the same java.util.HashMap then take the following advice to avoid deadlock....
Ask me about
AdSense Android ant Apache Applet Artigo C++ CI codec console CSS Debian DemoScene deployJava.js diff DIY Eclipse Excel fdisk find Firefox FixPC Flash fuse GC git GPG grep HotSpot hsdis HTML Icedove icedove Iceweasel ImageMagick iOS iPhone iSCSI ISO JarScan Java JavaFX JavaScript JCrete JDBC JDK Jenkins Jessie JIT JITWatch JVM lambdas lame Linux linux low latency LVM Mac MacPorts maven Microsoft mkfs mp3 MySQL Networking networking NFS Obj-C OpenJDK OpenJFX openSSL openssl optimisation OSX Patterns PHP PIX PostgreSQL powersaving PS3 Puzzle qmail Raspberry Pi RaspberryPi Safari samba Samba Scala scp scponly SEO ssh sshfs stunnel svn SWT sysctl syslog-ng tcpkill Thunderbird tmpfs Tomcat tripwire Ubuntu Unity UTF-8 vi VirtualBox website Websites wget Windows Windows 8 Word Xcode xen ZTE Blade