Premium

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



Question : You have been given below code.
package com.hadoopexam;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;

public class Welcome {
public static void main(String[] args) throws IOException {
Stream lines = Files.lines(Paths.get("C:\\Welcome.java"));
//n1
}
}
Which of the following line will print first line from Welcome.java file
 : You have been given below code.
1. lines.limit(1).forEach(System.out::println);

2. lines.limit(0).forEach(System.out::println);

3. Access Mostly Uused Products by 50000+ Subscribers

4. lines[0]

5. C and D


Correct Answer : Get Lastest Questions and Answer :
Explanation: Stream java.nio.file.Files.lines(Path path) throws IOException

Read all lines from a file as a Stream. Bytes from the file are decoded into characters using the UTF-8 charset.
This method works as if invoking it were equivalent to evaluating the expression:
Files.lines(path, StandardCharsets.UTF_8)
The limit(1) method truncates the result to one line; and the forEach() method, when passed with the System.out::println method reference, prints that line to the console.





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

package com.hadoopexam;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.function.BiPredicate;
import java.util.stream.Stream;

public class Welcome {
public static void main(String[] args) throws IOException {
BiPredicate biPredicate = (path, attrs) -> true;
try(Stream entries = Files.find(Paths.get("."), 1, biPredicate)) {
entries.forEach(System.out::println);
}
}
}
 : You have been given below code, what is 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 run, and print one level file information.


Correct Answer : Get Lastest Questions and Answer :
Explanation: : Stream java.nio.file.Files.find(Path start, int maxDepth, BiPredicate matcher, FileVisitOption... options)
throws IOException

Return a Stream that is lazily populated with Path by searching for files in a file tree rooted at a given starting file.
This method walks the file tree in exactly the manner specified by the walk method. For each file encountered, the given BiPredicate is invoked with its Path and BasicFileAttributes.
The Path object is obtained as if by resolving the relative path against start and is only included in the returned Stream if the BiPredicate returns true. Compare to calling filter
on the Stream returned by walk method, this method may be more efficient by avoiding redundant retrieval of the BasicFileAttributes.
The returned stream encapsulates one or more DirectoryStreams. If timely disposal of file system resources is required, the try-with-resources construct should be used to ensure that
the stream's close method is invoked after the stream operations are completed. Operating on a closed stream will result in an java.lang.IllegalStateException.
If an IOException is thrown when accessing the directory after returned from this method, it is wrapped in an UncheckedIOException which will be thrown from the method that caused
the access to take place.
Parameters:
start the starting file
maxDepth the maximum number of directory levels to search
matcher the function used to decide whether a file should be included in the returned stream
options options to configure the traversal





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

package com.hadoopexam;

import java.io.IOException;

public class Welcome extends Thread {

@Override
public void run() {
System.out.print("HadoopExam");
}

public static void main(String[] args) throws IOException {
Welcome wel = new Welcome();
System.out.println(".com");
}
}
 : 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. Access Mostly Uused Products by 50000+ Subscribers

4. It will print "HadoopExam"

5. It will print "HadoopExam.com"


Correct Answer : Get Lastest Questions and Answer :
Explanation: As we can see we have created the object of Thread class named Welcome , which represent a Thread object. However, we have not called start() method on that
Thread object. Hence, its run() method will not be executed. Only main() method Sysout will be printed.


Related Questions


Question : You have been given below code, what would be printed if executed

package com.hadoopexam;

class Welcome {
public static void main(String[] args) {
try {
int i = 10 / 0;
System.out.print("1 ");
} catch (ArithmeticException ae) {
System.out.print("2 ");
return;
} finally {
System.out.print("3 ");
}
System.out.print("4 ");
}
}
 : You have been given below code, what would be printed if executed
1. 1 2

2. 2 3

3. Access Mostly Uused Products by 50000+ Subscribers

4. 1 2 3

5. 2 3 4



Question : You have been given below code, please select correct behavior of it

package com.hadoopexam;

import java.util.Scanner;

class Welcome {
public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) {
scanner.close();
scanner.close();
}
}
}
 : You have been given below code, please select correct behavior of it
1. It will not compile

2. It will compile but run time , it will throw IllegalStateException

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will compile and run throw RuntimeException

5. It will compile, run and no output will be produced.



Question : You have been given below code, what happen if you execute it.
package com.hadoopexam;

class Welcome {
public static void main(String[] args) {
try {
assert false;
} catch (RuntimeException re) {
System.out.println("RuntimeException");
} catch (Exception e) {
System.out.println("Exception");
} catch (Error e) {
System.out.println("Error");
} catch (Throwable t) {
System.out.println("Throwable");
}
}
}
 : You have been given below code, what happen if you execute it.
1. It will print RuntimeException

2. It will print Exception

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will print Throwable

5. It will print nothing



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

package com.hadoopexam;

import java.nio.file.FileAlreadyExistsException;

class Welcome {
@SuppressWarnings("finally")
public static void call() throws Exception {
try {
throw new FileAlreadyExistsException(null);
} finally {
throw new Exception();
}
}

public static void main(String[] args) {
try {
call();
} catch (Throwable throwable) {
System.out.println(throwable);
}
}
}

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

2. It will compile and run with Throwable

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will compile and run with no output

5. It will compile and run with FileAlreadyExistsException



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

package com.hadoopexam;

import java.time.LocalDate;
import java.time.Month;
import java.time.Period;

class Welcome {
public static void main(String[] args) {
LocalDate date1 = LocalDate.of(2014, Month.MARCH, 01);
LocalDate date2 = LocalDate.of(2016, Month.NOVEMBER, 01);
System.out.println(Period.between(date2, date1).getYears());
}
}
 : You have been given following code, what is the behavior expected
1. It will give compile time error

2. It will compile and run perfectly and print 1

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will compile and run perfectly and print -1

5. It will compile and run perfectly and print -2



Question : Which one of the following classes is best suited for storing timestamp values of application events in a file?
 : Which one of the following classes is best suited for storing timestamp values of application events in a file?
1. java.time.ZoneId class

2. java.time.ZoneOffset class

3. Access Mostly Uused Products by 50000+ Subscribers

4. java.time.Duration class

5. java.time.Period class