Premium

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



Question : Which one of the following abstract methods does not take any argument but returns a value?


 : Which one of the following abstract methods does not take any argument but returns a value?
1. The accept() method in java.util.function.Consumer interface

2. The get() method in java.util.function.Supplier interface

3. Access Mostly Uused Products by 50000+ Subscribers

4. The apply() method in java.util.function.Function interface


Correct Answer : Get Lastest Questions and Answer :
Explanation: The signature of get() method in java.util.function.Supplier interface is: T get().




Question : You have been given following code. What is the behavior you expect?

package com.hadoopexam;

import java.util.function.Predicate;

public class Welcome {
public static void main(String args[]) {
Predicate checkValue = "HadoopExam Learning Resource"::contains; //n1
checkString(checkValue, "Quick");
}

static void checkString(Predicate predicate, String str) {
System.out.println(predicate.test(str) ? "It has given String" : "It does not have given String"); //n2
}
}
 : You have been given following code. What is the behavior you expect?
1. There will be a compile time error at n1, because you cannot have a method reference with an Object.

2. There will be a compile time error at n2.

3. Access Mostly Uused Products by 50000+ Subscribers

4. Program will compile and run as well and print "It does not have given String"


Correct Answer : Get Lastest Questions and Answer :
Explanation: It is ok to create method reference using Object. Here, we are creating method reference using "HadoopExam Learning Resource"::contains.
And signature of contains method and test method are same. Hence, no compile time error.




Question : What would happen, if you use below code.

package com.hadoopexam;

import java.util.function.Predicate;

import java.util.function.ObjIntConsumer;

class Welcome {
public static void main(String[] args) {
ObjIntConsumer charAt = (str, i) -> str.charAt(i); // n1
System.out.println(charAt.accept("java", 2)); // n2
}
}
 : What would happen, if you use below code.
1. There will be a compile time error at line n1

2. There will be a compile time error at line n2

3. Access Mostly Uused Products by 50000+ Subscribers

4. There will be no error, it runs perfectly and print v


Correct Answer : Get Lastest Questions and Answer :
Explanation: As we are using Consumer, which will take as an input arguments. Bud return a null value. Hence, in this code println() line give compile time error.
Because charAt function will not return any value. Which will cause println() to through compile time error.


Related Questions


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

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;

public class Welcome {
public static void main(String[] args) throws IOException {
Stream lines = Files.lines(Paths.get("C:\\Welcome.java"));
//n1
}
}
Which of the following line will print first line from Welcome.java file
 : You have been given below code.
1. lines.limit(1).forEach(System.out::println);

2. lines.limit(0).forEach(System.out::println);

3. Access Mostly Uused Products by 50000+ Subscribers

4. lines[0]

5. C and D



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.nio.file.attribute.BasicFileAttributes;
import java.util.function.BiPredicate;
import java.util.stream.Stream;

public class Welcome {
public static void main(String[] args) throws IOException {
BiPredicate biPredicate = (path, attrs) -> true;
try(Stream entries = Files.find(Paths.get("."), 1, biPredicate)) {
entries.forEach(System.out::println);
}
}
}
 : You have been given below code, what is 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 run, and print one level file information.



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

package com.hadoopexam;

import java.io.IOException;

public class Welcome extends Thread {

@Override
public void run() {
System.out.print("HadoopExam");
}

public static void main(String[] args) throws IOException {
Welcome wel = new Welcome();
System.out.println(".com");
}
}
 : You have been given below code. What is the expected behavior ?
1. It will give compile time error

2. It will give run time error

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will print "HadoopExam"

5. It will print "HadoopExam.com"



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

import java.io.IOException;

public class Welcome extends Thread {

@Override
public void run() {
System.out.print("HadoopExam");
}

public static void main(String[] args) throws IOException, InterruptedException {
Welcome wel = new Welcome();
wel.start();
Thread.sleep(500);
System.out.print(".com ");
}
}
 : You have been given below code, what is the expected behavior?
1. It will give compile time error

2. It will give run time error

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will print "HadoopExam"

5. It will print "HadoopExam.com"



Question : You have a various runnable tasks, which needs to be executed one by one, based on their priority (Between to ). However, you are keep getting higher priority tasks
in the Queue and you lower priority tasks will never get an opportunity to being executed. Which of the following problem is discussed in above statement?

A. Deadlock
B. Starvation
C. Livelock
D. R ace condition

 : You have a various runnable tasks, which needs to be executed one by one, based on their priority (Between  to ). However, you are keep getting higher priority tasks
1. Deadlock

2. Starvation

3. Access Mostly Uused Products by 50000+ Subscribers

4. R ace condition



Question : Which of the following definition are correct?

 : Which of the following definition are correct?
1. class Welocme {
public synchronized void foo() {}
}


2. abstract class Welcome {
public abstract synchronized void foo();
}


3. Access Mostly Uused Products by 50000+ Subscribers
public synchronized void foo();
}


4. A and C