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.Arrays;
import java.util.List;
import java.util.stream.Stream;

public class Welcome {
int courseId;
int coursePrice;

public Welcome(int courseId, int coursePrice) {
this.courseId = courseId;
this.coursePrice = coursePrice;
}

public String toString() {
return courseId + ":" + coursePrice;
}

public static void main(String[] args) {

List courses = Arrays.asList(new Welcome(1, 10), new Welcome(2, 30), new Welcome(3, 40));
Welcome p = courses.stream().reduce(new Welcome(4, 0), (p1, p2) -> {
p1.coursePrice += p2.coursePrice;
return new Welcome(p1.courseId, p1.coursePrice);
});

//System.out.println(courses);

((Stream) courses.stream().parallel())
.reduce((p1, p2) -> p1.coursePrice > p2.coursePrice ? p1 : p2)
.ifPresent(System.out::println);
}
}

 : You have been given below code, what is the expected behavior?
1. 3 : 40

2. 4: 0

3. Access Mostly Uused Products by 50000+ Subscribers

4. 4 : 80
2 : 30
3 : 40
1 : 10

5. The program prints nothing.


Correct Answer : Get Lastest Questions and Answer :
Explanation: As you can see, in first stream we are reducing and summing all the course prices. However, we are not using result produce by first stream function.
However, in second reduce function we are printing course which has highest feees.




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

package com.hadoopexam;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Welcome implements Comparator {
String courseName;
double coursePrice;

public Welcome() {
}

public Welcome(String courseName, double coursePrice) {
this.courseName = courseName;
this.coursePrice = coursePrice;
}

public int compare(Welcome b1, Welcome b2) {
return b1.courseName.compareTo(b2.courseName);
}

public String toString() {
return courseName + ":" + coursePrice;
}

public static void main(String[] args) {
List books = Arrays.asList(new Welcome("Java Training", 1), new Welcome("Hadoop Training", 2), new Welcome("Spark training", 3));
Collections.sort(books, new Welcome());
System.out.print(books);
}
}

 : You have been given below code, what is the expected behavior?
1. [ Java Training:1.0, Hadoop Training:2.0, Spark training:3.0]

2. [Hadoop Training:2.0, Java Training:1.0, Spark training:3.0]

3. Access Mostly Uused Products by 50000+ Subscribers

4. An Exceptionis thrown at run time.


Correct Answer : Get Lastest Questions and Answer :
Explanation: This code is perfectly fine. We are comparing Welcome objects and sort them by their course name.

void java.util.Collections.sort(List list, Comparator c)

Sorts the specified list according to the order induced by the specified comparator. All elements in the list must be mutually comparable using the
specified comparator (that is, c.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the list).
This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.
The specified list must be modifiable, but need not be resizable.
Parameters:
the class of the objects in the list
list the list to be sorted.
c the comparator to determine the order of the list. A null value indicates that the elements' natural ordering should be used.





Question : You have been given below code

package com.hadoopexam;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Welcome {

public static void main(String[] args) {
List listVal = Arrays.asList("HadoopExam", "QuickTechie", "Training4Exam", ".com");
System.out.println (
// line n1
);
}
}

Which code fragment, when inserted at line n1, enables the code to print the count of string
elements whose length is greater than 7?
 : You have been given below code
1. listVal.stream().filter(x -> x.length()>7).count()

2. listVal.stream().map(x -> x.length()>7).count()

3. Access Mostly Uused Products by 50000+ Subscribers

4. listVal.stream().filter(x -> x.length()>7).mapToInt(x -> x).count()

Correct Answer : Get Lastest Questions and Answer :
Explanation: Stream java.util.stream.Stream.filter(Predicate predicate)

Returns a stream consisting of the elements of this stream that match the given predicate.
This is an intermediate operation.

Related Questions


Question :
You have been given following code. What is the expected behavior?

package com.hadoopexam;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList;

class Welcome implements Callable {
public static void main(String[] args) {
ArrayList cowAList = new CopyOnWriteArrayList();
cowAList.addAll(Arrays.asList(1,2,3,4));
System.out.println(cowAList);
}
}
 :
1. It will give compile time error.

2. It will compile and run with output as [1,2,3,4]

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will compile and run but no output.



Question : Which one of the following methods return a Future object?


 : Which one of the following methods return a Future object?
1. The overloaded run() methods declared in the Thread class.

2. The run() method declared in the Runnable interface

3. Access Mostly Uused Products by 50000+ Subscribers

4. The call() method declared in the Callable interface



Question : Which of the following is not a correct option, with regard to JDBC?
 : Which of the following is not a correct option, with regard to JDBC?
1. It is the responsibility of Driver Manager to manage the list of available Data Sources.

2. It is the responsibility of Driver Manager to use appropriate driver to communicate with DBMS.

3. Access Mostly Uused Products by 50000+ Subscribers

4. A and C

5. B and C



Question : You have been given below code,

Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM table"));
int columnCount = resultSet.getMetaData().getColumnCount();

Select the correct statement, which applies?
A. Table header can be accessed using 0th Index.
B. Table header can be accessed using 1st Index
C. MetaData object cannot return number of columns in query.
D. A and C
E. B and C

 : You have been given below code,
1. Table header can be accessed using 0th Index.

2. Table header can be accessed using 1st Index

3. Access Mostly Uused Products by 50000+ Subscribers

4. A and C

5. B and C



Question : You have been given below code, once you execute it what will be the expected result?

package com.hadoopexam;

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

class Welcome {
public static void main(String[] args) {
Connection connection=null;
try (Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM User")) {
System.out.println(resultSet.getInt("user_id") + "\t"
+ resultSet.getString("UserName") + "\t"
+ resultSet.getString("lastName") + "\t"
+ resultSet.getString("emailId") + "\t"
+ resultSet.getString("Cell"));
} catch (SQLException sqle) {
System.out.println("SQLException");
}
}
}

 : You have been given below code, once you execute it what will be the expected result?
1. It will give compile time error

2. It will give runtime error

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will compile and run and print nothing.



Question : Select the correct statement with regards to JDBC Statement interface

 : Select the correct statement with regards to JDBC Statement interface
1. The Statement interface and its derived interfaces implement the AutoCloseable interface, hence Statement objects can be used with the try with- resources
statement.

2. You can use PreparedStatement is used to execute stored procedures

3. Access Mostly Uused Products by 50000+ Subscribers

4. A and C

5. B and C