Simplest way to read a File in a String with Java 8

Do you need a quick hack to read a text file into a Java String? With Java 8 this is a piece of cake! See this example: import; import java.nio.file.Files; import java.nio.file.Paths; public static void main(String[] args) throws IOException { String text = new String(Files.readAllBytes(Paths.get(“myfile.txt”))); } }

Speed up your Java coding with Lombok

We all know that one of the most annoying things in Java is the thing we need to place lots of boiler plate code when building our applications. Think for example of adding Constructors with all fields, getter and setter methods, Logger static methods, not to mention the boilerplate code to use common patterns in … Read more

Getting started with Java-based Machine Learning Libraries

There are over 70 Java-based open source machine learning projects listed on the website, and probably many more unlisted projects live at university servers, GitHub, or Bitbucket. In this article, we will review the major libraries and platforms, the kind of problems they can solve, the algorithms they support, and the kind of data they can work with. … Read more

How to kill a Java process from Java

Today I had to write a quick code to find out which Java process is using a Port and eventually killed it. You can use it as template in case you have to manage OS process in Linux from Java code: import; import; public class Execute { public static void main(String[] args) { … Read more

How to check if a port is open in Java

Here is a minimalist Java code which can be used to test if a port is available. In this example, we are checking for port 8080 by opening a new Socket to that port. We allow up to 10 retries if the port has been found already used. Enjoy it! import; import; public … Read more

Getting the process id (PID) programmatically in Java 9

Java 9 features a simple an portable way to retrieve the process id of the Java Virtual Machine. This can be done through the ProcessHandle which identifies and provides control of native processes. Each individual process can be monitored for liveness, list its children, get information about the process or destroy it. By comparison, Process … Read more