Premium

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



Question : You have been given a Course table, with following columns detail.

. COURSE_ID:INTEGER: PK
. COURSENAME:VARCHAR(100)
. COST:REAL
. QUANTITY:INTEGER

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

package com.hadoopexam;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Welcome {
public static void main(String[] args) {
try {
Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
String query = "Select * FROM SUBSCRIBER WHERE COURSE_ID = HDP100";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
System.out.println("COURSE ID:" + rs.getInt("COURSE_ID"));
System.out.println("Course name:" + rs.getString("COURSENAME"));
System.out.println("Cost of the course :" + rs.getDouble("COST"));
System.out.println("Total order :" + rs.getInt("QUANTITY"));
}
} catch (SQLException se) {
System.out.println("There is an Error");
}
}
}

 : You have been given a Course table, with following  columns detail.
1. An exception is thrown at runtime.

2. Compilation fails.

3. Access Mostly Uused Products by 50000+ Subscribers

4. The code prints information about Item HDP100.


Correct Answer : Get Lastest Questions and Answer :
Explanation:




Question : You have been given below code.

package com.hadoopexam;

import java.util.concurrent.CyclicBarrier;

public class Welcome extends Thread {
CyclicBarrier cb;

public Welcome(CyclicBarrier cb) {
this.cb = cb;
}

public void run() {
try {
cb.await();
System.out.println("Slave worker");
} catch (Exception ex) {
}
}
}

import java.util.concurrent.CyclicBarrier;

class Peer implements Runnable { // line n1
public void run() {
System.out.println("Controller Thread ...");

}

public static void main(String[] args) {
Peer master = new Peer();
CyclicBarrier cb = new CyclicBarrier(1, master);
//line n2
Welcome worker = new Welcome(cb);
worker.start();
}
}

Which of the following modification will help the code to run both the tread. First controller and then slave?

 : You have been given below code.
1. At line n2, insert CyclicBarrier cb = new CyclicBarrier(2, master);

2. Replace line n1 with class Master extends Thread {

3. Access Mostly Uused Products by 50000+ Subscribers

4. At line n2, insert CyclicBarrier cb = new CyclicBarrier(master);


Correct Answer : Get Lastest Questions and Answer :
Explanation: java.util.concurrent.CyclicBarrier.CyclicBarrier(int parties, Runnable barrierAction)

Creates a new CyclicBarrier that will trip when the given number of parties (threads) are waiting upon it, and which will execute the given
barrier action when the barrier is tripped, performed by the last thread entering the barrier.
Parameters:
parties the number of threads that must invoke await before the barrier is tripped
barrierAction the command to execute when the barrier is tripped, or null if there is no action





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

package com.hadoopexam;

import java.util.function.ToIntFunction;

public class Welcome {
public static void main(String[] args) {
String message = "Welcome to HadoopExam Learning Resources";
ToIntFunction index = message::indexOf;
int position = index.applyAsInt("H");
System.out.println(position);
}
}

 : You have been given below code, what is the expected output?
1. 0

2. 11

3. Access Mostly Uused Products by 50000+ Subscribers

4. A compilation error occurs.

5. A runtime error occurs.


Correct Answer : Get Lastest Questions and Answer :
Explanation: In this code we are finding first occurrence of H in message string.

java.util.function.ToIntFunction

@FunctionalInterface
Represents a function that produces an int-valued result. This is the int-producing primitive specialization for Function.
This is a functional interface whose functional method is applyAsInt(Object).
Parameters:
the type of the input to the function

int java.util.function.ToIntFunction.applyAsInt(String value)

Applies this function to the given argument.
Parameters:
value the function argument
Returns:
the function result



Related Questions


Question : You have been given below code,

package com.hadoopexam;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Welcome {

public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
System.out.print ("What is your course id? : ");
//n1
}
}
Which of the below code segment you will use, so that it can read the values entered from keyboard by user?
 : You have been given below code,
1. int courseId = Integer.parseInt (bufferedReader.readline());

