Top 25 Coffee Date, Fourth Dimension As Well As Calendar Interview Questions Answers

The Date together with Time API is a real of import 1 for 24-hour interval to 24-hour interval Java evolution operate but many interviewers don't enquire plenty questions on this topic. Most of the questions are based on either Java Collection framework like  HashMap, ConcurrentHashMap, or ArrayList or on multi-threading concepts similar volatile, synchronized together with atomic variables. This is non expert together with I intend many interviewers bring realized that a expert agreement of appointment together with fourth dimension API is also of import for a expert Java developer. That's the principal argue for an increasing number of date, fourth dimension together with calendar based Java interview questions inwards recent time, especially inwards terminal a twain of years.

Since Java evolution chore marketplace position is real expert at this minute together with at that spot are a lot of jobs open, especially inwards investment banking domain inwards the Asia Pacific, its in all probability the best fourth dimension to alter your job, especially if you lot are stuck alongside no learning, no salary growth together with non a pregnant bonus or incentives inwards terminal a twain of years.

Apart from stability, growth is real of import because if you lot don't motility frontward you lot volition hold out stuck together with eventually motility backward, thus changing chore is equally of import equally sticking to a chore which is working for you.

Btw, if you lot are novel to Java together with don't know much near Date together with Time classes so I propose you lot to rootage become through a comprehensive class like The Complete Java Masterclass on Udemy. It's also of late updated to comprehend the latest Java version together with non real expensive. You tin acquire it inwards precisely $10 inwards several Udemy flash sales which happens all some the year.




Top 10 Date, Time together with Calendar Interview Questions together with Answers

I bring been sharing interview questions on diverse Java topics from terminal a twain of years similar multithreading, collections, design patterns, coding problems, etc, but 1 topic which I haven't touched yet was appointment together with fourth dimension together with that's why I idea to part some of the interesting appointment together with time-based questions from recent Java interviews. In this article, you lot volition detect those.


1. Does SimpleDateFormat hold out condom to exercise inwards the multithreaded program? (answer)
No, unfortunately, DateFormat together with all its implementations including SimpleDateFormat is non thread-safe, hence, should non hold out used inwards the multi-threaded plan until external thread-safety measures are applied e.g. confining SimpleDateFormat object into a ThreadLocal variable. I

f you lot don't practice that, you lot volition acquire an wrong upshot spell parsing or formatting dates inwards Java. Though, for all practical appointment fourth dimension purpose, I highly recommend the joda-time library.


2. How practice you lot format a appointment inwards Java? e.g. inwards the ddMMyyyy format? (answer)
You tin either exercise SimpleDateFormat degree or joda-time library to format the appointment inwards Java. DateFormat degree allows you lot to format appointment on many pop formats. Please run into the reply for code samples to format the Date into dissimilar formats e.g. dd-MM-yyyy or ddMMyyyy.




3. Can you lot say some departure betwixt quondam together with novel Date Time API of Java 8?
Even though novel Date together with Time API are a completely novel API, you lot tin deduce the next departure betwixt them:
1) In quondam API, Date was mutable but inwards Java 8 all appointment together with fourth dimension classes e.g. LocalDate, LocalTime or LocalDateTime are Immutable.
2) In quondam API, SimpleDateFormat was non thread-safe, but inwards Java 8 Formatter are thread-safe.
3) In quondam Date together with Calendar API, Year starts alongside 1900, Months starts alongside 0, which is corrected inwards Java 8, hither numbers brand to a greater extent than sense.
4) Old Date together with Calendar API has precisely 1 degree Date to correspond appointment together with time, but Java 8 has separated classes for Date together with Time e.g. LocalDate together with LocalTime




4. Which appointment the next Date lawsuit represent?
Date aDate = novel Date(2015, 12, 25, 20, 40);

This is a actually tricky enquiry for whatever casual Java developers who bring non written appointment together with time-based code for himself because this volition non correspond the Christmas 24-hour interval or 25th Dec 2015. This code has got 2 bugs, first, the twelvemonth starts from 1900 to, to correspond 2015, you lot demand to overstep 115 i.e. 2015-1900.

The 2d number alongside this code is that calendar month is non correct. The calendar month starts from 0, so Dec would xi non 12, interesting right? That's why you lot should novel Date together with Time API from Java 8, which solves all these issues. Again, you lot tin check The Complete Java Masterclass to larn to a greater extent than near novel Date together with Time API.

 The Date together with Time API is a real of import 1 for 24-hour interval to 24-hour interval Java evolution operate but ma Top 25  Java Date, Time together with Calendar Interview Questions Answers



5. How practice you lot re-create a Date inwards Java? (answer)
It's a uncomplicated enquiry to answer. The Date degree implements the clone() method, so precisely telephone telephone date.clone() to practice a re-create of the Date object inwards Java.


6. What is the human relationship betwixt java.sql.Date together with java.util.Date? (answer)
This is 1 of the real interesting questions equally non many developers know this fine but obvious detail. The java.sql.Date extends java.util.Date together with suppress all time-related methods to human activity equally precisely a appointment class. This is inwards straight violation of the Liskov exchange principle.


7. Can you lot format Calendar inwards Java? (answer)
No, Calendar cannot hold out formatted inwards Java. You tin alone format dates.


8. How practice you lot convert a Calendar to Date together with vice-versa? (answer)
Well, you lot tin exercise the Calendar.setTime() together with Calendar.getTime() method to convert the Calendar to Date together with vice-versa.


9. What is the equivalent of Date degree inwards Java 8? (answer)
The Instance degree is the equivalent to java.util.Date inwards Java 8 because it also represents a millisecond value or an lawsuit inwards the timescale. Java 8 has also added conversion method e.g. toInstant() together with fromDate() to convert lawsuit to java.util.Date together with vice-versa. See Java SE 8 for Really Impatient By Cay S. Horstmann for to a greater extent than details.

 The Date together with Time API is a real of import 1 for 24-hour interval to 24-hour interval Java evolution operate but ma Top 25  Java Date, Time together with Calendar Interview Questions Answers



10. How practice you lot convert a millisecond to Date inwards Java? (answer)
One of the simplest enquiry to answer, you lot tin telephone telephone the getTime() method which returns the millisecond from the Epoch.


12. How practice you lot acquire a calendar month together with twelvemonth from a Date object inwards Java? (answer)
You tin convert a Date to Calendar together with so exercise its get() method alongside diverse fields to acquire the month, year, 24-hour interval of the calendar week together with other appointment particulars e.g.

int 24-hour interval = calendar.get(Calendar.DATE); // returns the day
int calendar month = calendar.get(Calendar.MONTH) + 1; // calendar month starts from 0
int twelvemonth = calendar.get(Calendar.YEAR) + 1900; // twelvemonth starts from 1900


13. How practice you lot convert XMLGregorianCalendar to Date inwards Java? (answer)
I bring discussed this occupation before, delight cheque the link for the detailed answer.


14. How practice you lot acquire the electrical current fourth dimension inwards GMT inwards Java? (answer)
The Java appointment is independent of fourth dimension together with display fourth dimension inwards a electrical current fourth dimension zone alone if you lot impress them. So, inwards lodge to convert the electrical current fourth dimension inwards GMT, you lot demand to exercise Calendar alongside fourth dimension zone equally shown inwards the given answer.


15. Is Date degree hold out Immutable inwards Java?
No, Date is non immutable. You tin alter it's internal to correspond a dissimilar date. This is the argue that when you lot bring a fellow member correspond Date, you lot must hold out careful non to leak its reference exterior using getDate() method, because so the customer tin modify the dry reason of the Immutable object, instead a re-create should hold out returned to the customer equally suggested in Effective Java book past times none other than Joshua Bloch, writer of several primal classes of JDK API.

 The Date together with Time API is a real of import 1 for 24-hour interval to 24-hour interval Java evolution operate but ma Top 25  Java Date, Time together with Calendar Interview Questions Answers



16. How practice you lot add together together with subtract a day, calendar month together with twelvemonth inwards a Date object? (answer)
This is 1 of the mutual 24-hour interval to 24-hour interval task of a Java developer, you lot tin exercise the code shared inwards the reply for adding or subtracting a 24-hour interval or calendar month from the Date object.


17. How practice you lot compare 2 dates inwards Java to cheque if they are equal? (answer)
This is 1 of the easier questions you lot volition run into inwards damage of science checking on Date classes. The java.util.Date degree implements the equals() method, which returns truthful if both Dates is same together with imitation otherwise.



