Premium

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



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

package com.hadoopexam;

class Welcome {
public static void main(String[] args) {
try {
int i = 10 / 0;
System.out.print("1 ");
} catch (ArithmeticException ae) {
System.out.print("2 ");
return;
} finally {
System.out.print("3 ");
}
System.out.print("4 ");
}
}
 : You have been given below code, what would be printed if executed
1. 1 2

2. 2 3

3. Access Mostly Uused Products by 50000+ Subscribers

4. 1 2 3

5. 2 3 4


Correct Answer : Get Lastest Questions and Answer :
Explanation: As soon as jvm reaches 10/0 it will ignore all the statement after that throw exception and directly goes to in respective catch block . Hence, it will

print 2 and then just after that it will go to finally block and print 3. Last line of the method will not be called because there is a return; statement in method which will send
control out of method. If you remove return; statement it will print 2 3 4.




Question : You have been given below code, please select correct behavior of it

package com.hadoopexam;

import java.util.Scanner;

class Welcome {
public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) {
scanner.close();
scanner.close();
}
}
}
 : You have been given below code, please select correct behavior of it
1. It will not compile

2. It will compile but run time , it will throw IllegalStateException

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will compile and run throw RuntimeException

5. It will compile, run and no output will be produced.


Correct Answer : Get Lastest Questions and Answer :
Explanation: : void java.util.Scanner.close()

Closes this scanner.
If this scanner has not yet been closed then if its underlying readable also implements the java.io.Closeable interface then the readable's close method will be invoked. If this
scanner is already closed then invoking this method will have no effect.
Attempting to perform search operations after a scanner has been closed will result in an IllegalStateException.
So here we are calling close() method 3 times. One with try resource, so automatically called in finally clause and 2 times explicitly we are calling it.





Question : You have been given below code, what happen if you execute it.
package com.hadoopexam;

class Welcome {
public static void main(String[] args) {
try {
assert false;
} catch (RuntimeException re) {
System.out.println("RuntimeException");
} catch (Exception e) {
System.out.println("Exception");
} catch (Error e) {
System.out.println("Error");
} catch (Throwable t) {
System.out.println("Throwable");
}
}
}
 : You have been given below code, what happen if you execute it.
1. It will print RuntimeException

2. It will print Exception

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will print Throwable

5. It will print nothing


Correct Answer : Get Lastest Questions and Answer :
Explanation: By default assertions are disabled. Hence, here it will not print anything. If you enable assertion than it will print Error. Because AssetionError is a
subclass of Error.


Related 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.



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.



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.



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

package com.hadoopexam;

import java.util.function.Function;

public class Welcome {
public static void main(String[] args) {
Function negate = (i -> -i), square = (i -> i * i), negateSquare = negate
.compose(square);
System.out.println(negateSquare.apply(13));
}
}
 : You have been given below code. What is the behavior of the code?
1. Code will be having a compile time error.

2. Code will produce the output as -169

3. Access Mostly Uused Products by 50000+ Subscribers

4. Code will produce output as 13



Question : You have been given a following method of Long class.
long parseLong(String s)
Now select the correct functional interface for which, you can pass method reference like.
Long::parseLong()


 : You have been given a following method of Long class.
1. BiPredicate

2. Function

3. Access Mostly Uused Products by 50000+ Subscribers

4. Predicate

5. Consumer




Question : You have been given below code, when you run this code. What would be the behavior?
package com.hadoopexam;

import java.util.function.BiFunction;

public class Welcome {
public static void main(String args[]) {
BiFunction stringCompare = (str1, str2) -> str1.equals(str2);
System.out.println(stringCompare.apply("HadoopExam", "HadoopExam"));
}
}
 : You have been given below code, when you run this code. What would be the behavior?
1. It will generate compile time error.

2. You cannot use predicate in Function interface. Hence, will generate RuntimeError

3. Access Mostly Uused Products by 50000+ Subscribers

4. Program runs perfectly and produce false.