Oracle Certified Professional Java Se 11 Developer · Free Practice Question Easy
Question 61
Question ID: UKOCP80759
Given code:
- package com.udayankhattry.ocp;
- import java.time.*;
- import java.time.format.*;
- public class Test {
- public static void main(String [] args) {
- var date = LocalDateTime.of(2025, Month.JANUARY, 1, 10, 10);
- var formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL);
- System.out.println(formatter.format(date));
- }
- }
Will above code display time part on to the console?
- A Yes
- B No
Reveal correct answer
Correct answer: B
Explanation
UKOCP80759:
DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL); statement returns formatter to format date part.
date is of LocalDateTime type hence it has both date part and time part.
formatter.format(date) simply formats the date part and ignores time part.
NOTE: You should aware of other formatter related methods for the exam, such as: 'ofLocalizedTime' and 'ofLocalizedDateTime'
Please also keep in mind below format styles:
FormatStyle.FULL => Full text style, with the most detail. For example, the format might be 'Tuesday, April 12, 1952 AD' or '3:30:42pm PST'.
FormatStyle.LONG => Long text style, with lots of detail. For example, the format might be 'January 12, 1952'.
FormatStyle.MEDIUM => Long text style, with lots of detail. For example, the format might be 'Jan 12, 1952'.
FormatStyle.SHORT => Short text style, typically numeric. For example, the format might be '12.13.52' or '3:30pm'.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
