Java SE 8/11 Programmer II Exam Series: Exception Handling and Assertions

Introduction In this post, we will look at the following exam objectives. Note that this is also a part of the Java SE 11 Programmer II Certification. Use the try-with-resources construct Create and use custom exception classes Test invariants by using assertions Use the try-with-resources construct The new try-with-resources statement automatically closes all resources opened […]

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. […]

Java SE 8/11 Programmer II Exam Series: Advanced Stream Pipeline Concepts

Introduction In this section, we will cover advanced stream pipeline concepts in Java 8. We will analyze chaining Optionals, predefined collectors, and learn how to use groupingBy, partitioningBy, and mapping methods. Chaining Optionals Chaining optionals help eliminate the nested if-statements for Optional variables. The function below prints the virus name if it contains Covid-19 without […]

Java SE 8/11 Programmer II Exam Series: Primitive Streams

Introduction In this post, we will cover creating primitive streams, using Optional types with primitives, and summarizing statistics in a single pass. Primitive Streams There are three types of primitive streams: IntStream (int, short, byte, and char), LongStream (long), and DoubleStream (double and float). Creating Primitive Streams Creating primitive streams is the same as a […]

Java SE 8/11 Programmer II Exam Series: Streams

Introduction In this post, we will cover the streams in Java 8. We will discover the three parts of the pipeline: source, terminal, and intermediate operations. What is a stream pipeline? Stream operations are divided into intermediate and terminal operations and are combined to form stream pipelines. A stream pipeline consists of a source; followed by zero or more intermediate […]

Java SE 8/11 Programmer II Exam Series: Built-in Functional Interfaces

Introduction Functional interfaces are the basics of functional programming in Java 8. If you master the six basic interfaces, you can derive the rest and understand the streams. In this section, we will cover the common functional interfaces in java.util.function package: Supplier, Consumer, Predicate, Function, UnaryOperator, and BinaryOperator. Class Hierarchy The diagram shows the class […]

Java SE 8/11 Programmer II Exam Series: Java Collections Framework

Introduction The collection interfaces are divided into two groups: the most basic interface java.util.Collection, and other collection interfaces based on java.util.Map. In this section, we will cover four main interfaces in the Java Collections Framework: List, Set, Map, and Queue. List You usually use a list when you want an ordered collection that can contain duplicate entries. All […]

Java SE 8/11 Programmer II Exam Series: Generics

Introduction Generics enable types (classes and interfaces) to be parameters when defining classes, interfaces, and methods. It enables you to re-use the same code. In this section, we will cover Generic Classes, Generic Interfaces, Generic Methods, and Bounded Type Parameters. Type Parameter Naming Conventions By convention, type parameter names are single, uppercase letters. The most […]

Java SE 8/11 Programmer II: Design Patterns and Principles

Introduction This section covers the OCP Java SE 8 Programmer II exam objectives: design an interface, define functional interfaces, implement polymorphism, create and use singleton classes and immutable classes. Designing an Interface Let’s revise the interface rules in Java 8. An interface may extend another interface, and in doing so it inherits all of the […]

Java SE 8/11 Programmer II: Advanced Class Design

Introduction In this post, we discover the basics of advanced class design for the Java SE 8 Programmer II Exam. We cover the instanceof operator; implement equals, hashCode, and toString; create enumerations and nested classes. Virtual methods Virtual functions are an important part of the run-time polymorphism in object-oriented programming. They are just non-static methods. […]