Premium

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



Question : You have been given below code. What is the behavior of the code?

package com.hadoopexam;

import java.util.function.Function;

public class Welcome {
public static void main(String[] args) {
Function negate = (i -> -i), square = (i -> i * i), negateSquare = negate
.compose(square);
System.out.println(negateSquare.apply(13));
}
}
 : You have been given below code. What is the behavior of the code?
1. Code will be having a compile time error.

2. Code will produce the output as -169

3. Access Mostly Uused Products by 50000+ Subscribers

4. Code will produce output as 13


Correct Answer : Get Lastest Questions and Answer :
Explanation: As you know , when you use compose for two functions, it will first call the function which is bracket like square. Hence, 13 will be squared to 169 first
and then it will be negated so result would be -169.




Question : You have been given a following method of Long class.
long parseLong(String s)
Now select the correct functional interface for which, you can pass method reference like.
Long::parseLong()


 : You have been given a following method of Long class.
1. BiPredicate

2. Function

3. Access Mostly Uused Products by 50000+ Subscribers

4. Predicate

5. Consumer



Correct Answer : Get Lastest Questions and Answer :
Explanation: The parseLong() method takes a String and returns a value, So we need to use the Function interface because it matches the signature of the
abstract method R apply(T t). In Function, the first type argument is the argument type and the second one is the return type. Given that parseLong takes a String
as the argument and returns a long (that can be wrapped in an Integer), we can assign it to Function.




Question : You have been given below code, when you run this code. What would be the behavior?
package com.hadoopexam;

import java.util.function.BiFunction;

public class Welcome {
public static void main(String args[]) {
BiFunction stringCompare = (str1, str2) -> str1.equals(str2);
System.out.println(stringCompare.apply("HadoopExam", "HadoopExam"));
}
}
 : You have been given below code, when you run this code. What would be the behavior?
1. It will generate compile time error.

2. You cannot use predicate in Function interface. Hence, will generate RuntimeError

3. Access Mostly Uused Products by 50000+ Subscribers

4. Program runs perfectly and produce false.


Correct Answer : Get Lastest Questions and Answer :
Explanation: BiFunction has an apply() function which take two arguments as an input. So here stringCompare is defined for the same. We will be providing two
arguments as an input and one Boolean as an output. So this code works fine and produce the true as an output. Because both the strings are same.


Related Questions


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



Question : You have been given below code, what is the expected behavior ?
package com.hadoopexam;

import java.nio.file.*;

public class Welcome {
public static void main(String[] args) {
Path hePath = Paths.get("C:\\HadoopExam\\he1.txt");
while (hePath.iterator().hasNext()) {
System.out.println("Next Path: " + hePath.iterator().next());
}
}
}
 : You have  been given below code, what is the expected behavior ?
1. It will give compile time error

2. It will give runtime error

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will print only once "Next Path: C:\HadoopExam\he1.txt"

5. It will go in infinite loop.



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

package com.hadoopexam;

import java.nio.file.Path;
import java.nio.file.Paths;

public class Welcome {
public static void main(String []args) {
Path path = Paths.get("D:\\HadoopExam\\HE\\..\\HE2\\com\\.\\Welcome.java");
path = path.normalize();
System.out.println(path.subpath(2, 3));
}
}
 : You have been given below path, what is the expected code behavior?
1. It gives compile time error

2. It will give runtime error

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will print "HadoopExam"

5. It will print "com"



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

package com.hadoopexam;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Welcome {
public static void main(String[] args) throws IOException {
Path path = Paths.get("C:\\HadoopExam\\he.txt");
System.out.println(path.isAbsolute());
}
}
 : You have been given below code, what is the expected behavior?
1. Compile time error

2. Runtime exception

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will print true

5. Depend on file exist or not