Tuesday, May 15, 2007

What do you understand by Synchronization?
Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access one resource at a time. In non synchronized multithreaded application, it is possible for one thread to modify a shared object while another thread is in the process of using or updating the object's value. Synchronization prevents such type of data corruption.

Wednesday, March 14, 2007

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

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.

Tuesday, December 12, 2006

Q: What is difference between jvm and a interpreter?

Acronym for Java Virtual Machine. An abstract computing machine, or virtual machine, JVM is a platform-independent execution environment that converts Java bytecode into machine language and executes it.

interpreter is a program that executes instructions written in a high-level language. An interpreter translates high-level instructions into an intermediate form, which it then executes. In contrast, a compiler translates high-level instructions directly into machine language. Compiled programs generally run faster than interpreted programs.

So JVM is like in an interpreter

Friday, November 10, 2006

Explain different ways of creating a thread?

Threads can be used by either :

  • Extending the Thread class
  • Implementing the Runnable interface.
The runnable interface is preferred, as it does not require your object to inherit a thread because when you need multiple inheritance, only interfaces can help you. In the above example we had to extend the Base class so implementing runnable interface is an obvious choice. Also note how the threads are started in each of the different cases as shown in the code sample.

Friday, October 13, 2006

Explain the directory structure of a WEB application?
The directory structure of a Web application
consists of two parts:

1. Public resource directory (document root): The document root is where JSP pages, client-side classes and archives, and static Web resources are stored.

2. A private directory called WEB-INF: which contains following files and directories:

- web.xml : Web application deployment descriptor.
-*.tld : Tag library descriptor files.
-classes : A directory that contains server side classes like servlets, utility classes, JavaBeans etc.
-lib : A directory where JAR (archive files of tag libraries, utility libraries used by the server side classes) files are stored.

JSP resources usually reside directly or under subdirectories of the document root, which are directly accessible to the user through the URL. If you want to protect your Web resources then hiding the JSP files behind the WEB-INF directory can protect the JSP files from direct access.

Wednesday, September 20, 2006

Tell me about JSP best practices?

Separate HTML code from the Java code: Combining HTML and Java code in the same source code can make the code less readable. Mixing HTML and scriplet will make the code extremely difficult to read and maintain. The display or behaviour logic can be implemented as a custom tags by the Java developers and Web designers can use these Tags as the ordinary XHTML tags.

Place data access logic in JavaBeans: The code within the JavaBean is readily accessible to other JSPs and Servlets.

Factor shared behaviour out of Custom Tags into common JavaBeans classes: The custom tags are not used outside JSPs. To avoid duplication of behaviour or business logic, move the logic into JavaBeans and get the custom tags to utilize the beans.

Choose the right “include” mechanism: What are the differences between static and a dynamic include? Using includes will improve code reuse and maintenance through modular design.

Use style sheets (e.g. css), template mechanism (e.g. struts tiles etc) and appropriate comments (both hidden and output comments).

Thursday, September 14, 2006

What is the difference between final, finally and finalize() in Java?

final - keyword is constant declaration.

finally - handles exception. The finally block is optional and provides a mechanism to clean up regardless of what happens within the try block (except System.exit(0) call). Use the finally block to close files or to release other system resources like database connections, statements etc.

finalize() - method helps in garbage collection. A method that is invoked before an object is discarded by the garbage collector, allowing it to clean up its state. Should not be used to release non-memory resources like file handles, sockets, database connections etc because Java has only a finite number of these resources and you do not know when the garbage collection is going to kick in to release these non-memory resources through the finalize() method.