Premium

Oracle Advacned Java Advanced Certification Questions and Answers (Dumps and Practice Questions)



Question : You have been given below code, what is the expected behavior?

package com.hadoopexam;

import java.util.Arrays;
import java.util.List;

public class Welcome {
public static void main(String[] args) {
List sites = Arrays.asList("HadoopExam", "QuickTechie", "Training4Exam");
sites.forEach(allSite -> System.out.print(allSite + " "));
String courseSite = sites.stream().filter(s -> s.contains("i")).reduce((s, t) -> s + t).get();
System.out.println("\n" + courseSite);
}
}
 : You have been given below code, what is the expected behavior?
1. It will print
HadoopExam QuickTechie Training4Exam
QuickTechieTraining4Exam

2. It will print
HadoopExam QuickTechie Training4Exam
HadoopExam

3. Access Mostly Uused Products by 50000+ Subscribers
QuickTechieTraining4Exam
HadoopExam QuickTechie Training4Exam

4. It will print
QuickTechieTraining4Exam



Correct Answer : Get Lastest Questions and Answer :
Explanation: sites.forEach(allSite -> System.out.print(allSite + " "));
Above line will print each element from list.

Below line , filter each element from list. It will consider only element which has i in it.

String courseSite = sites.stream().filter(s -> s.contains("i")).reduce((s, t) -> s + t).get();

Hence, the output will be
QuickTechieTraining4Exam





Question : You have been given below code, what is the expected behavior?

package com.hadoopexam;

import java.util.Arrays;
import java.util.List;
import java.util.function.Function;

public class Welcome {
public static void main(String[] args) {
List sites = Arrays.asList("HadoopExam.com", "Training4Exam.com", "QuickTechie.com");
Function funVal = s -> " Welcome to : ".concat(s);
sites.stream().map(funVal).peek(System.out::print);
}
}
 : You have been given below code, what is the expected behavior?
1. It will print Welcome to : HadoopExam.com Welcome to : Training4Exam.com Welcome to : QuickTechie.com

2. It will print HadoopExam.com: Training4Exam.com: QuickTechie.com

3. Access Mostly Uused Products by 50000+ Subscribers

4. There will be compilation error

5. There will be a runtime error.


Correct Answer : Get Lastest Questions and Answer :
Explanation: Stream operations and pipelines
Stream operations are divided into intermediate and terminal operations, and are combined to form stream pipelines. A stream pipeline consists of a source (such as a Collection,
an array, a generator function, or an I/O channel); followed by zero or more intermediate operations such as Stream.filter or Stream.map; and a terminal operation such
as Stream.forEach or Stream.reduce.
Intermediate operations return a new stream. They are always lazy; executing an intermediate operation such as filter() does not actually perform any filtering, but instead
creates a new stream that, when traversed, contains the elements of the initial stream that match the given predicate. Traversal of the pipeline source does not begin
until the terminal operation of the pipeline is executed.
Terminal operations, such as Stream.forEach or IntStream.sum, may traverse the stream to produce a result or a side-effect. After the terminal operation is performed,
the stream pipeline is considered consumed, and can no longer be used; if you need to traverse the same data source again, you must return to the data source to get a new stream.
In almost all cases, terminal operations are eager, completing their traversal of the data source and processing of the pipeline before returning. Only the terminal
operations iterator() and spliterator() are not; these are provided as an "escape hatch" to enable arbitrary client-controlled pipeline traversals in the event that the existing operations
are not sufficient to the task.
Processing streams lazily allows for significant efficiencies; in a pipeline such as the filter-map-sum example above, filtering, mapping, and summing can be fused into a single pass
on the data, with minimal intermediate state. Laziness also allows avoiding examining all the data when it is not necessary; for operations such as "find the first string longer than
1000 characters", it is only necessary to examine just enough strings to find one that has the desired characteristics without examining all of the strings available from the source.
(This behavior becomes even more important when the input stream is infinite and not merely large.)
Intermediate operations are further divided into stateless and stateful operations. Stateless operations, such as filter and map, retain no state from previously seen element when
processing a new element -- each element can be processed independently of operations on other elements. Stateful operations, such as distinct and sorted, may incorporate state from
previously seen elements when processing new elements.
Stateful operations may need to process the entire input before producing a result. For example, one cannot produce any results from sorting a stream until one has seen all elements
of the stream. As a result, under parallel computation, some pipelines containing stateful intermediate operations may require multiple passes on the data or may need to buffer
significant data. Pipelines containing exclusively stateless intermediate operations can be processed in a single pass, whether sequential or parallel, with minimal data buffering.
Further, some operations are deemed short-circuiting operations. An intermediate operation is short-circuiting if, when presented with infinite input, it may produce a finite stream
as a result. A terminal operation is short-circuiting if, when presented with infinite input, it may terminate in finite time. Having a short-circuiting operation in the pipeline is
a necessary, but not sufficient, condition for the processing of an infinite stream to terminate normally in finite time.





Question : You have been given below interface

package com.hadoopexam;

public interface Welcome {

public default void call(Integer distance) {
System.out.println("Welcome to HadoopExam Learning Resources");
}

public void run(Integer distance);
}

Which is the valid use of Welcome interface?
 : You have been given below interface
1. Welcome courseCount = n -> System.out.println("Start watching Hadoop Training " + n);
courseCount.run(1);
courseCount.call(2);


2. Welcome courseCount = n ->n + 10;
courseCount.run(1);
courseCount.call(2);


