Premium

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



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

package com.hadoopexam;

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

public class Welcome {
static Connection newConnection = null;

public static Connection getDBConnection() throws SQLException {
try (Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger")) {
newConnection = con;
}
return newConnection;
}

public static void main(String[] args) throws SQLException {
getDBConnection();
Statement st = newConnection.createStatement();
st.executeUpdate("INSERT INTO HADOOPEXAMUSER VALUES (102, 'Thomas')");
}
}

 : You have been given below code, what is the behavior expected?
1. The program executes successfully and the HADOOPEXAMUSER table is updated with one record.

2. The program executes successfully and the HADOOPEXAMUSER table is NOT updated with any record.

3. Access Mostly Uused Products by 50000+ Subscribers

4. A NullPointerExceptionis thrown as runtime.


Correct Answer : Get Lastest Questions and Answer :
Explanation: As we are using AutoClosable resource with try block. As soon as we are done with the getting connection it will close the connection. Which causes
executeUpdate statement as NullPointerException. Because, newConnection object is closed.




Question : You have been given below code, what will be printed when executed?

package com.hadoopexam;

import java.util.Optional;

public class Welcome {
Optional course;

Welcome(Optional course) {
this.course = course;
}

public Optional getCourse() {
return course;
}

public static void main(String[] args) {
Course address = null;
Optional addrs1 = Optional.ofNullable(address);
Welcome e1 = new Welcome(addrs1);
String eAddress = (addrs1.isPresent()) ? addrs1.get().getName() : "Course is not subscribed";
System.out.println(eAddress);
}
}

class Course {
String name = "Hadoop";

public String getName() {
return name;
}

public String toString() {
return name;
}

}


 : You have been given below code, what will be printed when executed?
1. Hadoop

2. Course is not subscribed

3. Access Mostly Uused Products by 50000+ Subscribers

4. A NoSuchElementExceptionis thrown at run time.


Correct Answer : Get Lastest Questions and Answer :
Explanation: : java.util.Optional

A container object which may or may not contain a non-null value. If a value is present, isPresent() will return true and get() will return the value.
Additional methods that depend on the presence or absence of a contained value are provided, such as orElse() (return a default value if value not present) and ifPresent() (execute a
block of code if the value is present).
This is a value-based class; use of identity-sensitive operations (including reference equality (==), identity hash code, or synchronization) on instances of Optional may have
unpredictable results and should be avoided.
boolean java.util.Optional.isPresent()

Return true if there is a value present, otherwise false.
Returns:
true if there is a value present, otherwise false





Question : You have been given below source code. Select the correct behavior of it

package com.hadoopexam;

import java.util.function.Predicate;

public class Welcome {
public static void main(String[] args) {
Predicate predicate = ((Predicate) (arg -> arg == null)).negate();
System.out.println(predicate.test(null));
}
}

 : You have been given below source code. Select the correct behavior of it
1. It will give compile time error.

2. Program will compile but give run time error.

3. Access Mostly Uused Products by 50000+ Subscribers

4. Program will run perfectly and print false

5. Program will through NullPointerException at run time.


Correct Answer : Get Lastest Questions and Answer :
Explanation: Given predicate expression is valid. Predicate predicate = ((Predicate) (arg -> arg == null)).negate();
As we are negating the expression result. Hence, if expression is producing true then it became false or from false to true.



Related Questions


Question : Which of the following modification in code will print "Welcome to HadoopExam Learning Resources"
package com.hadoopexam;
public class ParentException extends Exception {
public static void main(String[] args) throws ParentException, Exception {
Course v = new HadoopCourse();
v.message();
}
}

class Course {
void message() throws ParentException {// line n1
System.out.println("Welcome to HadoopExam Learning Resources");
}
}

class HadoopCourse extends Course {
public void message() throws Exception {// line n2
super.message();
}
}
 : Which of the following modification in code will print
1. Change line n2 with public void message() throws ParentException

2. Change line n1 with public void message() throws ParentException

3. Access Mostly Uused Products by 50000+ Subscribers

4. Change line n2 with private void message() throws Exception {



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;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Welcome {

private String courseName;
private Integer duration;

Welcome(String courseName, Integer duration) {
this.courseName = courseName;
this.duration = duration;
}

public Integer getDuration() {
return duration;
}

public String getCourseName() {
return courseName;
}

public static void main(String[] args) {
List subscriberList = Arrays.asList(new Welcome("Hadoop", 12),
new Welcome("Spark", 365), new Welcome("Cloud Computing", 180));

Predicate remainingDays = s -> s.getDuration() > 100;// line n1
subscriberList = subscriberList.stream().filter(remainingDays)
.collect(Collectors.toList());
Stream courseName = subscriberList.stream().map(Welcome::getCourseName);// line n2
courseName.forEach(n -> System.out.print(n + " "));
}
}

 : You have been given below code, what is the expected behavior?
1. It will print Spark Cloud Computing

2. It will print Hadoop Spark Cloud Computing

3. Access Mostly Uused Products by 50000+ Subscribers

4. A compilation error occurs at line n2.



Question : As you know, JDBC is a specification. And every vendor who wants to connect using Java needs to implement specification. Which of the below objects needs to be
implemented by vendor like Oracle, IBM ?


A. Object
B. java.sql.Date
C. Statement
D. ResultSet
E. Connection
F. SQLException


 : As you know, JDBC is a specification. And every vendor who wants to connect using Java needs to implement specification. Which of the below objects needs to be
1. A,B,C
2. C,D,E
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,B,E
5. A,C,F


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

package com.hadoopexam;

import java.time.LocalDate;
import java.time.Month;

public class Welcome {

public static void main(String[] args) {
LocalDate birthDate = LocalDate.of(1969, Month.JANUARY, 01);
LocalDate atFiftyYears = birthDate.plusYears(50);
atFiftyYears.plusDays(15); // line n1
System.out.println(atFiftyYears);
}
}
 : You have been given below code, what is the expected output?
1. 2019-01-16

2. 2019-01-01

3. Access Mostly Uused Products by 50000+ Subscribers

4. A DateTimeExceptionis thrown.



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

package com.hadoopexam;

import java.util.function.BiFunction;

public class Welcome {

public static void main(String[] args) {
BiFunction summation = (value1, value2) -> value1 + value2;//n1
System.out.println(summation.apply(1, 2.5)); //n2
}
}
 : You have been given below code, what is the expected behavior?
1. 3.5

2. 1

3. Access Mostly Uused Products by 50000+ Subscribers

4. A compilation error occurs at line n2.



Question : Which statement is true about java.time.Duration?


 : Which statement is true about java.time.Duration?
1. It tracks time zones.

2. It preserves daylight saving time.

3. Access Mostly Uused Products by 50000+ Subscribers

4. It defines date-based values.