1) What is the purpose of garbage collection in Java, and when is it used?
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.
2) Describe synchronization in respect to multithreading.
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.
>
3) How is JavaBeans differ from Enterprise JavaBeans?
The JavaBeans architecture is meant to provide a format for general-purpose components. On the other hand, the Enterprise JavaBeans architecture provides a format for highly specialized business logic components.
4) In what ways do design patterns help build better software?
Design patterns helps software developers to reuse successful designs and architectures. It helps them to choose design alternatives that make a system reusuable and avoid alternatives that compromise reusability through proven techniques as design patterns.
5) Describe 3-Tier Architecture in enterprise application development.
In 3-tier architecture, an application is broken up into 3 separate logical layers, each with a well-defined set of interfaces. The presentation layer typically consists of a graphical user interfaces. The business layer consists of the application or business logic, and the data layer contains the data that is needed for the application.
Advanced Enterprise Java interview questions
Labels: Advanced EJB, Enterprise Java, Interview Questions, J2EEQuestion 1: What is the three tier model?
Answer: It is the presentation, logic, backend
Question 2: Why do we have index table in the database?
Answer: Because the index table contain the information of the other tables. It will
be faster if we access the index table to find out what the other contain.
Question 3: Give an example of using JDBC access the database.
Answer:
try
{
Class.forName("register the driver");
Connection con = DriverManager.getConnection("url of db", "username","password");
Statement state = con.createStatement();
state.executeUpdate("create table testing(firstname varchar(20), lastname varchar(20))");
state.executeQuery("insert into testing values(’phu’,'huynh’)");
state.close();
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
Question 4: What is the different of an Applet and a Java Application
Answer: The applet doesn’t have the main function
Question 5: How do we pass a reference parameter to a function in Java?
Answer: Even though Java doesn’t accept reference parameter, but we can
pass in the object for the parameter of the function.
For example in C++, we can do this:
void changeValue(int& a)
{
a++;
}
void main()
{
int b=2;
changeValue(b);
}
however in Java, we cannot do the same thing. So we can pass the
the int value into Integer object, and we pass this object into the
the function. And this function will change the object.
Describe what happens when an object is created in Java?
Several things happen in a particular order to ensure the object is constructed properly:
1. Memory is allocated from heap to hold all instance variables and implementation-specific data of the object and its superclasses. Implementation-specific data includes pointers to class and method data.
2. The instance variables of the objects are initialized to their default values.
3. The constructor for the most derived class is invoked. The first thing a constructor does is call the constructor for its uppercase. This process continues until the constructor for java.lang.Object is called, as java.lang.Object is the base class for all objects in java.
4. Before the body of the constructor is executed, all instance variable initializers and initialization blocks are executed. Then the body of the constructor is executed. Thus, the constructor for the base class completes first and constructor for the most derived class completes last.
In Java, you can create a String object as below : String str = "abc"; & String str = new String("abc"); Why cant a button object be created as : Button bt = "abc"? Why is it compulsory to create a button object as: Button bt = new Button("abc"); Why this is not compulsory in String’s case?
Button bt1= "abc"; It is because "abc" is a literal string (something slightly different than a String object, by-the-way) and bt1 is a Button object. That simple. The only object in Java that can be assigned a literal String is java.lang.String. Important to not that you are NOT calling a java.lang.String constuctor when you type String s = "abc"; For example String x = "abc"; String y = "abc"; refer to the same object. While String x1 = new String("abc");What is the advantage of OOP?
String x2 = new String("abc"); refer to two different objects.
You will get varying answers to this question depending on whom you ask. Major advantages of OOP are:What are the main differences between Java and C++?
1. Simplicity: software objects model real world objects, so the complexity is reduced and the program structure is very clear;
2. Modularity: each object forms a separate entity whose internal workings are decoupled from other parts of the system;
3. Modifiability: it is easy to make minor changes in the data representation or the procedures in an OO program. Changes inside a class do not affect any other part of a program, since the only public interface that the external world has to a class is through the use of methods;
4. Extensibility: adding new features or responding to changing operating environments can be solved by introducing a few new objects and modifying some existing ones;
5. Maintainability: objects can be maintained separately, making locating and fixing problems easier;
6. Re-usability: objects can be reused in different programs
Everything is an object in Java( Single root hierarchy as everything gets derived from java.lang.Object). Java does not have all the complicated aspects of C++ ( For ex: Pointers, templates, unions, operator overloading, structures etc..) The Java language promoters initially said "No pointers!", but when many programmers questioned how you can work without pointers, the promoters began saying "Restricted pointers." You can make up your mind whether it’s really a pointer or not. In any event, there’s no pointer arithmetic. There are no destructors in Java. (automatic garbage collection), Java does not support conditional compile (#ifdef/#ifndef type). Thread support is built into java but not in C++. Java does not support default arguments. There’s no scope resolution operator :: in Java. Java uses the dot for everything, but can get away with it since you can define elements only within a class. Even the method definitions must always occur within a class, so there is no need for scope resolution there either. There’s no "goto " statement in Java. Java doesn’t provide multiple inheritance (MI), at least not in the same sense that C++ does. Exception handling in Java is different because there are no destructors. Java has method overloading, but no operator overloading. The String class does use the + and += operators to concatenate strings and String expressions use automatic type conversion, but that’s a special built-in case. Java is interpreted for the most part and hence platform independentWhat are interfaces?
Interfaces provide more sophisticated ways to organize and control the objects in your system.How can you achieve Multiple Inheritance in Java?
The interface keyword takes the abstract concept one step further. You could think of it as a “pure” abstract class. It allows the creator to establish the form for a class: method names, argument lists, and return types, but no method bodies. An interface can also contain fields, but The interface keyword takes the abstract concept one step further. You could think of it as a “pure” abstract class. It allows the creator to establish the form for a class: method names, argument lists, and return types, but no method bodies. An interface can also contain fields, but an interface says: “This is what all classes that implement this particular interface will look like.” Thus, any code that uses a particular interface knows what methods might be called for that interface, and that’s all. So the interface is used to establish a “protocol” between classes. (Some object-oriented programming languages have a keyword called protocol to do the same thing.) Typical example from "Thinking in Java":
import java.util.*;
interface Instrument {
int i = 5; // static & final
// Cannot have method definitions:
void play(); // Automatically public
String what();
void adjust();
}
class Wind implements Instrument {
public void play() {
System.out.println("Wind.play()");
public String what() { return "Wind"; }
public void adjust() {}
}
Java’s interface mechanism can be used to implement multiple inheritance, with one important difference from c++ way of doing MI: the inherited interfaces must be abstract. This obviates the need to choose between different implementations, as with interfaces there are no implementations.
interface CanFight {What is the difference between StringBuffer and String class?
void fight();
interface CanSwim {
void swim();
interface CanFly {
void fly();
class ActionCharacter {
public void fight() {}
class Hero extends ActionCharacter implements CanFight, CanSwim, CanFly {
public void swim() {}
public void fly() {}
}
You can even achieve a form of multiple inheritance where you can use the *functionality* of classes rather than just the interface:
interface A {
void methodA();
}
class AImpl implements A {
void methodA() { //do stuff }
}
interface B {
void methodB();
}
class BImpl implements B {
void methodB() { //do stuff }
}
class Multiple implements A, B {
private A a = new A();
private B b = new B();
void methodA() { a.methodA(); }
void methodB() { b.methodB(); }
}
This completely solves the traditional problems of multiple inheritance in C++ where name clashes occur between multiple base classes. The coder of the derived class will have to explicitly resolve any clashes. Don’t you hate people who point out minor typos? Everything in the previous example is correct, except you need to instantiate an AImpl and BImpl. So class Multiple would look like this:
class Multiple implements A, B {
private A a = new AImpl();
private B b = new BImpl();
void methodA() { a.methodA(); }
void methodB() { b.methodB(); }
}
A string buffer implements a mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls. The String class represents character strings. All string literals in Java programs, such as "abc" are constant and implemented as instances of this class; their values cannot be changed after they are created. Strings in Java are known to be immutable. What it means is that every time you need to make a change to a String variable, behind the scene, a "new" String is actually being created by the JVM. For an example: if you change your String variable 2 times, then you end up with 3 Strings: one current and 2 that are ready for garbage collection. The garbage collection cycle is quite unpredictable and these additional unwanted Strings will take up memory until that cycle occurs. For better performance, use StringBuffers for string-type data that will be reused or changed frequently. There is more overhead per class than using String, but you will end up with less overall classes and consequently consume less memory. Describe, in general, how java’s garbage collector works? The Java runtime environment deletes objects when it determines that they are no longer being used. This process is known as garbage collection. The Java runtime environment supports a garbage collector that periodically frees the memory used by objects that are no longer needed. The Java garbage collector is a mark-sweep garbage collector that scans Java’s dynamic memory areas for objects, marking those that are referenced. After all possible paths to objects are investigated, those objects that are not marked (i.e. are not referenced) are known to be garbage and are collected. (A more complete description of our garbage collection algorithm might be "A compacting, mark-sweep collector with some conservative scanning".) The garbage collector runs synchronously when the system runs out of memory, or in response to a request from a Java program. Your Java program can ask the garbage collector to run at any time by calling System.gc(). The garbage collector requires about 20 milliseconds to complete its task so, your program should only run the garbage collector when there will be no performance impact and the program anticipates an idle period long enough for the garbage collector to finish its job. Note: Asking the garbage collection to run does not guarantee that your objects will be garbage collected. The Java garbage collector runs asynchronously when the system is idle on systems that allow the Java runtime to note when a thread has begun and to interrupt another thread (such as Windows 95). As soon as another thread becomes active, the garbage collector is asked to get to a consistent state and then terminate.What’s the difference between == and equals method?
equals checks for the content of the string objects while == checks for the fact that the two String objects point to same memory location ie they are same references.What are abstract classes, abstract methods?
Simply speaking a class or a method qualified with "abstract" keyword is an abstract class or abstract method. You create an abstract class when you want to manipulate a set of classes through a common interface. All derived-class methods that match the signature of the base-class declaration will be called using the dynamic binding mechanism. If you have an abstract class, objects of that class almost always have no meaning. That is, abstract class is meant to express only the interface and sometimes some default method implementations, and not a particular implementation, so creating an abstract class object makes no sense and are not allowed ( compile will give you an error message if you try to create one). An abstract method is an incomplete method. It has only a declaration and no method body. Here is the syntax for an abstract method declaration: abstract void f(); If a class contains one or more abstract methods, the class must be qualified an abstract. (Otherwise, the compiler gives you an error message.). It’s possible to create a class as abstract without including any abstract methods. This is useful when you’ve got a class in which it doesn’t make sense to have any abstract methods, and yet you want to prevent any instances of that class. Abstract classes and methods are created because they make the abstractness of a class explicit, and tell both the user and the compiler how it was intended to be used.What is the difference between an Applet and an Application?
For example:
abstract class Instrument {
int i; // storage allocated for each
public abstract void play();
public String what() {
return "Instrument";
public abstract void adjust();
}
class Wind extends Instrument {
public void play() {
System.out.println("Wind.play()");
}
public String what() { return "Wind"; }
public void adjust() {}
Abstract classes are classes for which there can be no instances at run time. i.e. the implementation of the abstract classes are not complete. Abstract methods are methods which have no defintion. i.e. abstract methods have to be implemented in one of the sub classes or else that class will also become Abstract.
A Java application is made up of a main() method declared as public static void that accepts a string array argument, along with any other classes that main() calls. It lives in the environment that the host OS provides. A Java applet is made up of at least one public class that has to be subclassed from java.awt.Applet. The applet is confined to living in the user’s Web browser, and the browser’s security rules, (or Sun’s appletviewer, which has fewer restrictions). The differences between an applet and an application are as follows:Java says "write once, run anywhere". What are some ways this isn’t quite true?
1. Applets can be embedded in HTML pages and downloaded over the Internet whereas Applications have no special support in HTML for embedding or downloading.
2. Applets can only be executed inside a java compatible container, such as a browser or appletviewer whereas Applications are executed at command line by java.exe or jview.exe.
3. Applets execute under strict security limitations that disallow certain operations(sandbox model security) whereas Applications have no inherent security restrictions.
4. Applets don’t have the main() method as in applications. Instead they operate on an entirely different mechanism where they are initialized by init(),started by start(),stopped by stop() or destroyed by destroy().
As long as all implementaions of java are certified by sun as 100% pure java this promise of "Write once, Run everywhere" will hold true. But as soon as various java core implemenations start digressing from each other, this won’t be true anymore. A recent example of a questionable business tactic is the surreptitious behavior and interface modification of some of Java’s core classes in their own implementation of Java. Programmers who do not recognize these undocumented changes can build their applications expecting them to run anywhere that Java can be found, only to discover that their code works only on Microsoft’s own Virtual Machine, which is only available on Microsoft’s own operating systems.What is the difference between a Vector and an Array. Discuss the advantages and disadvantages of both?
Vector can contain objects of different types whereas array can contain objects only of a single type.What are java beans?
- Vector can expand at run-time, while array length is fixed.
- Vector methods are synchronized while Array methods are not
JavaBeans is a portable, platform-independent component model written in the Java programming language, developed in collaboration with industry leaders. It enables developers to write reusable components once and run them anywhere — benefiting from the platform-independent power of Java technology. JavaBeans acts as a Bridge between proprietary component models and provides a seamless and powerful means for developers to build components that run in ActiveX container applications. JavaBeans are usual Java classes which adhere to certain coding conventions:What is RMI?
1. Implements java.io.Serializable interface
2. Provides no argument constructor
3. Provides getter and setter methods for accessing it’s properties
RMI stands for Remote Method Invocation. Traditional approaches to executing code on other machines across a network have been confusing as well as tedious and error-prone to implement. The nicest way to think about this problem is that some object happens to live on another machine, and that you can send a message to the remote object and get a result as if the object lived on your local machine. This simplification is exactly what Java Remote Method Invocation (RMI) allows you to do. Above excerpt is from "Thinking in java". For more information refer to any book on Java.What does the keyword "synchronize" mean in java. When do you use it? What are the disadvantages of synchronization?
Synchronize is used when you want to make your methods thread safe. The disadvantage of synchronize is it will end up in slowing down the program. Also if not handled properly it will end up in dead lock.What gives java it’s "write once and run anywhere" nature?
Java is compiled to be a byte code which is the intermediate language between source code and machine code. This byte code is not platorm specific and hence can be fed to any platform. After being fed to the JVM, which is specific to a particular operating system, the code platform specific machine code is generated thus making java platform independent.What are native methods? How do you use them?
Native methods are methods written in other languages like C, C++, or even assembly language. You can call native methods from Java using JNI. Native methods are used when the implementation of a particular method is present in language other than Java say C, C++. To use the native methods in java we use the keyword nativeWhat is JDBC? Describe the steps needed to execute a SQL query using JDBC.
public native method_a(). This native keyword is signal to the java compiler that the implementation of this method is in a language other than java. Native methods are used when we realize that it would take up a lot of rework to write that piece of already existing code in other language to Java.
We can connect to databases from java using JDBC. It stands for Java DataBase Connectivity.How many different types of JDBC drivers are present? Discuss them.
Here are the steps:
1. Register the jdbc driver with the driver manager
2. Establish jdbc connection
3. Execute an sql statement
4. Process the results
5. Close the connection
Before doing these do import java.sql.*
JDBC is java based API for accessing data from the relational databases. JDBC provides a set of classes and interfaces for doing various database operations. The steps are:
Register/load the jdbc driver with the driver manager.
Establish the connection thru DriverManager.getConnection();
Fire a SQL thru conn.executeStatement();
Fetch the results in a result set
Process the results
Close statement/result set and connection object.
There are four JDBC driver types.Access specifiers: "public", "protected", "private", nothing?
Type 1: JDBC-ODBC Bridge plus ODBC Driver:
The first type of JDBC driver is the JDBC-ODBC Bridge. It is a driver that provides JDBC access to databases through ODBC drivers. The ODBC driver must be configured on the client for the bridge to work. This driver type is commonly used for prototyping or when there is no JDBC driver available for a particular DBMS.
Type 2: Native-API partly-Java Driver:
The Native to API driver converts JDBC commands to DBMS-specific native calls. This is much like the restriction of Type 1 drivers. The client must have some binary code loaded on its machine. These drivers do have an advantage over Type 1 drivers because they interface directly with the database.
Type 3: JDBC-Net Pure Java Driver:
The JDBC-Net drivers are a three-tier solution. This type of driver translates JDBC calls into a database-independent network protocol that is sent to a middleware server. This server then translates this DBMS-independent protocol into a DBMS-specific protocol, which is sent
to a particular database. The results are then routed back through the middleware server and sent back to the client. This type of solution makes it possible to implement a pure Java client. It also makes it possible to swap databases without affecting the client.
Type 4: Native-Protocol Pure Java Driver
These are pure Java drivers that communicate directly with the vendor’s database. They do this by converting JDBC commands directly into the database engine’s native protocol. This driver has no additional translation or middleware layer, which improves performance tremendously.
What does the "static" keyword mean in front of a variable? A method? A class? Curly braces {}?
static variable
- means a class level variable
static method:
-does not have "this". It is not allowed to access the not static members of the class.
can be invoked enev before a single instance of a class is created.
eg: main
static class:
no such thing.
static free floating block:
is executed at the time the class is loaded. There can be multiple such blocks. This may be useful to load native libraries when using native methods.
eg:
native void doThis(){
static{
System.loadLibrary("myLibrary.lib");
}
In the case of Public, Private and Protected, that is used to describe which programs can access that class or method: Public – any other class from any package can instantiate and execute the classes and methods. Protected – only subclasses and classes inside of the package can access the classes and methods. Private – the original class is the only class allowed to executed the methods.What does the "final" keyword mean in front of a variable? A method? A class?
FINAL for a variable : value is constantDoes Java have "goto"?
FINAL for a method : cannot be overridden
FINAL for a class : cannot be derived
A final variable cannot be reassigned,
but it is not constant. For instance,
final StringBuffer x = new StringBuffer()
x.append("hello");
is valid. X cannot have a new value in it,but nothing stops operations on the object
that it refers, including destructive operations. Also, a final method cannot be overridden
or hidden by new access specifications.This means that the compiler can choose
to in-line the invocation of such a method.(I don’t know if any compiler actually does
this, but it’s true in theory.) The best example of a final class is
String, which defines a class that cannot be derived.
No.What synchronization constructs does Java provide? How do they work?
The two common features that are used are:Does Java have multiple inheritance?
1. Synchronized keyword - Used to synchronize a method or a block of code. When you synchronize a method, you are in effect synchronizing the code within the method using the monitor of the current object for the lock.
The following have the same effect.
synchronized void foo() {
}
and
void foo() {
synchronized(this) {
}
If you synchronize a static method, then you are synchronizing across all objects of the same class, i.e. the monitor you are using for the lock is one per class, not one per object.
2. wait/notify. wait() needs to be called from within a synchronized block. It will first release the lock acquired from the synchronization and then wait for a signal. In Posix C, this part is equivalent to the pthread_cond_wait method, which waits for an OS signal to continue. When somebody calls notify() on the object, this will signal the code which has been waiting, and the code will continue from that point. If there are several sections of code that are in the wait state, you can call notifyAll() which will notify all threads that are waiting on the monitor for the current object. Remember that both wait() and notify() have to be called from blocks of code that are synchronized on the monitor for the current object.
Java does not support multiple inheritence directly but it does thru the concept of interfaces.How does exception handling work in Java?
We can make a class implement a number of interfaces if we want to achieve multiple inheritence type of functionality of C++.
1.It separates the working/functional code from the error-handling code by way of try-catch clauses.Does Java have destructors?
2.It allows a clean path for error propagation. If the called method encounters a situation it can’t manage, it can throw an exception and let the calling method deal with it.
3.By enlisting the compiler to ensure that "exceptional" situations are anticipated and accounted for, it enforces powerful coding.
4.Exceptions are of two types: Compiler-enforced exceptions, or checked exceptions. Runtime exceptions, or unchecked exceptions. Compiler-enforced (checked) exceptions are instances of the Exception class or one of its subclasses — excluding the RuntimeException branch. The compiler expects all checked exceptions to be appropriately handled. Checked exceptions must be declared in the throws clause of the method throwing them — assuming, of course, they’re not being caught within that same method. The calling method must take care of these exceptions by either catching or declaring them in its throws clause. Thus, making an exception checked forces the us to pay heed to the possibility of it being thrown. An example of a checked exception is java.io.IOException. As the name suggests, it throws whenever an input/output operation is abnormally terminated.
Garbage collector does the job working in the backgroundWhat does the "abstract" keyword mean in front of a method? A class?
Java does not have destructors; but it has finalizers that does a similar job.
the syntax is
public void finalize(){
}
if an object has a finalizer, the method is invoked before the system garbage collects the object
Abstract keyword declares either a method or a class.Are Java constructors inherited ? If not, why not?
If a method has a abstract keyword in front of it,it is called abstract method.Abstract method hs no body.It has only arguments and return type.Abstract methods act as placeholder methods that are implemented in the subclasses.
Abstract classes can’t be instantiated.If a class is declared as abstract,no objects of that class can be created.If a class contains any abstract method it must be declared as abstract
You cannot inherit a constructor. That is, you cannot create a instance of a subclass using a constructor of one of it’s superclasses. One of the main reasons is because you probably don’t want to overide the superclasses constructor, which would be possible if they were inherited. By giving the developer the ability to override a superclasses constructor you would erode the encapsulation abilities of the language.
EJB stands for Enterprise JavaBean and is a widely-adopted server side component architecture for J2EE. It enables rapid development of mission-critical application that are versatile, reusable and portable across middleware while protecting IT investment and preventing vendor lock-in.
2. What is session Facade?
Session Facade is a design pattern to access the Entity bean through local interface than accessing directly. It increases the performance over the network. In this case we call session bean which on turn call entity bean.
3. What is EJB role in J2EE?
EJB technology is the core of J2EE. It enables developers to write reusable and portable server-side business logic for the J2EE platform.
4. What is the difference between EJB and Java beans?
EJB is a specification for J2EE server, not a product; Java beans may be a graphical component in IDE.
5. What are the key features of the EJB technology?
1. EJB components are server-side components written entirely in the Java programming language
2. EJB components contain business logic only - no system-level programming & services, such as transactions, security, life-cycle, threading, persistence, etc. are automatically managed for the EJB component by the EJB server.
3. EJB architecture is inherently transactional, distributed, portable multi-tier, scalable and secure.
4. EJB components are fully portable across any EJB server and any OS.
5. EJB architecture is wire-protocol neutral–any protocol can be utilized like IIOP,JRMP, HTTP, DCOM,etc.
6. What are the key benefits of the EJB technology?
1. Rapid application development
2. Broad industry adoption
3. Application portability
4. Protection of IT investment
7. How many enterprise beans?
There are three kinds of enterprise beans:
1. session beans,
2. entity beans, and
3. message-driven beans.
8. What is message-driven bean?
A message-driven bean combines features of a session bean and a Java Message Service (JMS) message listener, allowing a business component to receive JMS. A message-driven bean enables asynchronous clients to access the business logic in the EJB tier.
9. What is Entity Bean and Session Bean ?
Entity Bean is a Java class which implements an Enterprise Bean interface and provides the implementation of the business methods. There are two types: Container Managed Persistence(CMP) and Bean-Managed Persistence(BMP).
Session Bean is used to represent a workflow on behalf of a client. There are two types: Stateless and Stateful. Stateless bean is the simplest bean. It doesn’t maintain any conversational state with clients between method invocations. Stateful bean maintains state between invocations.
10. How EJB Invocation happens?
Retrieve Home Object reference from Naming Service via JNDI. Return Home Object reference to the client. Create me a new EJB Object through Home Object interface. Create EJB Object from the Ejb Object. Return EJB Object reference to the client. Invoke business method using EJB Object reference. Delegate request to Bean (Enterprise Bean).
11. Is it possible to share an HttpSession between a JSP and EJB? What happens when I change a value in the HttpSession from inside an EJB?
You can pass the HttpSession as parameter to an EJB method, only if all objects in session are serializable.This has to be consider as passed-by-value, that means that it’s read-only in the EJB. If anything is altered from inside the EJB, it won’t be reflected back to the HttpSession of the Servlet Container.The pass-by-reference can be used between EJBs Remote Interfaces, as they are remote references. While it is possible to pass an HttpSession as a parameter to an EJB object, it is considered to be bad practice in terms of object-oriented design. This is because you are creating an unnecessary coupling between back-end objects (EJBs) and front-end objects (HttpSession). Create a higher-level of abstraction for your EJBs API. Rather than passing the whole, fat, HttpSession (which carries with it a bunch of http semantics), create a class that acts as a value object (or structure) that holds all the data you need to pass back and forth between front-end/back-end. Consider the case where your EJB needs to support a non HTTP-based client. This higher level of abstraction will be flexible enough to support it.
12. The EJB container implements the EJBHome and EJBObject classes. For every request from a unique client, does the container create a separate instance of the generated EJBHome and EJBObject classes?
The EJB container maintains an instance pool. The container uses these instances for the EJB Home reference irrespective of the client request. while refering the EJB Object classes the container creates a separate instance for each client request. The instance pool maintenance is up to the implementation of the container. If the container provides one, it is available otherwise it is not mandatory for the provider to implement it. Having said that, yes most of the container providers implement the pooling functionality to increase the performance of the application server. The way it is implemented is, again, up to the implementer.
13. Can the primary key in the entity bean be a Java primitive type such as int?
The primary key can’t be a primitive type. Use the primitive wrapper classes, instead. For example, you can use java.lang.Integer as the primary key class, but not int (it has to be a class, not a primitive).
14. Can you control when passivation occurs?
The developer, according to the specification, cannot directly control when passivation occurs. Although for Stateful Session Beans, the container cannot passivate an instance that is inside a transaction. So using transactions can be a a strategy to control passivation. The ejbPassivate() method is called during passivation, so the developer has control over what to do during this exercise and can implement the require optimized logic. Some EJB containers, such as BEA WebLogic, provide the ability to tune the container to minimize passivation calls. Taken from the WebLogic 6.0 DTD -The passivation-strategy can be either default or transaction. With the default setting the container will attempt to keep a working set of beans in the cache. With the transaction setting, the container will passivate the bean after every transaction (or method call for a non-transactional invocation).
15. What is the advantage of using Entity bean for database operations, over directly using JDBC API to do database operations? When would I use one over the other?
Entity Beans actually represents the data in a database. It is not that Entity Beans replaces JDBC API. There are two types of Entity Beans Container Managed and Bean Mananged. In Container Managed Entity Bean - Whenever the instance of the bean is created the container automatically retrieves the data from the DB/Persistance storage and assigns to the object variables in bean for user to manipulate or use them. For this the developer needs to map the fields in the database to the variables in deployment descriptor files (which varies for each vendor). In the Bean Managed Entity Bean - The developer has to specifically make connection, retrive values, assign them to the objects in the ejbLoad() which will be called by the container when it instatiates a bean object. Similarly in the ejbStore() the container saves the object values back the the persistance storage. ejbLoad and ejbStore are callback methods and can be only invoked by the container. Apart from this, when you use Entity beans you dont need to worry about database transaction handling, database connection pooling etc. which are taken care by the ejb container.
16. What is EJB QL?
EJB QL is a Query Language provided for navigation across a network of enterprise beans and dependent objects defined by means of container managed persistence. EJB QL is introduced in the EJB 2.0 specification. The EJB QL query language defines finder methods for entity beans with container managed persistenceand is portable across containers and persistence managers. EJB QL is used for queries of two types of finder methods: Finder methods that are defined in the home interface of an entity bean and which return entity objects. Select methods, which are not exposed to the client, but which are used by the Bean Provider to select persistent values that are maintained by the Persistence Manager or to select entity objects that are related to the entity bean on which the query is defined.
17. Brief description about local interfaces?
EEJB was originally designed around remote invocation using the Java Remote Method Invocation (RMI) mechanism, and later extended to support to standard CORBA transport for these calls using RMI/IIOP. This design allowed for maximum flexibility in developing applications without consideration for the deployment scenario, and was a strong feature in support of a goal of component reuse in J2EE. Many developers are using EJBs locally, that is, some or all of their EJB calls are between beans in a single container. With this feedback in mind, the EJB 2.0 expert group has created a local interface mechanism. The local interface may be defined for a bean during development, to allow streamlined calls to the bean if a caller is in the same container. This does not involve the overhead involved with RMI like marshalling etc. This facility will thus improve the performance of applications in which co-location is planned. Local interfaces also provide the foundation for container-managed relationships among entity beans with container-managed persistence.
18. What are the special design care that must be taken when you work with local interfaces?
It is important to understand that the calling semantics of local interfaces are different from those of remote interfaces. For example, remote interfaces pass parameters using call-by-value semantics, while local interfaces use call-by-reference. This means that in order to use local interfaces safely, application developers need to carefully consider potential deployment scenarios up front, then decide which interfaces can be local and which remote, and finally, develop the application code with these choices in mind. While EJB 2.0 local interfaces are extremely useful in some situations, the long-term costs of these choices, especially when changing requirements and component reuse are taken into account, need to be factored into the design decision.
19. What happens if remove( ) is never invoked on a session bean?
In case of a stateless session bean it may not matter if we call or not as in both cases nothing is done. The number of beans in cache is managed by the container. In case of stateful session bean, the bean may be kept in cache till either the session times out, in which case the bean is removed or when there is a requirement for memory in which case the data is cached and the bean is sent to free pool.
20. What is the difference between Message Driven Beans and Stateless Session beans?
In several ways, the dynamic creation and allocation of message-driven bean instances mimics the behavior of stateless session EJB instances, which exist only for the duration of a particular method call. However, message-driven beans are different from stateless session EJBs (and other types of EJBs) in several significant ways: Message-driven beans process multiple JMS messages asynchronously, rather than processing a serialized sequence of method calls. Message-driven beans have no home or remote interface, and therefore cannot be directly accessed by internal or external clients. Clients interact with message-driven beans only indirectly, by sending a message to a JMS Queue or Topic. Only the container directly interacts with a message-driven bean by creating bean instances and passing JMS messages to those instances as necessary. The Container maintains the entire lifecycle of a message-driven bean; instances cannot be created or removed as a result of client requests or other API calls.
22. How can I call one EJB from inside of another EJB?
EJBs can be clients of other EJBs. It just works. Use JNDI to locate the Home Interface of the other bean, then acquire an instance reference, and so forth.
23. What is an EJB Context?
EJBContext is an interface that is implemented by the container, and it is also a part of the bean-container contract. Entity beans use a subclass of EJBContext called EntityContext. Session beans use a subclass called SessionContext. These EJBContext objects provide the bean class with information about its container, the client using the bean and the bean itself. They also provide other functions. See the API docs and the spec for more details.
24. Is is possible for an EJB client to marshal an object of class java.lang.Class to an EJB?
Technically yes, spec. compliant NO! - The enterprise bean must not attempt to query a class to obtain information about the declared members that are not otherwise accessible to the enterprise bean because of the security rules of the Java language
25. Is it legal to have static initializer blocks in EJB?
Although technically it is legal, static initializer blocks are used to execute some piece of code before executing any constructor or method while instantiating a class. Static initializer blocks are also typically used to initialize static fields - which may be illegal in EJB if they are read/write - In EJB this can be achieved by including the code in either the ejbCreate(), setSessionContext() or setEntityContext() methods.
26. Is it possible to stop the execution of a method before completion in a SessionBean?
Stopping the execution of a method inside a Session Bean is not possible without writing code inside the Session Bean. This is because you are not allowed to access Threads inside an EJB.
27. What is the default transaction attribute for an EJB?
There is no default transaction attribute for an EJB. Section 11.5 of EJB v1.1 spec says that the deployer must specify a value for the transaction attribute for those methods having container managed transaction. In WebLogic, the default transaction attribute for EJB is SUPPORTS.
28. What is the difference between session and entity beans? When should I use one or the other?
An entity bean represents persistent global data from the database; a session bean represents transient user-specific data that will die when the user disconnects (ends his session). Generally, the session beans implement business methods (e.g. Bank.transferFunds) that call entity beans (e.g. Account.deposit, Account.withdraw)
29. Is there any default cache management system with Entity beans ?
In other words whether a cache of the data in database will be maintained in EJB ? - Caching data from a database inside the AAApplication Server are what Entity EJB’s are used for.The ejbLoad() and ejbStore() methods are used to synchronize the Entity Bean state with the persistent storage(database). Transactions also play an important role in this scenario. If data is removed from the database, via an external application - your Entity Bean can still be alive the EJB container. When the transaction commits, ejbStore() is called and the row will not be found, and the transaction rolled back.
30. Why is ejbFindByPrimaryKey mandatory?
An Entity Bean represents persistent data that is stored outside of the EJB Container/Server. The ejbFindByPrimaryKey is a method used to locate and load an Entity Bean into the container, similar to a SELECT statement in SQL. By making this method mandatory, the client programmer can be assured that if they have the primary key of the Entity Bean, then they can retrieve the bean without having to create a new bean each time - which would mean creating duplications of persistent data and break the integrity of EJB.
31. Why do we have a remove method in both EJBHome and EJBObject?
With the EJBHome version of the remove, you are able to delete an entity bean without first instantiating it (you can provide a PrimaryKey object as a parameter to the remove method). The home version only works for entity beans. On the other hand, the Remote interface version works on an entity bean that you have already instantiated. In addition, the remote version also works on session beans (stateless and stateful) to inform the container of your loss of interest in this bean.
32. How can I call one EJB from inside of another EJB?
EJBs can be clients of other EJBs. It just works. Use JNDI to locate the Home Interface of the other bean, then acquire an instance reference, and so forth.
33. What is the difference between a Server, a Container, and a Connector?
An EJB server is an application, usually a product such as BEA WebLogic, that provides (or should provide) for concurrent client connections and manages system resources such as threads, processes, memory, database connections, network connections, etc. An EJB container runs inside (or within) an EJB server, and provides deployed EJB beans with transaction and security management, etc. The EJB container insulates an EJB bean from the specifics of an underlying EJB server by providing a simple, standard API between the EJB bean and its container. A Connector provides the ability for any Enterprise Information System (EIS) to plug into any EJB server which supports the Connector architecture. See Sun’s J2EE Connectors for more in-depth information on Connectors.
34. How is persistence implemented in enterprise beans?
Persistence in EJB is taken care of in two ways, depending on how you implement your beans: container managed persistence (CMP) or bean managed persistence (BMP) For CMP, the EJB container which your beans run under takes care of the persistence of the fields you have declared to be persisted with the database - this declaration is in the deployment descriptor. So, anytime you modify a field in a CMP bean, as soon as the method you have executed is finished, the new data is persisted to the database by the container. For BMP, the EJB bean developer is responsible for defining the persistence routines in the proper places in the bean, for instance, the ejbCreate(), ejbStore(), ejbRemove() methods would be developed by the bean developer to make calls to the database. The container is responsible, in BMP, to call the appropriate method on the bean. So, if the bean is being looked up, when the create() method is called on the Home interface, then the container is responsible for calling the ejbCreate() method in the bean, which should have functionality inside for going to the database and looking up the data.
35. What is an EJB Context?
EJBContext is an interface that is implemented by the container, and it is also a part of the bean-container contract. Entity beans use a subclass of EJBContext called EntityContext. Session beans use a subclass called SessionContext. These EJBContext objects provide the bean class with information about its container, the client using the bean and the bean itself. They also provide other functions. See the API docs and the spec for more details.
36. Is method overloading allowed in EJB?
Yes you can overload methods Should synchronization primitives be used on bean methods? - No. The EJB specification specifically states that the enterprise bean is not allowed to use thread primitives. The container is responsible for managing concurrent access to beans at runtime.
37. Are we allowed to change the transaction isolation property in middle of a transaction?
No. You cannot change the transaction isolation level in the middle of transaction.
38. For Entity Beans, What happens to an instance field not mapped to any persistent storage, when the bean is passivated?
The specification infers that the container never serializes an instance of an Entity bean (unlike stateful session beans). Thus passivation simply involves moving the bean from the ready to the pooled bin. So what happens to the contents of an instance variable is controlled by the programmer. Remember that when an entity bean is passivated the instance gets logically disassociated from it’s remote object. Be careful here, as the functionality of passivation/activation for Stateless Session, Stateful Session and Entity beans is completely different. For entity beans the ejbPassivate method notifies the entity bean that it is being disassociated with a particular entity prior to reuse or for dereference.
39. What is a Message Driven Bean, what functions does a message driven bean have and how do they work in collaboration with JMS?
Message driven beans are the latest addition to the family of component bean types defined by the EJB specification. The original bean types include session beans, which contain business logic and maintain a state associated with client sessions, and entity beans, which map objects to persistent data. Message driven beans will provide asynchrony to EJB based applications by acting as JMS message consumers. A message bean is associated with a JMS topic or queue and receives JMS messages sent by EJB clients or other beans. Unlike entity beans and session beans, message beans do not have home or remote interfaces. Instead, message driven beans are instantiated by the container as required. Like stateless session beans, message beans maintain no client-specific state, allowing the container to optimally manage a pool of message-bean instances. Clients send JMS messages to message beans in exactly the same manner as they would send messages to any other JMS destination. This similarity is a fundamental design goal of the JMS capabilities of the new specification. To receive JMS messages, message driven beans implement the javax.jms.MessageListener interface, which defines a single onMessage() method. When a message arrives, the container ensures that a message bean corresponding to the message topic/queue exists (instantiating it if necessary), and calls its onMessage method passing the client’s message as the single argument. The message bean’s implementation of this method contains the business logic required to process the message. Note that session beans and entity beans are not allowed to function as message beans.
40. Does RMI-IIOP support code downloading for Java objects sent by value across an IIOP connection in the same way as RMI does across a JRMP connection?
Yes. The JDK 1.2 support the dynamic class loading. The EJB container implements the EJBHome and EJBObject classes. For every request from a unique client,
41. Does the container create a separate instance of the generated EJBHome and EJBObject classes?
The EJB container maintains an instance pool. The container uses these instances for the EJB Home reference irrespective of the client request. while refering the EJB Object classes the container creates a separate instance for each client request. The instance pool maintainence is up to the implementation of the container. If the container provides one, it is available otherwise it is not mandatory for the provider to implement it. Having said that, yes most of the container providers implement the pooling functionality to increase the performance of the application server. The way it is implemented is again up to the implementer.
42. What is the advantage of putting an Entity Bean instance from the Ready State to Pooled state
The idea of the Pooled State is to allow a container to maintain a pool of entity beans that has been created, but has not been yet synchronized or assigned to an EJBObject. This mean that the instances do represent entity beans, but they can be used only for serving Home methods (create or findBy), since those methods do not relay on the specific values of the bean. All these instances are, in fact, exactly the same, so, they do not have meaningful state. Jon Thorarinsson has also added: It can be looked at it this way: If no client is using an entity bean of a particular type there is no need for cachig it (the data is persisted in the database). Therefore, in such cases, the container will, after some time, move the entity bean from the Ready State to the Pooled state to save memory. Then, to save additional memory, the container may begin moving entity beans from the Pooled State to the Does Not Exist State, because even though the bean’s cache has been cleared, the bean still takes up some memory just being in the Pooled State.
- Can a main() method of class be invoked in another class?
- What is the difference between java command line arguments and C command line arguments?
- What is the difference between == & .equals
- What is the difference between abstract class & Interface.
- What is singleton class & it’s implementation.
- Use of static,final variable
- Examples of final class
- Difference between Event propagation & Event delegation
- Difference between Unicast & Multicast model
- What is a java bean
- What is synchronized keyword used for.
- What are the restrictions of an applet & how to make the applet access the local machines resources.
- What is reflect package used for & the methods of it.
- What is serialization used for
- Can methods be overloaded based on the return types ?
- Why do we need a finalze() method when Garbage Collection is there ?
- Difference between AWT and Swing compenents ?
- Is there any heavy weight component in Swings ?
- Can the Swing application if you upload in net, be compatible with your browser?
- What should you do get your browser compatible with swing components?
- What are the methods in Applet ?
- When is init(),start() called ?
- When you navigate from one applet to another what are the methods called?
- What is the difference between Trusted and Untrusted Applet ?
- What is Exception ?
- What are the ways you can handle exception ?
- When is try,catch block used ?
- What is finally method in Exceptions ?
- What are the types of access modifiers ?
- What is protected and friendly ?
- What are the other modifiers ?
- Is synchronised modifier ?
- What is meant by polymorphism ?
- What is inheritance ?
- What is method Overloading ? What is this in OOPS ?
- What is method Overriding ? What is it in OOPS ?
- Does java support multi dimensional arrays ?
- Is multiple inheritance used in Java ?
- How do you send a message to the browser in JavaScript ?
- Does javascript support multidimensional arrays ?
- Is there any tool in java that can create reports ?
- What is meant by Java ?
- What is meant by a class ?
- What is meant by a method ?
- What are the OOPS concepts in Java ?
- What is meant by encapsulation ? Explain with an example
- What is meant by inheritance ? Explain with an example
- What is meant by polymorphism ? Explain with an example
- Is multiple inheritance allowed in Java ? Why ?
- What is meant by Java interpreter ?
- What is meant by JVM ?
- What is a compilation unit ?
- What is meant by identifiers ?
- What are the different types of modifiers ?
- What are the access modifiers in Java ?
- What are the primitive data types in Java ?
- What is meant by a wrapper class ?
- What is meant by static variable and static method ?
- What is meant by Garbage collection ?
- What is meant by abstract class
- What is meant by final class, methods and variables ?
- What is meant by interface ?
- What is meant by a resource leak ?
- What is the difference between interface and abstract class ?
- What is the difference between public private, protected and static
- What is meant by method overloading ?
- What is meant by method overriding ?
- What is singleton class ?
- What is the difference between an array and a vector ?
- What is meant by constructor ?
- What is meant by casting ?
- What is the difference between final, finally and finalize ?
- What is meant by packages ?
- What are all the packages ?
- Name 2 calsses you have used ?
- Name 2 classes that can store arbitrary number of objects ?
- What is the difference between java.applet.* and java.applet.Applet ?
- What is a default package ?
- What is meant by a super class and how can you call a super class ?
- What is anonymous class ?
- Name interfaces without a method ?
- What is the use of an interface ?
- What is a serializable interface ?
- How to prevent field from serialization ?
- What is meant by exception ?
- How can you avoid the runtime exception ?
- What is the difference between throw and throws ?
- What is the use of finally ?
- Can multiple catch statements be used in exceptions ?
- Is it possible to write a try within a try statement ?
- What is the method to find if the object exited or not ?
- What is meant by a Thread ?
- What is meant by multi-threading ?
- What is the 2 way of creating a thread ? Which is the best way and why?
- What is the method to find if a thread is active or not ?
- What are the thread-to-thread communcation ?
- What is the difference between sleep and suspend ?
- Can thread become a member of another thread ?
- What is meant by deadlock ?
- How can you avoid a deadlock ?
- What are the three typs of priority ?
- What is the use of synchronizations ?
- Garbage collector thread belongs to which priority ?
- What is meant by time-slicing ?
- What is the use of ‘this’ ?
- How can you find the length and capacity of a string buffer ?
- How to compare two strings ?
- What are the interfaces defined by Java.lang ?
- What is the purpose of run-time class and system class
- What is meant by Stream and Types ?
- What is the method used to clear the buffer ?
- What is meant by Stream Tokenizer ?
- What is serialization and de-serialisation ?
- What is meant by Applet ?
- How to find the host from which the Applet has originated ?
- What is the life cycle of an Applet ?
- How do you load an HTML page from an Applet ?
- What is meant by Applet Stub Interface ?
- What is meant by getCodeBase and getDocumentBase method ?
- How can you call an applet from a HTML file
- What is meant by Applet Flickering ?
- What is the use of parameter tag ?
- What is audio clip Interface and what are all the methods in it ?
- What is the difference between getAppletInfo and getParameterInfo ?
- How to communicate between applet and an applet ?
- What is meant by event handling ?
- What are all the listeners in java and explain ?
- What is meant by an adapter class ?
- What are the types of mouse event listeners ?
- What are the types of methods in mouse listeners ?
- What is the difference between panel and frame ?
- What is the default layout of the panel and frame ?
- What is meant by controls and types ?
- What is the difference between a scroll bar and a scroll panel.
- What is the difference between list and choice ?
- How to place a component on Windows ?
- What are the different types of Layouts ?
- What is meant by CardLayout ?
- What is the difference between GridLayout and GridBagLayout
- What is the difference between menuitem and checkboxmenu item.
- What is meant by vector class, dictionary class , hash table class,and property class ?
- Which class has no duplicate elements ?
- What is resource bundle ?
- What is an enumeration class ?
- What is meant by Swing ?
- What is the difference between AWT and Swing ?
- What is the difference between an applet and a Japplet
- What are all the components used in Swing ?
- What is meant by tab pans ?
- What is the use of JTree ?
- How can you add and remove nodes in Jtree.
- What is the method to expand and collapse nodes in a Jtree
- What is the use of JTable ?
- What is meant by JFC ?
- What is the class in Swing to change the appearance of the Frame in Runtime.
- How to reduce flicking in animation ?
- What is meant by Javabeans ?
- What is JAR file ?
- What is meant by manifest files ?
- What is Introspection ?
- What are the steps involved to create a bean ?
- Say any two properties in Beans ?
- What is persistence ?
- What is the use of beaninfo ?
- What are the interfaces you used in Beans ?
- What are the classes you used in Beans ?
- What is the diffrence between an Abstract class and Interface
- What is user defined exception ?
- What do you know about the garbate collector ?
- What is the difference between C++ & Java ?
- How do you communicate in between Applets & Servlets ?
- What is the use of Servlets ?
- In an HTML form I have a Button which makes us to open another page in 15 seconds. How will do you that ?
- What is the difference between Process and Threads ?
- How will you initialize an Applet ?
- What is the order of method invocation in an Applet ?
- When is update method called ?
- How will you communicate between two Applets ?
- Have you ever used HashTable and Dictionary ?
- What are statements in JAVA ?
- What is JAR file ?
- What is JNI ?
- What is the base class for all swing components ?
- What is JFC ?
- What is Difference between AWT and Swing ?
- Considering notepad/IE or any other thing as process, What will Happen if you start notepad or IE 3 times? Where 3 processes are started or 3 threads are started ?
- How does thread synchronization occurs inside a monitor ?
- How will you call an Applet using a Java Script function ?
- Is there any tag in HTML to upload and download files ?
- Why do you Canvas ?
- How can you push data from an Applet to Servlet ?
- What are the benefits of Swing over AWT ?
- Where the CardLayout is used ?
- What is the Layout for ToolBar ?
- What is the difference between Grid and GridbagLayout ?
- How will you add panel to a Frame ?
- What is the corresponding Layout for Card in Swing ?
- What is light weight component ?
- What is bean ? Where it can be used ?
- What is difference in between Java Class and Bean ?
- What is the mapping mechanism used by Java to identify IDL language ?
- Diff between Application and Applet ?
- What is serializable Interface ?
- What is the difference between CGI and Servlet ?
- What is the use of Interface ?
- Why Java is not fully objective oriented ?
- Why does not support multiple Inheritance ?
- What it the root class for all Java classes ?
- What is polymorphism ?
- Suppose If we have variable ‘ I ‘ in run method, If I can create one or More thread each thread will occupy a separate copy or same variable will be shared ?
- What is Constructor and Virtual function? Can we call Virtual
- Funciton in a constructor ?
- Why we use OOPS concepts? What is its advantage ?
- What is the difference in between C++ and Java ? can u explain in detail?
- What is the exact difference in between Unicast and Multicast object ? Where we will use ?
- How do you sing an Applet ?
- In a Container there are 5 components. I want to display the all the components names, how will you do that one ?
- Why there are some null interface in java ? What does it mean ?
- Give me some null interfaces in JAVA ?
- Tell me the latest versions in JAVA related areas ?
- What is meant by class loader ? How many types are there? When will we use them ?
- What is meant by flickering ?
- What is meant by cookies ? Explain ?
- Problem faced in your earlier project
- How OOPS concept is achieved in Java
- Features for using Java
- How does Java 2.0 differ from Java 1.0
- Public static void main - Explain
- What are command line arguments
- Explain about the three-tier model
- Difference between String & StringBuffer
- Wrapper class. Is String a Wrapper Class
- What are the restriction for static method Purpose of the file class
- Default modifier in Interface
- Difference between Interface & Abstract class
- Can abstract be declared as Final
- Can we declare variables inside a method as Final Variables
- What is the package concept and use of package
- How can a dead thread be started
- Difference between Applet & Application
- Life cycle of the Applet
- Can Applet have constructors
- Differeence between canvas class & graphics class
- Explain about Superclass & subclass
- What is AppletStub
- Explain Stream Tokenizer
- What is the difference between two types of threads
- Checked & Unchecked exception
- Use of throws exception
- What is finally in exception handling Vector class
- What will happen to the Exception object after exception handling
- Two types of multi-tasking
- Two ways to create the thread
- Synchronization
- I/O Filter
- Can applet in different page communicate with each other
- Why Java is not 100 % pure OOPS ? ( EcomServer )
- When we will use an Interface and Abstract class ?
- How to communicate 2 threads each other ?
Java and Perl Web programming interview questions
Labels: Interview Questions, Java, Perl, Web Programming- Q1: How can we store the information returned from querying the database? and if it is too big, how does it affect the performance? In Java the return information will be stored in the ResultSet object. Yes, if the ResultSet is getting big, it will slow down the process and the performance as well. We can prevent this situation by give the program a simple but specific query statement.
- Q2: What is index table and why we use it? Index table are based on a sorted ordering of the values. Index table provides fast access time when searching.
- Q3: In Java why we use exceptions? Java uses exceptions as a way of signaling serious problems when you execute a program. One major benefit of having an error signaled by an exception is that it separates the code that deals with errors from the code that is executed when things are moving along smoothly. Another positive aspect of exceptions is that they provide a way of enforcing a response to particular errors.
- Q4: Write a code in Perl that makes a connection to Database.
#!/usr/bin/perl #makeconnection.pl use DBI; my $dbh = DBI->connect('dbi:mysql:test','root','foo')||die "Error opening database: $DBI::errstrn"; print"Successful connect to databasen"; $dbh->disconnect || die "Failed to disconnectn"; - Q5: Write a code in Perl that select all data from table Foo?
#!usr/bin/perl #connect.pl use DBI; my ($dbh, $sth, $name, $id); $dbh= DBI->connect('dbi:mysql:test','root','foo') || die "Error opening database: $DBI::errstrn"; $sth= $dbh->prepare("SELECT * from Foo;") || die "Prepare failed: $DBI::errstrn"; $sth->execute() || die "Couldn't execute query: $DBI::errstrn"; while(( $id, $name) = $sth->fetchrow_array) { print "$name has ID $idn"; } $sth->finish(); $dbh->disconnect || die "Failed to disconnectn";
- What is the difference between an Abstract class and Interface ?
- What is user defined exception ?
- What do you know about the garbage collector ?
- What is the difference between C++ & Java ?
- Explain RMI Architecture?
- How do you communicate in between Applets & Servlets ?
- What is the use of Servlets ?
- What is JDBC? How do you connect to the Database ?
- In an HTML form I have a Button which makes us to open another page in 15 seconds. How will do you that ?
- What is the difference between Process and Threads ?
- What is the difference between RMI & Corba ?
- What are the services in RMI ?
- How will you initialize an Applet ?
- What is the order of method invocation in an Applet ?
- When is update method called ?
- How will you pass values from HTML page to the Servlet ?
- Have you ever used HashTable and Dictionary ?
- How will you communicate between two Applets ?
- What are statements in JAVA ?
- What is JAR file ?
- What is JNI ?
- What is the base class for all swing components ?
- What is JFC ?
- What is Difference between AWT and Swing ?
- Considering notepad/IE or any other thing as process, What will happen if you start notepad or IE 3 times? Where 3 processes are started or 3 threads are started ?
- How does thread synchronization occurs inside a monitor ?
- How will you call an Applet using a Java Script function ?
- Is there any tag in HTML to upload and download files ?
- Why do you Canvas ?
- How can you push data from an Applet to Servlet ?
- What are 4 drivers available in JDBC ?
- How you can know about drivers and database information ?
- If you are truncated using JDBC, How can you know ..that how much data is truncated ?
- And What situation , each of the 4 drivers used ?
- How will you perform transaction using JDBC ?
- In RMI, server object first loaded into the memory and then the stub reference is sent to the client ? or whether a stub reference is directly sent to the client ?
- Suppose server object is not loaded into the memory, and the client request for it , what will happen?
- What is serialization ?
- Can you load the server object dynamically? If so, what are the major 3 steps involved in it ?
- What is difference RMI registry and OSAgent ?
- To a server method, the client wants to send a value 20, with this value exceeds to 20,. a message should be sent to the client ? What will you do for achieving for this ?
- What are the benefits of Swing over AWT ?
- Where the CardLayout is used ?
- What is the Layout for ToolBar ?
- What is the difference between Grid and GridbagLayout ?
- How will you add panel to a Frame ?
- What is the corresponding Layout for Card in Swing ?
- What is light weight component ?
- Can you run the product development on all operating systems ?
- What is the webserver used for running the Servlets ?
- What is Servlet API used for connecting database ?
- What is bean ? Where it can be used ?
- What is difference in between Java Class and Bean ?
- Can we send object using Sockets ?
- What is the RMI and Socket ?
- How to communicate 2 threads each other ?
- What are the files generated after using IDL to Java Compilet ?
Java networking and algoritms interview questions
Labels: Algorithms, Interview Questions, Java, Networking- What is the protocol used by server and client ?
- Can I modify an object in CORBA ?
- What is the functionality stubs and skeletons ?
- What is the mapping mechanism used by Java to identify IDL language ?
- Diff between Application and Applet ?
- What is serializable Interface ?
- What is the difference between CGI and Servlet ?
- What is the use of Interface ?
- Why Java is not fully objective oriented ?
- Why does not support multiple Inheritance ?
- What it the root class for all Java classes ?
- What is polymorphism ?
- Suppose If we have variable ‘ I ‘ in run method, If I can create one or more thread each thread will occupy a separate copy or same variable will be shared ?
- In servlets, we are having a web page that is invoking servlets username and password ? which is checked in the database ? Suppose the second page also If we want to verify the same information whether it will connect to the database or it will be used previous information?
- What are virtual functions ?
- Write down how will you create a binary Tree ?
- What are the traverses in Binary Tree ?
- Write a program for recursive Traverse ?
- What are session variable in Servlets ?
- What is client server computing ?
- What is Constructor and Virtual function? Can we call Virtual function in a constructor ?
- Why we use OOPS concepts? What is its advantage ?
- What is the middleware ? What is the functionality of Webserver ?
- Why Java is not 100 % pure OOPS ? ( EcomServer )
- When we will use an Interface and Abstract class ?
- What is an RMI?
- How will you pass parameters in RMI ? Why u serialize?
- What is the exact difference in between Unicast and Multicast object ? Where we will use ?
- What is the main functionality of the Remote Reference Layer ?
- How do you download stubs from a Remote place ?
- What is the difference in between C++ and Java ? can u explain in detail ?
- I want to store more than 10 objects in a remote server ? Which methodology will follow ?
- What is the main functionality of the Prepared Statement ?
- What is meant by static query and dynamic query ?
- What are the Normalization Rules ? Define the Normalization ?
- What is meant by Servlet? What are the parameters of the service method ?
- What is meant by Session ? Tell me something about HTTPSession Class ?
- How do you invoke a Servlet? What is the difference in between doPost and doGet methods ?
- What is the difference in between the HTTPServlet and Generic Servlet ? Explain their methods ? Tell me their parameter names also ?
- Have you used threads in Servlet ?
- Write a program on RMI and JDBC using StoredProcedure ?
- How do you sing an Applet ?
- In a Container there are 5 components. I want to display the all the components names, how will you do that one ?
- Why there are some null interface in java ? What does it mean ? Give me some null interfaces in JAVA ?
- Tell me the latest versions in JAVA related areas ?
- What is meant by class loader ? How many types are there? When will we use them ?
- How do you load an Image in a Servlet ?
- What is meant by flickering ?
- What is meant by distributed Application ? Why we are using that in our applications ?
- What is the functionality of the stub ?
- Have you used any version control ?
- What is the latest version of JDBC ? What are the new features are added in that ?
- Explain 2 tier and 3 -tier Architecture ?
- What is the role of the webserver ?
- How have you done validation of the fields in your project ?
- What is the main difficulties that you are faced in your project ?
- What is meant by cookies ? Explain ?
- What is a class? A class is a blueprint, or prototype, that defines the variables and the methods common to all objects of a certain kind.
- What is a object? An object is a software bundle of variables and related methods.An instance of a class depicting the state and behavior at that particular time in real world.
- What is a method? Encapsulation of a functionality which can be called to perform specific tasks.
- What is encapsulation? Explain with an example. Encapsulation is the term given to the process of hiding the implementation details of the object. Once an object is encapsulated, its implementation details are not immediately accessible any more. Instead they are packaged and are only indirectly accessible via the interface of the object
- What is inheritance? Explain with an example. Inheritance in object oriented programming means that a class of objects can inherit properties and methods from another class of objects.
- What is polymorphism? Explain with an example. In object-oriented programming, polymorphism refers to a programming language’s ability to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes. For example, given a base class shape, polymorphism enables the programmer to define different area methods for any number of derived classes, such as circles, rectangles and triangles. No matter what shape an object is, applying the area method to it will return the correct results. Polymorphism is considered to be a requirement of any true object-oriented programming language
- Is multiple inheritance allowed in Java? No, multiple inheritance is not allowed in Java.
- What is interpreter and compiler? Java interpreter converts the high level language code into a intermediate form in Java called as bytecode, and then executes it, where as a compiler converts the high level language code to machine language making it very hardware specific
- What is JVM? The Java interpreter along with the runtime environment required to run the Java application in called as Java virtual machine(JVM)
- What are the different types of modifiers? There are access modifiers and there are other identifiers. Access modifiers are public, protected and private. Other are final and static.
- What are the access modifiers in Java? There are 3 access modifiers. Public, protected and private, and the default one if no identifier is specified is called friendly, but programmer cannot specify the friendly identifier explicitly.
- What is a wrapper class? They are classes that wrap a primitive data type so it can be used as a object
- What is a static variable and static method? What’s the difference between two? The modifier static can be used with a variable and method. When declared as static variable, there is only one variable no matter how instances are created, this variable is initialized when the class is loaded. Static method do not need a class to be instantiated to be called, also a non static method cannot be called from static method.
- What is garbage collection? Garbage Collection is a thread that runs to reclaim the memory by destroying the objects that cannot be referenced anymore.
- What is abstract class? Abstract class is a class that needs to be extended and its methods implemented, aclass has to be declared abstract if it has one or more abstract methods.
- What is meant by final class, methods and variables? This modifier can be applied to class method and variable. When declared as final class the class cannot be extended. When declared as final variable, its value cannot be changed if is primitive value, if it is a reference to the object it will always refer to the same object, internal attributes of the object can be changed.
- What is interface? Interface is a contact that can be implemented by a class, it has method that need implementation.
- What is method overloading? Overloading is declaring multiple method with the same name, but with different argument list.
- What is method overriding? Overriding has same method name, identical arguments used in subclass.
- What is singleton class? Singleton class means that any given time only one instance of the class is present, in one JVM.
- What is the difference between an array and a vector? Number of elements in an array are fixed at the construction time, whereas the number of elements in vector can grow dynamically.
- What is a constructor? In Java, the class designer can guarantee initialization of every object by providing a special method called a constructor. If a class has a constructor, Java automatically calls that constructor when an object is created, before users can even get their hands on it. So initialization is guaranteed.
- What is casting? Conversion of one type of data to another when appropriate. Casting makes explicitly converting of data.
- What is the difference between final, finally and finalize? The modifier final is used on class variable and methods to specify certain behaviour explained above. And finally is used as one of the loop in the try catch blocks, It is used to hold code that needs to be executed whether or not the exception occurs in the try catch block. Java provides a method called finalize( ) that can be defined in the class. When the garbage collector is ready to release the storage ed for your object, it will first call finalize( ), and only on the next garbage-collection pass will it reclaim the objects memory. So finalize( ), gives you the ability to perform some important cleanup at the time of garbage collection.
- What is are packages? A package is a collection of related classes and interfaces providing access protection and namespace management.
- What is a super class and how can you call a super class? When a class is extended that is derived from another class there is a relationship is created, the parent class is referred to as the super class by the derived class that is the child. The derived class can make a call to the super class using the keyword super. If used in the constructor of the derived class it has to be the first statement.
- What is meant by a Thread? Thread is defined as an instantiated parallel process of a given program.
- What is multi-threading? Multi-threading as the name suggest is the scenario where more than one threads are running.
- What are two ways of creating a thread? Which is the best way and why? Two ways of creating threads are, one can extend from the Java.lang.Thread and can implement the rum method or the run method of a different class can be called which implements the interface Runnable, and the then implement the run() method. The latter one is mostly used as first due to Java rule of only one class inheritance, with implementing the Runnable interface that problem is sorted out.
- What is deadlock? Deadlock is a situation when two threads are waiting on each other to release a resource. Each thread waiting for a resource which is held by the other waiting thread. In Java, this resource is usually the object lock obtained by the synchronized keyword.
- What are the three types of priority? MAX_PRIORITY which is 10, MIN_PRIORITY which is 1, NORM_PRIORITY which is 5.
- What is the use of synchronizations? Every object has a lock, when a synchronized keyword is used on a piece of code the, lock must be obtained by the thread first to execute that code, other threads will not be allowed to execute that piece of code till this lock is released.
- What are synchronized methods and synchronized statements? Synchronized methods are methods that are used to control access to an object. For example, a thread only executes a synchronized method after it has acquired the lock for the method’s object or class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.
- What are different ways in which a thread can enter the waiting state? A thread can enter the waiting state by invoking its sleep() method, blocking on I/O, unsuccessfully attempting to acquire an object’s lock, or invoking an object’s wait() method. It can also enter the waiting state by invoking its (deprecated) suspend() method.
- Can a lock be acquired on a class? Yes, a lock can be acquired on a class. This lock is acquired on the class’s Class object.
- What’s new with the stop(), suspend() and resume() methods in new JDK 1.2? The stop(), suspend() and resume() methods have been deprecated in JDK 1.2.
- What is the preferred size of a component? The preferred size of a component is the minimum component size that will allow the component to display normally.
- What method is used to specify a container’s layout? The setLayout() method is used to specify a container’s layout. For example, setLayout(new FlowLayout()); will be set the layout as FlowLayout.
- Which containers use a FlowLayout as their default layout? The Panel and Applet classes use the FlowLayout as their default layout.
- What state does a thread enter when it terminates its processing? When a thread terminates its processing, it enters the dead state.
- What is the Collections API? The Collections API is a set of classes and interfaces that support operations on collections of objects. One example of class in Collections API is Vector and Set and List are examples of interfaces in Collections API.
- What is the List interface? The List interface provides support for ordered collections of objects. It may or may not allow duplicate elements but the elements must be ordered.
- How does Java handle integer overflows and underflows? It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.
- What is the Vector class? The Vector class provides the capability to implement a growable array of objects. The main visible advantage of this class is programmer needn’t to worry about the number of elements in the Vector.
- What modifiers may be used with an inner class that is a member of an outer class? A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.
- If a method is declared as protected, where may the method be accessed? A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.
- What is an Iterator interface? The Iterator interface is used to step through the elements of a Collection.
- How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters? Unicode requires 16 bits, ASCII require 7 bits (although the ASCII character set uses only 7 bits, it is usually represented as 8 bits), UTF-8 represents characters using 8, 16, and 18 bit patterns, UTF-16 uses 16-bit and larger bit patterns
- What is the difference between yielding and sleeping? Yielding means a thread returning to a ready state either from waiting, running or after creation, where as sleeping refers a thread going to a waiting state from running state. With reference to Java, when a task invokes its yield() method, it returns to the ready state and when a task invokes its sleep() method, it returns to the waiting state
- What are wrapper classes? Wrapper classes are classes that allow primitive types to be accessed as objects. For example, Integer, Double. These classes contain many methods which can be used to manipulate basic data types
- Does garbage collection guarantee that a program will not run out of memory? No, it doesn’t. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection. The main purpose of Garbage Collector is recover the memory from the objects which are no longer required when more memory is needed.
- Name Component subclasses that support painting? The following classes support painting: Canvas, Frame, Panel, and Applet.
- What is a native method? A native method is a method that is implemented in a language other than Java. For example, one method may be written in C and can be called in Java.
- How can you write a loop indefinitely?
for(;;) //for loop
while(true); //always true - Can an anonymous class be declared as implementing an interface and extending a class? An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.
- What is the purpose of finalization? The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected. For example, closing a opened file, closing a opened database Connection.
- What invokes a thread’s run() method? After a thread is started, via its start() method or that of the Thread class, the JVM invokes the thread’s run() method when the thread is initially executed.
- What is the GregorianCalendar class? The GregorianCalendar provides support for traditional Western calendars.
- What is the SimpleTimeZone class? The SimpleTimeZone class provides support for a Gregorian calendar.
- What is the Properties class? The properties class is a subclass of Hashtable that can be read from or written to a stream. It also provides the capability to specify a set of default values to be used.
- What is the purpose of the Runtime class? The purpose of the Runtime class is to provide access to the Java runtime system.
- What is the purpose of the System class? The purpose of the System class is to provide access to system resources.
- What is the purpose of the finally clause of a try-catch-finally statement? The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught. For example,
try
{
//some statements
}
catch
{
// statements when exception is cought
}
finally
{
//statements executed whether exception occurs or not
} - What is the Locale class? The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.
- What must a class do to implement an interface? It must provide all of the methods in the interface and identify the interface in its implements clause.
- What are the steps involved in establishing a JDBC connection? This action involves two steps: loading the JDBC driver and making the connection.
- How can you load the drivers?
Loading the driver or drivers you want to use is very simple and involves just one line of code. If, for example, you want to use the JDBC-ODBC Bridge driver, the following code will load it:Class.forName(”sun.jdbc.odbc.JdbcOdbcDriver”);
Your driver documentation will give you the class name to use. For instance, if the class name is jdbc.DriverXYZ, you would load the driver with the following line of code:
Class.forName(”jdbc.DriverXYZ”);
- What will Class.forName do while loading drivers? It is used to create an instance of a driver and register it with the
DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS. - How can you make the connection? To establish a connection you need to have the appropriate driver connect to the DBMS.
The following line of code illustrates the general idea:String url = “jdbc:odbc:Fred”;
Connection con = DriverManager.getConnection(url, “Fernanda”, “J8?);
- How can you create JDBC statements and what are they?
A Statement object is what sends your SQL statement to the DBMS. You simply create a Statement object and then execute it, supplying the appropriate execute method with the SQL statement you want to send. For a SELECT statement, the method to use is executeQuery. For statements that create or modify tables, the method to use is executeUpdate. It takes an instance of an active connection to create a Statement object. In the following example, we use our Connection object con to create the Statement objectStatement stmt = con.createStatement();
- How can you retrieve data from the ResultSet?
JDBC returns results in a ResultSet object, so we need to declare an instance of the class ResultSet to hold our results. The following code demonstrates declaring the ResultSet object rs.ResultSet rs = stmt.executeQuery(”SELECT COF_NAME, PRICE FROM COFFEES”);
The method getString is invoked on the ResultSet object rs, so getString() will retrieve (get) the value stored in the column COF_NAME in the current row of rs.
String s = rs.getString(”COF_NAME”);
- What are the different types of Statements?
Regular statement (use createStatement method), prepared statement (use prepareStatement method) and callable statement (use prepareCall) - How can you use PreparedStatement? This special type of statement is derived from class Statement.If you need a
Statement object to execute many times, it will normally make sense to use a PreparedStatement object instead. The advantage to this is that in most cases, this SQL statement will be sent to the DBMS right away, where it will be compiled. As a result, the PreparedStatement object contains not just an SQL statement, but an SQL statement that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatement’s SQL statement without having to compile it first.PreparedStatement updateSales = con.prepareStatement("UPDATE COFFEES SET SALES = ? WHERE COF_NAME LIKE ?"); - What does setAutoCommit do?
When a connection is created, it is in auto-commit mode. This means that each individual SQL statement is treated as a transaction and will be automatically committed right after it is executed. The way to allow two or more statements to be grouped into a transaction is to disable auto-commit mode:con.setAutoCommit(false);
Once auto-commit mode is disabled, no SQL statements will be committed until you call the method commit explicitly.
con.setAutoCommit(false); PreparedStatement updateSales = con.prepareStatement( "UPDATE COFFEES SET SALES = ? WHERE COF_NAME LIKE ?"); updateSales.setInt(1, 50); updateSales.setString(2, "Colombian"); updateSales.executeUpdate(); PreparedStatement updateTotal = con.prepareStatement("UPDATE COFFEES SET TOTAL = TOTAL + ? WHERE COF_NAME LIKE ?"); updateTotal.setInt(1, 50); updateTotal.setString(2, "Colombian"); updateTotal.executeUpdate(); con.commit(); con.setAutoCommit(true); - How do you call a stored procedure from JDBC?
The first step is to create a CallableStatement object. As with Statement an and PreparedStatement objects, this is done with an open
Connection object. A CallableStatement object contains a call to a stored procedure.CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}"); ResultSet rs = cs.executeQuery(); - How do I retrieve warnings?
SQLWarning objects are a subclass of SQLException that deal with database access warnings. Warnings do not stop the execution of an
application, as exceptions do; they simply alert the user that something did not happen as planned. A warning can be reported on a
Connection object, a Statement object (including PreparedStatement and CallableStatement objects), or a ResultSet object. Each of these
classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling object:SQLWarning warning = stmt.getWarnings(); if (warning != null) { System.out.println("n---Warning---n"); while (warning != null) { System.out.println("Message: " + warning.getMessage()); System.out.println("SQLState: " + warning.getSQLState()); System.out.print("Vendor error code: "); System.out.println(warning.getErrorCode()); System.out.println(""); warning = warning.getNextWarning(); } } - How can you move the cursor in scrollable result sets?
One of the new features in the JDBC 2.0 API is the ability to move a result set’s cursor backward as well as forward. There are also methods that let you move the cursor to a particular row and check the position of the cursor.Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
The first argument is one of three constants added to the ResultSet API to indicate the type of a ResultSet object: TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE , and TYPE_SCROLL_SENSITIVE. The second argument is one of two ResultSet constants for specifying whether a result set is read-only or updatable: CONCUR_READ_ONLY and CONCUR_UPDATABLE. The point to remember here is that if you specify a type, you must also specify whether it is read-only or updatable. Also, you must specify the type first, and because both parameters are of type int , the compiler will not complain if you switch the order. Specifying the constant TYPE_FORWARD_ONLY creates a nonscrollable result set, that is, one in which the cursor moves only forward. If you do not specify any constants for the type and updatability of a ResultSet object, you will automatically get one that is TYPE_FORWARD_ONLY and CONCUR_READ_ONLY.
ResultSet srs = stmt.executeQuery(”SELECT COF_NAME, PRICE FROM COFFEES”);
- What’s the difference between TYPE_SCROLL_INSENSITIVE , and TYPE_SCROLL_SENSITIVE?
You will get a scrollable ResultSet object if you specify one of these ResultSet constants.The difference between the two has to do with whether a result set reflects changes that are made to it while it is open and whether certain methods can be called to detect these changes. Generally speaking, a result set that is TYPE_SCROLL_INSENSITIVE does not reflect changes made while it is still open and one that is TYPE_SCROLL_SENSITIVE does. All three types of result sets will make changes visible if they are closed and then reopened:Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet srs = stmt.executeQuery("SELECT COF_NAME, PRICE FROM COFFEES"); srs.afterLast(); while (srs.previous()) { String name = srs.getString("COF_NAME"); float price = srs.getFloat("PRICE"); System.out.println(name + " " + price); } - How to Make Updates to Updatable Result Sets?
Another new feature in the JDBC 2.0 API is the ability to update rows in a result set using methods in the Java programming language rather than having to send an SQL command. But before you can take advantage of this capability, you need to create a ResultSet object that is updatable. In order to do this, you supply the ResultSet constant CONCUR_UPDATABLE to the createStatement method.Connection con = DriverManager.getConnection("jdbc:mySubprotocol:mySubName"); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet uprs = stmt.executeQuery("SELECT COF_NAME, PRICE FROM COFFEES");