An object is considered immutable if its state cannot change after it is constructed. Since they cannot change state, they cannot be corrupted by thread interference or observed in an inconsistent state making them useful in concurrent applications.
Switch statement in Java is for decision making. Unlike
if-then-else statements, the
switch statement can have a number of possible execution paths.
Lately, I have been thinking why shouldn't I complie set of questions that I generally include in interviews for mid-senior level Java Developers. Though I am a big fan of algorithm questions in interviews for developer, I believe including these questions either in screening or half of time in second round interview would give chance to hear about candidate's understanding on core concepts of Java 8+. I like these these questions since they include core concepts in Java that developers use in day to day jobs.
Java 8 has introduced a new abstraction called Stream, letting us processing data in a declarative way. Furthermore, streams can leverage multi-core architectures without you having to write a single line of multithread code.
Deep cloning of object has always been something that every Java developers work on so frequently. There are a lot of articles talking about a different way to clone objects deeply and obviously, the preferred method is to use Copy Constructors since it overcomes the design issues of Object.clone() and provides better control over object construction.
This has been one of the popular programming tasks for Java developer, particularly focusing on text processing.
Since Java 8, a lot of boilerplate code can be replaced with lambda expressions in our codebase. I really want to put out an article about Streams in Java, but since that carries real value only if we combine them with lambda expressions, I want to write about some ideas about playing around with lambda expressions first.
This has been one of the most frequently asked questions in Java interviews. With streams introduced after Java 8, this can be achieved in an elegant and functional way.
Java 8 introduced the
Optionalclass to make handling of nulls less error-prone. For example, the following program to pick the lucky name has a null check as: