Premium

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



Question : Which statement is true about the single abstract method of the java.util.function.Function interface?


 : Which statement is true about the single abstract method of the java.util.function.Function interface?
1. It accepts one argument and returns void.

2. It accepts one argument and returns boolean.

3. Access Mostly Uused Products by 50000+ Subscribers

4. It accepts an argument and produces a result of any data type.


Correct Answer : Get Lastest Questions and Answer :
Explanation: The Function interface defines a single abstract method named apply() that takes an argument of
generic type T and returns an object of generic type R

A Function "operates" on something and returns something: it takes one argument (of generic
type T) and returns an object (of generic type R). You can call apply() method on a Function object.

R java.util.function.Function.apply(T t)

Applies this function to the given argument.
Parameters:
t the function argument
Returns:
the function result





Question : Which statement is true about the DriverManager class?


 : Which statement is true about the DriverManager class?
1. It returns an instance of Connection.

2. it executes SQL statements against the database.

3. Access Mostly Uused Products by 50000+ Subscribers

4. it is written by different vendors for their specific database


Correct Answer : Get Lastest Questions and Answer :
Explanation: JDBC hides the heterogeneity of all the DBMSs and offers a single set of APIs to interact with all types of databases.
The complexity of heterogeneous interactions is delegated to the JDBC driver manager and JDBC drivers.
. The getConnection() method in the DriverManager class takes three arguments: a URL string, a username string, and a password string and returns the Connection with database.
. The syntax of the URL (which needs to be specified to get the Connection object) is jdbc: :.
. If the JDBC API is not able to locate the JDBC driver, it throws a SQLException. If jars for the drivers are available, they need to be included in the classpath to
enable the JDBC API to locate the driver.





Question : You have been given below code, how will you replace n , so that it will print maximum value from given list?

package com.hadoopexam;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class Welcome {


public static void main(String[] args) {
List nums = Arrays.asList (101, 201, 108);
System.out.println (
//line n1

);
}
}
 : You have been given below code, how will you replace n , so that it will print maximum value from given list?
1. nums.stream().max(Comparator.comparing(a -> a)).get()

2. nums.stream().max(Integer :: max).get()

3. Access Mostly Uused Products by 50000+ Subscribers

4. nums.stream().map(a -> a).max();


Correct Answer : Get Lastest Questions and Answer :
Explanation: In stream max() method you have to provide comparator and not comparable.

Optional java.util.stream.Stream.max(Comparator comparator)

Returns the maximum element of this stream according to the provided Comparator. This is a special case of a reduction.
This is a terminal operation.
Parameters:
comparator a non-interfering, stateless Comparator to compare elements of this stream
Returns:
an Optional describing the maximum element of this stream, or an empty Optional if the stream is empty
Throws:
NullPointerException - if the maximum element is null


Comparator java.util.Comparator.comparing(Function keyExtractor)

Accepts a function that extracts a Comparable sort key from a type T, and returns a Comparator that compares by that sort key.
The returned comparator is serializable if the specified function is also serializable.
Parameters:
the type of element to be compared
the type of the Comparable sort key
keyExtractor the function used to extract the Comparable sort key
Returns:
a comparator that compares by an extracted key



Related Questions


Question : You have been given below code, which of the given snippet can be replaced at line n. So that entire file content can be printed at console?

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.stream.Stream;

class Welcome {

public static void main(String[] args) throws IOException {

Path file = Paths.get ("HadoopExam.txt");
//n1
}
}
 : You have been given below code, which of the given snippet can be replaced at line n. So that entire file content can be printed at console?
1. Stream fc = (Stream) Files.readAllLines(file);
fc.forEach (s -> System.out.println(s));

2. Stream fc = Files.lines (file);
fc.forEach (s -> System.out.println(s));


3. List fc = Files.readAllLines(file);
fc.stream().forEach (s -> System.out.println(s));



Question : You have following declaration, please select the one which correctly applies

package com.hadoopexam;

public abstract final class Welcome { }
 : You have following declaration, please select the one which correctly applies
1. It will throw a compile time error, as you cannot have Class without any method.

2. It will not throw any compile time error.

3. It will throw compile time error because, you can not have a final abstract class.

4. You must have at least one abstract method.



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

package com.hadoopexam;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;

class Welcome {
public void fileDelete(String dirName) throws IOException {
File[] allFilesAndDir = new File(dirName).listFiles();
System.out.println(Arrays.toString(allFilesAndDir));
if (allFilesAndDir != null && allFilesAndDir.length > 0) {
for (File file : allFilesAndDir) {
if (file.isDirectory()) {
fileDelete(file.getAbsolutePath());
} else {
if (file.getName().endsWith(".class")) {
System.out.println("Deleted "+file);
file.delete();
}
}
}
}
}

public static void main(String[] args) throws IOException {
Welcome wel = new Welcome();
System.out.println(System.getProperty("user.dir"));
wel.fileDelete(System.getProperty("user.dir"));

}
}






 : You have been given below code, what is the expected behavior ?
1. The method deletes all the.class files in the Projects directory and its subdirectories.

2. The method deletes the .class files of the Projects directory only.

3. The method executes and does not make any changes to the Projects directory.

4. The method throws an IOException.







Question : What is the behavior of the below code?

package com.hadoopexam;

class Welcome {
public Welcome() {
System.out.println("In Welcome");
}

public class Company {
public Company() {
System.out.println("In Company");
}
}
}

class TestColor {
public static void main(String[] args) {
Welcome.Company comp = new Welcome().Company(); // n1
}
}
 : What is the behavior of the below code?
1. It will compile without any error but give RuntimeError

2. It will also run without any error and print "In Company"

3. It will also run without any error and print "In Welcome"

4. It will not compile as it will give error at line n1.

5. If you want to create an instance of an inner class. Then you also have to create instance of an outer class. As below Welcome.
Company comp = new Welcome().new Company();


Question : You have been given below code, however you see there is some compilation error. How would you resolve this.

package com.hadoopexam;

class Welcome {

{
try {
doStuff();
} catch (ArithmeticException | NumberFormatException | Exception e) {
System.out.println(e1.getMessage());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}

void doStuff() throws ArithmeticException, NumberFormatException, Exception {
if (Math.random() > -1)
throw new Exception("There is an Error , using this code. Contact www.HadoopExam.com");
}

}


 : You have been given below code, however you see there is some compilation error. How would you resolve this.
1. We should remove following code segment
catch (Exception e) {
System.out.println(e.getMessage());
}

2. Replace this line catch (ArithmeticException | NumberFormatException | Exception e)
With catch (Exception | ArithmeticException | NumberFormatException e)

3. Replace this line catch (ArithmeticException | NumberFormatException | Exception e) With catch (ArithmeticException | NumberFormatException e)

4. There will be no compilation error.



Question : You have been given below code, what would be the behavior of the given code? Both the classes are in their respective files.

package com.hadoopexam;

class Welcome {
private boolean isCompany;
protected int totalProductss;

public Welcome() {
isCompany = false;
totalProductss = 0;
}

public class Company {
public void print() {
System.out.println("isCompany: " + isCompany);
System.out.println("totalProductss: " + totalProductss);
}
}
}

package com.hadoopexam;

class Test {
public static void main(String[] args) {
Welcome.Company comp = new Welcome().new Company();
comp.print();
}
}

 : You have been given below code, what would be the behavior of the given code? Both the classes are in their respective files.
1. It will throw compile time error.

2. It will compile but throw RuntimeError

3. It will run and compile successfully and print below
isCompany: false
totalProductss: 0


4. Compiler error: an inner class cannot access private members of the outer class