Lambda Expressions

Lambda expressions add a new ability to the Java language: to pass a function as an argument to another method. Before lambda expressions you could do something similar using anonymous inner classes and functional interfaces, but the result code became less legible and clear:

Lambda expressions let you create ..Continue Reading

Calendar Classes

Java 8 introduced a replacement for the old date and time classes existing in the java.util.Date package: the new java.time package, based on the Joda-Time project, designed for multiple calendar systems (the default is the ISO8601) and supporting time zone, duration, format and parsing. The four java.time classes you must know ..Continue Reading

The Java Collections API

Arrays are good and fast, but they are static (once they are created they can’t grow). In this lesson we’re going to review three hierarchically related types from the Java Collections API that provide dynamic data structures: Type extends implements Description interface Collection  Iterable  –  General dynamic collection of elements that ..Continue Reading

The StringBuilder Class

A StringBuilder object is like a String object but it can be modified. Internally it’s treated like a variable-length array that contains a sequence of characters: it has capacity (max number of characters it can contain) and length (number of characters of the string that the object represents). StringBuilder Main ..Continue Reading

The String Class

The String class is immutable: once it’s created, a String object can’t be changed. Therefore its methods never affect the original String object but create and return a new String object that contains the result of the operation. In order to correctly answer questions in the exam about strings you ..Continue Reading

Catching and Handling Exceptions

The try Statement The try statement is used wherever there is code that could throw an exception. It involves the use of three reserved words: try, catch and finally. The syntax is the following:

The try statement must contain at least one catch block or one finally block. The ..Continue Reading

Exceptions

An exception is an event that disrupts the normal flow of execution in a program. Some of the advantages of using exceptions are: Separating error-handling code from regular code Easily differentiating error types Being able to propagate errors up the call stack For the exam, you should be familiar with the ..Continue Reading

Class Initialization and Inheritance

Class and instance initializers are blocks of code outside constructors or methods. A class can have any number of initializers. They can be anywhere in the class body and are called in the order that they appear in the source code. Class initializers (also called static initialization blocks) use the ..Continue Reading

Interfaces

An interface is a reference type similar to an abstract class but it can contain only: Constants. All fields defined in an interface are implicitly public, static, and final (these modifiers can and should be omitted) Abstract methods to be implemented by classes implementing the interface. Except for default methods, ..Continue Reading

Abstract Methods and Classes

Abstract classes are usually meant to share pieces of implementation and to be extended:

Abstract methods are methods declared without an implementation (no body and semicolon at the end).

An important thing to remember about abstract methods is that if a class has one or more abstract methods then ..Continue Reading