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 »

Internationalize/ Localize java application using locales/ ResourceBundle (example)

Given a java application supporting different languages like French,German, Korean, Japanese, English etc. We will localize strings for each language in different property files. e.g. String pertaining to English language will be kept in one property file Similarly, String of french language will be kept in french property file. We will load property file depending… Read More »

CopyOnWriteArrayList concurrent collection in java (example)

CopyOnWriteArrayList is thread-safe variant of ArrayList. New copy of underlying array is created when any add, set (or modification) operations performed on CopyOnWriteArrayList. CopyOnWriteArrayList can be visualize as combination of words, COPY + On Write + ArrayList. New copy of underlying array is created, when any write/update/remove operation is performed on CopyOnWriteArrayList. i.e. When any… Read More »

Page 3 of 4412345...102030...Last »