Fastest padLeft-function in Java

Fastest padLeft function in JavaSince Java does not have a function to pad strings on the left or right side, you either have to program such function yourself or use an existing library, such as Apache Commons. Because I recently needed a function that would pad a numeric string on the left side (= padLeft) with zeros up to a length of 8 characters, but did not want to include a whole library for such a simple task, the only option was to write a padLeft function myself.
However, when researching and implementing, I found various solution approaches and so I ended up with six different padLeft implementations. In order to find the best padLeft function for my use case, I tested all six implementations during a small performance test and found the fastest padLeft function. Before I get […]

How to open the default mail client in Java

Open standard mail in JavaIn the following post there is once again a small Java code snippet, by means of which the standard mail program can be called/opened.
In order to open the standard mail application in almost any operating system, a URI with the mailto protocol is suitable. Therefore, the following Java code must be able to compose the mailto URI format.
The second difficulty is to resolve this URI (or in simple words – to execute this URI). Unfortunately, this can not be executed directly using the Runtime.getRuntime().exec()-command, but must be started as a parameter via a system-specific program. Our Java-Snippet must therefore be able to distinguish between the operating systems.
Open standard mail in Java
The sample code can be run as it is and opens the default mail program with a few […]

How to detect operating system in Java

Detect operating system in javaIn the following article, there is a short Java snippet that can be used to read the operating system of the computer running the Java program.
In addition, it is the first Java snippet at all here in the blog. Although I have been writing a few lines of Java code again and again for a couple of years, I really couldn’t befriend myself (especially with regard to my C # passion) with Java so far yet. But since I have to deal more and more with Java on the job, however, this will soon be reflected in the blog. But let’s come to the Snippet now…
Read operating system in Java
In order to identify the computer’s operating system in Java, the getProperty-method of the system-class is suitable. Using this […]