0% found this document useful (0 votes)
240 views

XJava

This document contains questions about Java 8 features like lambda expressions, functional interfaces, streams, date time API and other new features. It provides examples of using these features and asks which options correctly describe the examples' output or characteristics of the features. Some key points covered include lambda expressions needing effectively final variables, functional interfaces representing operations with different parameters and return types, intermediate and terminal stream operations, and the packages for streams and date time API classes.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
240 views

XJava

This document contains questions about Java 8 features like lambda expressions, functional interfaces, streams, date time API and other new features. It provides examples of using these features and asks which options correctly describe the examples' output or characteristics of the features. Some key points covered include lambda expressions needing effectively final variables, functional interfaces representing operations with different parameters and return types, intermediate and terminal stream operations, and the packages for streams and date time API classes.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

public interface Adder { String add(Function<String, String> f);

void add(Consumer<Integer> f); } public class AdderImpl implements Adder


{ @Override public String add(Function<String, String> f)
{ return f.apply("Welcome "); } @Override
public void add(Consumer<Integer> f) {} } On calling add() method as
described below, String r = adderImpl.add(a -> a + " lambda");
System.out.println(r); -runtime error

Which of the following is correct about Java 8 lambda expression?-both

public class App{ public static void main(String [] args){ String


name="WelcomeJava";
Runnable r1=() -> System.out.println(name); String name1="";
name1=name.toUpperCase();
Runnable r2=() -> System.out.println(name1); r1.run(); } } What is the o/p of the
above program?-compilation error
====================
Which of these interfaces are functional interfaces?
public interface Cards{ int totalCount(int a, int b); }
A functional interface acts as target types for which of the following?-all
What functional interface would you use for the following? No parameters , returns
a value-supplier
Which of the following functional interface represents an operation that accepts a
single input argument and returns no result?-Consumer t

Below code includes a valid Functional Interface ? package


functionalInterfaceExample;
@FunctionalInterface public interface MyFirstFunctionalInterface { public void
firstWork(); @Override public String toString();
@Override public boolean equals(Object obj); -True
}-

A FunctionalInterface annotation (@FunctionalInterface) is necessary for making an


interface a functional interface-True
Which of the following functional interface represents an operation that accepts an
object-valued and an int-valued argument, and returns no result?-objintconsumer t
Which of the following functional interface represents a function that accepts an
int-valued argument and produces a long-valued result?-int to long function
Which of the following functional interface represents an operation upon two long-
valued operands and produces a long-valued result?-long to binary
=============
Each pipeline ends with a-terminal
Terminal operation produces another stream as its output-false

Identify intermediate and terminal operations in the code. double average =


roster .stream() .filter(p -> p.getGender() == Person.Sex.MALE)
.mapToInt(Person::getAge) .average() .getAsDouble();
Intermediate: filter, mapToInt Terminal: average

Stream operations in java 8 can be divided into-false


Stream operation iterations are internal over the source of elements-false
The newly introduced Streams API is available in which package of java 8-
java.util.stream
Which of these does Stream filter() operates on-predicate
If you wanted to process a stream of names, extract the male names, and store them
in a new List, What is the appropriate operation to be used?-stream.collect
=============
Type annotation used to depict non blank string value-notblank
On which of these does annotations can be used on in Java 8-all
Optional type validation can be used to substitute runtime validations.-False
========
Library used to write reactive programs in java-RxJava
We need to override which Predicate method in Java 8. Which is the right method
call-predict(T t)
Which of these should be used to show package-level and class-level dependencies of
Class files in Java 8-jdeps

DateTimeFormatter dateFormat=DateTimeFormatter.ISO_DATE;
LocalDate dateOfBirth= LocalDate.of(2015,Month.FEBRUARY,31);
System.out.println(dateFormat.format(dateOfBirth)); - Java date time exception

ZoneId zoneId=ZoneId.of("Asia/Singapore");
ZonedDateTime.of(LocalDateTime.now(),zoneId);
System.out.println(ZonedDateTime.getOffset());
Assume that the offset value for Asia/Singapore time zone from UTC/Greenwich is
+08:00. Choose the correct option.-Prints +08:00

Which class can be used Instead of System.getCurrentTimeMillis() to get a date and


time in Java 8-clock

import java.time.Clock;
public class App{
public static void main(String [] args){
final Clock clock=Clock.systemUTC();
System.out.println(clock.instant());
System.out.println(clock.millis());
}
} - compilation error

Example of functional interfaces in Java 8-both

LocalDate date1 = LocalDate.now();


LocalDate date2 = date1.plus(1, ChronoUnit.MONTHS);
Period period = Period.between(date2, date1);
System.out.println("Period: " + period);
Choose the correct output.1

Which of the following is the correct lambda expression which add two numbers and
return their sum?-(a, b) -> a + b
Which method is used to connect the consumer to the source in reactive programming-
subscribe()

DateTimeFormatter formatter=DateTimeFormatter.ofPattern("EEEE",Locale.US);
System.out.println(formatter.format(LocalDateTime.now())); - Friday

Which of the following can be a valid input for jdeps dependency analyzer-all
'map' and 'filter' are-intermediate

Method used to fetch the parameter types using method parameter reflection-
getParameterizedType()
In java 8, Static methods cannot be added to a Interface-False
In Functional Reactive Programming, we pull the stream of data-false
Which methods preserve parameter names in Java bytecode (through reflection API)-
specify -parameters during compilation
Which is new command line tool for the Nashorn JavaScript engine in java 8-jjs

You might also like