The Date as well as Time API is real of import i for twenty-four hours to twenty-four hours Java evolution operate but many interviewers don't inquire plenty questions on this topic. Most of the questions are based on either Java Collection framework e.g. HashMap, ConcurrentHashMap or ArrayList, or on multi-threading concepts e.g. volatile, synchronized as well as atomic variables. This is non skillful as well as I intend many interviewers convey realized that a skillful agreement of appointment as well as fourth dimension API is also of import for a skillful Java developer. That's the principal argue of increasing number of date, fourth dimension as well as calendar based Java interview questions inward recent time, peculiarly inward 2017.
Since Java evolution task marketplace position is real skillful at this instant as well as at that topographic point are a lot of jobs open, peculiarly inward investment banking domain inward Asia Pacific, its likely the best fourth dimension to modify your job, especially if you lot are stuck amongst no learning, no salary growth as well as non a pregnant bonus or incentives inward concluding a brace of years.
Apart from stability, growth is real of import because if you lot don't motility forrad you lot volition last stuck as well as eventually motility backward, so changing task is every bit of import every bit sticking to a task which is working for you.
Does SimpleDateFormat last rubber to usage inward the multithreaded program? (answer)
No, unfortunately, DateFormat as well as all its implementations including SimpleDateFormat is non thread-safe, hence, should non last used inward the multi-threaded plan until external thread-safety measures are applied e.g. confining SimpleDateFormat object into a ThreadLocal variable. If you lot don't practise that, you lot volition acquire an wrong consequence piece parsing or formatting dates inward Java. Though, for all practical appointment fourth dimension purpose, I highly recommend joda-time library.
How practise you lot format a appointment inward Java? e.g. inward the ddMMyyyy format? (answer)
You tin either usage SimpleDateFormat cast or joda-time library to format the appointment inward Java. DateFormat cast allows you lot to format appointment on many pop formats. Please run across the respond for code samples to format the appointment into unlike formats e.g. dd-MM-yyyy or ddMMyyyy.
Can you lot state about divergence betwixt sometime as well as novel Date Time API of Java 8?
Even though novel Date as well as Time API are a completely novel API, you lot tin deduce next divergence betwixt them:
1) In sometime API, Date was mutable but inward Java 8 all appointment as well as fourth dimension classes e.g. LocalDate, LocalTime or LocalDateTime are Immutable.
2) In sometime API, SimpleDateFormat was non thread-safe, but inward Java 8 Formatter are thread-safe.
3) In sometime Date as well as Calendar API, Year starts amongst 1900, Months starts amongst 0, which is corrected inward Java 8, hither numbers brand to a greater extent than sense.
4) Old Date as well as Calendar API has exactly i cast Date to stand upwardly for appointment as well as time, but Java 8 has separated classes for Date as well as Time e.g. LocalDate as well as LocalTime
Which appointment the next Date illustration represent?
Date aDate = novel Date(2015, 12, 25, 20, 40);
This is a actually tricky enquiry for whatever casual Java developers who convey non written appointment as well as time-based code for himself because this volition non stand upwardly for the Christmas twenty-four hours or 25th Dec 2015. This code has got 2 bugs, first, the twelvemonth starts from 1900 to, to stand upwardly for 2015, you lot demand to top 115 i.e. 2015-1900. The 2nd number amongst this code is that calendar month is non correct. The calendar month starts from 0, so Dec would eleven non 12, interesting right? That's why you lot should novel Date as well as Time API from Java 8, which solves all these issues.
Does Date cast last Immutable inward Java?
No, Date is non immutable. You tin modify it's internal to stand upwardly for a unlike date. This is the argue that when you lot convey a fellow member stand upwardly for Date, you lot must last careful non to leak its reference exterior using getDate() method, because so the customer tin modify the country of the Immutable object, instead a re-create should last returned to the customer every bit suggested inward Effective Java.
How practise you lot re-create a Date inward Java? (answer)
It's a unproblematic enquiry to answer. The Date cast implements the clone() method, so exactly telephone yell upwardly date.clone() to practise a re-create of the Date object inward Java.
What is the human relationship betwixt java.sql.Date as well as java.util.Date? (answer)
This is i of the real interesting questions every bit non many developers know this fine but obvious detail. The java.sql.Date extends java.util.Date as well as suppress all time-related methods to human activeness every bit exactly a appointment class. This is inward forthwith violation of Liskov commutation principle.
Can you lot format Calendar inward Java?
No, Calendar cannot last formatted inward Java. You tin solely format dates.
How practise you lot convert a Calendar to Date as well as vice-versa?
Well, you lot tin usage the Calendar.setTime() as well as Calendar.getTime() method to convert the Calendar to Date as well as vice-versa.
What is the equivalent of Date cast inward Java 8?
The Instance cast is equivalent of java.util.Date inward Java 8 because it also represents a millisecond value or an illustration inward timescale. Java 8 has also added conversion method e.g. toInstant() as well as fromDate() to convert illustration to java.util.Date as well as vice-versa. See Java SE 8 for Really Impatient By Cay S. Horstmann for to a greater extent than details.
How practise you lot convert a millisecond to Date inward Java? (answer)
One of the simplest enquiry to answer, you lot tin telephone yell upwardly the getTime() method which returns the millisecond from the Epoch.
How practise you lot acquire calendar month as well as twelvemonth from a Date object inward Java? (answer)
You tin convert a Date to Calendar as well as so usage its get() method amongst diverse fields to acquire the month, year, twenty-four hours of calendar week as well as other appointment particulars e.g.
int twenty-four hours = 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
How practise you lot convert XMLGregorianCalendar to Date inward Java? (answer)
I convey discussed this occupation before, delight depository fiscal establishment gibe the link for the detailed answer.
How practise you lot acquire the electrical current fourth dimension inward GMT inward Java? (answer)
The Java appointment is independent of fourth dimension as well as display fourth dimension inward a electrical current fourth dimension zone solely if you lot impress them. So, inward gild to convert the electrical current fourth dimension inward GMT, you lot demand to usage Calendar amongst fourth dimension zone every bit shown inward the given answer.
How practise you lot add together as well as subtract a day, calendar month as well as twelvemonth inward a Date object? (answer)
This is i of the mutual twenty-four hours to twenty-four hours task of a Java developer, you lot tin usage the code shared inward the respond for adding or subtracting a twenty-four hours or calendar month from the Date object.
How practise you lot compare 2 dates inward Java to depository fiscal establishment gibe if they are equal? (answer)
This is i of the easier questions you lot volition run across inward damage of science checking on Date classes. The java.util.Date cast implements the equals() method, which returns truthful if both Dates is same as well as faux otherwise.
How practise you lot notice if i appointment comes earlier or subsequently about other appointment inward Java? (answer)
This is the follow-up enquiry of the previous question. Interviewer farther checks candidate's appointment comparing science past times hollo for this question. The respond is simple, the java.util.Date cast provides before() as well as after() method which returns truthful as well as faux if the appointment on which method is called comes earlier or subsequently the other appointment passed every bit a method argument.
How practise you lot convert java.util.Date to java.sql.Date inward 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 exactly acquire the fourth dimension inward millisecond as well as passed it to SQL appointment every bit shown below:
Date at nowadays = novel Date();
java.sql.Date sqlDate = novel java.sql.Date(now.getTime());
Simple as well as tardily right? but at that topographic point are about interesting follow-up questions when you lot write this code, I propose you lot depository fiscal establishment gibe the respond link for to a greater extent than detailed discussion, where I convey answered those follow-up questions every bit well.
How to convert local fourth dimension to GMT inward Java? (answer)
This is similar to i of the previous questions where nosotros demand to acquire the electrical current fourth dimension inward GMT
How practise you lot demo timezone inward formatted appointment inward Java? (answer)
run across the respond link for a code example
The divergence betwixt java.util.Date as well as java.sql.Date inward Java? (answer)
There are many divergence betwixt them but the most of import i is that java.sql.Date is from JDBC bundle as well as it acts every bit converted betwixt Date as well as Time information types inward database as well as Date inward Java.
How practise you lot calculate the divergence betwixt 2 dates inward Java? (program)
There are multiple ways to calculate the divergence betwixt 2 dates inward Java e.g. you lot tin acquire the long millisecond values from 2 dates as well as acquire the divergence but that's non real valuable, you lot by as well as large demand the divergence inward days or hours etc. See the plan to larn to a greater extent than most those differences.
How practise you lot convert a String(YYYYMMDD) to appointment inward Java? (answer)
You tin usage SimpleDateFormat prior to JDK 8 as well as DateTimeFormatter along amongst format as well as parse method to convert a String to appointment inward Java.
That's all most the date, time, as well as Calendar based Java Interview Questions. It's real of import for a Java developer to convey a enterprise agreement of Date as well as Time API of Java, both sometime as well as novel because you lot volition non notice Java 8 inward every projection you lot work. You nevertheless demand to
Other Java Interview Questions Articles.
Top 10 Spring Framework Interview Questions amongst Answers (see here)
Since Java evolution task marketplace position is real skillful at this instant as well as at that topographic point are a lot of jobs open, peculiarly inward investment banking domain inward Asia Pacific, its likely the best fourth dimension to modify your job, especially if you lot are stuck amongst no learning, no salary growth as well as non a pregnant bonus or incentives inward concluding a brace of years.
Apart from stability, growth is real of import because if you lot don't motility forrad you lot volition last stuck as well as eventually motility backward, so changing task is every bit of import every bit sticking to a task which is working for you.
Top 10 Date, Time as well as Calendar Interview Questions as well as Answers
I convey been sharing interview questions on diverse Java topics from concluding a brace of years e.g. multithreading, collections, pattern patterns etc, but i topic which I haven't touched yet was appointment as well as fourth dimension as well as that's why I idea to part about of the interesting appointment as well as time-based questions from recent Java interviews. In this article, you lot volition notice those.Does SimpleDateFormat last rubber to usage inward the multithreaded program? (answer)
No, unfortunately, DateFormat as well as all its implementations including SimpleDateFormat is non thread-safe, hence, should non last used inward the multi-threaded plan until external thread-safety measures are applied e.g. confining SimpleDateFormat object into a ThreadLocal variable. If you lot don't practise that, you lot volition acquire an wrong consequence piece parsing or formatting dates inward Java. Though, for all practical appointment fourth dimension purpose, I highly recommend joda-time library.
How practise you lot format a appointment inward Java? e.g. inward the ddMMyyyy format? (answer)
You tin either usage SimpleDateFormat cast or joda-time library to format the appointment inward Java. DateFormat cast allows you lot to format appointment on many pop formats. Please run across the respond for code samples to format the appointment into unlike formats e.g. dd-MM-yyyy or ddMMyyyy.
Can you lot state about divergence betwixt sometime as well as novel Date Time API of Java 8?
Even though novel Date as well as Time API are a completely novel API, you lot tin deduce next divergence betwixt them:
1) In sometime API, Date was mutable but inward Java 8 all appointment as well as fourth dimension classes e.g. LocalDate, LocalTime or LocalDateTime are Immutable.
2) In sometime API, SimpleDateFormat was non thread-safe, but inward Java 8 Formatter are thread-safe.
3) In sometime Date as well as Calendar API, Year starts amongst 1900, Months starts amongst 0, which is corrected inward Java 8, hither numbers brand to a greater extent than sense.
4) Old Date as well as Calendar API has exactly i cast Date to stand upwardly for appointment as well as time, but Java 8 has separated classes for Date as well as Time e.g. LocalDate as well as LocalTime
Which appointment the next Date illustration represent?
Date aDate = novel Date(2015, 12, 25, 20, 40);
This is a actually tricky enquiry for whatever casual Java developers who convey non written appointment as well as time-based code for himself because this volition non stand upwardly for the Christmas twenty-four hours or 25th Dec 2015. This code has got 2 bugs, first, the twelvemonth starts from 1900 to, to stand upwardly for 2015, you lot demand to top 115 i.e. 2015-1900. The 2nd number amongst this code is that calendar month is non correct. The calendar month starts from 0, so Dec would eleven non 12, interesting right? That's why you lot should novel Date as well as Time API from Java 8, which solves all these issues.
Does Date cast last Immutable inward Java?
No, Date is non immutable. You tin modify it's internal to stand upwardly for a unlike date. This is the argue that when you lot convey a fellow member stand upwardly for Date, you lot must last careful non to leak its reference exterior using getDate() method, because so the customer tin modify the country of the Immutable object, instead a re-create should last returned to the customer every bit suggested inward Effective Java.
How practise you lot re-create a Date inward Java? (answer)
It's a unproblematic enquiry to answer. The Date cast implements the clone() method, so exactly telephone yell upwardly date.clone() to practise a re-create of the Date object inward Java.
What is the human relationship betwixt java.sql.Date as well as java.util.Date? (answer)
This is i of the real interesting questions every bit non many developers know this fine but obvious detail. The java.sql.Date extends java.util.Date as well as suppress all time-related methods to human activeness every bit exactly a appointment class. This is inward forthwith violation of Liskov commutation principle.
Can you lot format Calendar inward Java?
No, Calendar cannot last formatted inward Java. You tin solely format dates.
How practise you lot convert a Calendar to Date as well as vice-versa?
Well, you lot tin usage the Calendar.setTime() as well as Calendar.getTime() method to convert the Calendar to Date as well as vice-versa.
What is the equivalent of Date cast inward Java 8?
The Instance cast is equivalent of java.util.Date inward Java 8 because it also represents a millisecond value or an illustration inward timescale. Java 8 has also added conversion method e.g. toInstant() as well as fromDate() to convert illustration to java.util.Date as well as vice-versa. See Java SE 8 for Really Impatient By Cay S. Horstmann for to a greater extent than details.
How practise you lot convert a millisecond to Date inward Java? (answer)
One of the simplest enquiry to answer, you lot tin telephone yell upwardly the getTime() method which returns the millisecond from the Epoch.
How practise you lot acquire calendar month as well as twelvemonth from a Date object inward Java? (answer)
You tin convert a Date to Calendar as well as so usage its get() method amongst diverse fields to acquire the month, year, twenty-four hours of calendar week as well as other appointment particulars e.g.
int twenty-four hours = 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
How practise you lot convert XMLGregorianCalendar to Date inward Java? (answer)
I convey discussed this occupation before, delight depository fiscal establishment gibe the link for the detailed answer.
How practise you lot acquire the electrical current fourth dimension inward GMT inward Java? (answer)
The Java appointment is independent of fourth dimension as well as display fourth dimension inward a electrical current fourth dimension zone solely if you lot impress them. So, inward gild to convert the electrical current fourth dimension inward GMT, you lot demand to usage Calendar amongst fourth dimension zone every bit shown inward the given answer.
How practise you lot add together as well as subtract a day, calendar month as well as twelvemonth inward a Date object? (answer)
This is i of the mutual twenty-four hours to twenty-four hours task of a Java developer, you lot tin usage the code shared inward the respond for adding or subtracting a twenty-four hours or calendar month from the Date object.
How practise you lot compare 2 dates inward Java to depository fiscal establishment gibe if they are equal? (answer)
This is i of the easier questions you lot volition run across inward damage of science checking on Date classes. The java.util.Date cast implements the equals() method, which returns truthful if both Dates is same as well as faux otherwise.
How practise you lot notice if i appointment comes earlier or subsequently about other appointment inward Java? (answer)
This is the follow-up enquiry of the previous question. Interviewer farther checks candidate's appointment comparing science past times hollo for this question. The respond is simple, the java.util.Date cast provides before() as well as after() method which returns truthful as well as faux if the appointment on which method is called comes earlier or subsequently the other appointment passed every bit a method argument.
How practise you lot convert java.util.Date to java.sql.Date inward 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 exactly acquire the fourth dimension inward millisecond as well as passed it to SQL appointment every bit shown below:
Date at nowadays = novel Date();
java.sql.Date sqlDate = novel java.sql.Date(now.getTime());
Simple as well as tardily right? but at that topographic point are about interesting follow-up questions when you lot write this code, I propose you lot depository fiscal establishment gibe the respond link for to a greater extent than detailed discussion, where I convey answered those follow-up questions every bit well.
How to convert local fourth dimension to GMT inward Java? (answer)
This is similar to i of the previous questions where nosotros demand to acquire the electrical current fourth dimension inward GMT
How practise you lot demo timezone inward formatted appointment inward Java? (answer)
run across the respond link for a code example
The divergence betwixt java.util.Date as well as java.sql.Date inward Java? (answer)
There are many divergence betwixt them but the most of import i is that java.sql.Date is from JDBC bundle as well as it acts every bit converted betwixt Date as well as Time information types inward database as well as Date inward Java.
How practise you lot calculate the divergence betwixt 2 dates inward Java? (program)
There are multiple ways to calculate the divergence betwixt 2 dates inward Java e.g. you lot tin acquire the long millisecond values from 2 dates as well as acquire the divergence but that's non real valuable, you lot by as well as large demand the divergence inward days or hours etc. See the plan to larn to a greater extent than most those differences.
How practise you lot convert a String(YYYYMMDD) to appointment inward Java? (answer)
You tin usage SimpleDateFormat prior to JDK 8 as well as DateTimeFormatter along amongst format as well as parse method to convert a String to appointment inward Java.
That's all most the date, time, as well as Calendar based Java Interview Questions. It's real of import for a Java developer to convey a enterprise agreement of Date as well as Time API of Java, both sometime as well as novel because you lot volition non notice Java 8 inward every projection you lot work. You nevertheless demand to
Other Java Interview Questions Articles.
Top 10 Spring Framework Interview Questions amongst Answers (see here)
xv Data Structure as well as Algorithm Questions from Java Interviews (read here)
20 Great Java Design Pattern Questions asked on Interviews (see here)
10 often asked Servlet Interview Questions amongst 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)
xv Java NIO as well as Networking Interview Questions amongst Answers (see here)
Top 10 Trick Java Interview Questions as well as Answers (see here)
Top forty Core Java Phone Interview Questions amongst answers (list)
Thanks for reading this article so far. If you lot similar these questions so delight part amongst your friends as well as colleagues too.
More Resources
Java Programming Interview Exposed
Cracking the Coding Interview: 150 Programming Questions as well as Solutions
Elements of Programming Interviews: 300 Questions as well as Solutions
20 Great Java Design Pattern Questions asked on Interviews (see here)
10 often asked Servlet Interview Questions amongst 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)
xv Java NIO as well as Networking Interview Questions amongst Answers (see here)
Top 10 Trick Java Interview Questions as well as Answers (see here)
Top forty Core Java Phone Interview Questions amongst answers (list)
More Resources
Java Programming Interview Exposed
Cracking the Coding Interview: 150 Programming Questions as well as Solutions
Elements of Programming Interviews: 300 Questions as well as Solutions

0 Response to "Top ten Java Date, Time as well as Calendar Interview Questions Answers"
Posting Komentar