Unzip or decompress files in java using ZipInputStream & ZipEntry (example)

Given a zipped or compressed file in java. Write a program to unzip or decompress the contents of zip file using ZipInputStream in java. Zip file may contain nested directory structure. e.g. Zip file may have compressed files having following directory structure. FirstFile.txt SecondFile.txt Dir1\Dir1_F1.txt Dir1\Dir1_F2.txt Dir1\Dir11\Dir11_F1.txt Dir1\Dir11\Dir11_F2.txt ….. Read the content of zip files… Read More »

Generate UUID or GUID from String in java (with example)

Given an string representing unique identifier. We would like to convert string to corresponding universal unique identifier (UUID) or Globally unique identifier (GUID). We will use java.util.UUID class to create UUID or GUID from string. e.g UUID generateUUID = UUID.fromString(inputUUID) Program: generate UUID or GUID from String in java package org.learn.uuid; import java.util.UUID; public class GenerateUUIDFromString {… Read More »

Generate/create random GUID or UUID in java (JUG library/example)

Generate guid or uuid using RandomBasedGenerator class of Java UUID Generator (JUG) library. In current post, we will generate random uuid using JUG library. Generate random UUID using RandomBasedGenerator class in java. Generate custom random UUID using input random number in java. 1. Maven dependency of JUG library <dependency> <groupId>com.fasterxml.uuid</groupId> <artifactId>java-uuid-generator</artifactId> <version>3.1.3</version> </dependency> 2. Generate or… Read More »

Time based uuid generator in java (JUG library / example)

Generate time based uuid in java using JUG (Java Uuid Generator) library. JUG library provides couple of generator viz TimeBasedGenerator & RandomBasedGenerator. In current post, we will demonstrate TimeBasedGenerator of JUG library. Generate time based UUID using TimeBasedGenerator Get the timestamp of generated UUID. Generate custom UUID using network interface. Maven dependency of JUG library <dependency> <groupId>com.fasterxml.uuid</groupId> <artifactId>java-uuid-generator</artifactId> <version>3.1.3</version>… Read More »

Get IP Address from hostname (loopback, local & standard hosts) in java (example)

Given hostname in java, we would like to find out the corresponding IP address. We will discuss out the following scenarios: Input loopback hostname & get corresponding ip address. We will use API InetAddress.getLoopbackAddress() to get loopback address. Input local hostname & get local IP address. We will use API InetAddress.getLocalHost() to get local host… Read More »