3. Access Mostly Uused Products by 50000+ Subscribers
courseCount.run(1);
Welcome.call(2)


4. Welcome is not correctly declare to be used in a lambda expression.


Correct Answer : Get Lastest Questions and Answer :
Explanation: : It's a simple lambda expression in option 1. Option 3 is clearly wrong, call method is not static.

In option 2 , you are trying to return a value n+2, however it is not expected as per the Welcome class method.



Related Questions


Question : You have been given the below code, what is the behavior you expect.

package com.hadoopexam;

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

class Welcome {
public static void main(String[] args) {
Deque deque = new ArrayDeque<>();
deque.addAll(Arrays.asList(1, 2, 3, 4, 5));
System.out.println("First removed element is = " + deque.remove());
}
}
 : You have been given the below code, what is the behavior you expect.
1. Code will through compile time exception.

2. Code will compile but through Runtime exception "IllegalStateException"

3. Code will compile and run perfectly and print First removed element is = 5

4. Code will compile and run perfectly and print First removed element is = 1



Question : You have been given below code. Select the correct behavior of the code.

package com.hadoopexam;

class Parent {

private T test;
void call(T t) {
test = t;
System.out.println("Testing Method 1");
}
}



package com.hadoopexam;

class Welcome extends Parent {
public Welcome(S s) {
}

void call(S s) {
System.out.println("Testing Method 2");
}
}

package com.hadoopexam;

class Test {
public static void main(String[] args) {
Welcome err = new Welcome("Test");
err.call("Calling");
}
}

 : You have been given below code. Select the correct behavior of the code.
1. Code will compile and run with the output as "Testing Method 2"

2. Code will compile and run with the output as "Testing Method 1"

3. Access Mostly Uused Products by 50000+ Subscribers

4. Code will not compile because there is an ambiguity in code call method



Question : Select the correct functional interface from below.

A. java.util.stream.Stream
B. java.util.function.Consumer
C. java.util.function.Supplier
D. java.util.function.Predicate
E. java.util.function.Function

 : Select the correct functional interface from below.
1. A,B,C
2. B,C,D
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D,E
5. B,C,D,E


Question : You have been given below code.
package com.hadoopexam;

import java.io.IOException;
import java.io.ObjectInputStream.GetField;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

class Welcome {

String fName;
String lName;

public Welcome(String fn, String ln) {
fName = fn;
lName = ln;
}

public String getfName() {
return fName;
}

public String getlName() {
return lName;
}

public static void main(String[] args) throws IOException {
List allUser = Arrays.asList (
new Welcome ("Amit", "Kumar"),
new Welcome ("Amit", "Jain"),
new Welcome ("Vineet", "Sinha"));
List sortedUser = allUser.stream()
//n1

.collect(Collectors.toList());
sortedUser.stream().forEach((wel) -> System.out.println(wel.getfName() + " " + wel.getlName()));
}
}

Which of the below code will be replaced at n1, will print following result?

Vineet Sinha
Amit Jain
Amit Kumar


 : You have been given below code.
1. .sorted (Comparator.comparing(Welcome::getfName).reversed().thenComparing(Welcome::getlName))

2. .sorted (Comparator.comparing(Welcome::getfName).thenComparing(Welcome::getlName))

3. Access Mostly Uused Products by 50000+ Subscribers

4. map(Welcome::getfName).sorted(Comparator.reverseOrder().map(Welcome::getlName).reserved



Question : You have been given below code

package com.hadoopexam;

public enum INR {
RS1(100), QUARTERRS(25);
private int value;

public INR(int value) {
this.value = value;
}

public int getValue() {
return value;
}
}


package com.hadoopexam;

public class Coin {

public static void main(String[] args) {
INR inr = new INR.QUARTERRS;
System.out.println(inr.getValue());
}
}

There seems to be a compile time error. How, will fix it?

A. Remove new keyword from this line INR inr = new INR.QUARTERRS;
B. Correct statement as INR inr = new INR.QUARTERRS();
C. Keep INR class as subclass of Coin class.
D. Change the access modifier public to private for INR(int value)
 : You have been given below code
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D
5. B,D


Question : You have been given below code, what is expected behavior?

package com.hadoopexam;

class PDFScanner implements AutoCloseable {
public void close() throws Exception {
System.out.print("3 Scanner closed, ");
}

public void scanPDF() throws Exception {
System.out.print("1 PDF Scanner , ");
throw new Exception("2 Unable to scan, ");
}
}

package com.hadoopexam;

class PDFPrinter implements AutoCloseable {
public void close() throws Exception {
System.out.print("5 Printer closed, ");
}

public void printCoursePDF() {
System.out.print("4 Print pdf, ");
}
}


package com.hadoopexam;

import java.io.IOException;

class Welcome {

public static void main(String[] args) throws IOException {
try (PDFScanner courseScanner = new PDFScanner(); PDFPrinter taskPrinter = new PDFPrinter()) {
courseScanner.scanPDF();
taskPrinter.printCoursePDF();
} catch (Exception e) {
System.out.print(e.getMessage());
}
}
}

 : You have been given below code, what is expected behavior?
1. 1 PDF Scanner , 5 Printer closed, 3 Scanner closed, 2 Unable to scan,

2. 5 Printer closed, 3 Scanner closed,

3. Access Mostly Uused Products by 50000+ Subscribers

4. 3 Scanner closed