Premium

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



Question : You have been given below information

Character Stream : Derived using Reader(Reading from Character file) and Writer (Writing character to files) interface
Byte Stream : Derived using InputStream(Reading from file) and OutputStream(for writing to file)

Which of the following statement is correct?
 : You have been given below information
1. In character streams (e.g. HadoopExam.com), data is handled in terms of bytes (e.g. 0100001001), in byte streams, data is handled in terms of Unicode characters
e.g. UTF-8. UTF-16.

2. Character streams are suitable for reading or writing to files such as executable files, image files, and files in low-level file formats such as .zip, .class,
and .jpg.

3. Access Mostly Uused Products by 50000+ Subscribers

4. Byte streams are meant for handling binary data (e.g. 1010101010); character streams are meant for human-readable characters.


Correct Answer : Get Lastest Questions and Answer :
Explanation: In character streams (e.g. I am learning Java HadoopExam.com), data is handled in terms of Unicode characters, whereas in byte streams, data is handled in
terms of bytes. Byte streams are suitable for reading or writing to files such as executable files, image files, and files in low-level file formats such as .zip, .class, and .jar.
Character streams are suitable for reading or writing to text-based I/O such as documents and text, XML, and HTML files




Question : You have been given below code,

package com.hadoopexam;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;

class Welcome implements Serializable {
int value;
Welcome(int val) {
value = val;
}

public static void main(String[] args) throws IOException {
Welcome welcome = new Welcome(100);
try (ObjectOutputStream oos = new ObjectOutputStream(
new FileOutputStream("HadoopExam.data"))) {
oos.writeObject(welcome);
welcome.setValue(101);
oos.writeObject(welcome);
}
}

private void setValue(int i) {
value = i;
}
}

What would be printed when you desacralize the "HadoopExam.data" and extract value;

 : You have been given below code,
1. 101

2. 100

3. Access Mostly Uused Products by 50000+ Subscribers

4. Null

5. Cannot be predicted


Correct Answer : Get Lastest Questions and Answer :
Explanation: At the time of serialization, JVM checks for the duplicate object; if an object is already serialized then JVM do not serialize the object again; instead,
JVM stores a reference to the serialized object. As you are trying to set the value to already serialize welcome class object.




Question : Which of the following is a correct way to create Local instance?

A. Locale loc1 = "CA";
B. Locale loc2 = Locale.getInstance("en");
C. Locale loc3 = Locale.getLocaleFactory("CA");
D. Locale loc4 = Locale.GERMANY;
E. Locale loc5 = new Locale("en", "CA");

 : Which of the following is a correct way to create Local instance?
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. D,E
5. A,E

Correct Answer : Get Lastest Questions and Answer :
Explanation: 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.

Locale java.util.Locale.GERMANY

Useful constant for country.



Related Questions


Question : You have been given following code snippet. Based on the below code, select the correct option which can have overridden method in child class.

package com.hadoopexam;

import java.nio.file.FileAlreadyExistsException;

class Parent {
private T test;

void call(T t) throws FileSystemException{
test = t;
System.out.println("Testing Method 1");
}
}
 : You have been given following code snippet. Based on the below code, select the correct option which can have overridden method in child class.
1. void call(T t) throws FileAlreadyExistsException{}

2. void call(T t) throws Exception{}

3. Access Mostly Uused Products by 50000+ Subscribers

4. None of the above



Question : You have been given following code. When you run it what is the expected output.

package com.hadoopexam;
class Welcome {
public static void call() {
try {
throw new ArrayIndexOutOfBoundsException();
} catch (ArrayIndexOutOfBoundsException boundException) {
RuntimeException runtimeException = new RuntimeException(boundException);
runtimeException.initCause(boundException);
throw runtimeException;
}
}

public static void main(String[] args) {
try {
call();
} catch (Exception exception) {
System.out.println(exception.getClass());
}
}
}
 : You have been given following code. When you run it what is the expected output.
1. class java.lang.RuntimeException

2. class java.lang.IllegalStateException

3. Access Mostly Uused Products by 50000+ Subscribers

4. class java.lang.ArrayIndexOutOfBoundsException



Question : You have been given below exception, select the correct behavior
package com.hadoopexam;

class Welcome {
public static void call() {
try {
throw new IndexOutOfBoundsException();
} catch (IndexOutOfBoundsException ioob) {
throw new Exception(ioob);
}
}

public static void main(String[] args) {
try {
call();
} catch (Exception e) {
System.out.println(e.getCause());
}
}
}
 : You have been given below exception, select the correct behavior
1. Code will give compile time error.

2. Code will run and print nothing.

3. Access Mostly Uused Products by 50000+ Subscribers

4. Code will run and print IllegalStateException



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