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.concurrent.atomic.AtomicInteger;

public class Welcome {
static AtomicInteger atomicInt = new AtomicInteger(100);

public static void plustOne() {
atomicInt.incrementAndGet();
}

public static void minusOne() {
atomicInt.getAndDecrement();
}

public static void setValue() {
atomicInt.compareAndSet(100, 99);
}

public static void main(String[] args) {
plustOne();
minusOne();
setValue();
System.out.println(atomicInt);
}
}

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

2. It will print 100

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will print 99

5. It will print "Null"


Correct Answer : Get Lastest Questions and Answer :
Explanation: Here imporatnat method is belwo.
boolean java.util.concurrent.atomic.AtomicInteger.compareAndSet(int expect, int update)

Atomically sets the value to the given updated value if the current value == the expected value.
Parameters:
expect the expected value
update the new value
Returns:
true if successful. False return indicates that the actual value was not equal to the expected value.

int java.util.concurrent.atomic.AtomicInteger.getAndDecrement()

Atomically decrements by one the current value.
Returns:
the previous value

int java.util.concurrent.atomic.AtomicInteger.incrementAndGet()

Atomically increments by one the current value.
Returns:
the updated value





Question : You have been given below code, what is the output, when executed using command "java -ea RateOfInterest"
package com.hadoopexam;
public class Welcome {

public static void main(String[] args) {
int courseFee = 0;
String courseName = "Web Service";
switch (courseName) {
case "Hadoop":
courseFee = 79;
break;
case "Spark":
courseFee = 89;
break;
default:
assert false : "Given course is in Progress and currently not available"; // line n1
}
System.out.println("Fees for the course is :" + courseFee);
}
}
 : You have been given below code, what is the output, when executed using command
1. AssertionError: Given course is in Progress and currently not available

2. It will print Given course is in Progress and currently not available.

3. Access Mostly Uused Products by 50000+ Subscribers

4. A compilation error occurs at line n1.


Correct Answer : Get Lastest Questions and Answer :
Explanation: No matching course is found. Hence, control will go to default statement. In default statement it will throw assertion error.




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

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 Callable {
String message;

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

public String call() throws Exception {
return message.concat("Welcome to HadoopExam Learning Resources");
}

public static void main(String[] args) throws InterruptedException, ExecutionException {
ExecutorService executorService = Executors.newFixedThreadPool(4); // line n1
Future futureResult = executorService.submit(new Welcome("Thank you ... "));
String resultValue = futureResult.get().toString();
System.out.println(resultValue);
}
}

 :
1. The program prints Thank you ... Welcome to HadoopExam Learning Resources and terminates.

2. The program prints Thank you ... Welcome to HadoopExam Learning Resources and does not terminate.

3. Access Mostly Uused Products by 50000+ Subscribers

4. An ExecutionExceptionis thrown at run time.


Correct Answer : Get Lastest Questions and Answer :
Explanation: you need to manually release the ExecutorService by calling the shutdown() method to terminate the program.


Future java.util.concurrent.ExecutorService.submit(Callable task)

Submits a value-returning task for execution and returns a Future representing the pending results of the task. The Future's get method will return the task's result upon successful
completion.
If you would like to immediately block waiting for a task, you can use constructions of the form result = exec.submit(aCallable).get();
Note: The Executors class includes a set of methods that can convert some other common closure-like objects, for example, java.security.PrivilegedAction to Callable form so they can
be submitted.
Parameters:
task the task to submit
the type of the task's result
Returns:
a Future representing pending completion of the task
Throws:
RejectedExecutionException - if the task cannot be scheduled for execution
NullPointerException - if the task is null



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



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



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


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