Category Archives: Core Java

We will discuss commonly asked questions related to java 8 , exception handling, string operations, java io etc.

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 »

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 »