Java Programming Tips


How to Get the List of Running Processes in Mac Using Java

In a Mac machine, the list of all running processes can be retrieved using the following command in the console. The option -e displays all processes including processes owned by other users. The -o command flag instructs ps to show only the command name (with arguments). To get the command name without arguments, use comm […]

How to Iterate Through a Directory Tree in Java

The following example Java program iterates through all the files and directories in a given folder. It also walks through the entire directory tree printing names of sub-directories and files. Note that this example requires Java 8 or above since it uses java.nio.file.Files class and the walk method in it. The following program has 3 […]

Connecting to MongoDB from Java

To connect to MongoDB from Java, you need MongoDB Java driver. Depending on the type of project you are working on there are 3 ways to use this driver. If you are using Gradle or Maven, you can add it as a dependency. If you are not using a build system, you can use the […]

How to Create SHA256 RSA Signature Using Java

SHA256 with RSA signature is an efficient asymmetric encryption method used in many secure APIs. This algorithm first calculates a unique hash of the input data using SHA256 algorithm. The hash is then encrypted with a private key using the RSA algorithm. This is useful in scenarios where we only need to verify that the […]

How to Generate Expires Value for Amazon S3 or Google Cloud Storage Using Java

Google Cloud Storage and Amazon S3 supports signed URLs for protected objects. Signed URLs can be used to enable temporary public access to protected content. Anyone with the signed URL can access the protected resource. However the validity of the signed URL is specified by a query parameter named Expires. This parameter specifies the validity […]