Premium

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



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

package com.hadoopexam;

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

public class Welcome {

public static void main(String[] args) {
Path path1 = Paths.get("/my/./file/");
Path res1 = path1.resolve("file.txt");
Path path2 = Paths.get("/data/use/");
Path res2 = path2.resolve("/hadoop.txt/");
System.out.println(res1);
System.out.println(res2);
}
}


 : You have been given below code, what is the expected result ?
1. \my\.\file\file.txt
\data\use\hadoop.txt

2. \my\.\file\file.txt
\hadoop.txt

3. It will throw error : java.nio.file.InvalidPathException: UNC path is missing sharename:
4. java.nio.file.InvalidPathException: UNC path is missing sharename: //hadoop.txt/


Correct Answer : 2
Explanation: If you used this kind of path on a Windows machine (a path starting with /) the path would be interpreted as relative to the current drive.

Path java.nio.file.Path.resolve(String other)

Converts a given path string to a Path and resolves it against this Path in exactly the manner specified by the resolve method. For example, suppose that the name separator is "/"
and a path represents "foo/bar", then invoking this method with the path string "gus" will result in the Path "foo/bar/gus".
Parameters:
other the path string to resolve against this path
Returns:
the resulting path
Throws:
InvalidPathException - if the path string cannot be converted to a Path.
See Also:
FileSystem.getPath





Question : Which of the following can be a valid syntax for , resource bundle property files ?





 : Which of the following can be a valid syntax for , resource bundle property files ?
1. Key:value

2. Key=value

3. Key==value

4. Key;value




Correct Answer : 2
Explanation: In the resource bundle property files, the key values are separated using the = symbol,
with each line in the resource file separated by a newline character.




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

package com.hadoopexam;

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

public class Welcome {

public static void main(String[] args) {
List allSites = Arrays.asList("HadoopExam", "QuickTechie", "Training4Exam");
Predicate predicate = site -> {
System.out.println("Watching Hadoop Training Course ...");
return site.contains("Hadoop");
};
allSites.stream().filter(siteName -> siteName.length() > 3).allMatch(predicate);
}
}



 : You have been given below code, what is the behavior expected?
1. It will print Watching Hadoop Training Course ...

2. It will print
Watching Hadoop Training Course ...
Watching Hadoop Training Course ...

3. It will print
Watching Hadoop Training Course ...
Watching Hadoop Training Course ...
Watching Hadoop Training Course ...

4. There will be a compile time error.


Correct Answer : 2
Explanation: allMatch will check for the element until it return true or you can say until it find first false.
In this code, it will check siteName contains "Hadoop" word in string for "HadoopExam" its true , hence print statement. Next will check for second string "QuickTechie" its false ,
by that time print statement executed. Hence, allMatch will stop here. So its checking only two times.

boolean java.util.stream.Stream.allMatch(Predicate predicate)

Returns whether all elements of this stream match the provided predicate. May not evaluate the predicate on all elements if not necessary for determining the result.
If the stream is empty then true is returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
Parameters:
predicate a non-interfering, stateless predicate to apply to elements of this stream
Returns:
true if either all elements of the stream match the provided predicate or the stream is empty, otherwise false
@apiNote
This method evaluates the universal quantification of the predicate over the elements of the stream (for all x P(x)). If the stream is empty, the quantification
is said to be vacuously satisfied and is always true (regardless of P(x)).



Related Questions


Question : What will be the output when you run below program?

class Welcome {
int counter1;

void Welcome() {
counter1 = 10;
}

void printValue () {
System.out.println("Counter Value = " + counter1);
}

public static void main(String[] args) {
Welcome wel = new Welcome();
wel.printValue();
}
}
 : What will be the output when you run below program?
1. It will be having a compile time error. Because counter1 is not properly initialized.

2. It will compile and will print "Counter Value = 0"

3. It will compile and will print "Counter Value = 10"

4. It will give runtime error as it will not get value initialized for counter. And Null primitive is not correct.



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

package com.hadoopexam;

