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.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

class Welcome {
public static void main(String[] args) {
ZoneId zoneId = ZoneId.of("Asia/Kolkata");
ZonedDateTime zonedDateTime = ZonedDateTime.of(LocalDateTime.now(), zoneId);
System.out.println(zonedDateTime.getOffset());
}
}
 : You have been given below code, what is the expected behavior?
1. It will not compile.

2. It will compile and print +5:30[Asia/Kolkata]

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will compile and print +5:30[UTC]

5. It will compile and print +5:30


Correct Answer : Get Lastest Questions and Answer :
Explanation: ZoneId java.time.ZoneId.of(String zoneId)

Obtains an instance of ZoneId from an ID ensuring that the ID is valid and available for use.
This method parses the ID producing a ZoneId or ZoneOffset. A ZoneOffset is returned if the ID is 'Z', or starts with '+' or '-'.
ZonedDateTime java.time.ZonedDateTime.of(LocalDateTime localDateTime, ZoneId zone)

Obtains an instance of ZonedDateTime from a local date-time.
This creates a zoned date-time matching the input local date-time as closely as possible. Time-zone rules, such as daylight savings, mean that not every local date-time is valid for
the specified zone, thus the local date-time may be adjusted.

ZoneOffset java.time.ZonedDateTime.getOffset()

Gets the zone offset, such as '+01:00'.
This is the offset of the local date-time from UTC/Greenwich





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

package com.hadoopexam;

import java.time.LocalDate;
import java.time.Month;
import java.time.format.DateTimeFormatter;

class Welcome {
public static void main(String[] args) {
DateTimeFormatter dateFormat = DateTimeFormatter.ISO_DATE;
LocalDate dateOfBirth = LocalDate.of(2016, Month.FEBRUARY, 29);
System.out.println(dateFormat.format(dateOfBirth));
}
}
 : You have been given below code, what behavior is expected?
1. It will give compile time error.

2. It will produce output as '2016-02-29'

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will produce output as '2016-Feb-29'


Correct Answer : Get Lastest Questions and Answer :
Explanation: DateTimeFormatter java.time.format.DateTimeFormatter.ISO_DATE

The ISO date formatter that formats or parses a date with the offset if available, such as '2011-12-03' or '2011-12-03+01:00'.
This returns an immutable formatter capable of formatting and parsing the ISO-8601 extended date format. The format consists of:
LocalDate java.time.LocalDate.of(int year, Month month, int dayOfMonth)

Obtains an instance of LocalDate from a year, month and day.
This returns a LocalDate with the specified year, month and day-of-month. The day must be valid for the year and month, otherwise an exception will be thrown.
Parameters:
year the year to represent, from MIN_YEAR to MAX_YEAR
month the month-of-year to represent, not null
dayOfMonth the day-of-month to represent, from 1 to 31

String java.time.format.DateTimeFormatter.format(TemporalAccessor temporal)

Formats a date-time object using this formatter.
This formats the date-time to a String using the rules of the formatter.
Parameters:
temporal the temporal object to format, not null





Question : You have been given following code, and running from a system which are installed in India on Saturday and month is November and Year is . What will be the behavior
of the code?
package com.hadoopexam;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

class Welcome {
public static void main(String[] args) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEEE",Locale.US);
System.out.println(formatter.format(LocalDateTime.now()));
}
}
 : You have been given following code, and running from a system which are installed in India on Saturday and month is November and Year is . What will be the behavior
1. It will not compile.

2. It will print NOVEMBER

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will print Satu.


Correct Answer : Get Lastest Questions and Answer :
Explanation: E is the day name in the week; the pattern "EEEE" prints the name of the day in its full format. "Sat" is a short form that would be printed by the pattern
"E", but "EEEE" prints the day of the week in full form: for example, "Saurday". Because the locale is Locale.US, the result is printed in English.

DateTimeFormatter java.time.format.DateTimeFormatter.ofPattern(String pattern, Locale locale)

Creates a formatter using the specified pattern and locale.
This method will create a formatter based on a simple pattern of letters and symbols as described in the class documentation. For example, d MMM uuuu will format 2011-12-03 as '3 Dec 2011'.
The formatter will use the specified locale. This can be changed using DateTimeFormatter.withLocale(Locale) on the returned formatter
The returned formatter has no override chronology or zone. It uses SMART resolver style.
String java.time.format.DateTimeFormatter.format(TemporalAccessor temporal)

Formats a date-time object using this formatter.
This formats the date-time to a String using the rules of the formatter.
Parameters:
temporal the temporal object to format, not null
Returns:
the formatted string, not null



Related Questions


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

package com.hadoopexam;

import java.io.FileInputStream;
import java.io.InputStreamReader;

public class Welcome {

public static void main(String[] args) {
int i;
char c;
try (FileInputStream fileInputStream = new FileInputStream("resources\\Message.properties");
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);) {
while (inputStreamReader.ready()) { // line n1
inputStreamReader.skip(2);
i = inputStreamReader.read();
c = (char) i;
System.out.print(c);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
 : You have been given below code, what is expected behavior?
1. tHoEmo?

2. t:HoEmo?

3. Access Mostly Uused Products by 50000+ Subscribers

4. A compilation error occurs at line n1.



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


package com.hadoopexam;

public class Welcome {
private T t;

public T get() {
return t;
}

public void set(T t) {
this.t = t;
}

public static void main(String args[]) {
Welcome siteName = new Welcome<>();
Welcome userId = new Welcome();// line n1
siteName.set("HadoopExam.com");
userId.set(101);// line n2
System.out.print(siteName.get() + ":" + userId.get());
}
}
 : You have been given below code, what is the expected output?
1. HadoopExam.com:101

2. java.lang.string@java.lang.Integer@

3. Access Mostly Uused Products by 50000+ Subscribers
Welcome userId = new Welcome();

4. A compilation error occurs. To rectify it, replace line n2with:
userId.set (Integer(101));



Question : You have been given below class and its member variables ,

package com.hadoopexam;

public class Welcome {
String name;

void setName(String name) {
this.name = name;
}

String getName() {
return name;
}
}

Which action encapsulates the Welcome class?
 : You have been given below class and its member variables ,
1. Make the Vehicle class public.

2. Make the name variable public.

3. Access Mostly Uused Products by 50000+ Subscribers

4. Make the name variable private.

5. Make the setName method private.




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.



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.



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