18. How practice you lot detect if 1 appointment comes earlier or afterward some other appointment inwards Java? (answer)
This is the follow-up enquiry of the previous question. The interviewer farther checks the candidate's appointment comparing science past times quest this question. The reply is simple, the java.util.Date degree provides before() together with after() method which returns truthful together with imitation if the appointment on which method is called comes earlier or afterward the other appointment passed equally a method argument.


19. How practice you lot convert java.util.Date to java.sql.Date inwards Java JDBC? (answer)
It's the follow-up enquiry of sixth question. Since java.sql.Date is a subclass of java.util.Date you lot tin merely acquire the fourth dimension inwards millisecond together with passed it to SQL appointment equally shown below:

Date straightaway = novel Date();
java.sql.Date sqlDate = novel java.sql.Date(now.getTime());

Simple together with slowly right? but at that spot are some interesting follow-up questions when you lot write this code, I propose you lot cheque the reply link for to a greater extent than detailed discussion, where I bring answered those follow-up questions equally well. You tin farther see  The Date together with Time API is a real of import 1 for 24-hour interval to 24-hour interval Java evolution operate but ma Top 25  Java Date, Time together with Calendar Interview Questions Answers


Btw, you lot would demand a answer)
This is similar to 1 of the previous questions where nosotros demand to acquire the electrical current fourth dimension inwards GMT


21. How practice you lot exhibit timezone inwards formatted appointment inwards Java? (answer)
run into the reply link for a code example


22. What is the departure betwixt java.util.Date together with java.sql.Date inwards Java? (answer)
There are much departure betwixt them but the most of import 1 is that java.sql.Date is from JDBC bundle together with it acts equally converted betwixt Date together with Time information types inwards database together with Date inwards Java.


23. How practice you lot calculate the departure betwixt 2 dates inwards Java? (program)
There are multiple ways to calculate the departure betwixt 2 dates inwards Java e.g. you lot tin acquire the long millisecond values from 2 dates together with acquire the departure but that's non real valuable, you lot generally demand the departure inwards days or hours, etc. See the plan to larn to a greater extent than near those differences.


24 How practice you lot convert a String(YYYYMMDD) to appointment inwards Java? (answer)
You tin exercise SimpleDateFormat prior to JDK 8 together with DateTimeFormatter along alongside format together with parse method to convert a String to appointment inwards Java.

That's all near the date, time, together with Calendar based Java Interview Questions. It's real of import for a Java developer to bring a corporation agreement of Date together with Time API of Java, both quondam together with novel because you lot volition non detect Java 8 inwards every projection you lot work. You however demand to know how to operate alongside quondam Date together with Calendar API spell maintaining the legacy projection for a twain of to a greater extent than years.

Further Learning
Complete Java Masterclass
see here)
  • 15 Data Structure together with Algorithm Questions from Java Interviews (read here)
  • 20 Great Java Design Pattern Questions asked on Interviews (see here)
  • 10 often asked Servlet Interview Questions alongside Answers (see here)
  • Top 10 JSP Questions  from J2EE Interviews (read here)
  • 12 Good RESTful Web Services Questions from Interviews (read here)
  • 10 Great Hibernate Interview Questions for Java EE Developer (see here)
  • 10 Great JDBC Interview Questions for Java Programmers (questions)
  • 15 Java NIO together with Networking Interview Questions alongside Answers (see here)
  • Top 10 Trick Java Interview Questions together with Answers (see here)
  • Top xl Core Java Phone Interview Questions alongside answers (list)
  • 50+ Data Structure together with Algorithm Interview Questions (data structure)
  • 20+ String based Coding Problems from Interviews (questions)


  • Thanks for reading this article so far. If you lot similar these questions so delight part alongside your friends together with colleagues too. If you lot bring whatever questions or feedback so delight driblet a note.

    P. S. - If you lot are looking to fill upwards gaps inwards your Java noesis or desire to larn Java from scratch, hither are some useful free online Java courses to expect out.

    0 Response to "Top 25 Coffee Date, Fourth Dimension As Well As Calendar Interview Questions Answers"

    Post a Comment

    Iklan Atas Artikel

    Iklan Tengah Artikel 1

    Iklan Tengah Artikel 2

    Iklan Bawah Artikel