class Welcome {
int distance;
Welcome(int x) {
this.distance = x;
}

public void increSpeed(int time) {
int timeTravel = time;
class Car {
int value = 0;
public void speed() {
value = distance / timeTravel;
System.out.println("Velocity with new speed " + value + "kmph");
}
}
new Car().speed();
}

public static void main(String[] args) {
Welcome wel = new Welcome (100);
wel.increSpeed(60);
}
}


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

2. It will give run time error

3. It will print "Velocity with new speed 1kmph"

4. It will print "Velocity with new speed 1.4kmph"

5. It will give NullPointerException
Correct Answer : Exp : It is a Question of mixing Inner classes as well access outer class variable. As we know distance variable is accessible from inner class.
While creating constructor of Welcome class , we assigned distance=100. In Inner class we are acceding defined value of timeTravel=60. Hence, value= 100/60 , as we know both
are int value hence result would be int value. Which is 1. So it will print Velocity with new speed 1kmph


Question : You have been given below code. Please select the correct options, which applies to this code.

package com.hadoopexam;

class Parent {
public void printValue() {
System.out.println("It is a Parent Class");
}
}

abstract class Child extends Parent { // n1
public static void main(String[] args) {
Parent obj = new Parent();
obj.printValue (); // n2
}
}
 : You have been given below code, what is the expected behavior?
1. You cannot have an abstract class which can extend non abstract class. Hence, it will give compile time error.

2. Parent class printValue() method is not accessible from a child class.

3. Program will compile successfully and also run perfectly with "It is a Parent Class".

4. There will be a RuntimeError. As child class is an abstract class.



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

package com.hadoopexam;

import java.util.function.IntFunction;
import java.util.function.IntUnaryOperator;
import java.util.stream.IntStream;

class Welcome {
public static void main(String[] args) {
IntStream stream = IntStream.of(1, 2, 3);
IntFunction inFu= x -> y -> x*y;//line n1
IntStream newStream = stream.map(inFu.apply(10));// line n2
newStream.forEach(System.out::print);
}
}
 : You have been given below code, what is the expected behavior?
1. This code will compile and run perfectly and produce 102030

2. This code will compile, but give run time error.

3. This code will compile and run with the 302010 as output.

4. This code will be executed successfully by changing n1 line with this "IntFunction inFu = x -> y -> x*y;"



Question : package com.hadoopexam;

class Parent {}

class FirstChild extends Parent {}

class SecondChild extends Parent {}

class Welcome {
public static void main(String[] args) {
Parent[] array = new FirstChild[3]; //n1
array[0] = new FirstChild(); //n2
array[2] = new SecondChild(); //n3
System.out.println(array.length); //n4
}
}
 : package com.hadoopexam;
1. It will throws an ArrayStoreException, when program is run.

2. It will throw compile time exception at line n1 and n2 both.

3. It will throw compile time exception at line n3.

4. It will run successfully and print 3

5. It will run successfully and print 2



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

package com.hadoopexam;

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

class Welcome {
public static void main(String[] args) {
List values = Arrays.asList(5,5,5);
values.stream().map(n -> n * 2).peek(System.out::print).count();
}
}
 : You have been given below code, what is the expected output?
1. It will compile time error

2. It will compile perfectly but give RuntimeError

3. It will compile and run perfectly, but will not produce any output.

4. It will compile and run perfectly, but will produce 555 as output.

5. It will compile and run perfectly, but will produce 101010 as output.



Question : Please select the correct statement for the given method.
package com.hadoopexam;

class Welcome {
int counter;

Welcome() {
Welcome(10);
}

Welcome(int r) {
counter = r;
}

void printValue() {
System.out.println("Counter Value = " + counter );
}

public static void main(String[] args) {
Welcome wel = new Welcome();
wel.printValue();
}
}
 : Please select the correct statement for the given method.
1. It will compile and run perfectly with output as Counter Value =10.

2. It will compile perfectly, but give runtime Exception.

3. It will not even compile, because method Welcome(int ) is not available.

4. It will compile and run perfectly with output as Counter Value =0.

5. : As you know, whenever you do constructor chaining i.e. Same class constructor should be called by another constructor. You should have use this(10)
instead of Welcome(10). As it is trying to look for Welcome(10) method.