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 java.io.IOException; import java.net.Socket; 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