2. int courseId = bufferedReader.read();

3. int courseId = bufferedReader.nextInt();

4. int courseId = Integer.parseInt (bufferedReader.next());



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

package com.hadoopexam;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

class Welcome {

public static void main(String[] args) throws IOException {
Path source = Paths.get ("resources\\test\\Message.properties");
Path destination = Paths.get("resources");
Files.copy(source, destination);
}
}
 : You have been given below code, what is the behavior expected?
1. It will create a new file name Message.properties in resources directory.

2. It will create a new file "resources\\resources\\test\\Message.properties"

3. It will throw run time exception, with " FileAlreadyExistsException"

4. It will not do anything , just run and come out.



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

package com.hadoopexam;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

class Welcome {

String course, name, city;

public Welcome(String name, String course, String city) {
this.course = course;
this.name = name;
this.city = city;
}

public String toString() {
return course + ":" + name + ":" + city;
}

public String getCourse() {
return course;
}

public void setCourse(String course) {
this.course = course;
}

public static void main(String[] args) throws IOException {
List stds = Arrays.asList(
new Welcome ("Amit", "Hadoop", "Chennai"),
new Welcome ("Kumar", "Spark", "New Delhi"),
new Welcome ("Jatin", "AWS", "Kolkata"));
stds.stream().collect(Collectors.groupingBy(Welcome::getCourse)).forEach((src, res) -> System.out.print(src+":"));
}
}

 : You have been given below code, what is the expected behavior?
1. It will print "Hadoop:Spark:AWS:"

2. It will print "Jatin:Kumar:Amit:"

3. It will print "New Delhi:Chennai:Kolkata:"

4. It will not print "Jatin:New Delhi:Chennai:"



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

package com.hadoopexam;

import java.util.function.Predicate;

interface CourseFilter extends Predicate {
public default boolean test(String str) {
return str.equals("Hadoop");
}
}

package com.hadoopexam;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

class Welcome {

public static void main(String[] args) throws IOException {
List strs = Arrays.asList("Hadoop and Spark", "Hadoop and HBase", "Hadoop and AWS", "Hadoop ");
Predicate predicate = s -> s.length() > 4;
Predicate cf2 = new CourseFilter() { // line n1
public boolean test(String s) {
return s.contains("Hadoop ");
}
};

long c = strs.stream().filter(predicate).filter(cf2)// line n2
.count();
System.out.println(c);
}
}

 : You have been given below code, what is the expected behavior?
1. It will fail to compile

2. It will run and print 3

3. It will run and print 4

4. It will run and print 0



Question : You have been given following code, what will be the behavior?

package com.hadoopexam;

import java.util.stream.DoubleStream;

public class Welcome {
public static void main(String[] args) {
DoubleStream nums = DoubleStream.of(1.0, 2.0, 3.0).map(i -> -i); // n1
System.out.printf("Total element count = %d, Sum of all elements = %f", nums.count(), nums.sum());
}
}
 : You have been given following code, what will be the behavior?
1. Code will compile and run successful with output as Total element count = 3, Sum of all elements = 6

2. Code will compile and run successful with output as Total element count = 3, Sum of all elements =

3. Code will give compile time exception as you can not use same stream twice.

4. Code will compile, but will throw a RuntimeException "java.lang.IllegalStateException: stream has already been operated upon or closed"



Question : You have been given following code, what would be the behavior of it.

package com.hadoopexam;

class Welcome {
private static boolean checkChars(int c) {
switch (c) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
return true;
}
return false;
}

public static void main(String[] args) {
"hadoopexam.com".chars().filter(Welcome::checkChars)
.forEach(ch -> System.out.printf("%c", ch));
}
}
 : You have been given following code, what would be the behavior of it.
1. It will compile and run successfully and print nothing

2. It will compile and run successfully and print hdpxm.cm

3. It will compile and run successfully and print aooeao

4. It will give compile time error. Because, you don't have break and default statement in switch.