Java SE 8/11 Programmer II Exam Series: Internationalization and Localization

Introduction In this post, we will look at how to add internationalization and localization to the Java application. We will learn how to pick a locale, create and use properties files in different languages, and to format the numbers. Note that the localization is also a part of the Java SE 11 Programmer II Certification. […]

Item 42: Prefer lambdas to anonymous classes

Anonymous classes were adequate for the classic objected-oriented design patterns requiring function objects. Here’s a code snippet using an anonymous class. // Anonymous class instance as a function object – obsolete! Collections.sort(words, new Comparator<String>() { public int compare(String s1, String s2) { return Integer.compare(s1.length(), s2.length()); } }); Interfaces with a single abstract method are now […]

Item 15: Minimize the accessibility of classes and members

Encapsulation A well-designed component hides all its implementation details, cleanly separating its API from its implementation. Components then communicate only through their APIs and are oblivious to each others’ inner workings. This concept, known as information hiding or encapsulation, is a fundamental tenet of software design. The advantages of encapsulation are as follows: Speeds up […]

Class Initialization

Today, I will briefly mention about the class initialization. When we execute any java program (e.g.: java InitTest), Java Virtual Machine loads and link the class, execute initializers, and invokes the main class. Initialization process has some rules. Before we go into the details, spend a few minutes to figure out the output. class SuperClass { static { System.out.print(“0 […]