Showing posts with label Java 8 Interview Questions and Answers. Show all posts
Showing posts with label Java 8 Interview Questions and Answers. Show all posts

January 01, 2020

#Java8 Transform object into another type

Sometimes we need to convert or cast or transform an object from one type to another class. There are many ways, by which we can do it.

Let's say we have two objects ExternalPeopleInfo and InternalPeopleInfo. Assume we get ExternalPeopleInfo by calling some external API, but to save the details in our system we need to convert it in to InternalPeopleInfo.

July 29, 2018

Exceptions in Java 8 Streams and Lambda Expressions

Java 8 Lambda Expressions allow us to do functional programming, but sadly they don't deal with exceptions very well.

Handling Unchecked Exceptions
Let's say we have a list of integers and we are dividing a constant number (lets say 16) with every element of this list, we need to print result of this division.

List < Integer > myList = Arrays.asList(7, 9, 16, 25, 27);
myList.forEach(i - > System.out.println(16 / i));

June 01, 2016

#Java8 : Java 8 Interview Questions and Answers..

What are new features introduced with Java 8 ?
Lambda Expressions, Interface Default and Static Methods, Method Reference, Parameters Name, Optional, Streams, Concurrency.
  • Lambda Expressions : a new language feature allowing treating actions as objects
  • Method References : enable defining Lambda Expressions by referring to methods directly using their names
  • Optional : special wrapper class used for expressing optionality
  • Functional Interface – an interface with maximum one abstract method, implementation can be provided using a Lambda Expression
  • Default methods : give us the ability to add full implementations in interfaces besides abstract methods
  • Nashorn, JavaScript Engine : Java-based engine for executing and evaluating JavaScript code
  • Stream API : a special iterator class that allows processing collections of objects in a functional manner
  • Date API : an improved, immutable JodaTime-inspired Date API