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

class Welcome {
public static void main(String[] args) {
Locale locale = new Locale("quick", "Hadoop");
System.out.println(locale);
}
}



 : You have been given below code, what is the expected behavior?
1. It will give compile time error.

2. It will give runtime error.

3. It will compile and run but no output.

4. It will give NullPointer Exception at run time

5. It will produce output as "quick_HADOOP"


Correct Answer : 5
Explanation: java.util.Locale.Locale(String language, String country)

Construct a locale from language and country. This constructor normalizes the language value to lowercase and the country value to uppercase.
Note:
. ISO 639 is not a stable standard; some of the language codes it defines (specifically "iw", "ji", and "in") have changed. This constructor accepts both the
old codes ("iw", "ji", and "in") and the new codes ("he", "yi", and "id"), but all other API on Locale will return only the OLD codes.
. For backward compatibility reasons, this constructor does not make any syntactic checks on the input.
Parameters:
language An ISO 639 alpha-2 or alpha-3 language code, or a language subtag up to 8 characters in length. See the Locale class description about valid language values.
country An ISO 3166 alpha-2 country code or a UN M.49 numeric-3 area code. See the Locale class description about valid country values.
Throws:
NullPointerException - thrown if either argument is null.

The toString() method of Locale class returns a string representation of the Locale object consisting of language, country, variant





Question : You have been given below code, what is the behavior expected?
package com.hadoopexam;
class ParentException extends Exception {}

class ChildException extends ParentException {}

public class Welcome {
public void subscribeForCourse(String courseName, int fee) throws ParentException, ChildException {
if (courseName.length() < 6) {
throw new ParentException();
} else if (fee >= 60) {
throw new ChildException();
} else {
System.out.println("You are allowed for this course");
}
}

public static void main(String[] args) throws ParentException {
Welcome t = new Welcome();
t.subscribeForCourse("Hadoop", 60);
}
}

 : You have been given below code, what is the behavior expected?
1. It will print : You are allowed for this course

2. It will print : Hadoop

3. It will throw Exception in thread "main" com.hadoopexam.ChildException

4. It will give compile time error.

5. It will throw Exception in thread "main" com.hadoopexam.ParentException


Correct Answer : 3
Explanation:




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

package com.hadoopexam;

import java.util.Locale;

class Welcome {
public static void main(String[] args) {
Locale l1 = new Locale("en");
Locale l2 = new Locale("en", "in");
Locale l3 = new Locale("th", "TH", "TH");
Locale l4 = new Locale(l3);
System.out.println(l1 + " " + l2 + " " + l3 + " " + l4);
}
}
 : You have been given below code, what is the expected behavior when executed?
1. It will give compile time error.

2. It will give run time error.

3. It will compile and run with output as "en en_IN th_TH_TH_#u-nu-thai th_TH_TH_#u-nu-thai"

4. It will compile and run with output as "en en_IN th_TH_TH_#u-nu-thai th_TH_TH_#u-nu-IN"


Correct Answer : 1
Explanation: You cannot create Locale using another locale instance.
The Locale class provides three constructors:
Locale(String language)
Locale(String language, String country)
Locale(String language, String country, String variant)

These constructors allow you to create a Locale object with language, country and variant, but you cannot specify script or extensions.
Factory Methods
The method forLanguageTag creates a Locale object for a well-formed BCP 47 language tag.



Related Questions


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

package com.hadoopexam;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class Welcome {
public static void main(String[] args) {
Map map = new HashMap<>();
map.put(1, "a");
map.put(5, "b");
map.put(30, "c");
map.put(70, "d");
map.put(15, "e");
Map treeMap = new TreeMap(
new Comparator() {
@Override
public int compare(Integer o1, Integer o2) {
return o2.compareTo(o1);
}
});
treeMap.putAll(map);
for (Map.Entry entry : treeMap.entrySet()) {
System.out.print(entry.getValue() + " ");
}
}
}
 : You have been given below code, what is the behavior of the code?
1. It will give compile time error

2. It will compile nut produce , runtime error

3. It will compile and run perfectly and produce a,b,c,d,e

4. It will compile and run perfectly and produce e,d,c,b,a

5. It will compile and run perfectly and produce d c e b a


Question : What is the behavior of the following code?
package com.hadoopexam;

class Parent { }
class Child1 extends Parent { }
class Child2 extends Parent { }
class GrandChild extends Child1, Child2 { }


 : What is the behavior of the following code?
1. It will compile and run perfectly.

2. It will compile perfectly but give NullPointerException when run

3. It will not compile correctly.

4. It will not compile and there will be an exception e.g. ClassNotFoundException.



Question : Which two reasons should you use interfaces instead of abstract classes?
A. You expect that classes that implement your interfaces have many common methods or fields,
or require access modifiers other than public.
B. You expect that unrelated classes would implement your interfaces.
C. You want to share code among several closely related classes.
D. You want to declare non-static on non-final fields.
E. You want to take advantage of multiple inheritance of type

 : Which two reasons should you use interfaces instead of abstract classes?
1. A,B
2. B,C
3. C,D
4. D,E
5. A,E


Question : What would be the output when you run below code ?

package com.hadoopexam;

class Welcome {
public void print(Integer i) {
System.out.println("Integer value");
}

public void print(int i) {
System.out.println("primitive int value ");
}

public void print(long i) {
System.out.println("primitive long value");
}

public static void main(String args[]) {
Welcome wel = new Welcome();
wel.print(10);
}
}
 : What would be the output when you run below code ?
1. It will print "Integer value".

2. It will print "primitive int value "

3. It will print "primitive long value"

4. It will give Runtime Error. Method Ambiguity found.



Question : You have been given below code, what is the expected behavior when executed with -ea option

package com.hadoopexam;

public class Welcome {
public static void main(String[] args) {
int val1 = 10;
int val2 = -1;
assert (val2 >= 1) : "Invalid value have been provided";
int result = val1 / val2;
System.out.println(result);
}
}

 : You have been given below code, what is the expected behavior when executed with -ea option
1. It will run and produce output as -10

2. It will run and produce output as 0

3. It will run and produce output as -1

4. It will run and throw AssertionError: Invalid value have been provided



Question : You have been given below two class in separate files. What is the correct replacement for the XXXXX?

package com.hadoopexam;

public class Welcome {
protected void print() {
System.out.println("Parent Class");
}
}

package com.hadoopexam;

public class Company extends Welcome {
XXXXX void display() {
System.out.println("Child Class");
}
}

 : You have been given below two class in separate files. What is the correct replacement for the XXXXX?
1. You can use only abstract,

2. You can use public or protected

3. You can only use public

4. You can only use protected.