JavaSE 8

Here you will find the frequently asked JavaSE 8 questions and answers, these questions will help you to ace the job interviews.

Q.1 Specify the new features introduced in JAVA 8?
Some of the new features in Java 8 are -
1. Lambda expression − It adds functional processing capability to Java.
2. Method references − It is a referencing functions by their names instead of invoking them directly. Using functions as parameter.
3. Default method − It is an interface to have default method implementation.
4. New tools − New compiler tools and utilities are added like 'jdeps' to figure out dependencies.
5. Stream API − New stream API to facilitate pipeline processing.
6. Date Time API − Improved date time API.
7. Optional − Emphasis on best practices to handle null values properly.
8. Nashorn, JavaScript Engine − A Java-based engine to execute JavaScript code.
Q.2 Why do you use lambda expression?
Lambda expressions are primarily used to define inline implementation of a functional interface, with an interface with a single method only. Lambda expression is used to eliminates the need of anonymous class and gives a very simple yet powerful functional programming capability to Java.
Q.3 What are the default methods and when do we use it?
Default method is a method with an implementation that can be found in an interface. We can use a default method to add a new functionality to an interface while maintaining backward compatibility with classes that are already implementing the interface. In general. when a new abstract method is added to an interface, all implementing classes will break until they implement the new abstract method. Ideally in Java 8, the problem has been solved by the use of default method.
Q.4 How do you define a Lambda Expression and what is it's purpose?
A lambda expression is a function that can be referenced and passed around as an object. Lambda expressions is primarily used to introduce functional style processing in Java and facilitate the writing of compact and easy-to-read code. Due to which lambda expressions are a natural replacement for anonymous classes as method arguments. Lambda expressions are mainly used to define inline implementations of functional interfaces.
Q.5 How do you define Nashorn in Java8?
In Java8, Nashorn is the new Javascript processing engine for the Java platform that has been shipped with Java 8. Until JDK 7, the Java platform used Mozilla Rhino for the same purpose. as a Javascript processing engine. Nashorn offers better compliance with the ECMA normalized JavaScript specification and better runtime performance than its predecessor.
Q.6 What is JJS, in Java 8?
In Java 8, JJS is the new executable or command line tool which used to execute Javascript code at the console.
Q.7 How do you define a stream, and how does it different from a collection?
A stream is an iterator whose primary role is to accept a set of actions to apply on each of the elements it contains.
Some of the points of difference are -
The stream represents a sequence of objects from a source like a collection, that supports aggregate operations.
Streams have been designed to make collection processing simple and concise. In contrast the collections, the concept of iteration is implemented inside the stream, so that we can use methods like map and flatMap for performing a declarative processing.
The Stream API is fluent and allows pipelining, and yet another important distinction from collections is that streams are inherently lazily loaded and processed.
Q.8 How do you define stream pipelining in Java 8?
In Java8, stream pipelining is the concept of chaining operations together. This is performed by splitting the operations which can happen on a stream into two categories namely -
1. Intermediate operations - Each intermediate operation returns an instance of Stream itself when it runs, an arbitrary number of intermediate operations can, therefore, be set up to process data forming a processing pipeline.
2. Terminal operations - There must then be a terminal operation which returns a final value and terminates the pipeline.
Q.9 How do you define a Functional Interface and what is SAM Interface?
Functional Interface is an interface, that contains one and only one abstract method. The functional Interface is also referred as SAM Interface since it contains only one abstract method. SAM Interface is abbreviated for Single Abstract Method Interface. Also Java SE 8 API has defined many Functional Interfaces.
Q.10 How do you define Spliterator in Java SE 8?
Spliterator is abbreviated for Splitable Iterator. This is newly introduced by Oracle Corporation as part Java SE 8 like Iterator and ListIterator, It is also one of the Iterator interface.
Q.11 What is 'Optional' in Java 8 and what is the use of Optional and the advantages of Java 8 Optional?
Optional' is a final Class introduced as part of Java SE 8 that is defined in java.util package.

Some of the uses of 'Optional' in Java 8 are -
1. It is used to represent optional values that is either exist or not exist.
2. It can contain either one value or zero value. If it contains a value, we can get it. Otherwise, we get nothing.
3. It is a bounded collection that is it contains at most one element only. It is an alternative to “null” value.
Primary advantage of Optional are -
1. It is used to avoid null checks.
2. It is used to avoid “NullPointerException”.
Q.12 How do you define functional interfaces?
Functional interfaces have a single functionality to exhibit. For instance a comparable interface with a single method 'compareTo' which is used for comparison purpose. Java 8 has defined a lot of functional interfaces to be used extensively in lambda expressions.
Q.13 Define the purpose of BiConsumer functional interface.
BiConsumer functional interface represents an operation that accepts two input arguments, and returns no result.
Q.14 What is the purpose of DoubleBinaryOperator functional interface?
DoubleBinaryOperator functional interface represents an operation upon two double-valued operands and producing a double-valued result.
Q.15 How can you create a Base64 decoder?
getDecoder() method of Base64 class returns a Base64. Decoder that decodes using the Basic type base64 encoding scheme
Get Govt. Certified Take Test