Premium

Oracle Advacned Java Advanced Certification Questions and Answers (Dumps and Practice 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.


Correct Answer : Get Lastest Questions and Answer :
Explanation: : java.util.function.UnaryOperator

@FunctionalInterface
Represents an operation on a single operand that produces a result of the same type as its operand. This is a specialization of Function for the case where the operand and result are
of the same type.
This is a functional interface whose functional method is apply(Object).
Parameters:
the type of the operand and result of the operator





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


Correct Answer : Get Lastest Questions and Answer :
Explanation: Locale locale = new Locale("en", "US");

ResourceBundle labels = ResourceBundle.getBundle("i18n.MyBundle", locale);

System.out.println(labels.getString("label1"));
Here is an example of what the content of the property file could look like:
label1 = Label 1 is done!
label2 = Label 2 is through!

In order to provide strings in different languages, create a property file for each language, and suffix them with underscore (_) and then the language code. For instance:
MyBundle.properties
MyBundle_da.properties
MyBundle_de.properties
MyBundle_fr.properties
All of these files should be located in the same package (directory).
The file without language suffix (e.g. MyBundle.properties) is the default property file. In case no property file is available for the language (Locale) passed to the
ResourceBundle.getBundle() method, and the system has no default Locale set (e.g. a German computer will have a German Locale as default), this file is read and returned as a
ResourceBundle.





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


Correct Answer : Get Lastest Questions and Answer :
Explanation: The br.close() statement will close the BufferedReader object and the underlying stream objects referred to by findings and dataStream. The readLine() method
invoked in the statement br.readLine() can throw an IOException; if this exception is thrown, br.close() will not be called, resulting in a resource leak. Note that Garbage Collector
will only collect unreferenced memory resources; it is the programmer's responsibility to ensure that all other resources such as stream objects are released.


Related Questions


Question : You have been given following code, what is the 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.stream.Stream; public final class Welcome {
public static void main(String[] args) {
Stream paths = Stream.of(Paths.get("resources\\Message.properties"),
Paths.get("resources\\Message.txt"), Paths.get("resources\\Message.xml"));
paths.filter(s -> s.toString().endsWith("txt")).forEach(s -> {
try {
Files.readAllLines(s).stream().forEach(System.out::println); // line n1
} catch (IOException e) {
System.out.println("Exception");
} });
}
}
 : You have been given following code, what is the expected behavior?
1. The program prints the content of resources\\Message.txt file.

2. The program prints:
Exception
<>
Exception

3. Access Mostly Uused Products by 50000+ Subscribers

4. The program prints the content of the three files.


Question : You have been given below code, which of the following changes will help to compile the code?
package com.hadoopexam;

import java.io.IOException;

final class Peer {// line n1
// line n2
public void message() {
System.out.print("Welcome to HadoopExam");
}


}

public class Peer2 {
public static void main(String[] args) throws Exception {
try (Peer f = new Peer()) {
f.message();
}
}
}
A. Replace n1 with implements AutoCloseable {
B. Replace n2 with
public void close() throws IOException {
System.out.print("Close");
}
C. Replaceline n1with:
class Folder extends Closeable {

D. Replaceline n1with:
class Folder extends Exception {

 : You have been given below code, which of the following changes will help to compile the code?
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D
5. B,D


Question : Which of the following are true for creating Singleton object?
A. Make the classstatic.
B. Make the constructorprivate.
C. Overrideequals() andhashCode() methods of the java.lang.Object class.
D. Use astaticreference to point to the single instance.
E. Implement theSerializableinterface.

 : Which of the following are true for creating Singleton object?
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. D,E
5. A,E


Question : You have been given below code, what would be printed?

package com.hadoopexam;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public final class Welcome {
public static void main(String[] args) throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
String query = "SELECT userId FROM Subscriber";
try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery(query);
stmt.executeQuery("SELECT userId FROM Course");
while (rs.next()) {
// process the results
System.out.println("User ID: " + rs.getInt("userId"));
}
} catch (Exception e) {
System.out.println("Error");
}
}
}
 : You have been given below code, what would be printed?
1. The program prints subscriber IDs.

2. The program prints course IDs.

3. Access Mostly Uused Products by 50000+ Subscribers

4. compilation fails.



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

package com.hadoopexam;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.function.UnaryOperator;

public final class Welcome {
public static void main(String[] args) throws SQLException {
List codes = Arrays.asList(1, 2);
UnaryOperator unaryOperator = s -> s + 1;
codes.replaceAll(unaryOperator);
codes.forEach(value -> System.out.print(value));
}
}
 : You have been given below code, what is the expected behavior?
1. It will print 23

2. It will print 12

3. Access Mostly Uused Products by 50000+ Subscribers

4. A compilation error occurs.

5. A NumberFormatExceptionis thrown at run time.



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

package com.hadoopexam;

public class Welcome {
private String courseName;
private String userName;
private static int totalSubscriber;

public Welcome(String courseName, String userName) {
courseName = courseName;
userName = userName;
++totalSubscriber;
}

static {
totalSubscriber = 0;
}

public static int getTotalSubscriber() {
return totalSubscriber;
}
}

public class Peer {
public static void main(String[] args) {
Welcome c1 = new Welcome("Amit", "Kumar");
Welcome c2 = new Welcome("Venkat", "G");
Welcome c3 = new Welcome("Rahul", "Khetan");
Welcome c4 = new Welcome("Vijay", "Chauhan");
c4 = null;
c3 = c2;
System.out.println(Welcome.getTotalSubscriber());
}
}
 : You have been given below code, what is the expected output?
1. 0

2. 2

3. Access Mostly Uused Products by 50000+ Subscribers

4. 4

5. 5