Loading up and using MessageBundles

Create your messages_en.properties with your messages as a key value pair greeting_hello=Hello {0} Now in code use the following ResourceBundle resourceBundle= PropertyResourceBundle.getBundle(“messages_en.properties”); String message = resourceBundle.getString(“greeting_hello”); MessageFormat messageFormat = new MessageFormat(message); String formattedMessage = messageFormat.format(“Markzi”); System.out.println(formattedMessage); This will print out Hello Markzi

Read More »

ParseException when parsing time

Came across this when trying to parse a time. DateFormat timeFormat = DateFormat.getTimeInstance(); timeFormat.parse(“11:23:00”): Caused by: java.text.ParseException: Unparseable date: “11:23:00” at java.text.DateFormat.parse(DateFormat.java:347) Solution was a simple one. Set the style and locale on the DateFormat DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.UK); timeFormat.parse(“11:23:00”):

Read More »