khaleel. Powered by Blogger.

Java Interview Questions

Monday 6 June 2011

1)How will you convert a String array to an ArrayList object?

A.String[] stringArray = new String[] {"x", "y", "Z"};
   List list = Arrays.asList(stringArray);

2)What's the difference between the methods sleep() and wait()

A.The code sleep(1000); puts thread aside for exactly one second. The code wait(1000),   

causes a wait of up to one second. A thread could stop waiting earlier if it receives   

the notify() or notifyAll() call. The method wait() is defined in the class Object and     

the method sleep() is defined in the class Thread.

3)You are planning to do an indexed search in a list of objects. Which of the two Java

collections should you use: ArrayList or LinkedList?

A.ArrayList

4)How would you make a copy of an entire Java object with its state?

A.Have this class implement Cloneable interface and call its method clone().

5)There are two classes: A and B. The class B need to inform a class A when some important

event has happened. What Java technique would you use to implement it?

A. If these classes are threads then consider notify() or notifyAll(). For regular classes

one can use the Observer interface.

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...
Promote Your Blog

About This Blog

This blog is for java lovers

Total Pageviews

About Me

khaleel-bapatla
BAPATLA, ap, India
simple and honest
View my complete profile

  © Blogger template On The Road by Ourblogtemplates.com 2009

Back to TOP