Display name,id, GMT offset of all time zones in JVM (java/example)

We would like to list all available time zones supported by JDK. TimeZone represents a time zone offset, and also figures out daylight savings. We will use package java.util.TimeZone to list available time zones. We will display following properties of each timezone. DisplayName of time zone. Id of time zone. Timezone offset in GMT format 1.… Read More »

Get & Set default timezone of java virtual machine (JVM) – example

We would like to get/set the default timezone in java. TimeZone represents a time zone offset, and also figures out daylight savings. We will use package java.util.TimeZone to get/set default time zone. 1. Important methods of TimeZone class 2. Program: Get & Set default timezone of java virtual machine (JVM) package org.learn; import java.util.TimeZone; public class DemoTimeZone… Read More »

Convert local file path to URL & URI in java (example)

Given a File in java. We would like to convert path of a file to URL & URI path. e.g. If path of file on local windows operating system is “D:\Code\Local File Path.txt” URL & URI of local file path will be “file:/D:/Code/Local%20File%20Path.txt” We will use toURL() and toURI() method of File class . 1.… Read More »

Create or Write property file in java (example)

Given a key value pairs of properties in java. We would like to create or write properties to property file We will use Properties class to set properties file. Procedure to create property file in java. Set properties using Properties class. properties.setProperty(“user.name”, “admin”); properties.setProperty(“user.age”, “25”); We will use store method of the Properties class, to… Read More »

Sort user defined objects/POJO in array (java/example/Comparator interface)

Given an array of user defined objects/POJO in java. We would like to sort user defined objects on certain properties/data members. We will use Arrays.sort method to sort objects. 1. Example – Sort POJO or user defined object using comparator interface. Given a Array containing Vehicle objects. Vehicle class has following data members. public String model public… Read More »

Copy properties from one bean into another bean/object (java/ example)

Given a source bean or object in java. We would like to copy properties from source bean into destination bean in java. i.e. We would like to convert one object into another object. 1. Example: Convert one object into another object in java (copy properties) Given an EmployeeDB object containing information about employees, present in… Read More »

Display currency code/ symbol from Locale in java (example)

Given Locale for given language & country code in java. We would like to display currency code & symbol for given locale. 1. Example: Display currency code/ symbol from Locale in java Suppose we would like to display currency code for country=US and Language=English. We would use default locale class to get currency information. We should… Read More »

Page 2 of 4312345...102030...Last »