IntelliJ IDEA 14.1 HiDPI issues

I’m a user and big fan of JetBrains’ IntelliJ IDEA IDE. Having tried and used several Java IDEs in the past, I personally think it’s the best out there. On top of that, every major update bring a couple of new amazing features.

Yesterday the 14.1 update of the IDE was released. As usual I rushed to download and install the new version, after a quick glance of the release notes. But as a first, I ran into a major issue.

I’m usually use my desktop or my laptop for programming, but a while ago I got myself a Microsoft Surface Pro 3, to carry around more easily. I also use this for programming. The Surface Pro 3 has a very high-resolution display, which makes whatever is displayed look nice and crisp. But if you use the native resolution, everything will also be very tiny. Microsoft has solved this issue by having Windows do DPI scaling of applications. This essentially simply scales them up to make everything readable to the user. Some applications support this and those that do provide a very nice upscaled crisp interface.

Up until now, IntelliJ has not supported high DPI displays, and as a result, the native OS would just scale it up, making text look slightly blurry, as well as other elements in the UI. To resolve this JetBrains has worked on adding support for these displays on all platforms into their IDE. This is where it got messy.

After installing the new version, and running it, I quickly noticed that there was something wrong. My code looked very crisp for sure, but it was incredibly tiny. Also icons on the toolbar had been shrunk down to a small size. To find the answer, I had to dig through some of JetBrains’ bugtracker issues and found a fix for the problem.

The problem is that (for some reason) the IDE does not detect that I’m running a high-DPI display. So solve this, you have to force it into the HiDPI mode. You can do this by editing the vmoptions files for the IDE, which are located in the same folder that holds the IDE’s binary files. For example “C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.1\bin” on Windows 8.1 x64. Add the argument -Dhidpi=true to the end file. Be warned though, there are vmoptions files for both 32-bit and 64-bit, make sure you change the right one, or change both to be sure.

It’s clear that there’s still a few issues for JetBrains to work out, even in HiDPI mode, the text in the tip of the day window is pretty small, but they are well on their way towards properly supporting these displays.

Read More

Java: Download File

The following code will allow you to download a file in java from a source URL to a target File.

public static void download(URL orig, File dest) throws IOException {
	OutputStream os = null;
	InputStream is = null;
	try {
		byte[] buf;
		int count, length = 0;
		os = new BufferedOutputStream(new FileOutputStream(dest));
		is = orig.openConnection().getInputStream();
		buf = new byte[4096];
		while ((count = != -1) {
			os.write(buf, 0, count);
			length += count;
	} finally {

Read More

JNI For Delphi Preview

I’m currently developing a new modernized JNI wrapper for Delphi 2010 and up.  The old wrappers found here and here do work, but my wrapper requires less work to set up and uses a lot of new Delphi language features to ensure it works smoothly. The wrapper has been rewritten from scratch to include all features of JNI in JDK 1.6. Note that this wrapper is NOT backwards compatible with the old JNI wrappers, but switching to this one shouldn’t be too hard. At the moment the wrapper itself is far from complete, but it’s a preview including a small sample application. Afterwards I might also be wrapping JVMTI and create a bigger more user-friendly framework to encapsulate JNI. You can download the preview here:

Read More

Delphi <=> Java: Datatypes

So you know Delphi or Java and want to learn the other language? A very important thing to know is what datatypes you are using, as these differ in each language.

As you may know, Java does not have any unsigned datatypes, Delphi however has both signed and unsigned datatypes. Because of this the unsigned types are not listed in the table below, but in order for the integer types these are Byte/UInt8, Word/UInt16, Cardinal/LongWord/UInt32, UInt64. Delphi also has ansi strings/chars, these can be stores in string and Char but those can also hold unicode versions, the actual ansi types are AnsiString and AnsiChar. And of course Delphi also comes with a Pointer type as well as it has the ability to create types that hold pointers to specific types.

byteShortInt, Int88-bit signed integer-128 to 127
shortSmallInt, Int1616-bit signed integer-32768 to 32767
intInteger, LongInt, Int3232-bit signed integer-2147483648 to 2147483647
longInt6464-bit signed integer-9223372036854775808 to 9223372036854775807
floatSingle32-bit floating point value
doubleDouble64-bit floating point value
booleanBooleanboolean valuetrue or false
charChar (stores both ansi and unicode chars), WideChar, UnicodeChar16-bit unicode charactera single unicode character
Stringstring (stores both ansi and unicode strings), Widestring, UnicodeStringunicode stringa string consisting out of unicode characters
ObjectTObjectan objectobject pointer

Read More

Java: ShellSort

ShellSort is not a comparison-based sorting algorithm like those previously shown on this blog, it uses the property of InsertionSort that nearly sorted arrays of values are sorted very quickly. It has a performance of O(n log² n) which makes it a lot faster than a lot of other algorithms, certainly the O(n²) ones, but not entirely the fastest.

public static void shellSort(int[] ia) {
	int l = ia.length;
	if (l == 1)
	int inc = l / 2;
	while (inc != 0) {
		for (int i = inc; i != l; i++) {
			int t = ia[i];
			int j = i;
			while (j >= inc && ia[j - inc] > t) {
				ia[j] = ia[j - inc];
				j = j - inc;
			ia[j] = t;
		inc = (int) (inc / 2.2);

Read More

Java: SelectionSort

SelectionSort is another sorting algorithm that has a performance of O(n²) like BubbleSort. It sorts an array of numbers by finding the smallest element in the unsorted part of the array and switching it with the current item. This is repeated until the entire array is sorted.

public static void selectionSort(int[] ia) {
	int l = ia.length;
	if (l == 1)
	for (int i = 0; i != l; i++) {
		int s = i;
		for (int j = i; j != l; j++)
			if (ia[j] < ia[s])
				s = j;
		int t = ia[i];
		ia[i] = ia[s];
		ia[s] = t;

Read More

Java: BubbleSort

The bubblesort algorithm is one of the slowest sorting algorithms around as it’s performance is O(n²). As a result of this the algorithm is barely ever used in any real life applications, however, even though the algorithm will always stay rather slow, it can be tweaked to improve the code’s performance.

The implementation of the algorithm you see below has been optimized in various ways and it also makes use of the property that all items in an array of numbers that come after the last index that was sorted in a run through the array by the algorithm are already sorted.

public static void bubbleSort(int[] ia) {
	int l = ia.length, i = l;
	if (l == 1)
	while (i != 0) {
		int last = 0;
		for (int j = 1; j != i; j++)
			if (ia[j - 1] > ia[j]) {
				int t = ia[j];
				ia[j] = ia[j - 1];
				ia[j - 1] = t;
				last = j;
		i = last;

Read More