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.nio.file.*;

public class Welcome {
public static void main(String[] args) {
Path hePath = Paths.get("C:\\HadoopExam\\he1.txt");
while (hePath.iterator().hasNext()) {
System.out.println("Next Path: " + hePath.iterator().next());
}
}
}
 : 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. Access Mostly Uused Products by 50000+ Subscribers

4. It will print only once "Next Path: C:\HadoopExam\he1.txt"

5. It will go in infinite loop.


Correct Answer : Get Lastest Questions and Answer :
Explanation: When you call hePath.iterator() , it will return a temporary iterator variable. And once you call next() method on it. This temporary variable will be lost
and goes in infinite loop.

Correct syntax will be

Iterator itr = hePath.iterator();
while (itr.hasNext()) {
System.out.println("Next Path: " + itr.next());
}





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

package com.hadoopexam;

import java.nio.file.Path;
import java.nio.file.Paths;

public class Welcome {
public static void main(String []args) {
Path path = Paths.get("D:\\HadoopExam\\HE\\..\\HE2\\com\\.\\Welcome.java");
path = path.normalize();
System.out.println(path.subpath(2, 3));
}
}
 : You have been given below path, what is the expected code behavior?
1. It gives compile time error

2. It will give runtime error

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will print "HadoopExam"

5. It will print "com"


Correct Answer : Get Lastest Questions and Answer :
Explanation: Path java.nio.file.Path.normalize()

Returns a path that is this path with redundant name elements eliminated.
The precise definition of this method is implementation dependent but in general it derives from this path, a path that does not contain redundant name elements. In many file
systems, the "." and ".." are special names used to indicate the current directory and parent directory. In such file systems all occurrences of "." are considered redundant. If a
".." is preceded by a non-".." name then both names are considered redundant (the process to identify such names is repeated until it is no longer applicable).

After normalize path will be : D:\HadoopExam\HE2\com\Welcome.java
Path starts with "HadoopExam" and also its indexing start with 0, 1, 2,3 ect.

0 -> HadoopExam
1 -> HE2
2 -> com
3-> Welcome.java

Hence, subpath (2, 3) where 3 is not inclusive but 2 is inclusive.





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

package com.hadoopexam;

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

public class Welcome {
public static void main(String[] args) throws IOException {
Path path = Paths.get("C:\\HadoopExam\\he.txt");
System.out.println(path.isAbsolute());
}
}
 : You have been given below code, what is the expected behavior?
1. Compile time error

2. Runtime exception

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will print true

5. Depend on file exist or not


Correct Answer : Get Lastest Questions and Answer :
Explanation: boolean java.nio.file.Path.isAbsolute()

Tells whether or not this path is absolute.
An absolute path is complete in that it doesn't need to be combined with other path information in order to locate a file.
Returns:
true if, and only if, this path is absolute
To use methods such as isAbsolute(), the actual file need not exist. Because the
path represents an absolute path (and not a relative path), this program prints true



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



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);



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.



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

package com.hadoopexam;

import java.util.Arrays;
import java.util.List;

public class Welcome {
public static void main(String[] args) {
List sites = Arrays.asList("HadoopExam", "QuickTechie", "Training4Exam");
sites.forEach(allSite -> System.out.print(allSite + " "));
String courseSite = sites.stream().filter(s -> s.contains("i")).reduce((s, t) -> s + t).get();
System.out.println("\n" + courseSite);
}
}
 : You have been given below code, what is the expected behavior?
1. It will print
HadoopExam QuickTechie Training4Exam
QuickTechieTraining4Exam

2. It will print
HadoopExam QuickTechie Training4Exam
HadoopExam

3. Access Mostly Uused Products by 50000+ Subscribers
QuickTechieTraining4Exam
HadoopExam QuickTechie Training4Exam

4. It will print
QuickTechieTraining4Exam




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

public class Welcome {
public static void main(String[] args) {
List sites = Arrays.asList("HadoopExam.com", "Training4Exam.com", "QuickTechie.com");
Function funVal = s -> " Welcome to : ".concat(s);
sites.stream().map(funVal).peek(System.out::print);
}
}
 : You have been given below code, what is the expected behavior?
1. It will print Welcome to : HadoopExam.com Welcome to : Training4Exam.com Welcome to : QuickTechie.com

2. It will print HadoopExam.com: Training4Exam.com: QuickTechie.com

3. Access Mostly Uused Products by 50000+ Subscribers

4. There will be compilation error

5. There will be a runtime error.



Question : You have been given below interface

package com.hadoopexam;

public interface Welcome {

public default void call(Integer distance) {
System.out.println("Welcome to HadoopExam Learning Resources");
}

public void run(Integer distance);
}

Which is the valid use of Welcome interface?
 : You have been given below interface
1. Welcome courseCount = n -> System.out.println("Start watching Hadoop Training " + n);
courseCount.run(1);
courseCount.call(2);


2. Welcome courseCount = n ->n + 10;
courseCount.run(1);
courseCount.call(2);


3. Access Mostly Uused Products by 50000+ Subscribers
courseCount.run(1);
Welcome.call(2)


4. Welcome is not correctly declare to be used in a lambda expression.