42). How to format date from one form to another?
[A]SimpleDateFormat
[B]DateFormat
[C]SimpleFormat
[D]DateConverter
Show Answer
Correct Answer: SimpleDateFormat
Notes:
Answer: a
Explanation: SimpleDateFormat can be used as
Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-mm-dd'T'hh:MM:ss");
String nowStr = sdf.format(now);
System.out.println("Current Date: " + );
43). How to convert Date object to String?
[A]SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.parse(new Date());
[B]SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.format(new Date());
[C]SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); new Date().parse();
[D]SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); new Date().format();
Show Answer
Correct Answer: SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.format(new Date());
Notes:
Answer: b
Explanation: SimpleDateFormat takes a string containing pattern. sdf.format converts the Date object to String.
44). How to convert a String to a Date object?
[A]SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.parse(new Date());
[B]SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.format(new Date());
[C]SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); new Date().parse();
[D]SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); new Date().format();
Show Answer
Correct Answer: SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.parse(new Date());
Notes:
Answer: a
Explanation: SimpleDateFormat takes a string containing pattern. sdf.parse converts the String to Date object.
45). Is SimpleDateFormat thread safe?
[A]True
[B]False
[C]none
[D]none
Show Answer
Correct Answer: False
Notes:
Answer: b
Explanation: SimpleDateFormat is not thread safe. In the multithreaded environment, we need to manage threads explicitly.
46). How to identify if a timezone is eligible for DayLight Saving?
[A] useDaylightTime() of Time class
[B]useDaylightTime() of Date class
[C] useDaylightTime() of TimeZone class
[D]useDaylightTime() of DateTime class
Show Answer
Correct Answer: useDaylightTime() of TimeZone class
Notes:
Answer: c
Explanation: public abstract boolean useDaylightTime() is provided in TimeZone class.
47). What is the replacement of joda time library in java 8?
[A] java.time (JSR-310)
[B] java.date (JSR-310)
[C]java.joda
[D]java.jodaTime
Show Answer
Correct Answer: java.time (JSR-310)
Notes:
Answer: a
Explanation: In java 8, we are asked to migrate to java.time (JSR-310) which is a core part of the JDK which replaces joda library project.
48). How is Date stored in database?
[A]java.sql.Date
[B] java.util.Date
[C]java.sql.DateTime
[D]java.util.DateTime
Show Answer
Correct Answer: java.sql.Date
Notes:
Answer: a
Explanation: java.sql.Date is the datatype of Date stored in database.
49). What does LocalTime represent?
[A]Date without time
[B]Time without Date
[C]Date and Time
[D]Date and Time with timezone
Show Answer
Correct Answer: Time without Date
Notes:
Answer: b
Explanation: LocalTime of joda library represents time without date.
50). How to get difference between two dates?
[A]long diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis();
[B] long diffInMilli = java.time.difference(dateTime1, dateTime2).toMillis();
[C]Date diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis();
[D]Time diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis();
Show Answer
Correct Answer: long diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis();
Notes:
Answer: a
Explanation: Java 8 provides a method called between which provides Duration between two times.
51). How to get UTC time?
[A]Time.getUTC();
[B] Date.getUTC();
[C] Instant.now();
[D]TimeZone.getUTC();
Show Answer
Correct Answer: Instant.now();
Notes:
Answer: c
Explanation: In java 8, Instant.now() provides current time in UTC/GMT.