Java SE 8/11 Programmer II Exam Series: Concurrency (Part 1)

Introduction This post is currently in progress… In this post, we will look at the exam objective; create worker threads using Runnable, Callable, and use an ExecutorService to concurrently execute tasks. Note that this is also a part of the Java SE 11 Programmer II Certification. Runnable Interface Runnable interface Usages of Runnable interface Creating a […]

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

Item 45: Use streams judiciously

Introduction Streams in Java 8 support functional-style operations on streams of elements. This API makes it easier to perform bulk operations, sequentially or in parallel. When used appropriately, streams can make programs shorter and clearer. When used inappropriately, they can make programs difficult to read and maintain. When to use streams? Streams are a good […]