Premium

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



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

package com.hadoopexam;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

public class Welcome implements Runnable {
String fileName;

public Welcome(String fileName) {
this.fileName = fileName;
}

public void run() {
System.out.println(fileName);
}

public static void main(String[] args) throws IOException, InterruptedException {
ExecutorService executorService = Executors.newCachedThreadPool();
Stream allFiles = Files.walk(Paths.get(System.getProperty("user.dir")));
allFiles.forEach(file -> {
executorService.execute(new Welcome(file.getFileName().toString())); //n1
});
executorService.shutdown();
executorService.awaitTermination(5, TimeUnit.DAYS);// n2
}
}

 : You have been given below code, what is expected behavior?
1. The program throws a runtime exception at line n2.

2. The program prints files names concurrently.

3. Access Mostly Uused Products by 50000+ Subscribers

4. A compilation error occurs at line n1.


Correct Answer : Get Lastest Questions and Answer :
Explanation: : ExecutorService java.util.concurrent.Executors.newCachedThreadPool()

Creates a thread pool that creates new threads as needed, but will reuse previously constructed threads when they are available. These pools will typically improve the performance of
programs that execute many short-lived asynchronous tasks. Calls to execute will reuse previously constructed threads if available. If no existing thread is available, a new thread
will be created and added to the pool. Threads that have not been used for sixty seconds are terminated and removed from the cache. Thus, a pool that remains idle for long enough
will not consume any resources. Note that pools with similar properties but different details (for example, timeout parameters) may be created using ThreadPoolExecutor constructors.
Returns:
the newly created thread pool





Question :
You have been given below code

package com.hadoopexam;


public class Welcome {
public static int checkValue(String s1, String s2) {
return s1.length() - s2.length();
}

public static void main(String[] args) {
String[] siteArray = new String[] { "Hadoop" , "Quick" , "Training" };
// line n1
for (String siteName : siteArray) {
System.out.print(siteName + " ");
}
}
}

Which code segment from below, will help us to print as "Quick Hadoop Training"

 :
1. Arrays.sort(siteArray, Welcome:: checkValue);

2. Arrays.sort(siteArray, (Welcome :: new) :: checkValue);

3. Access Mostly Uused Products by 50000+ Subscribers

4. Arrays.sort(siteArray, Welcome :: new :: checkValue);


Correct Answer : Get Lastest Questions and Answer :
Explanation: void java.util.Arrays.sort(String[] a, Comparator c)

Sorts the specified array of objects according to the order induced by the specified comparator. All elements in the array must be mutually comparable by the specified comparator
(that is, c.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the array).
This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.
Implementation note: This implementation is a stable, adaptive, iterative mergesort that requires far fewer than n lg(n) comparisons when the input array is partially sorted, while
offering the performance of a traditional mergesort when the input array is randomly ordered. If the input array is nearly sorted, the implementation requires approximately n
comparisons. Temporary storage requirements vary from a small constant for nearly sorted input arrays to n/2 object references for randomly ordered input arrays.
The implementation takes equal advantage of ascending and descending order in its input array, and can take advantage of ascending and descending order in different parts of the the
same input array. It is well-suited to merging two or more sorted arrays: simply concatenate the arrays and sort the resulting array.
The implementation was adapted from Tim Peters's list sort for Python ( TimSort). It uses techniques from Peter McIlroy's "Optimistic Sorting and Information Theoretic Complexity",
in Proceedings of the Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474, January 1993.
Parameters:
the class of the objects to be sorted
a the array to be sorted
c the comparator to determine the order of the array. A null value indicates that the elements' natural ordering should be used.





Question : You have been given below code, which of the following statement, replace at n can produce "Hadoop Data Science Spark"

package com.hadoopexam;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;public class Welcome {
String courseName;

Welcome(String course) {
this.courseName = course;
}

public static void main(String[] args) {
List courseName = Arrays.asList(new Welcome(" Hadoop"),
new Welcome(" Data Science"), new Welcome(" Spark"));
Stream stream = courseName.stream();
// line n1


}
}
 : You have been given below code, which of the following statement, replace at n can produce
1. stream.forEach(System.out::print);

2. stream.map(a-> a.courseName).forEach(System.out::print);

3. Access Mostly Uused Products by 50000+ Subscribers

4. stream.forEachOrdered(System.out::print);


Correct Answer : Get Lastest Questions and Answer :
Explanation: In option 2, we are getting course name instead of entire object.

Stream java.util.stream.Stream.map(Function mapper)

Returns a stream consisting of the results of applying the given function to the elements of this stream.
This is an intermediate operation.
Parameters:
The element type of the new stream
mapper a non-interfering, stateless function to apply to each element
Returns:
the new stream



Related Questions


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

package com.hadoopexam;

import java.time.LocalDate;
import java.time.Month;

public class Welcome {

public static void main(String[] args) {
LocalDate birthDate = LocalDate.of(1969, Month.JANUARY, 01);
LocalDate atFiftyYears = birthDate.plusYears(50);
atFiftyYears.plusDays(15); // line n1
System.out.println(atFiftyYears);
}
}
 : You have been given below code, what is the expected output?
1. 2019-01-16

2. 2019-01-01

3. Access Mostly Uused Products by 50000+ Subscribers

4. A DateTimeExceptionis thrown.



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

package com.hadoopexam;

import java.util.function.BiFunction;

public class Welcome {

public static void main(String[] args) {
BiFunction summation = (value1, value2) -> value1 + value2;//n1
System.out.println(summation.apply(1, 2.5)); //n2
}
}
 : You have been given below code, what is the expected behavior?
1. 3.5

2. 1

3. Access Mostly Uused Products by 50000+ Subscribers

4. A compilation error occurs at line n2.



Question : Which statement is true about java.time.Duration?


 : Which statement is true about java.time.Duration?
1. It tracks time zones.

2. It preserves daylight saving time.

3. Access Mostly Uused Products by 50000+ Subscribers

4. It defines date-based values.



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.UnaryOperator;

public class Welcome {

public static void main(String[] args) {
UnaryOperator doubleValue = s -> s * 2;// line n1
List dataList = Arrays.asList(5, 10,20,25);
dataList.stream().filter(value -> value >= 10).map(newValue -> doubleValue.apply(newValue))
.forEach(val1 -> System.out.print(val1 + " ")); //n2
}
}
 : You have been given below code, what is the expected behavior?
1. 20 40 50

2. 110

3. Access Mostly Uused Products by 50000+ Subscribers

4. A compilation error occurs at line n2.



Question : You have been asked to create a ResourceBundle which uses a properties file to localize an application.
Which of the below example specifies valid keys and values ?
?


 : You have been asked to create a ResourceBundle which uses a properties file to localize an application.
1. Paper Menu

2. menu1Exam Menu
menu2Paper Menu

3. Access Mostly Uused Products by 50000+ Subscribers

4. menu1 = Exam Menu
menu2 = Paper Menu



Question : You have been given below code, select the correct statement which applies to it.
package com.hadoopexam;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

class Welcome {
public static void main(String[] args) throws IOException {
FileInputStream findings = new FileInputStream("HadoopExam.txt");
DataInputStream dataStream = new DataInputStream(findings);
BufferedReader br = new BufferedReader( new InputStreamReader(dataStream));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
}
}
 : You have been given below code, select the correct statement which applies to it.
1. br.close() statement will close only the BufferedReader object, and findings and dataStream will remain unclosed.
2. The br.close() statement will close the BufferedReader object and the underlying stream objects referred by findings and dataStream.

3. Access Mostly Uused Products by 50000+ Subscribers
collects all resources.

4. All of the above