Premium

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



Question : You have been given below code. What would be the behavior.

package com.hadoopexam;

import java.util.Arrays;

class Welcome {
public static void main(String[] args) {
"HadoopExam.com".chars().distinct()
.peek(ch -> System.out.printf("%c ", ch)).sorted();
}
}
 : You have been given below code. What would be the behavior.
1. It will print "H a d o p E x m . c"

2. It will print "H a d o o p E x a m . c o m"

3. Code will not compile.

4. Code will not print any output.


Correct Answer : 4
Explanation: As you know, stream is lazily evaluated and to call the intermediate functions of the stream it requires that you call termiate function like count().
If you change the statement like "HadoopExam.com".chars().distinct()
.peek(ch -> System.out.printf("%c ", ch)).sorted().count();

Output will be "H a d o p E x m . c"





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

package com.hadoopexam;

import java.util.stream.IntStream;

class Welcome {
public static void main(String[] args) {
IntStream.rangeClosed(5, 5).forEach(System.out::println);
}
}

 : You have been given following code, what is the behavior you expect.
1. It will compile and run perfectly and print 5,6

2. It will compile and run perfectly and print 5,5

3. It will compile and run perfectly and print 5

4. It will compile and run perfectly but not print anything

5. It will compile and run perfectly but throw exception at runtime. NoSufficientArgumentsProvided.


Correct Answer : 3
Explanation: When you call a menthod rangeClosed() on intStream, it will consider 2nd argument as inclusive. Hence, 5 will be included. So it will print 5 as an output.
Also forEach is a stream termination function. Hence, it will be called.




Question : You have been given below source code and Message.properties file

package com.hadoopexam;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;


class Welcome {

public static void main(String[] args) throws IOException {
Properties prop = new Properties ();
FileInputStream fis = new FileInputStream("resources//Message.properties");
prop.load(fis);
System.out.println(prop.getProperty("hadoopexam"));
System.out.println(prop.getProperty("training", "Welcome to Training4Exam.com"));
System.out.println(prop.getProperty("quickTechie"));
System.out.println(prop.getProperty("quicktechie"));
}

}

- resources\Message.properties
hadoopexam=Welcome to HadoopExam Learning Resources
quickTechie=Welcome to QuickTechie Professional Network

What is the behavior of the code?
 : You have been given below source code and Message.properties file
1. It will give compile time error.

2. It will give "NullPointerException" when executed.

3. It will run perfectly and print as below.
Welcome to HadoopExam Learning Resources
Welcome to Training4Exam.com
Welcome to QuickTechie Professional Network
null

4. It will run perfectly and print as below.
Welcome to HadoopExam Learning Resources
Welcome to Training4Exam.com
Welcome to QuickTechie Professional Network



Correct Answer : 3
Explanation: String java.util.Properties.getProperty(String key, String defaultValue)

Searches for the property with the specified key in this property list. If the key is not found in this property list, the default property list, and its defaults, recursively, are
then checked. The method returns the default value argument if the property is not found.
Parameters:
key the hashtable key.
defaultValue a default value.
Returns:
the value in this property list with the specified key value.

String java.util.Properties.getProperty(String key)
Searches for the property with the specified key in this property list. If the key is not found in this property list, the default property list, and its defaults, recursively, are
then checked. The method returns null if the property is not found.
Parameters:
key the property key.
Returns:
the value in this property list with the specified key value.



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

public class Welcome {
public static void main(String[] args) {
List str = Arrays.asList("Welcome", "to", "HadoopExam", "Learning", "Resources");
Predicate predicate = s -> {
int counter = 0;
boolean result = s.contains("Hadoop");
System.out.print((counter++) + ":");
return result;
};
str.stream().filter(predicate).findFirst().ifPresent(System.out::print);

}
}

 : You have been given below code, what is the expected behavior?
1. 0 : 0 : 0: HadoopExam

2. 0 : 1 : 2 : Hadoop

3. Access Mostly Uused Products by 50000+ Subscribers

4. 0 : 1 : 2 : 3 : 4 :

5. A compilation error occurs.



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

package com.hadoopexam;

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

public class Welcome {
public static void main(String[] args) {
List subscriberInfo = Arrays.asList("100, Amit, Hadoop : ", "200, Martha, Spark : ", "101, Piyush, Java : ");
subscriberInfo.stream().filter(s -> s.contains("1")).sorted()
.forEach(System.out::print); // line n1
}
}
 : You have bene given code, what is the expected behavior?
1. 101, Piyush, Java : 100, Amit, Hadoop :

2. 100, Amit, Hadoop : 101, Piyush, Java :

3. Access Mostly Uused Products by 50000+ Subscribers

4. 100, Amit, Hadoop : 101, Piyush, Java : 200, Martha, Spark :

5. Compile time error.



Question : You have been given below code, which of the code segment can be replaced at n. Which create an instance of Welcome class?

package com.hadoopexam;

public class Welcome {

private String name;

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

public static void main(String[] args) {
// n1

}
}

interface Hello {
Welcome get(String name);
}
 : You have been given below code, which of the code segment can be replaced at n. Which create an instance of Welcome class?
1. Welcome wel = Welcome ("Welcome to HadoopExam.com"):: new;

2. Welcome wel = Welcome :: new;
Welcome wel1 = wel :: get("Welcome to HadoopExam.com");

3. Access Mostly Uused Products by 50000+ Subscribers
Welcome wel = hello.get("Welcome to HadoopExam.com");

4. Welcome vehicle = Hello :: new :: get("Welcome to HadoopExam.com");



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.



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



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();