Premium

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



Question : You have been given below code, please select the correct option which applies to it.

package com.hadoopexam;

import java.util.*;

class Welcome {
public static void main(String []args) {
List hList = new ArrayList<>();
hList.add(1);
hList.add(2);
System.out.println("Contents in list are : " + hList);
}
}
 : You have been given below code, please select the correct option which applies to it.
1. Code will compile and run perfectly and print to "Contents in list are : [1,2]"

2. Code will compile and run perfectly and print to "Contents in list are : [2,1]"

3. Code will compile successfully but will produce run time error IllegalStateException

4. Code will not compile


Correct Answer : 4
Explanation: Yes code, will not compile. Because you cannot use Int primitive in as generic. You have to change primitive int to Integer class.




Question : You have been given below code, what would be printed once you run the code.

package com.hadoopexam;

import java.util.*;

class Welcome {
public static void main(String[] args) {
List integerList = new LinkedList<>();
List doublelList = new LinkedList<>();
System.out.println("Type of integerList = " + integerList.getClass());
System.out.println("Type of doublelList = " + doublelList.getClass());
}
}
 : You have been given below code, what would be printed once you run the code.
1. It will print following statements
Type of integerList = class java.util.LinkedList
Type of doublelList = class java.util.LinkedList

2. It will print following statements
Type of integerList = class java.util.LinkedList<>
Type of doublelList = class java.util.LinkedList<>

3. It will print following statements
Type of integerList = class java.util.LinkedList
Type of doublelList = class java.util.LinkedList

4. It will print following statements
Type of integerList = class java.util.List
Type of doublelList = class java.util.List



Correct Answer : 1
Explanation: As you know, Generics are compile time only. Hence, all the Generic information can be removed once the code is compiled and byte code is generated.
As well as there is a dynamic binding so at run time actual class will be used when you refer an object. Here LinkedList is the actual data type for both list.




Question : You have been given following code, please select the correct statement for it.

package com.hadoopexam;

import java.util.Arrays;

class Welcome {
public static void main(String[] args) {
String[] names = { "Bala", "Reena", "Iva", "Cate" };
Arrays.sort(names, null); //n1
for (String name : names) {
System.out.print(name + " ");
}
}
}

 : You have been given following code, please select the correct statement for it.
1. Code will not compile.

2. Code will compile but produce runtime error. As no InvalidComparatorException is defined.

3. There will be no compile time error. Code will be run successfully and print Bala Cate Iva Reena

4. There will be no compile time error. Code will be run successfully and print "Bala", "Reena", "Iva", "Cate"


Correct Answer : 3
Explanation: Code will compile and run successfully and print Bala Cate Iva Reena. When null is passed as a second argument to the Arrays.sort() method,
it means that the default Comparable (i.e., laxographical ordering for the elements) should be used. The default Comparator results in sorting the elements in ascending order.


Related Questions


Question : You have been given below code, what would be the behavior of the code

package com.hadoopexam;
class Welcome {
public static void call1() throws IndexOutOfBoundsException {
throw new IndexOutOfBoundsException();
}

public static void call2() throws ArithmeticException {
throw new ArithmeticException();
}

public static void main(String[] args) {
try {
call1();
call2();
} catch (IndexOutOfBoundsException || ArithmeticException ex) {
System.out.println(ex);
}
}
}
 : You have been given below code, what would be the behavior of the code
1. It will give compile time error.

2. It will run and print IndexOutOfBoundsException

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will run and print Exception.



Question : You have been given following exception hierarchy.

HParentException
HChild1Exception extends HParentException
HChild2Exception extends HParentException

Which of the below given multi catch statement would be correct?
 : You have been given following exception hierarchy.
1. catch (HParentException | HChild1Exception exception)

2. catch (HChild2Exception | HParentException exception)

3. Access Mostly Uused Products by 50000+ Subscribers

4. catch (HChild1Exception ex1 | HChild2Exception ex2)



Question : You have been given following exception hierarchy.

HParentException
HChild1Exception extends HParentException
HChild2Exception extends HParentException

Below is the given code?

try {
HChild2Exception ch2 = new HChild2Exception ();
throw (Exception) ch2;
}
catch (HChild2Exception anfe) {
System.out.println("HChild2Exception ");
}
catch (HChild1Exception ae) {
System.out.println("HChild1Exception ");
}
catch (Exception e) {
System.out.println("Exception");
}

What is the expected output?

 : You have been given following exception hierarchy.
1. HChild2Exception

2. HChild1Exception

3. Access Mostly Uused Products by 50000+ Subscribers

4. Cannot be predicted



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

package com.hadoopexam;


class ParentException extends IndexOutOfBoundsException {
}

class ParentClass {
void call() throws IndexOutOfBoundsException {
throw new IndexOutOfBoundsException();
}
}

class ChildClass extends ParentClass {
public void call() throws ParentException { // n1
throw new ParentException();
}
}

public class Welcome {
public static void main(String[] args) {
try {
ParentClass parentClass = new ChildClass();
parentClass.call();
} catch (Exception e) {
System.out.println(e);
}
}
}

 : You have been given below code, what is the behavior of the code?
1. It will print com.hadoopexam.ParentException

2. It will print IndexOutOfBoundsException

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will print IllegalStateException

5. It will not compile.



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

package com.hadoopexam;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class Welcome implements Runnable {
String str;

public Welcome(String s) {
this.str = s;
}

public void run() {
System.out.println(str.concat(" : Welcome to HadoopExam Learning Resoueces"));
}

public static void main(String[] args) throws InterruptedException,
ExecutionException {
ExecutorService es = Executors.newFixedThreadPool(2);
Future f1 = es.submit(new CourseCreator("Start Creating Course"));
Future f2 = es.submit(new Welcome("Start Watching Course"));
String str1 = (String) f1.get();
String str2 = (String) f2.get();// line n1
System.out.println(str1 + " : " + str2);
}
}

class CourseCreator implements Callable {
String author;

public CourseCreator(String s) {
this.author = s;
}

public String call() throws Exception {
return author.concat(" : by HadoopExam");
}
}

 : You have been given below code, what is the expected behavior?
1. Start Watching Course : Welcome to HadoopExam Learning Resoueces
Start Creating Course : by HadoopExam : null


2. Start Watching Course : Welcome to HadoopExam Learning Resoueces
Start Creating Course : by HadoopExam : Start Watching Course


3. Access Mostly Uused Products by 50000+ Subscribers

4. An Exception thrown at run time



Question : You have been given below code, in their respective file.

public interface IParent {
public abstract void draw();
}

class Parent implements IParent{
public void draw () { }
}

public abstract class Child1 extends Parent { }


public class Child2 extends Parent {
protected void draw (int color) { }
}


public class GrandChild extends Parent implements IParent {
public void resize() {
}
}

Which is the correct statement?

 : You have been given below code, in their respective file.
1. Child1 does not compile.

2. Child2 does not compile.

3. Access Mostly Uused Products by 50000+ Subscribers

4. IParent does not compile.

5. All classes compile successfully.