Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

Object o = () -> {System.out.println(“Example”); }; Object o can be replaced with ?

Runnable r--correct

Lambda Expressions are based on

Functional Programming--correct

public interface Adder { String add(Function f); void add(Consumer 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--correct

Lambda Expressions in Java allow us to treat

Code as data--correct

which of the following are not valid lambda expressions?

None of the options--correct

Parameter types be inferred in Lambda expressions ?

True--correct

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

Both--correct

Following lambda expression is valid (x, y) -> return x + y

False--correct

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--correct

Which of the following are valid uses of lambda expressions?

public void execute(Runnable r){ r.run(); } Execute(() -> {});--correct

Which of these interfaces are functional interfaces?


public interface Cards{ int totalCount(int a, int b); }--correct

A functional interface acts as target types for which of the following?

All the options mentioned--correct

Which of the following functional interface represents an operation that accepts a


single input argument and returns no result?

Consumer--correct

Which of the following functional interface represents a function that accepts an


int-valued argument and produces a long-valued result?

IntToLongFunction--correct

Which of the following functional interface represents an operation upon two long-
valued operands and produces a long-valued result?

LongBinaryOperator--correct

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


interface a functional interface

False--correct

What functional interface would you use for the following? No parameters , returns
a value

Supplier--correct

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--correct

Which of the following functional interface represents an operation that accepts an


object-valued and an int-valued argument, and returns no result?

ObjIntConsumer--correct

Which of these does Stream filter() operates on

Predicate--correct

Stream operations in java 8 can be divided into


All--correct

Stream operation iterations are internal over the source of elements

False--correct

Which of the following is valid Stream operation type

Both--correct

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--correct

The newly introduced Streams API is available in which package of java 8

java.util.stream---correct

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--correct

Terminal operation produces another stream as its output

False--correct

Each pipeline ends with a

Terminal operation--correct

Repeating annotations can be added with below 2 declarations

1) Declare a repeatable annotation type 2) Declare the containing annotation type--


correct

On which of these does annotations can be used on in Java 8

All the options mentioned--correct

Optional type validation can be used to substitute runtime validations.

False--correct

Type annotation used to depict non blank string value

@NotBlank--correct

Repeating annotations can be retrieved using

getAnnotationsByType()--correct

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--correct

'map' and 'filter' are

Intermediate operation--correct

DateTimeFormatter formatter=DateTimeFormatter.ofPattern("EEEE",Locale.US);
System.out.println(formatter.format(LocalDateTime.now()));
Choose the correct output.

Friday--correct

Which package contains Date/Time (JSR 310) API in Java 8

java.time--correct

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


time in Java 8

Clock--correct

In Functional Reactive Programming, we pull the stream of data

False--correct

Library used to write reactive programs in java

RxJava--correct

Which of the following can be a valid input for jdeps dependency analyzer?

All the options mentioned--correct

Which of these should be used to show package-level and class-level dependencies of


Class files in Java 8

jdeps--correct

Which methods preserve parameter names in Java bytecode (through reflection API)

All methods--wrong

In java 8, Static methods cannot be added to a Interface


False--correct

You might also like