General Java Interveiw Questions

Started by nithyasubramanian, Jan 12, 2009, 08:47 PM

Previous topic - Next topic

nithyasubramanian

Q: What is the difference between an Interface and an Abstract class?

A: An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.

Q: What is the purpose of garbage collection in Java, and when is it used?

A: The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.

Q: Describe synchronization in respect to multithreading.

A: With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchonization, it is possible for one thread to modify a shared variable while another thread is in the process of using or updating same shared variable. This usually leads to significant errors.
   
Q :Explain different way of using thread?

A :The thread could be implemented by using runnable interface or by inheriting from the Thread class. The former is more advantageous, 'cause when you are going for multiple inheritance..the only interface can help.

Q: What is the difference between a constructor and a method?

A: A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator.
A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.

Thanks and Regards
- Nithya Subramanian
Kenvivo Communications
http://nithya-subramanian.blogspot.com/

kavee



Give one Example of static Synchronized method in JDBC API?
A. getConnection() method in DriverManager class.Which is used to get object of Connection interface.

What is a Connection?A. Connection is an interface, which is used to make a connection between client and Database (ie opening a session with a particular database).

What is the difference between execute() ,executeUpdate() and executeQuery() ? where we will use them?
Ans:
execute() method returns a boolean value (ie if the given query  returns a resutset then it returns true else false), so depending upon  the return value we can get the ResultSet object (getResultset()) or  we can know how many rows have bean affected by our query (getUpdateCount()).That is we can use this method for Fetching queries and Non-Fetching queries.
Fetching queries are the queries which are used to fetch the records from database (ie which returns resutset)   ex: Select * from emp.

Non-Fetching queries are the queries which are used to update,insert,create or delete the records from database    ex: update emp set sal=10000 where empno=7809.
executeUpdate() method is used for nonfetching queries.which returns int value.
executeQuery() method is used for fetching queries which returns ResulSet object ,Which contains methods to fetch the values.

How is jndi useful for Database connection?
Ans: Server identified the object with JDNI name
JNDI (java naming directory interface)

What are the uses of jndi?
Ans: The role of the JNDI API in the J2EE platform is two fold.
a) It provides the means to perform standard operations to a directory service resource such as LDAP (Lightweight Directory Access Protocol),Novell Directory Services, or Netscape Directory Services.
  b) A J2EE application utilizes JNDI to look up interfaces used to create, amongst other things, EJBs, and JDBC connection.

How vendor Naming registry supports JNDI?


What is the difference between JDBC and ODBC?
Ans:  a) OBDC is for Microsoft and JDBC is for Java applications.
b)   ODBC can't be directly used with Java because it uses a C interface.
c)   ODBC  makes use of pointers which have been removed totally from Java.
d)   ODBC mixes simple and advanced features together and has complex options for simple queries. But JDBC is designed to keep things simple while allowing advanced capabilities when required.
e)   ODBC requires manual installation of the ODBC driver manager and driver on all client machines. JDBC drivers are written in Java and JDBC code is automatically installable, secure, and portable on all platforms.