Interview Questions and Answers for 'Date' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Date' - 14 question(s) found - Order By Newest

  Q1. Explain OOPs

or

Explain OOPs Principles

or

Explain OOPs Concepts

or

Explain OOPs features

or

Tell me something about OOPs
Core Java
Ans. OOPs or Object Oriented Programming is a Programming model which is organized around Objects instead of processes. Instead of a process calling series of processes, this model stresses on communication between objects. Objects that all self sustained, provide security by encapsulating it's members and providing abstracted interfaces over the functions it performs. OOP's facilitate the following features

1. Inheritance for Code Reuse
2. Abstraction for modularity, maintenance and agility
3. Encapsulation for security and protection
4. Polymorphism for flexibility and interfacing

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     oops  oops features     Asked in 260 Companies      basic        frequent


 Q2. If you are given a choice to implement the code to either Insert a Record or Update if already exist, Which approach will you follow ?

1. Insert into the DB Table. If exception occurs, update the existing record.
2. Check if the record exists and update it if it exists, If not insert a new record.
Solution
Ans. In first case, there would be 2 DB calls in worst case and 1 in best case. In 2nd approach there will be always 2 DB calls.

Decision on the approach should depend on the following considerations -

1. How costly is the call to DB ? Are we using indices , hibernate etc

If calls to DB are costly , 1st approach should be the choice.

2. Exception Book keeping load upon exception.

The benefit of saving 1st call in approach 1 should be bigger than the Book keeping for the exception.

3. Probability of the exception in first apparoach.

If the DB Table is almost empty, it makes sense to follow Approach 1 as majority of the 1st calls will pass through without exception.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     database   insert-update   db exceution plan   db strategy   design   architecture   technical lead


 Q3. Will this code Work ? If not , Why ?

java.util.Calendar c = new java.util.Calendar();
Core Java
Ans. No. It gives the error "Cannot Instantiate the type Calendar". Calendar is an abstract class and hence Calendar object should be instantiated using Calendar.getInstance().

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   date   calendar   abstract class   yes-no


 Q4. Is java.util.Date an abstract Class ? Is java.util.Calendar an abstract Class ?Core Java
Ans. Date is not a abstract class whereas Calendar is.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   date   calendar   abstract class


 Q5. What will the following code print ?

java.util.Calendar c = java.util.Calendar.getInstance();
c.add(Calendar.MONTH, 5);
System.out.println(c.getTime());
Core Java
Ans. Date and Time after 5 months from now.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   date   calendar   scjp   ocjp   coding   code


 Q6. Which of the following code is correct ?

a. DateFormat df = DateFormat.getInstance();
b. DateFormat df = DateFormat.getDateInstance();
c. DateFormat df = DateFormat.getInstance(DateFormat.FULL);
d. DateFormat df = DateFormat.getDateInstance(DateFormat.FULL);
Core Java
Ans. All except c are correct.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   date   dateformat


 Q7. What is the use of parse method in DateFormat ?
Ans. It is used to parse String to get the Date Object with initialized date.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   date   dateformat


 Q8. Which of the following code is correct ?

a. Date date = DateFormat.newInstance(DateFormat.LONG, Locale.US).parse(str);

b. Date date = DateFormat.newInstance(DateFormat.LONG, Locale.US).format(str);

c. Date date = DateFormat.getDateInstance(DateFormat.LONG, Locale.US).parse(str);
Core Java
Ans. c

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   java.util   date   dateformat


 Q9. What will the following code do ?

String dateStr = "2011 11 19";
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = dateFormat.parse(dateStr);
System.out.println(date);

Ans. It will throw the ParseException as the date format doesn't abide with the format of the specified date.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     date   utility classes   dateformat   exception   parseexception


 Q10. Name few Date and Time Classes you have used in your projects ?
Ans. http://www.buggybread.com/2015/02/java-util-date-time-classes-and.html

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   util   java.util.date   time


 Q11. Which interfaces are implemented by BatchUpdateException?
Ans. [Iterable]

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   BatchUpdateException   include


 Q12. What is the difference between following time formats ?

hh:mm:ss
HH:mm:ss
kk:mm:ss
KK:mm:ss
Core Java
Ans. hh= hours in 1-12 format
HH= hours in 0-23 format
kk = Hours in 1-24 format
KK= hours in 0-11 format

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Date  Date Time Format  Date Time


 Q13. Write a Program to validate an email addressCore Java
Ans. public class Class{
public static void main(String[] args){
String str = "xyz@123.com";

if(!str.contains("@") && !str.contains(".") && (str.indexOf('.') < str.indexOf('@'))){
System.out.println("Not a Valid Email Address");
}
}
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     validate an email address  coding  code     Asked in 3 Companies


 Q14. Write a Program to find age by birth date ?Core Java
Ans. LocalDate today = LocalDate.now();
LocalDate birthday = LocalDate.of(1960, Month.JANUARY, 1);
Period p = Period.between(birthday, today); //Now access the values as below
System.out.println(period.getDays());
System.out.println(period.getMonths());
System.out.println(period.getYears());

  Sample Code for LocalDate

  Sample Code for Period

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     coding  code  date  LocalDate  Period     Asked in 1 Companies



Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: