Documente Academic
Documente Profesional
Documente Cultură
(Applets)
The differences between an applet and an application are as follows:
Question What are the Applet's Life Cycle methods? Explain them? (Applets)
init() method - called when an applet is first loaded. This method is called
only once in the entire cycle of an applet. This method usually intialize
the variables to be used in the applet
stop() method - called when the browser moves off the applet’s page
destroy() method - called when the browser is finished with the applet
Question What is the sequence for calling the methods by AWT for applets? (Applets)
Answer When an applet begins, the AWT calls the following methods, in this
sequence:
init()
start()
paint()
When an applet is terminated, the following sequence of method calls
takes place
stop()
destroy()
Question How are the differences between Applets and Applications? (Applets)
Application:
Answer
Applets
And within the init() of your applet, Use the following line to get the value.
When an user wants to send an int from HTML what does he needs to
Question
do? (Applets)
Either the user wants to send an int or a String, it will be the same. Here
are steps he might do to get an int
[html]
[applet code="Launch.class" archive="bak.jar" width=740 height=460]
[param name="mynum" value="098765"]
Answer [/applet]
[/html]
And within the init() of your applet, Use the following line to get the value.
URL targetURL;
String URLString = "http://localhost:8080/mypage.jsp";
AppletContext context = getAppletContext();
try
Answer {
targetURL = new URL(URLString);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
context.showDocument(targetURL);
Question Which classes and interfaces does Applet class consist? (Applets)
Applet class consists of a single class, the Applet class and three
Answer
interfaces: AppletContext, AppletStub, and AudioClip
Question What are the methods to retrive information about an applet? (Applets)
getAppletInfo() : Returns a string describing the applet, its author,
copyright information, etc.
Answer
getParameterInfo( ) method: Returns an array of string describing the
applet’s parameters
Question If you need to display a String on the applet, what would you do? (Applets)
drawString() is used to output a String to an applet. This method is
Answer
included in the paint() of the Applet
Question
How do you play audio clips without using applet class? (Applets)
You can do this using Java Media Framework. I dont have much context
Answer
on this API.
Question which containers use a border Layout as their default layout? (AWT)
The window, Frame and Dialog classes use a border layout as their
Answer
default layout
Answer Panel
Answer Window
Question What class is the top of the AWT event hierarchy? (AWT)
The java.awt.AWTEvent class is the highest-level class in the AWT event-
Answer
class hierarchy
In which package are most of the AWT events that support the event-
Question
delegation model defined? (AWT)
Most of the AWT-related events of the event-delegation model are
Answer defined in the java.awt.event package. The AWTEvent class is defined in
the java.awt package.
Answer Frame
What is the relationship between the Canvas class and the Graphics
Question
class? (AWT)
A Canvas object provides access to a Graphics object via its paint()
Answer
method.
Question What is the difference between the Font and FontMetrics classes? (AWT)
The FontMetrics class is used to define implementation-specific properties,
Answer
such as ascent and descent, of a Font object.
Question How can a GUI component handle its own events? (AWT)
A component can handle its own events by implementing the required
Answer
event-listener interface and adding itself as its own event listener.
Question What is the difference between the paint() and repaint() methods? (AWT)
The paint() method supports painting via a Graphics object. The repaint()
Answer
method is used to cause paint() to be invoked by the AWT painting thread.
Question How can the Checkbox class be used to create a radio button? (AWT)
Question Which Component subclass is used for drawing and painting? (AWT)
Answer Canvas
What are the problems faced by Java programmers who dont use layout
Question
managers? (AWT)
Answer Without layout managers, Java programmers are faced with determining
how their GUI will be displayed across multiple windowing systems and
finding a common sizing and positioning that will work within the
constraints imposed by each windowing system
Question Can there be an abstract class with no abstract methods in it? (CoreJava)
Answer Yes
Answer No
I made my class Cloneable but I still get 'Can't access protected method
Question
clone. Why? (CoreJava)
Answer Yeah, some of the Java books, in particular "The Java Programming
Language", imply that all you have to do in order to have your class
support clone() is implement the Cloneable interface. Not so. Perhaps that
was the intent at some point, but that's not the way it works currently. As
it stands, you have to implement your own public clone() method, even if
it doesn't do anything special and just calls super.clone().
How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8
Question
characters? (CoreJava)
Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII
character set uses only 7 bits, it is usually represented as 8 bits. UTF-8
Answer
represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit
and larger bit patterns.
What are order of precedence and associativity, and how are they
Question
used? (CoreJava)
Order of precedence determines the order in which operators are
Answer evaluated in expressions. Associatity determines whether an expression is
evaluated left-to-right or right-to-left
Question What is the catch or declare rule for method declarations? (CoreJava)
If a checked exception may be thrown within the body of a method, the
Answer
method must either catch the exception or declare it in its throws clause.
Question What is the difference between the Boolean & operator and the &&
operator? (CoreJava)
If an expression involving the Boolean & operator is evaluated, both
operands are evaluated. Then the & operator is applied to the operand.
When an expression involving the && operator is evaluated, the first
Answer operand is evaluated. If the first operand returns a value of true then the
second operand is evaluated. The && operator is then applied to the first
and second operands. If the first operand evaluates to false, the evaluation
of the second operand is skipped.
How are commas used in the intialization and iteration parts of a for
Question
statement? (CoreJava)
Commas are used to separate multiple statements within the initialization
Answer
and iteration parts of a for statement.
What value does read() return when it has reached the end of a
Question
file? (CoreJava)
Answer The read() method returns -1 when it has reached the end of a file.
Question What is an object's lock and which object's have locks? (CoreJava)
An object's lock is a mechanism that is used by multiple threads to obtain
synchronized access to the object. A thread may execute a synchronized
Answer method of an object only after it has acquired the object's lock. All objects
and classes have locks. A class's lock is acquired on the class's Class
object.
Answer It is written x ? y : z.
What is the difference between the Reader/Writer class hierarchy and the
Question
InputStream/OutputStream class hierarchy? (CoreJava)
The Reader/Writer class hierarchy is character-oriented, and the
Answer
InputStream/OutputStream class hierarchy is byte-oriented.
If a class is declared without any access modifiers, where may the class
Question
be accessed? (CoreJava)
A class that is declared without any access modifiers is said to have
Answer package access. This means that the class can only be accessed by other
classes and interfaces that are defined within the same package.
Question What modifiers can be used with a local inner class? (CoreJava)
Question When does the compiler supply a default constructor for a class? (CoreJava)
Question What class allows you to read objects directly from a stream? (CoreJava)
The ObjectInputStream class supports the reading of objects from input
Answer
streams.
Question How are this() and super() used with constructors? (CoreJava) Discuss in Detail
this() is used to invoke a constructor of the same class. super() is used to
Answer
invoke a superclass constructor.
Question Why are the methods of the Math class static? (CoreJava)
Answer So they can be invoked as if they are a mathematical code library.
Question What are the legal operands of the instanceof operator? (CoreJava)
The left operand is an object reference or null value and the right
Answer
operand is a class, interface, or array type.
Question What an I/O filter? (CoreJava)
An I/O filter is an object that reads from one stream and writes to
Answer another, usually altering the data in some way as it is passed from one
stream to another.
Question What happens when you add a double value to a String? (CoreJava)
Answer Hellonull
Question How does Java handle integer overflows and underflows? (CoreJava)
It uses those low order bytes of the result that can fit into the size of the
Answer
type allowed by the operation.
Question What is the difference between the >> and >>> operators? (CoreJava)
The >> operator carries the sign bit when shifting right. The >>> zero-
Answer
fills bits that have been shifted out.
Does garbage collection guarantee that a program will not run out of
Question
memory? (CoreJava)
Garbage collection does not guarantee that a program will not run out of
memory. It is possible for programs to use up memory resources faster
Answer
than they are garbage collected. It is also possible for programs to create
objects that are not subject to garbage collection
Can an object's finalize() method be invoked while it is
Question
reachable? (CoreJava)
An object's finalize() method cannot be invoked by the garbage collector
Answer while the object is still reachable. However, an object's finalize() method
may be invoked by other objects.
What value does readLine() return when it has reached the end of a
Question
file? (CoreJava)
Answer The readLine() method returns null when it has reached the end of a file.
Question What is the diffrence between inner class and nested class? (CoreJava)
When a class is defined within a scope od another class, then it becomes
inner class.
Answer
If the access modifier of the inner class is static, then it becomes nested
class.
Question Diffrence between JRE And JVM AND JDK (CoreJava) (CoreJava)
The "JDK" is the Java Development Kit. I.e., the JDK is bundle of software
that you can use to develop Java based software. The "JRE" is the Java
Runtime Environment. I.e., the JRE is an implementation of the Java
Answer Virtual Machine which actually executes Java programs. Typically, each
JDK contains one (or more) JRE's along with the various development tools
like the Java source compilers, bundling and deployment tools, debuggers,
development libraries, etc.
Question What is the difference between a public and a non-public class? (CoreJava)
A public class may be accessed outside of its package. A non-public class
Answer
may not be accessed outside of its package.
Answer Yes
What is the difference between the prefix and postfix forms of the ++
Question
operator? (CoreJava)
The prefix form performs the increment operation and returns the value
of the increment operation. The postfix form returns the current value all
Answer
of the expression and then performs the increment operation on that
value.
Question What are the Object and Class classes used for? (CoreJava)
The Object class is the highest-level class in the Java class hierarchy. The
Answer Class class is used to represent the classes and interfaces that are loaded
by a Java program.
How does a try statement determine which catch clause should be used
Question
to handle an exception? (CoreJava)
When an exception is thrown within the body of a try statement, the
catch clauses of the try statement are examined in the order in which they
Answer
appear. The first catch clause that is capable of handling the exception is
executed. The remaining catch clauses are ignored.
Question What gives java it's "write once and run anywhere" nature? (CoreJava)
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,
Answer
which is specific to a particular operating system, the code platform
specific machine code is generated thus making java platform
independent.
You can create a String object as String str = "abc"; Why cant a button
Question
object be created as Button bt = "abc";? Explain (CoreJava)
The main reason you cannot create a button by Button bt1= "abc"; is
because "abc" is a literal string (something slightly different than a String
object, by-the-way) and bt1 is a Button object. The only object in Java that
Answer
can be assigned a literal String is java.lang.String. Important to note that
you are NOT calling a java.lang.String constuctor when you type String s =
"abc";
What are the practical benefits, if any, of importing a specific class rather
Question than an entire package (e.g. import java.net.* versus import
java.net.Socket)? (CoreJava)
It makes no difference in the generated class files since only the classes
that are actually used are referenced by the generated class file. There is
another practical benefit to importing single classes, and this arises when
two (or more) packages have classes with the same name. Take
java.util.Timer and javax.swing.Timer, for example. If I import java.util.*
and javax.swing.* and then try to use "Timer", I get an error while
Answer compiling (the class name is ambiguous between both packages). Let's say
what you really wanted was the javax.swing.Timer class, and the only
classes you plan on using in java.util are Collection and HashMap. In this
case, some people will prefer to import java.util.Collection and import
java.util.HashMap instead of importing java.util.*. This will now allow them
to use Timer, Collection, HashMap, and other javax.swing classes without
using fully qualified class names in.
Does the code in finally block get executed if there is an exception and a
Question
return statement in a catch block? (CoreJava)
If an exception occurs and there is a return statement in catch block, the
finally block is still executed. The finally block will not be executed when
Answer the System.exit(1) statement is executed earlier or the system shut down
earlier or the memory is used up earlier before the thread goes to finally
block.
Question What are the Object and Class classes used for? (CoreJava)
The Object class is the highest-level class in the Java class hierarchy. The
Answer Class class is used to represent the classes and interfaces that are loaded
by a Java program.
Question What class allows you to read objects directly from a stream? (CoreJava)
The ObjectInputStream class supports the reading of objects from input
Answer
streams.
If a class is declared without any access modifiers, where may the class
Question
be accessed? (CoreJava)
A class that is declared without any access modifiers is said to have
Answer package or friendly access. This means that the class can only be accessed
by other classes and interfaces that are defined within the same package.
Question When a Serializable object is written with writeObject, then modified and
written a second time, why is the modification missing when the stream is
deserialized? (CoreJava)
The ObjectOutputStream class keeps track of each object it serializes and
sends only the handle if the object is written into the stream a subsequent
time. This is the way it deals with graphs of objects. The corresponding
ObjectInputStream keeps track of all of the objects it has created and their
handles so when the handle is seen again it can return the same object.
Answer
Both output and input streams keep this state until they are freed.
You can use the ByteArray I/O streams as an intermediate place to write
and read bytes to/from the random access file and create Object I/O
streams from the byte streams to write/read the objects. You just have to
make sure that you have the entire object in the byte stream or
Answer
reading/writing the object will fail.
Answer Another example of Singleton use is for Object Factories. Say you have a
class called FooFactory that is responsible for fetching/saving Foo objects
to/from a database. You want to ensure that for each Foo record in the db,
there is only one corresponding Foo object floating around your
application. By centralizing all the creation logic in a single class, and
making that class a Singleton, you eliminate the possibility fo duplicate
objects.
The code that uses a connection obtained from the connection pool is
another matter. If all it does is do a getData() type operation, there is no
harm in having more than one of them.
Question How are this() and super() used with constructors? (CoreJava)
this() is used to invoke a constructor of the same class. super() is used to
Answer
invoke a superclass constructor
Question What is the difference between Shallow Copy and Deep Copy? (CoreJava)
Answer Shallow Copy:
If a shallow copy is performed on an object, then it gets copied but its
contained objects are not copied. Also any changes made in the cloned
object is automatically reflected in the shallowed copy object as well. An
example
When you execute the programme, the output will be "new name", this
shows that both st1 and st2 instances are the same, changing one changes
other too.
Deep Copy:
A deep copy occurs when an object is copied along with the objects to
which it refers to are also copied. This occurs only when every object in the
tree is serializable. An example
import java.io.*;
When you execute the programme, the output will be "guddu", this shows
that st1 and st2 instances are different.
Answer Yes
Answer Yes
if(str == str1)
SOP("true");
(CoreJava)
Yes, And its going to be true as the objects have not been allocated any
Answer
memory location.
Question What's the difference between constructors and other methods? (CoreJava)
Constructors must have the same name as the class and can not return a
Answer value. They are only called once while
regular methods could be called many times.
e.g.
What would you use to compare two String variables - the operator ==
Question
or the method equals()? (CoreJava)
I'd use the method equals() to compare the values of the Strings and the
Answer == to check if two variables point at the
same instance of a String object.
Question What will the output of the following programme be? Look at the
programme carefully, we have an instance method and
static method (class method) defined in both Animal class and Cat class.
For class methods, the runtime system invokes the method defined in the
compile-time type of the reference on which the
method is called. In the example, the compile-time type of myAnimal is
Answer
Animal. Thus, the runtime system invokes the hide
method defined in Animal. For instance methods, the runtime system
invokes the method defined in the runtime type of the
reference on which the method is called. In the example, the runtime type
of myAnimal is Cat. Thus, the runtime system
invokes the override method defined in Cat.
class A {
void c() {
System.out.println("In A class");
}
}
Question public class B extends A {
void d() {
System.out.println("In B class");
}
Answer
If the main() was not static, you would require an instance of the class in
order to execute the method.
If this is the case, what would create the instance of the class? What if
your class did not have a public constructor?
java Test
Assume you have an ArrayList with 7 objects in it. And there is an int[] as
How do you go about deleting objects from ArrayList based on the values
present in int[]? (CoreJava)
Answer This looks to be very simple question as we can make a for loop and
remove objects from
ArrayList. But remember that for the first time when you try to remove an
object at index 2 from ArrayList,
you would end up with an ArrayList size reduced from 7 to 6.
The above code doesn't work as the ArrayList size would shrink when you
try to remove the first element.
You should try to delete from the bottom of the ArrayList. So that the size
of the ArrayList doesn't effect the index of the objects
that we are trying to delete.
How does a try statement determine which catch clause should be used
Question
to handle an exception? (CoreJava)
When an exception is thrown within the body of a try statement, the
catch clauses of the try statement are examined in the order in which they
Answer appear.
The first catch clause that is capable of handling the exceptionis executed.
The remaining catch clauses are ignored
Example 1:
class Test {
private String name;
}
This class is tightly encapsulated as you can't access the member "name".
Example 2:
class Test2 {
private String name;
The standard way to protect the data is to make it private, so that no other
class can get direct access to it, and
then write public methods to get the data and set the data. The method
that sets the data should carry out appropriate
checks to make sure the incoming data is valid.
In Example 2 we are validating the incoming data with "test2". If its test2
we are allowing the data to be set, else
we are throwing an exception.
Tight encapsulation will not only protect direct access to data members,
but will also prevent those members from being
set to improper values.
public class A
{
public static void main(String args[])
{
System.out.println("in A");
}
}
package corejava;
public class B
{
public static void main(String args[])
{
System.out.println("in B");
String str = "one,two";
String[] strArray = str.split(str);
A.main(strArray);
}
}
Question Can we write a static keyword before the main class? (CoreJava)
Answer No
In the first line we are creating an int array with size 5 but in the second
line we are creating an int array with 5 elements in it.
Answer
In short you are initializing an int array in line one and you are creating an
int array with elements in line two.
Question What are the different inner classes available in java? Explain each inner
class with an example. (CoreJava)
Answer There are four types of inner classes in java
1. Member class
2. Static member class
3. Local class
4. Anonymous class
1. Member class
You must provide an instance of the enclosing class when you create a new
instance of member class.
or
E.g.
public class EnclosingClass {
private static int static_var = 0; // Has got access
public int instance_var = 0; // Has got no access
Because the inner class is static, it can access only the static_var variable,
even though it is private
It cannot access the instance_var variable because it is not static,
regardless of the fact that it is public
i.showName ();
} //End of main
3. Local class
Local classes are declared within a block of code and are visible only within
that block, just as any other method
variable. Local classes are good way to maintain Encapsulation.
Local classes, like local variables, cannot be declared public, protected,
private, or static.
Local classes cannot have static members.
Local classes can only access final local variables and method arguments of
the enclosing method.
Local inner classes can be declared as abstract and final.
Example
4. Anonymous class
Example
Example
Answer Inheritance:
Inheritance is the ability to derive one class from another; the derived class
(also called the subclass) inherits all
of the methods and data members of its superclass.
class Fruit {
//...
}
class Apple extends Fruit {
//...
}
Composition:
class Fruit {
//...
}
class Apple {
private Fruit fruit = new Fruit();
//...
}
In this example, Apple is what I will call front-end class and Fruit is what I
will call back-end class.
In a composition relationship, the front-end class holds a reference in one
of its instance variables to a back-end class.
class Base
{
public void show()
{
System.out.println("In Base class");
}
}
When an object is upcast it becomes a base object for the purpose of the
cast, therefore any new fields and methods
declared in the derived class are not accessible.
Why Java is not complete Object Oriented Programming
Question
language? (CoreJava)
I am not sure what the interviewer has in his mind, but I can think of
only one reason,
Answer
"Java doesn't support multiple inheritance".
public class A
{
public static void main(String args[]) throws Exception
{
/**
* outputs the following format
*1
*23
*345
*4567
*/
for (int i = 1; i <= 4; i++) {
for (int j = 0; j < i; j++) {
System.out.print(i + j +" ");
}
System.out.println("");
}
System.out.println("*****************");
/**
* outputs the following format
*1
*12
*123
*1234
*/
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j +" ");
}
System.out.println("");
}
System.out.println("*****************");
/**
* outputs the following format
*1
*23
*456
* 7 8 9 10
*/
int k=1;
int y = 1;
for (int i = 1; i <= 4; i++) {
for (int j = 0; j < k; j++) {
System.out.print(y++ +" ");
}
k++;
System.out.println("");
}
}
}
break: breaks the current loop and moves the cursor to next line after the
loop
e.g.
for(int i=0; i < 10; i++)
{
System.out.println("i"+i);
if(i == 5) break;
}
continue: Use continue when you have to skip few lines of code in a loop
when a condition is satisfied
e.g.
return: When a condition is satisfied you may want to return from the
method itself.
e.g.
public int getValue() {
int retValue = 0;
for(int i=0; i < 10; i++)
{
retValue = i;
System.out.println("i:"+i);
if(i == 5) return retValue;
System.out.println("ii:"+i);
}
return retValue;
}
a. lazyloading - load classes only when they are required. This helps in
memory management.
E.g.
What is the difference between local inner class and non-local inner
Question
class? (CoreJava)
Answer Local inner classes may only access the local variables or method
parameters of the code block in which
they are defined. Local inner classes may only access final variables which
have been assigned a value.
A non-local inner class has access to all variables declared within the
encapsulating class
Pure Virtual functions from C++ could be abstract functions without body.
Make your class abstract, define the pure virtual methods you want
subclasseses to provide implementation for
(using the abstract keyword in their definition) and you should be good.
Since Object class is the super class of every class in java and suppose if I
Question write class x extends y and this class x also extending Object,
Is this multiple Inheritance ? (CoreJava)
When you write "public class x" which doesn't extend any other class by
default x is extending Object.
Answer When you write "public class x extends y" x is extending y and y is
extending Object class
For example
1. FileReader frdr = new FileReader(filename);
2. LineNumberReader lrdr = new LineNumberReader(frdr);
Answer Line 1 creates a file reader (frdr), and line 2 adds line-number tracking.
What are the difference between DAO (Data Access Object ) and DAC
Question
(Data Access Component)? (DesignPatterns)
Answer The advantage of using data access objects is that any business object
(which contains application or operation specific details)
does not require direct knowledge of the final destination for the
information it manipulates. As a result, if it is
necessary to change where or how that data is stored that modification can
be made without needing to change the main application.
Data Access Objects can be used in Java to insulate an application from
the underlying Java persistence technology, which could
be JDBC, JDO, EJB, Hibernate, or any one of a range of technologies. Using
Data Access Objects means the underlying technology
can be upgraded or swapped without changing other parts of the
application.
Is it possible to write two EJB's that share the same Remote and Home
Question interfaces, and have different bean classes? if so, what are the
advantages/disadvantages? (EJB)
It's certainly possible. In fact, there's an example that ships with the
Inprise Application Server of an Account interface with separate
Answer
implementations for CheckingAccount and SavingsAccount, one of which
was CMP and one of which was BMP.
Is there any way to force an Entity Bean to store itself to the db? I don't
Question wanna wait for the container to update the db, I want to do it NOW! Is it
possible? (EJB)
Specify the transaction attribute of the bean as RequiresNew. Then as per
section 11.6.2.4 of the EJB v 1.1 spec EJB container automatically starts a
Answer
new transaction before the method call. The container also performs the
commit protocol before the method result is sent to the client.
How do the six transaction attributes map to isolation levels like "dirty
Question read"? Will an attribute like "Required" lock out other readers until I'm
finished updating? (EJB)
The Transaction Attributes in EJB do not map to the Transaction Isolation
levels used in JDBC. This is a common misconception. Transaction
Attributes specify to the container when a Transaction should be started,
Answer
suspended(paused) and committed between method invocations on
Enterprise JavaBeans. For more details and a summary of Transaction
Attributes refer to section 11.6 of the EJB 1.1 specification.
Can the primary key in the entity bean be a Java primitive type such as
Question
int? (EJB)
The primary key can't be a primitive type--use the primitive wrapper
Answer 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)
Question What is the need of Remote and Home interface. Why cant it be in
one? (EJB)
In a few words, I would say that the main reason is because there is a
clear division of roles and responsibilities between the two interfaces.
The home interface is your way to communicate with the container, that is
who is responsible of creating, locating even removing one or more beans.
Answer
The remote interface is your link to the bean, that will allow you to
remotely access to all its methods and members.
As you can see there are two distinct elements (the container and the
beans) and you need two different interfaces for accessing to both of them.
Question What is the difference between Java Beans and EJB?s? (EJB)
Java Beans are client-side objects and EJBs are server side object, and
Answer
they have completely different development, lifecycle, purpose.
The EJB specification says that we cannot use Bean Managed Transaction
Question
in Entity Beans. Why? (EJB)
The short, practical answer is... because it makes your entity beans
useless as a reusable component. Also, transaction management is best
left to the application server - that's what they're there for. It's all about
Answer atomic operations on your data. If an operation updates more than one
entity then you want the whole thing to succeed or the whole thing to fail,
nothing in between. If you put commits in the entity beans then it's very
difficult to rollback if an error occurs at some point late in the operation.
What is the advantage of using Entity bean for database operations, over
Question directly using JDBC API to do database operations? When would I use one
over the other? (EJB)
Answer 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. But in case of JDBC you have to explicitly do the above features.
what suresh told is exactly perfect. ofcourse, this comes under the
database transations, but i want to add this. the great thing about the
entity beans of container managed, whenever the connection is failed
during the transaction processing, the database consistancy is mantained
automatically. the container writes the data stored at persistant storage of
the entity beans to the database again to provide the database
consistancy. where as in jdbc api, we, developers has to do manually.
What is the difference between session and entity beans? When should I
Question
use one or the other? (EJB)
An entity bean represents persistent global data from the database; a
session bean represents transient user-specific data that will die when the
Answer 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)
Question Why do we have a remove method in both EJBHome and EJBObject? (EJB)
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
Answer 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 statefull) to inform the
container of your loss of interest in this bean.
Question How can I call one EJB from inside of another EJB? (EJB)
EJBs can be clients of other EJBs. It just works. Use JNDI to locate the
Answer Home Interface of the other bean, then acquire an instance reference, and
so forth.
Question For Entity Beans, What happens to an instance field not mapped
Question
to any persistent storage,when the bean is passivated? (EJB)
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
Answer
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 dereferenc.
The EJB container implements the EJBHome and EJBObject classes. For
Question every request from a unique client, does the container create a separate
instance of the generated EJBHome and EJBObject classes? (EJB)
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.
Another Answer
Answer 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 app server. How it is implemented, it is again up to the
implementer.
What is the advantage of putting an Entity Bean instance from the "Ready
Question
State" to "Pooled state"? (EJB)
Answer 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".
Question Is there any way to read values from an entity bean without locking it for
the rest of the transaction (e.g. read-only transactions)? We have a key-
value map bean which deadlocks during some concurrent reads. Isolation
levels seem to affect the database only, and we need to work within a
transaction. (EJB)
The only thing that comes to (my) mind is that you could write a 'group
accessor' - a method that returns a single object containing all of your
entity bean's attributes (or all interesting attributes). This method could
then be placed in a 'Requires New' transaction. This way, the current
Answer transaction would be suspended for the duration of the call to the entity
bean and the entity bean's fetch/operate/commit cycle will be in a separate
transaction and any locks should be released immediately. Depending on
the granularity of what you need to pull out of the map, the group accessor
might be overkill.
Question Which XML parser comes with WebLogic Server 6.1? (EJB)
Answer We bundle a parser, based on Apache's Xerces 1.3.1 parser, in WebLogic
Server 6.1. In addition, we include a WebLogic proprietary high-
performance non-validating parser that you can use for small to medium
sized XML documents. The WebLogic XML Registry allows you to configure
the parser you want to use for specific document types.
How can I run multiple instances of the same servlet class in the same
Question
WebLogic Server instance? (EJB)
If you want to run multiple instances, your servlet will have to implement
the SingleThreadModel interface. An instance of a class that implements
the SingleThreadModel interface is guaranteed not to be invoked by
multiple threads simultaneously. Multiple instances of a SingleThreadModel
interface are used to service simultaneous requests, each running in a
single thread.
Answer
When designing your servlet, consider how you use shared resources
outside of the servlet class such as file and database access. Because there
are multiple instances of servlets that are identical, and may use exactly
the same resources, there are still synchronization and sharing issues that
must be resolved, even if you do implement the SingleThreadModel
interface.
Question What causes Java.io exceptions in the log file of WebLogic Server? (EJB)
Answer You may see messages like these in the log file:
(Windows NT)
java.io.IOException Connection Reset by Peer
java.io.EOFException Connection Reset by Peer
(Solaris)
java.io.Exception: Broken pipe
These messages occur when you are using servlets. A client initiates an
HTTP request, and then performs a series of actions on the browser:
1. Click Stop or enter equivalent command or keystrokes
2. Click Refresh or enter equivalent command or keystrokes
3. Send a new HTTP request.
The messages indicate that WebLogic Server has detected and recovered
from an interrupted HTTP request.
Question What are the enhancements in EJB 2.0 with respect to CMP? (EJB)
EJB 2.0 extends CMP to include far more robust modeling capability, with
support for declarative management of relationships between entity EJBs.
Developers no longer need to re-establish relationships between the
various beans that make up their application -- the container will restore
the connections automatically as beans are loaded, allowing bean
Answer developers to navigate between beans much as they would between any
standard Java objects.
EJB 2.0 also introduces for the first time a portable query language, based
on the abstract schema, not on the more complex database schema. This
provides a database and vendor-independent way to find entity beans at
run time, based on a wide variety of search criteria.
What are the special design care that must be taken when you work with
Question
local interfaces? (EJB)
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
Answer
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.
Can the bean class implement the EJBObject class directly? If not
Question
why? (EJB)
It is better not to do it will make the Bean class a remote object and its
methods can be accessed without the containers? security, and transaction
Answer
implementations if our code by mistake passed it in one of its parameters.
Its just a good design practice.
Question How should you type cast a remote object? Why? (EJB)
A client program that is intended to be interoperable with all compliant
EJB Container implementations must use the
javax.rmi.PortableRemoteObject.narrow(...) method to perform type-
Answer narrowing of the client-side representations of the remote home and
remote interfaces. Programs using the cast operator for narrowing the
remote and remote home interfaces are likely to fail if the Container
implementation uses RMI-IIOP as the underlying communication transport.
Question What does a remove method do for different cases of beans? (EJB)
Answer Stateless Session : Does not do anything to the bean as moving the bean
from free pool to cache are managed by the container depending on load.
Stateful Session: Removes the bean from the cache.
Entity Bean: Deletes the bean (data) from persistent storage
What is the new basic requirement for a CMP entity bean class in 2.0
Question
from that of ejb 1.1? (EJB)
It must be abstract class. The container extends it and implements
Answer
methods which are required for managing the relationships
Question What are the basic classes required in the client for invoking an EJB? (EJB)
The home and the remote interfaces, the implementation of the Naming
Context Factory, the stubs and skeletons.
Answer
In some App servers the stubs and the skeletons can be dynamically
downloaded from the server
Question What design pattern would you use to reduce JNDI lookups? (EJB)
Answer Use ServiceLocator/EJBHomeFactory Pattern to reduce expensive JNDI
lookup process.
How it works is to cache those service objects when the client performs
JNDI lookup first
time and reuse that service object from the cache second time onwards for
other clients.
This technique maintains a cache of service objects and looks up the JNDI
only first time
for a service object. This technique reduces redundant and expensive JNDI
lookup process
thus increasing performance significantly.
Question What are the different XML files used in J2EE? (EJB)
While working with an .ear deployment, you would generally be having
What are the basic configurations that needs to be taken care before an
Question
application is deployed in weblogic server 8.1? (General)
I remember of the following configurations
Question Which java.util classes and interfaces support event handling? (JavaUtil)
The EventObject class and the EventListener interface support event
Answer
processing
Question How does an included file in jsp look in the compiled .java file? (JavaUtil)
Answer If you are using jsp action include as <jsp:include page="a.jsp"/> then
you see the following line of code in the service method of the .java file
(servlet)
org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response,
"a.jsp", out, false);
If you are using directive include as *lt;%@ include file="a.jsp" %> then
you see the following line of code within the static block as
static {
_jspx_dependants = new java.util.Vector(1);
_jspx_dependants.add("/a.jsp");
}
Depending on number of times you are using these classes you can import
any one of the
package. e.g. Assume you are using java.util.Date for 5 times in your code
and you are
using java.sql.Date only for one time then import java.util.* and for using
java.sql.Date
What is the query used to display all tables names in SQL Server (Query
Question
analyzer)? (JDBC)
Answer select * from information_schema.tables
Question How many types of JDBC Drivers are present and what are they? (JDBC)
Question What is cold backup, hot backup, warm backup recovery? (JDBC)
a. cold backup - All these files must be backed up at the same time,
before the databaseis restarted.
Answer b. hot backup - official name is 'online backup' ? is a backup taken of each
tablespace while the database is running and is being accessed by the
users.
Question What are collection pools? What are the advantages? (JDBC)
A connection pool is a cache of database connections that is maintained in
Answer
memory, so that the connections may be reused
How do you get Column names only for a table (SQL Server)? Write the
Question
Query. (JDBC)
select name from syscolumns where id=(select id from sysobjects where
Answer
name='user_hdr') order by colid --user_hdr is the table name
Answer YES
What are different types of isolation levels in JDBC and explain where you
Question
can use them? (JDBC)
Answer If the application needs only committed records, then
TRANSACTION_READ_COMMITED isolation is the good choice.
If the application needs to read a row exclusively till you finish your work,
then TRANSACTION_REPEATABLE_READ is the best choice.
If the application needs to control all of the transaction problems(dirty
read, phantom read and unrepeatable read), you can choose
TRANSACTION_SERIALIZABLE for maximum safety. Performance issues
have to be taken care with this. E.g Banking applications.
If the application don't have to deal with concurrent transactions, then the
best choice is TRANSACTION_NONE to improve performance.
If the application is searching for records from the database then you can
easily choose TRANSACTION_READ_UNCOMMITED because you need not
worry about other programmes that are inserting records at the same
time. It improves performance.
Class.forName("mypackage.MyClass");
Connection con = DriverManager.getConnection("some connection
Question
string");
Answer The above statements can throw any or all of the following exceptions
LinkageError - if the linkage fails
ExceptionInInitializerError - if the initialization provoked by this method
fails
ClassNotFoundException - if the class cannot be located
SQLException - if a database access error occurs
For example, the following code fragment returns the runtime Class
Answer
descriptor for the class
named java.lang.Thread:
Class t = Class.forName("java.lang.Thread")
If your SQL gets truncated in the process of execution, How would you
Question know how much of data is trnasfered
and how much of data is left over? (JDBC)
This can be known using the class DataTruncation. DataTruncation is an
exception that reports a DataTruncation
warning (on reads) or throws a DataTruncation exception (on writes) when
JDBC unexpectedly truncates (meaning
that less information was read or written than requested) a data value. So
all we should do is write our code
Answer using the getDataSize() and getTransferSize() methods of this class in our
catch block trapping this SQLException.
The getDataSize() returns the number of bytes of data that should have
been transferred while the getTransferSize()
method returns the number of bytes of data actually transferred. The
SQLstate for a DataTruncation is 01004.
Type 2:
A native-API partly Java technology-enabled driver converts JDBC calls into
calls on the client API for Oracle, Sybase,
Informix, DB2, or other DBMS. Note that, like the bridge driver, this style of
driver requires that some binary code be
loaded on each client machine.
Type 3:
A net-protocol fully Java technology-enabled driver translates JDBC API
calls into a DBMS-independent net protocol which
is then translated to a DBMS protocol by a server. This net server
middleware is able to connect all of its Java
technology-based clients to many different databases. The specific protocol
used depends on the vendor. In general,
this is the most flexible JDBC API alternative. It is likely that all vendors of
this solution will provide products
suitable for Intranet use. In order for these products to also support
Internet access they must handle the additional
requirements for security, access through firewalls, etc., that the Web
imposes. Several vendors are adding JDBC
technology-based drivers to their existing database middleware products.
Type 4:
A native-protocol fully Java technology-enabled driver converts JDBC
technology calls into the network protocol used by
DBMSs directly. This allows a direct call from the client machine to the
DBMS server and is a practical solution for
Intranet access. Since many of these protocols are proprietary the database
vendors themselves will be the primary
source for this style of driver. Several database vendors have these in
progress.
Question How may messaging models do JMS provide for and what are they? (JMS)
JMS provide for two messaging models, publish-and-subscribe and point-
Answer
to-point queuing
Can two different JMS services talk to each other? For instance, if A and B
are two different JMS providers, can Provider A send messages directly to
Question
Provider B? If not, then can a subscriber to Provider A act as a publisher to
Provider B? (JMS)
Answer The answers are no to the first question and yes to the second. The JMS
specification does not require that one JMS provider be able to send
messages directly to another provider. However, the specification does
require that a JMS client must be able to accept a message created by a
different JMS provider, so a message received by a subscriber to Provider
A can then be published to Provider B. One caveat is that the publisher to
Provider B is not required to handle a JMSReplyTo header that refers to a
destination that is specific to Provider A.
Question What is MDB and What is the special feature of that? (JMS)
MDB is Message driven bean, which very much resembles the Stateless
session bean. The incoming and out going messages can be handled by the
Answer
Message driven bean. The ability to communicate asynchronously is the
special feature about the Message driven bean.
Question What is the difference between the Mailing and Messaging? (JMS)
Java Mailing is the set of APIs that primarily concerns with the sending of
Mail messages through the standard mail protocols. Messaging is the way
Answer of communicating to the remote machines using Message Oriented
Middlewares. Message Oriented Middlewares do not use mailing internally
for communication. They create their own channels for communication.
What are the core JMS-related objects required for each JMS-enabled
Question
application? (JMS)
Each JMS-enabled client must establish the following:
· A connection object provided by the JMS server (the message broker)
· Within a connection, one or more sessions, which provide a context for
message sending and receiving
· Within a session, either a queue or topic object representing the
Answer destination (the message staging area) within the message broker
· Within a session, the appropriate sender or publisher or receiver or
subscriber object (depending on whether the client is a message producer
or consumer and uses a point-to-point or publish/subscribe strategy,
respectively)
Within a session, a message object (to send or to receive)
Question What are the various message types supported by JMS? (JMS)
Question How does the Application server handle the JMS Connection? (JMS)
- App server creates the server session and stores them in a pool
- Connection consumer uses the server session to put messages in the
session of the JMS.
Answer
- Server session is the one that spawns the JMS session.
- Applications written by Application programmers creates the message
listener
Question What are native methods? How do you use them? (JNI)
Native methods are methods written in other languages like C, C++, or
Answer even assembly language.
You can call native methods from Java using JNI
Answer No
Question What is the difference between ServletContext and PageContext? (JSP)
Question What is the difference between directive include and jsp include? (JSP)
<%@ include> : Used to include static resources during translation time.
Answer
: Used to include dynamic content or static content during runtime.
Question What is the difference between Model 1 and Model 2 architecture? (JSP)
Answer In Model 1 there is no Controller and in Model 2 there is a Controller
Question How many JSP scripting elements are there and what are they? (JSP)
<%!
public void jspDestroy() {
...
}
%>
Question Can I stop JSP execution while in the midst of processing a request? (JSP)
Answer Yes. Preemptive termination of request processing on an error condition
is a good way to maximize the throughput of a high-volume JSP engine.
The trick (asuming Java is your scripting language) is to use the return
statement when you want to terminate further processing. For example,
consider:
<% if (request.getParameter("foo") != null) {
// generate some html or update bean property
} else {
/* output some error message or provide redirection back to the input
form after creating a memento bean updated with the 'valid' form
elements that were input. this bean can now be used by the previous form
to initialize the input elements that were valid then, return from the body
of the _jspService() method to terminate further processing */
return;
}
%>
How can I get to view any compilation/parsing errors at the client while
Question
developing JSP pages? (JSP)
With JSWDK 1.0, set the following servlet initialization property within the
\WEB-INF\servlets.properties file for your application:
Answer jsp.initparams=sendErrToClient=true
This will cause any compilation/parsing errors to be sent as part of the
response to the client.
Question Is there a way to reference the "this" variable within a JSP page? (JSP)
Yes, there is. Under JSP 1.0, the page implicit object is equivalent to
Answer
"this", and returns a reference to the servlet generated by the JSP page.
Question How can you store international / Unicode characters into a cookie? (JSP)
How can I implement a thread-safe JSP page? What are the advantages
Question
and Disadvantages of using it? (JSP)
You can make your JSPs thread-safe by having them implement the
SingleThreadModel interface. This is done by adding the directive
<%@ page isThreadSafe="false" %> within your JSP page.
With this, instead of a single instance of the servlet generated for your JSP
page loaded in memory, you will have N instances of the servlet loaded
and initialized, with the service method of each instance effectively
synchronized. You can typically control the number of instances (N) that
are instantiated for all servlets implementing SingleThreadModel through
Answer the admin screen for your JSP engine.
More importantly, avoid using the <%! DECLARE %> tag for variables. If
you do use this tag, then you should set isThreadSafe to true, as
mentioned above. Otherwise, all requests to that page will access those
variables, causing a nasty race condition.
SingleThreadModel is not recommended for normal use. There are many
pitfalls, including the example above of not being able to use <%! %>.
You should try really hard to make them thread-safe the old fashioned
way: by making them thread-safe
Question Response has already been commited error. What does it mean? (JSP)
Answer This error show only when you try to redirect a page after you already
have written something in your page. This happens because HTTP
specification force the header to be set up before the lay out of the page
can be shown (to make sure of how it should be displayed...content-
type="text/html" or "text/xml" or "plain-text" or "image/jpg", etc...) When
you try to send a redirect status (Number is line_status_402), your HTTP
server cannot send it right now if it hasn't finished to set up the header. If
not starter to set up the header, there are no problems, but if it 's already
begin to set up the header, then your HTTP server expects these headers to
be finished setting up and it cannot be the case if the stream of the page is
not over... In this last case it's like you have a file started with <HTML
Tag> <Some Headers> <Body> some output (like testing your
variables...) ... and before you indicate that the file is over (and before the
size of the page can be setted up in the header), you try to send a redirect
status... It s simply impossible due to the specification of HTTP 1.0 and 1.1
How can I enable session tracking for JSP pages if the browser has
Question
disabled cookies? (JSP)
Answer We know that session tracking uses cookies by default to associate a
session identifier with a unique user. If the browser does not support
cookies, or if cookies are disabled, you can still enable session tracking
using URL rewriting.
URL rewriting essentially includes the session ID within the link itself as a
name/value pair. However, for this to be effective, you need to append the
session ID for each and every link that is part of your servlet response.
Adding the session ID to a link is greatly simplified by means of of a couple
of methods: response.encodeURL() associates a session ID with a given
URL, and if you are using redirection, response.encodeRedirectURL() can
be used by giving the redirected URL as input.
Both encodeURL() and encodeRedirectedURL() first determine whether
cookies are supported by the browser; if so, the input URL is returned
unchanged since the session ID will be persisted as a cookie.
Consider the following example, in which two JSP files, say hello1.jsp and
hello2.jsp, interact with each other. Basically, we create a new session
within hello1.jsp and place an object within this session. The user can then
traverse to hello2.jsp by clicking on the link present within the page.Within
hello2.jsp, we simply extract the object that was earlier placed in the
session and display its contents. Notice that we invoke the encodeURL()
within hello1.jsp on the link used to invoke hello2.jsp; if cookies are
disabled, the session ID is automatically appended to the URL, allowing
hello2.jsp to still retrieve the session object.
Try this example first with cookies enabled. Then disable cookie support,
restart the brower, and try again. Each time you should see the
maintenance of the session across pages.
Do note that to get this example to work with cookies disabled at the
browser, your JSP engine has to support URL rewriting.
hello1.jsp
<%@ page session="true" %>
<%
Integer num = new Integer(100);
session.putValue("num",num);
String url =response.encodeURL("hello2.jsp");
%>
<a href='<%=url%>'>hello2.jsp</a>
hello2.jsp
<%@ page session="true" %>
<%
Integer i= (Integer )session.getValue("num");
out.println("Num value in session is "+i.intValue());
file2.jsp
<%@include file="file1.jsp"%>
<html>
<body>
<%test(out);% >
</body>
</html>
Question Is there a way I can set the inactivity lease period on a per-session basis?
(JSP)
Typically, a default inactivity lease period for all sessions is set within
your JSP engine admin screen or associated properties file. However, if
your JSP engine supports the Servlet 2.1 API, you can manage the
inactivity lease period on a per-session basis. This is done by invoking the
HttpSession.setMaxInactiveInterval() method, right after the session has
Answer been created. For example:
<%
session.setMaxInactiveInterval(300);
%>
would reset the inactivity period for this session to 5 minutes. The
inactivity interval is set in seconds.
Question How can I set a cookie and delete a cookie from within a JSP page? (JSP)
How can I prevent the word "null" from appearing in my HTML input text
Question
fields when I populate them with a resultset that has null values? (JSP)
You could make a simple wrapper function, like
<%!
String blanknull(String s) {
return (s == null) ? "" : s;
Answer }
%>
then use it inside your JSP form, like
<input type="text" name="shoesize" value="<%=blanknull(shoesize)%
>" >
How can I get to print the stacktrace for an exception occuring within my
Question
JSP page? (JSP)
Answer By printing out the exception's stack trace, you can usually diagonse a
problem better when debugging JSP pages. By looking at a stack trace, a
programmer should be able to discern which method threw the exception
and which method called that method. However, you cannot print the
stacktrace using the JSP out implicit variable, which is of type JspWriter.
You will have to use a PrintWriter object instead. The following snippet
demonstrates how you can print a stacktrace from within a JSP error page:
<%@ page isErrorPage="true" %>
<%
out.println("
");
PrintWriter pw = response.getWriter();
exception.printStackTrace(pw);
out.println("
");
%>
Question How can my JSP page communicate with an EJB Session Bean? (JSP)
Answer The following is a code snippet that demonstrates how a JSP page can
interact with an EJB session bean:
<%@ page import="javax.naming.*, javax.rmi.PortableRemoteObject,
foo.AccountHome, foo.Account" %>
<%!
//declare a "global" reference to an instance of the home interface of the
session bean
AccountHome accHome=null;
public void jspInit() {
//obtain an instance of the home interface
InitialContext cntxt = new InitialContext( );
Object ref= cntxt.lookup("java:comp/env/ejb/AccountEJB");
accHome =
(AccountHome)PortableRemoteObject.narrow(ref,AccountHome.class);
}
%>
<%
//instantiate the session bean
Account acct = accHome.create();
//invoke the remote methods
acct.doWhatever(...);
// etc etc...
%>
Question What is the difference between page and request scopes? (JSP)
If you specify scope as Page then its life span is until page is displayed or
control is forwarded to a new page. Accessibility is current page only.
Answer But if u specify as Request, its life span is until the request has been
completely processed and the response has been sent back to the user.
Accessibility is current page and any included or for-warded pages
How do you print the contents of a.jsp in b.jsp. How do you include the
Question
file? (JSP)
Answer a.jsp
<%!
public int i=10;
%>
b.jsp
<%@ include file="a.jsp" %>
<%
out.println(i);
%>
do not use as this will include the file at runtime where as the above
includes (directive include) the file at compile time
a.jsp
<%!
int x = 10;
%>
b.jsp
<%@ include file="a.jsp" %>
Question
<%
int x = 20;
out.println("x:"+x);
%>
<html>
<title>Welcome to my web page</title>
<h1>This example demonstrates the output of test.jsp</h1>
Question <%! String name=request.getParameter(``name``); %>
Name is <%=name %>
</html>
How can we access a Vector from one jsp page to another jsp page.? You
Question also need to restrict a third jsp page from having access to this
Vector. (JSP)
Answer If you use session.setAttribute("key","value"); then the object that is put
into the session is available till the session is timed out. In this case
if you need to restrict the vector in third jsp page, put it in request scope
e.g. request.setAttribute("key", "value"); By this way your object
is available till your request has been processed.
Question What are the two important TCP Socket classes? (Networking)
Socket and ServerSocket. ServerSocket is used for normal two-way
socket communication. Socket class allows us to read and write through
Answer
the sockets. getInputStream() and getOutputStream() are the two
methods available in Socket class.
Considering a=4 and b=10. Can you swap the values without using any
Question
temp variable? The final output should be a=10 and b=4. (Other)
a = a + b // 4 + 10 = 14
b = a - b // 14 - 10 = 4
a = a - b // 14 - 4 = 10
Answer
b=4
a = 10
Write a query for getting the second maximum marks of students from
Question
students table? (Other)
select max(marks) from students where marks <(select max(marks)
Answer
from students)
Considering a=4 and b=10. Can you swap the values without using any
Question
temp variable? The final output should be a=10 and b=4. (Other)
a = a + b // 4 + 10 = 14
b = a - b // 14 - 10 = 4
a = a - b // 14 - 4 = 10
Answer
b=4
a = 10
Question How many types of protocol implementations does RMI have? (RMI)
RMI has at least three protocol implementations: Java Remote Method
Protocol(JRMP), Internet Inter ORB Protocol(IIOP), and Jini Extensible
Answer Remote Invocation(JERI). These are alternatives, not part of the same
thing, All three are indeed layer 6 protocols for those who are still speaking
OSI reference model.
Does RMI-IIOP support code downloading for Java objects sent by value
Question across an IIOP connection in the same way as RMI does across a JRMP
connection? (RMI)
Answer Yes. The JDK 1.2 support the dynamic class loading.
Answer
In stand alone java application:
Create a .policy file that points to the code base where the application
resides.
Question Can we use the constructor, instead of init(), to initialize servlet? (Servlets)
Answer Yes , of course you can use the constructor instead of init(). There's
nothing to stop you. But you shouldn't. The original reason for init() was
that ancient versions of Java couldn't dynamically invoke constructors with
arguments, so there was no way to give the constructur a ServletConfig.
That no longer applies, but servlet containers still will only call your no-arg
constructor. So you won't have access to a ServletConfig or
ServletContext.
How can a servlet refresh automatically if some new data has entered the
Question
database? (Servlets)
Answer You can use a client-side Refresh or Server Push
Question The code in a finally clause will never fail to execute, right? (Servlets)
Answer Using System.exit(1); in try block will not allow finally code to execute.
This will refresh the page in the browser automatically and loads the new
data every 5 seconds.
How many cookies can one set in the response object of the servlet?
Question
Also, are there any restrictions on the size of cookies? (Servlets)
If the client is using Netscape, the browser can receive and store 300
total cookies
Answer
4 kilobytes per cookie (including name)
20 cookies per server or domain
What?s the difference between sendRedirect( ) and forward( )
Question
methods? (Servlets)
A sendRedirect method creates a new request (it?s also reflected in
browser?s URL ) where as forward method forwards the same request to
the new target(hence the chnge is NOT reflected in browser?s URL).
Answer
The previous request scope objects are no longer available after a redirect
because it results in a new request, but it?s available in forward.
SendRedirectis slower compared to forward.
Is there some sort of event that happens when a session object gets
Question
bound or unbound to the session? (Servlets)
HttpSessionBindingListener will hear the events When an object is added
and/or remove from the session object, or when the session is invalidated,
Answer
in which case the objects are first removed from the session, whether the
session is invalidated manually or automatically (timeout).
Question The first time a Jsp page is requested which method is called? (Servlets)
The first time a jsp page is requested jspInit method is called and the
Answer request is
handled by _jspService
Assume there is a servlet which is placed inside a .jar file and the .jar file
is placed under WEB-INF/lib folder. Now you
have the same servlet class under WEB-INF/classes folder. Which servlet
Question
class do you think will be called when there is a
request to that particular servlet? i.e. the servlet in WEB-INF/lib or the
servlet in WEB-INF/classes (Servlets)
The servlet in WEB-INF/classes folder will be called. classes under WEB-
Answer
INF/classes will override the classes under WEB-INF/lib.
How do I support both GET and POST protocol from the same
Question
Servlet? (Servlets)
The easy way is, just support POST, then have your doGet() method call
your doPost() method:
Implementing the service() method is usually not what you want to do,
since HttpServlet provides its own implementation
of service() that turns around and calls doGet() and doPost()
Question What is the difference between the doGet and doPost methods? (Servlets)
doGet() is called in response to an HTTP GET request. This happens when
users click on a link, or enter a URL into the
browser's address bar. It also happens with some HTML FORMs (those with
METHOD="GET" specified in the FORM tag).
How does one choose between overriding the doGet(), doPost(), and
Question
service() methods? (Servlets)
Answer The differences between the doGet() and doPost() methods are that they
are called in the HttpServlet that your servlet
extends by its service() method when it recieves a GET or a POST request
from a HTTP protocol request.
A GET request is a request to get a resource from the server. This is the
case of a browser requesting a web page. It
is also possible to specify parameters in the request, but the length of the
parameters on the whole is limited. This
is the case of a form in a web page declared this way in html: <form
method="GET"> or <form>.
The GenericServlet has a service() method that gets called when a client
request is made. This means that it gets called
by both incoming requests and the HTTP requests are given to the servlet
as they are (you must do the parsing yourself).
The HttpServlet instead has doGet() and doPost() methods that get called
when a client request is GET or POST. This
means that the parsing of the request is done by the servlet: you have the
appropriate method called and have
convenience methods to read the request parameters.
NOTE: the doGet() and doPost() methods (as well as other HttpServlet
methods) are called by the service() method.
What is the diffence between client side validations and server side
Question validations and under what scenerio we use these validations. Which one is
better? (Servlets)
When you say Clien side validation its Javascript validation. This
validation doesn't require a request to the server.
The validation is done within the browser itself.
Server side validation, The validation is done at the server end. You will
need to make a request to the server
and pass all the form data to the server to do the validation.
There is no rule that says use Client side validation for this and use Server
Answer side valiedation for that. It all depends on
your application.
If there are any simple validations, e.g. check if First name is entered and
entered email address is valid you can go for
Client side validation. If there are business rules that needs to validate
user input, then you will go for Server side
validation.
Server side validation has more control over your data validation and is
secure (You dont display your validation logic to the users)
Assume your web application name is javagalaxy then you would have
javagalaxy
- (put all your jsp's, java script files, css files here. You may create
different folders to segregate files)
-WEB-INF (put your web.xml file here)
-WEB-INFlib ( put all your library files here e.g. struts.jar, log4j.jar)
-WEB-INFclasses (put all your class files here e.g. servlets, struts action
class)
Can you please tell me how many instances of servlet will be created for a
Question
very complex 500 users system? Question by : Sonal (Servlets)
This actually depends on your configuration in web.xml
1. <load-on-startup>200</load-on-startup>
2. <load-on-startup>1</load-on-startup>
In the first point you are asking the server to create 200 instances of a
given servlet. There are Pros and Cons for this. This actually takes
much of your memory.
Answer
In the second point you are creating only one servlet instance at startup.
This is a good practice. So when the server is unable to server requests
by just this one instance, then the server would create another instance of
the servlet to handle more requests. This would continue until the
server can handle the requests.
service(), doGet() and doPost() are available by default to your servlet, but
it depends on what method you
are overriding. You can have only service() or doGet() or both doGet() and
doPost(). or all of them. It all
depends on what you wanted to acheive in your servlet.
Question What is the difference between 2 tier & 3 tier architecture? (Servlets)
In 2 tier architecture client directly interacts with the database but in 3
tier
architecture there is a middle tier that connects between client and
database.
Answer
So in 3 tier when the user asks for some information from DB, middle tier
interacts
with DB and does necessary processing on the records and gives
information to user.
Question What are the Difference between Functions and Procedures? (SQL)
1. Functions are used for computations where as Procedures can be used
for performing business logic
6) we can select the fields from function.in the case of procdure we cannot
select the fields.
<b> Types of joins </b> INNER JOIN, OUTER JOIN, CROSS JOIN.
OUTER JOIN is further classified as LEFT OUTER JOINS, RIGHT OUTER
JOINS and FULL OUTER JOINS.
Table details
<b> Cross Join </b> - A cross join merges two tables on every record in a
geometric fashion, every record of one table
is combined with every record from the other table. Two tables of 10
records each in a cross join will create a
table of 100 (10 X 10) records.
<b> Inner Join </b> - An Inner join is used to match two tables based on
values of a common field.
An inner join gets data from both tables where the specified data exists in
both tables. For E.g.
<b> Outer Join </b> - An outer join gets data from the source table at all
times, and returns data from the outer
joined table ONLY if it matches the criteria. When using outer joins, fields
will be set to NULL if data does
not exist in the outer-joined table. For E.g.
<i> a </i> Left Outer join - All outer joins retrieve records from both
tables, just as an inner join does. However,
an outer join retrieves all of the records from one of the tables. A column
in the result is NULL if the
corresponding input table did not contain a matching record.
<i> b </i> Right Outer join - The right outer join is similar to the left
outer join in that it retrieves all the
records from one side of the relationship, but this time it's the right table.
Only records where the condition
values match are retrieved from the left.
<i> c </i> Full Outer Join - The full outer join retrieves all records from
both the left and the right table.
SELECT "column_name"
FROM "table_name"
WHERE "column_name" BETWEEN 'value1' AND 'value2'
This will select all rows whose column has a value between 'value1' and
'value2'.
The number of values in the parenthesis can be one or more, with each
values separated by comma. Values can be numerical
or characters. If there is only one value inside the parenthesis, this
commend is equivalent to
Answer Yes
What is 'LIKE' used for in WHERE clause? What are the wildcard
Question
characters? (SQL)
LIKE is another keyword that is used in the WHERE clause. Basically, LIKE
allows you to do a search based on a
pattern rather than specifying exactly what is desired (as in IN) or spell out
a range (as in BETWEEN).
The syntax for is as follows:
Answer
SELECT "column_name"
FROM "table_name"
WHERE "column_name" LIKE {PATTERN}
‘%’ ( for a string of any character ) and ‘_’ (for any single character ) are
the two wild card characters.
2. Consistency - states that only valid data will be written to the database.
If, for some reason, a transaction is
executed that violates the database’s consistency rules, the entire
transaction will be rolled back and the database
will be restored to a state consistent with those rules. On the other hand, if
a transaction successfully executes,
it will take the database from one state that is consistent with the rules to
another state that is also consistent
with the rules.
Answer
3. Isolation - requires that multiple transactions occurring at the same
time not impact each other's execution.
For example, if Joe issues a transaction against a database at the same
time that Mary issues a different transaction,
both transactions should operate on the database in an isolated manner.
The database should either perform Joe's entire
transaction before executing Mary's or vice-versa. This prevents Joe's
transaction from reading intermediate data
produced as a side effect of part of Mary’s transaction that will not
eventually be committed to the database.
Note that the isolation property does not ensure which transaction will
execute first, merely that they will not
interfere with each other.
What are cursors? Explain different types of cursors. What are the
Question disadvantages of cursors?
How can you avoid cursors? (SQL)
Cursors allow row-by-row prcessing of the resultsets.
Different Types of cursors - Static, Dynamic, Forward-only, Keyset-driven.
Disadvantages of cursors - Each time you fetch a row from the cursor, it
results in a network roundtrip, where as a
normal SELECT query makes only one rowundtrip, however large the
Answer
resultset is. Cursors are also costly because they
require more resources and temporary storage (results in more IO
operations). Furthere, there are restrictions on
the SELECT statements that can be used with some types of cursors.
Most of the times, set based operations can be used instead of cursors.
What errors would arise when you try to execute a query and at the same
Question
time DB is down? (SQL)
Answer An SQLException would arise
How do you select second maximum marks from a Student table with a
Question
single statement? (SQL)
select max(marks) from Student where marks < (select max(marks)
Answer
from Student);
Question How to display the details of all employees. (Oracle DB) (SQL)
Question How to display the name and job for all employees. (Oracle DB) (SQL)
Question How to display name and salary for all employees. (Oracle DB) (SQL)
How to display employee number and total salary for each employee.
Question
(Oracle DB) (SQL)
Answer select empno, sal+comm from emp;
How to display employee name and annual salary for all employees.
Question
(Oracle DB) (SQL)
Answer select empno, empname, 12*sal+nvl(comm,0) annualsal from emp;
How to display the names of all employees who are working in department
Question
number 10. (Oracle DB) (SQL)
Answer select ename from emp where deptno=10;
How to display the names of all employees working as clerks and drawing
Question
a salary more than 3000. (Oracle DB) (SQL)
Answer select ename from emp where job='CLERK' and sal>3000;
How to display employee number and names for employees who earn
Question
commission. (Oracle DB) (SQL)
Answer select empno, ename from emp where comm is not null and comm>0;
How to display the names of employees who are working in the company
Question
for the past 5 years. (Oracle DB) (SQL)
Answer select ename from emp where sysdate-hiredate>5*365;
How to display the list of employees who have joined the company before
Question
30th June 90 sor after 31st dec 90. (Oracle DB) (SQL)
select * from emp where hiredate between '30-jun-1990' and '31-
Answer
dec-1990';
How to display the list of users in your database (using log table). (Oracle
Question
DB) (SQL)
Answer select * from dba_users;
How to display the names of all tables from the current user. (Oracle
Question
DB) (SQL)
Answer select * from tab;
Question How to display the name of the current user. (Oracle DB) (SQL)
How to display the names of employees whose name starts with alphabet
Question
S. (Oracle DB) (SQL)
Answer select ename from emp where ename like 'S%';
How to display employee names for employees whose name ends with
Question
alphabet. (Oracle DB) (SQL)
Answer select ename from emp where ename like '%S';
How to display all rows from EMP table. The system should wait after
Question
every screen full of information. (Oracle DB) (SQL)
Answer set pause on;
How to display the total salary being paid to all employees. (Oracle
Question
DB) (SQL)
Answer select sum(sal)+sum(nvl(comm,0)) from emp;
Question How to display the maximum salary from emp table. (Oracle DB) (SQL)
Question How to display the minimum salary from emp table. (Oracle DB) (SQL)
Question How to display the average salary from emp table. (Oracle DB) (SQL)
How to display the maximum salary being paid in dept no 20. (Oracle
Question
DB) (SQL)
Answer select max(sal) from emp where deptno=20;
How to display the min Sal being paid to any SALESMAN. (Oracle
Question
DB) (SQL)
Answer select min(sal) from emp where job='SALESMAN';
Question How to display the average salary drawn by managers. (Oracle DB) (SQL)
How to display the total salary drawn by analyst working in dept no 40.
Question
(Oracle DB) (SQL)
Answer select sum(sal)+sum(nvl(comm,0)) from emp where deptno=40;
How to display the names of employees in order of salary i.e. the name of
Question
the employee earning lowest salary should appear first. (Oracle DB) (SQL)
Answer select ename from emp order by sal;
How to display the details from emp table in order of emp name. (Oracle
Question
DB) (SQL)
Answer select ename from emp order by ename;
Question How to display empno, ename, deptno, and sal. Sort the output first
based on name and within name by deptno and within deptno by Sal;
(Oracle DB) (SQL)
Answer select * from emp order by ename,deptno,sal;
How to display the name of the employee along with their annual salary
Question (Sal * 12). The name of the employee earning highest annual salary
should appear first. (Oracle DB) (SQL)
select ename, 12*(sal+nvl(comm,0)) Annual from emp order by
Answer
12*(sal+nvl(comm,0)) desc;
How to display name, Sal, hra, pf, da, total Sal for each employee. The
output should be in the order of
Question
total Sal, hra 15% of Sal, da 10% of sal, pf 5% of sal total salary will be
(sal*hra*da)-pf. (Oracle DB) (SQL)
select ename,sal,sal*15/100 HRA, sal*5/100 PF, sal*10/100
Answer
DA,sal+sal*15/100-sal*5/100+sal*10/100 TOTAL_SALARY from emp
How to display dept numbers and total number of employees within each
Question
group. (Oracle DB) (SQL)
Answer select deptno,count(*) from emp group by deptno;
How to display the various jobs and total number of employees with each
Question
job group. (Oracle DB) (SQL)
Answer select job, count(*) from emp group by job;
How to display the various jobs and total salary for each job. (Oracle
Question
DB) (SQL)
Answer select job, sum(sal) from emp group by job;
How to display each job along with minimum sal being paid in each job
Question
group. (Oracle DB) (SQL)
Answer select job, min(sal) from emp group by job;
How to display the department numbers with more than three employees
Question
in each dept. (Oracle DB) (SQL)
Answer select deptno, count(*) from emp group by deptno having count(*)>3;
How to display the various jobs along with total sal for each of the jobs
Question
where total sal is greater than 40000. (Oracle DB) (SQL)
Answer select job, sum(sal) from emp group by job having sum(sal)>40000;
How to display the various jobs along with total number of employees in
Question each job. The output should
contain only those jobs with more than three employees. (Oracle DB) (SQL)
Answer select job, count(*) from emp group by job having count(*)>3;
Question How to display the name of emp who earns highest sal. (Oracle DB) (SQL)
Answer select ename from emp where sal=(select max(sal) from emp);
How to display the names of the salesman who earns a salary more than
Question
the highest salary of any clerk. (Oracle DB) (SQL)
select ename from emp where job='SALESMAN' and sal >
Answer
(select max(sal) from emp where job='CLERK');
How to display the names of clerks who earn salary more than that of
Question
James of that of sal lesser than that of Scott. (Oracle DB) (SQL)
select ename from emp where job='CLERK' and sal<(select sal from emp
Answer where ename='SCOTT') and sal>(select sal from emp where
ename='JAMES');
How to display the names of employees who earn a Sal more than that of
Question
James or that of salary greater than that of Scott. (Oracle DB) (SQL)
select ename from emp where sal <
Answer (select sal from emp where ename='SCOTT') and sal >
(select sal from emp where ename='JAMES');
How to display the names of the employees who earn highest salary in
Question
their respective departments. (Oracle DB) (SQL)
select * from emp e where sal =
Answer
(select max(sal) from emp where deptno=e.deptno)
How to display the names of employees who earn highest salaries in their
Question
respective job groups. (Oracle DB) (SQL)
select * from emp e where sal in
Answer
(select max(sal) from emp group by job having e.job=job)
Question How to display the employee names who are working in accountings
dept. (Oracle DB) (SQL)
select ename from emp where deptno =
(select deptno from dept where dname="ACCOUNTING");
Answer (or)
select ename from emp where deptno in (select deptno from dept where
dname="ACCOUNTING");
How to display the employee names who are working in Chicago. (Oracle
Question
DB) (SQL)
select ename from emp where deptno =
Answer
(select deptno from dept where loc='CHICAGO');
How to display the job groups having total salary greater then the
Question
maximum salary for managers. (Oracle DB) (SQL)
select job, sum(sal) from emp group by job having sum(sal) >
Answer
(select max(sal) from emp where job='MANAGER');
Question How to display the names of employees in Upper case. (Oracle DB) (SQL)
Question How to display the names of employees in lower case. (Oracle DB) (SQL)
Question How to display the name of employees in proper case. (Oracle DB) (SQL)
How to find out the length of your name using appropriate function.
Question
(Oracle DB) (SQL)
Answer select length('India') from dual;
Question How to display the length of all employees' names. (Oracle DB) (SQL)
How to find the first occurrence of character a from the following string
Question
'computer maintenance corporation'. (Oracle DB) (SQL)
Answer select instr('computer maintenance corporation','a',1,1) from dual;
How to display the information from EMP table. Wherever job 'manager'
Question is found it should be displayed
as boss(replace function). (Oracle DB) (SQL)
Answer select empno, ename, replace(job, 'MANAGER', 'Boss') JOB from emp;
How to display empno, ename, deptno from EMP table. Instead of display
Question department numbers display the
related department name (use decode function). (Oracle DB) (SQL)
select e.empno, e.ename, d.dname from emp e,dept d where e.deptno =
Answer
d.deptno;
How to display current date as 15th august Friday nineteen forty seven.
Question
(Oracle DB) (SQL)
Answer select to_char(sysdate,'ddth month day year') from dual;
How to display the following output for each row from EMP table as 'scott
Question has joined the company
on Wednesday 13th august nineteen ninety'. (Oracle DB) (SQL)
Answer select ename||' has joined the company on '||to_char(hiredate,'day ddth
month year') from emp;
How to find the date of nearest Saturday after current day. (Oracle
Question
DB) (SQL)
Answer select next_day(sysdate, 'SATURDAY') from dual;
How to display the date three months before the current date. (Oracle
Question
DB) (SQL)
Answer select add_months(sysdate,-3) from dual;
How to display the common jobs from department number 10 and 20.
Question
(Oracle DB) (SQL)
select job from emp where deptno=10 and job in(select job from emp
where deptno=20);
Answer (or)
select job from emp where deptno=10 intersect select job from emp where
deptno=20;
Question How to display the jobs which are unique to dept no 10. (Oracle DB) (SQL)
select job from emp where deptno=10 minus select job from emp where
deptno!=10;
Answer (or)
select job from emp where deptno = 10 and job not in (select job from
emp where deptno<>10);
How to display the details of those who do not have any person working
Question
under them. (Oracle DB) (SQL)
select empno from emp where empno not in (select mgr from emp where
Answer
mgr is not null);
How to display the details of employees who are in sales dept and grade
Question
is 3. (Oracle DB) (SQL)
Answer select * from emp where sal>=(select losal from salgrade where
grade=3) and sal<=(select hisal
from salgrade where grade=3) and deptno=(select deptno from dept
where dname='SALES');
How to display those who are not managers and who are managers any
Question
one. (Oracle DB) (SQL)
select * from emp where empno in(select mgr from emp) union
Answer select * from emp where empno not in(select mgr from emp where mgr is
not null);
How to display those employees whose name contains not less than 4
Question
chars. (Oracle DB) (SQL)
Answer Select * from emp where length(ename)>4;
How to display those departments whose name start with 'S' while
Question
location name end with 'O'. (Oracle DB) (SQL)
Answer select * from dept where dname like 'S%' and loc like '%O';
How to display those employees whose salary is more than 3000 after
Question
giving 20% increment. (Oracle DB) (SQL)
select * from emp where sal*120/100 > 3000;
Answer (or)
select * from emp where sal+sal*20/100 > 3000;
Question How to display all employees with there dept name. (Oracle DB) (SQL)
Answer select ename, dname from emp e, dept d where e.deptno = d.deptno;
Question How to display ename who are working in sales dept. (Oracle DB) (SQL)
select empno, ename from emp where deptno=(select deptno from dept
Answer
where dname='SALES');
How to display employee name, deptname, salary and comm. for those
Question Sal in between 2000 to 5000 while
location is Chicago. (Oracle DB) (SQL)
select empno,ename,deptno from emp where deptno=(select deptno
Answer from dept where loc='CHICAGO') and
sal between 2000 and 5000;
How to display those employees whose salary greater than his manager
Question
salary. (Oracle DB) (SQL)
select * from emp e where sal>(select sal from emp where
Answer
empno=e.mgr);
How to display those employees who are working in the same dept where
Question
his manager is working. (Oracle DB) (SQL)
select * from emp e where deptno = (select deptno from emp where
Answer
empno=e.mgr);
How to display those employees who are not working under any manger.
Question
(Oracle DB) (SQL)
Answer select * from emp where mgr is null or empno=mgr;
How to display grade and employees name for the dept no 10 or 30 but
Question grade is not 4, while joined the
company before 31-dec-82. (Oracle DB) (SQL)
select empno,ename,sal,deptno,hiredate,grade from emp e,salgrade s
where e.sal>=s.losal
Answer
and e.sal<=s.hisal and deptno in(10,30) and grade<>4 and hiredate<'01-
dec-1981';
How to update the salary of each employee by 10% increments that are
Question
not eligible for commission. (Oracle DB) (SQL)
Answer update emp set sal=sal+(sal*10/100) where comm is null;
How to delete those employees who joined the company before 31-
Question dec-82 while there dept location
is 'NEW YORK' or 'CHICAGO'. (Oracle DB) (SQL)
delete from emp where hiredate<'31-dec-1982' and deptno in
Answer
(select deptno from dept where loc in('NEW YORK','CHICAGO'));
How to display employee name, job, deptname, location for all who are
Question
working as managers. (Oracle DB) (SQL)
select ename,job,dname,loc from emp e, dept d where
Answer
e.deptno=d.deptno and empno in (select mgr from emp);
How to display name and salary of ford if his Sal is equal to high Sal of
Question
his grade. (Oracle DB) (SQL)
select ename,sal from emp e where ename='FORD' and sal=(select hisal
Answer from salgrade where
grade=(select grade from salgrade where e.sal>=losal and e.sal<=hisal));
Question How to display employee name, his job, his dept name, his manager
name, his grade and make out of an
under department wise. (Oracle DB) (SQL)
break on deptno;
select d.deptno, e.ename, e.job, d.dname, m.ename, s.grade from
Answer
emp e, emp m, dept d, salgrade s where e.deptno=d.deptno and e.sal
between s.losal and s.hisal and e.mgr=m.empno order by e.deptno;
How to List out all the employees name, job, and salary grade and
department name for every one in the
Question
company except 'CLERK'. Sort on salary display the highest salary. (Oracle
DB) (SQL)
select empno, ename, sal, dname, grade from emp e, dept d, salgrade s
Answer where e.deptno=d.deptno
and e.sal between s.losal and s.hisal and e.job<>'CLERK' order by sal;
How to display employee name, his job and his manager. display also
Question
employees who are without manager. (Oracle DB) (SQL)
select e.ename, e.job, m.ename Manager from emp e,emp m where
Answer e.mgr=m.empno union select
ename,job,'no manager' from emp where mgr is null;
Question How to find out the top 5 earner of company. (Oracle DB) (SQL)
select * from emp e where 5>(select count(*) from emp where sal>e.sal)
Answer
order by sal desc;
How to display the name of those employees who are getting highest
Question
salary. (Oracle DB) (SQL)
Answer select empno,ename,sal from emp where sal=(select max(sal) from emp);
How to display dname where at least 3 are working and display only
Question
dname. (Oracle DB) (SQL)
select dname from dept where deptno in
Answer
(select deptno from emp group by deptno having count(*)>3);
How to display name of those managers name whose salary is more than
Question
average salary of secompany. (Oracle DB) (SQL)
select ename, sal from emp where empno in(select mgr from emp) and
Answer
sal > (select avg(sal) from emp);
How to display those managers name whose salary is more than an
Question
average salary of his employees. (Oracle DB) (SQL)
select ename, sal from emp e where empno in(select mgr from emp) and
Answer
e.sal>(select avg(sal) from emp where mgr=e.empno);
How to display employee name, Sal, comm and net pay for those
employees whose net pay are greater
Question
than or equal to any other employee salary of the company? (Oracle
DB) (SQL)
select ename, sal, comm, sal+nvl(comm,0) netPay from emp where
Answer
sal+nvl(comm.,0)>=any(select sal from emp);
How to display those employees whose salary is less than his manager
Question
but more than salary of any other managers. (Oracle DB) (SQL)
select * from emp e where sal<(select sal from emp where empno =
Answer
e.mgr) and sal>any(select sal from emp where empno!=e.mgr);
How to find out the last 5(least) earner of the company? (Oracle
Question
DB) (SQL)
select * from emp e where 5>(select count(*) from emp where sal<e.sal)
Answer
order by sal;
How to find out the number of employees whose salary is greater than
Question
there manager salary? (Oracle DB) (SQL)
select count(*) from emp e where sal>(select sal from emp where
Answer
empno=e.mgr);
How to display those manager who are not working under president but
Question
they are working under any other manager? (Oracle DB) (SQL)
select * from emp e where mgr in(select empno from emp where
Answer
ename<>'KING');
How to delete those records from EMP table whose deptno not available
Question
in dept table? (Oracle DB) (SQL)
Answer delete from emp where deptno not in(select deptno from dept);
How to display those earners whose salary is out of the grade available in
Question
Sal grade table? (Oracle DB) (SQL)
select * from emp where sal<(select min(losal) from salgrade) or
Answer
sal>(select max(hisal) from salgrade);
How to display employee name, Sal, comm. and whose net pay is greater
Question
than any other in the company? (Oracle DB) (SQL)
Select ename, sal, comm from emp where sal+sal*15/100-sal*5/100
Answer +sal*10/100 =
(select max(sal+sal*15/100-sal*5/100+sal*10/100) from emp);
How to display name of those employees who are going to retire 31-
Question dec-99. If the maximum job is
period is 18 years? (Oracle DB) (SQL)
Answer select * from emp where (to_date('31-dec-1999')-hiredate)/365>18;
How to display those employees who joined in the company in the month
Question
of DEC? (Oracle DB) (SQL)
Answer select * from emp where upper(to_char(hiredate,'mon'))='DEC';
How to display those employees whose first 2 characters from hire date-
Question
last 2 characters of salary? (Oracle DB) (SQL)
select substr(hiredate,0,2)||substr(sal,length(sal)-1,2) from emp;
Answer
select concat( substr(hiredate,0,2), substr(sal,length(sal)-1,2) ) from emp;
How to display those employees whose 10% of salary is equal to the year
Question
of joining? (Oracle DB) (SQL)
Answer select * from emp where to_char(hiredate,'yy')=sal*10/100;
How to display those employees who joined the company before 15th of
Question
the month? (Oracle DB) (SQL)
select empno,ename from emp where hiredate<(to_date('15-'||
Answer
to_char(hiredate,'mon')||'-'||to_char(hiredate,'yyyy')));
How to delete those employees who joined the company 21 years back
Question
from today? (Oracle DB) (SQL)
select * from emp where round((sysdate-hiredate)/365)>21; or
Answer select * from emp where (to_char (sysdate, 'yyyy')-to_char
(hiredate ,'yyyy') )>21;
How to count the no of employees who are working as manager (use set
Question
operation)? (Oracle DB) (SQL)
Answer select count(*) from emp where empno in(select mgr from emp);
How to display the name of then dept those employees who joined the
Question
company on the same date? (Oracle DB) (SQL)
select empno,ename,hiredate,deptno from emp e where hiredate in
Answer
(select hiredate from emp where empno<>e.empno);
How to list all employees with hire date in the format 'June 4 1988'?
Question
(Oracle DB) (SQL)
Answer select to_char(hiredate,'month dd yyyy') from emp;
How to print a list of employees displaying 'Less Salary' if less than 1500
if exactly 1500 display
Question
as 'Exact Salary' and if greater than 1500 display 'More Salary'? (Oracle
DB) (SQL)
select empno,ename,'Less Salary '||sal from emp where sal<1500
union
Answer select empno,ename,'More Salary '||sal from emp where sal>1500
union
select empno,ename,'Exact Salary '||sal from emp where sal=1500
How to write query to calculate the length of employee has been with the
Question
company? (Oracle DB) (SQL)
Answer Select round(sysdate-hiredate) from emp;
How to display those mangers who are getting less than his employees
Question
Sal. (Oracle DB) (SQL)
Select empno from emp e where sal<any(select sal from emp where
Answer
mgr=e.empno);
How to print the details of all the employees who are sub ordinate to
Question
Blake. (Oracle DB) (SQL)
Select * from emp where mgr=(select empno from emp where
Answer
ename='BLAKE');
How to display those who working as manager using co related sub query.
Question
(Oracle DB) (SQL)
Answer Select * from emp where empno in(select mgr from emp);
How to display those employees whose manger name is Jones and also
Question
with his manager name. (Oracle DB) (SQL)
Select * from emp where mgr=(select empno from emp where
Answer ename='JONES') union select * from emp
where empno=(select mgr from emp where ename='JONES');
How to define variable representing the expressions used to calculate on
Question
employee's total annual renumaration. (Oracle DB) (SQL)
Answer define emp_ann_sal=(sal+nvl(comm,0))*12;
How to use the variable in a statement which finds all employees who can
Question
earn 30,000 a year or more. (Oracle DB) (SQL)
Answer select * from emp where &emp_ann_sal>30000;
How to find out how many mangers are there with out listing them.
Question
(Oracle DB) (SQL)
Answer Select count (*) from EMP where empno in (select mgr from EMP);
How to find out the avg sal and avg total remuneration for each job type
Question
remember salesman earn commission. (Oracle DB) (SQL)
select job,avg(sal+nvl(comm,0)),sum(sal+nvl(comm,0)) from emp group
Answer
by job;
How to check whether all employees number are indeed unique. (Oracle
Question
DB) (SQL)
select count(empno),count(distinct(empno)) from emp having
Answer
count(empno)=(count(distinct(empno)));
How to list out the lowest paid employees working for each manager,
Question exclude any groups where min sal
is less than 1000 sort the output by sal. (Oracle DB) (SQL)
select e.ename,e.mgr,e.sal from emp e where sal in(select min(sal) from
Answer
emp where mgr=e.mgr) and e.sal>1000 order by sal;
How to list ename, job, annual sal, deptno, dname and grade who earn
Question
30000 per year and who are not clerks. (Oracle DB) (SQL)
Select e.ename, e.job, (e.sal+nvl(e.comm,0))*12, e.deptno, d.dname,
s.grade from emp e, salgrade s , dept d
Answer
where e.sal between s.losal and s.hisal and e.deptno=d.deptno and
(e.sal+nvl(comm,0))*12> 30000 and e.job <> 'CLERK';
How to find out the all employees who joined the company before their
Question
manager. (Oracle DB) (SQL)
Select * from emp e where hiredate<(select hiredate from emp where
Answer
empno=e.mgr);
How to list out the all employees by name and number along with their
Question manager's name and number also
display 'No Manager' who has no manager. (Oracle DB) (SQL)
Answer select e.empno,e.ename,m.empno Manager,m.ename ManagerName from
emp e,emp m where e.mgr=m.empno
union
select empno,ename,mgr,'No Manager' from emp where mgr is null;
How to find out the employees who earned the highest Sal in each job
Question
typed sort in descending Sal order. (Oracle DB) (SQL)
select * from emp e where sal =(select max(sal) from emp where
Answer
job=e.job);
How to find out the employees who earned the min Sal for their job in
Question
ascending order. (Oracle DB) (SQL)
select * from emp e where sal =(select min(sal) from emp where
Answer
job=e.job) order by sal;
How to find out the most recently hired employees in each dept order by
Question
hire date (Oracle DB) (SQL)
Answer select * from emp order by deptno,hiredate desc;
How to display ename, sal and deptno for each employee who earn a Sal
Question greater than the avg of their
department order by deptno (Oracle DB) (SQL)
select ename,sal,deptno from emp e where sal>(select avg(sal) from
Answer
emp where deptno=e.deptno) order by deptno;
How to find in which year did most people join the company. display the
Question
year and number of employees (Oracle DB) (SQL)
select count(*),to_char(hiredate,'yyyy') from emp group by
Answer
to_char(hiredate,'yyyy');
Question How to display avg sal figure for the dept (Oracle DB) (SQL)
How to write a query of display against the row of the most recently hired
Question employee. display ename hire
date and column max date showing. (Oracle DB) (SQL)
Answer select empno,hiredate from emp where hiredate=(select max (hiredate)
from emp);
How to display employees who can earn more than lowest Sal in dept no
Question
30 (Oracle DB) (SQL)
select * from emp where sal>(select min(sal) from emp where
Answer
deptno=30);
How to find employees who can earn more than every employees in dept
Question
no 30 (Oracle DB) (SQL)
select * from emp where sal>(select max(sal) from emp where
Answer deptno=30);
select * from emp where sal>all(select sal from emp where deptno=30);
Question How to select dept name dept no and sum of Sal (Oracle DB) (SQL)
break on deptno on dname;
Answer select e.deptno,d.dname,sal from emp e, dept d where e.deptno=d.deptno
order by e.deptno;
How to find all dept's which have more than 3 employees (Oracle
Question
DB) (SQL)
Answer select deptno from emp group by deptno having count(*)>3;
How to display the half of the enames in upper case and remaining lower
Question
case (Oracle DB) (SQL)
select concat ( upper ( substr ( ename, 0 , length (ename)/ 2) ),
Answer lower (substr (ename, length(ename) / 2+1, length(ename) )) ) from
emp;
Question How to select ename if ename exists more than once. (Oracle DB) (SQL)
select distinct(ename) from emp e where ename in(select ename from
Answer
emp where e.empno<>empno);
Question How to display all enames in reverse order. (Oracle DB) (SQL)
Question How to list out the employees ename, sal, PF from emp (Oracle DB) (SQL)
Question How to create table emp with only one column empno (Oracle DB) (SQL)
How to add primary key constraint after the table has been created?
Question
(Oracle DB) (SQL)
Answer alter table emp add constraint emp_empno primary key (empno);
Question How to add salary column to emp table. (Oracle DB) (SQL)
How to add column called as mgr to your emp table. This column should
Question be related to empno. Give a
command to add this constraint (Oracle DB) (SQL)
Alter table emp add mgr number (5);
Answer
Alter table emp add constraint emp_mgr foreign key (empno);
How to add dept no column to your emp table. This dept no column
Question should be related to deptno column of
dept table (Oracle DB) (SQL)
Alter table emp add deptno number (3);
Answer Alter table emp1 add constraint emp1_deptno foreign key(deptno)
references dept(deptno);
How to create table called as new emp. Using single command create this
Question table as well as to get data
into this table (use create table as) (Oracle DB) (SQL)
Answer create table newemp as select *from emp;
How to create table called as newemp. This table should contain only
Question
empno,ename, dname (Oracle DB) (SQL)
create table newemp as select empno,ename,dname from emp e , dept d
Answer
where e.deptno=d.deptno;
How to delete the rows of employees who are working in the company for
Question
more than 2 years. (Oracle DB) (SQL)
Answer delete from emp where floor(sysdate-hiredate)>2*365;
How to display employee name and department name for each employee.
Question
(Oracle DB) (SQL)
Answer select ename,dname from emp e, dept d where e.deptno=d.deptno;
Question How to display employee name and his manager name. (Oracle DB) (SQL)
Answer Select e.ename, m.ename from emp e, emp m where e.mgr=m.empno;
How to display the department name along with total salary in each
Question
department. (Oracle DB) (SQL)
Answer Select deptno, sum(sal) from emp group by deptno;
Question How to display the current date and time (Oracle DB) (SQL)
Answer select to_char(sysdate,'month mon dd yy yyyy hh:mi:ss') from dual;
Can you write your own method in Action class other than execute() and
Question call that user method
directly? (Struts)
Answer Yes, We can create any number of methods in Action class and instruct
the action tag in
struts-config.xml file to call that user method. This is possible by using
DispatchAction class.
}
In the above Action class if the user wants to call any method, he would do
something
like this in my struts-config.xml file
<action path="/somePage"
type="StudentAction"
name="studentForm"
<b>parameter="methodToCall"</b>
scope="request"
validate="true"
input="/student.jsp">
What happens when the user has not provided required information that
is needed by the struts
Question
validator framework? Explain how struts handles to display the validation
messages? (Struts)
When the user has not provided any required information, the validation
messages are
displayed to the user and this block of code does this job.
<logic:messagesPresent>
<bean:message key="errors.header.login"/>
Answer
<ul>
<html:messages id="error">
<li><bean:write name="error"/></li>
</html:messages>
</ul><hr />
</logic:messagesPresent>
Question Brief on how struts validation is working (Struts)
Struts uses 2 XML files to validate the user form. validator-rules.xml and
validation.xml
files. The validator-rules.xml defines a set of standard validations and
these validations
Answer are used in validation.xml file.
Generally the rules defined in validator-rules.xml file are typical java class
files that does
the validation in the backend.
Do you write an ActionForm class for every form that you need to
Question
process? (Struts)
Answer No, I define DynaValidatorForm as this class takes care of defining
get/set methods and
doing the validation for me. And I need to define this class in struts-
config.xml file. An e.g.
would be
<form-beans>
<form-bean name="categoryForm"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="category" type="java.lang.String"/
>
</form-bean>
</form-beans>
Question How would struts handle "messages" required for the application? (Struts)
Messages are defined in a .properties file as name value pairs. To make
these messages
available to the application, you need to place the .properties file in WEB-
INF/classes
folder. And define the following tag in struts-config.xml file
Answer
<message-resources parameter="ApplicationResources" />
<bean:message key="title.mytitle"/>
What is the name of the XML file which handles requests and gives
Question responses? And acts
as a controller? (Struts)
Answer struts-config.xml file
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<!-- module configurations -->
<init-param>
<param-name>config/exercise</param-name>
<param-value>/WEB-INF/exercise/struts-config.xml</param-
value>
</init-param>
<init-param>
<param-name>config/upload</param-name>
<param-value>/WEB-INF/upload/struts-config.xml</param-
value>
</init-param>
</servlet>
Question What is the role of ActioMapping object in Struts Action class? (Struts)
An ActionMapping knows about the mapping of a particular request to an
Answer
instance of a particular Action class.
Sun Microsystems has provided the JSP / Servlet API specifications, and its
the web server or application server vendor who implements the logic for
the API.
What I understand from your question is, You are having multiple forms
in different pages and needs to
process this information to server at the last form.
e.g. Form 1, 2, 3 and 4 in 4 different web pages and process the data to
server at the final web page.
It is easy to have a form that spans multiple jsp's with struts. Make sure
that your form bean is part
Answer
of the session and not the request object. Also be sure to include some
type of form validation routine
that checks to make sure all of the required information has been
submitted before you send the whole
form off to the server for processing.
You cannot have single web page with multiple forms and submit all of it at
once. When you click on submit button in a form only the form that has
submit button will be submitted to server.
Question What is the difference between Action messages & Action errors? (Struts)
Why does JComponent have add() and remove() methods but Component
Question
does not? (Swing)
because JComponent is a subclass of Container, and can contain other
Answer
components and jcomponents
Question How would you create a button with rounded edges? (Swing)
There are 2 ways. The first thing is to know that a JButton?s edges are
drawn by a Border. so you can override the Button?s
paintComponent(Graphics) method and draw a circle or rounded rectangle
Answer
(whatever), and turn off the border. Or you can create a custom border
that draws a circle or rounded rectangle around any component and set
the button?s border to it.
Why won’t the JVM terminate when I close all the application
Question
windows? (Swing)
The AWT event dispatcher thread is not a daemon thread. You must
Answer
explicitly call System.exit to terminate the JVM.
Question When a thread is created and started, what is its initial state? (Threads)
Answer A thread is in the ready state after it has been created and started.
Question What happens when a thread cannot acquire a lock on an object? (Threads)
If a thread attempts to execute a synchronized method or synchronized
Answer statement and is unable to acquire an object's lock, it enters the waiting
state until the lock becomes available.
What are three ways in which a thread can enter the waiting
Question
state? (Threads)
A thread can enter the waiting state by invoking its sleep() method, by
blocking on I/O, by unsuccessfully attempting to acquire an object's lock, or
Answer
by invoking an object's wait() method. It can also enter the waiting state by
invoking its (deprecated) suspend() method.
What are the two basic ways in which classes that can be run as threads
Question
may be defined? (Threads)
A thread class may be declared as a subclass of Thread, or it may
Answer
implement the Runnable interface.
If there are 20 threads waiting in the waiting pool with same priority, how
Question
can you invoke 15th thread from the waiting pool? (Threads)
Its not possible do call a particular thread. The methods notify() will calls
thread from waiting pool, but there is no guaranty which thread is invoked.
Answer
The method notifyAll() method puts all the waiting threads from the
waiting pool in ready state.
The most common deadlock scenario occurs when two threads are both
waiting for each other to do something. The following (admittedly
contrived) code snippet makes what's going on painfully obvious:
Now, imagine a scenario whereby one thread (call it Wilma) calls fred(),
passes through the synchronization of lock_1, and is then preempted,
allowing another thread (call it Betty) to execute. Betty calls barney(),
acquires lock_2, and tries to acquire lock_1, but can't because Wilma has
it. Betty is now blocked, waiting for lock_1 to become available, so Wilma
wakes up and tries to acquire lock_2 but can't because Betty has it. Wilma
and Betty are now deadlocked. Neither one can ever execute.
(Note that lock_1 and lock_2 have to be one-element arrays rather than
simple ints, because only objects have monitors in Java; the argument to
synchronized must be an object. An array is a first-class object in Java; a
primitive-type such as int is not. Consequently, you can synchronize on it.
Moreover, a one-element array is efficient to bring into existence compared
to a more elaborate object (like an Integer) since it's both small and does
not require a constructor call. Also, note that I can keep the reference to
the lock as a simple Object reference, since I'll never access the array
elements.
Can you explain the difference between green threads and native
Question
threads? (Threads)
Green threads is thread mechanism implemented in JVM itself. It is blind
and can run on any OS, so actually all threads are run in one native thread
and scheduling is up to JVM. This is disadvantageously for SMP systems,
since only one processor can serve Java application.
Answer
Native threads is a mechanism based on OS threading mechanism. This
allows to use features of hardware and OS. For example,there is IBM's JDK
for AIX that supports native threads. The perfomance of applications can
be highly imploved by this.
I have created a program with a main method that instantiates and starts
Question three threads, the first two of which are daemons. Why daemons does die
when normal thread die? (Threads)
Because of nature of daemon threads. They are alive if exists at least one
Answer
"normal user's" thread. Otherwise they die immediately
On multi-CPU machines, native threads can run more than one thread
Answer
simultaneously by assigning different threads to
different CPUs. Green threads run on only one CPU.
Native threads create the appearance that many Java processes are
running: each thread takes up its own entry in the
process table. One clue that these are all threads of the same process is
that the memory size is identical for all the
threads - they are all using the same memory.
Individual programs are all isolated from each other in terms of their
memory and data, but individual threads are not as
they all share the same memory and data variables. Hence, implementing
multitasking is relatively easier in an operating system than implementing
multithreading.
Which UML diagram would you use to view and understand large complex
Question
systems, on a high level? (UML)
Answer Package Diagrams
Give 2 examples of non-functional requirements considered during the
Question
Design Phase? (UML)
Answer Performance and Security
Question What is the term used to describe the dependency between classes? (UML)
Answer Coupling
What is the difference between DOM and SAX? What would you use if an
Question
option is given? (XML)
Answer DOM parses an XML document and returns an instance of
org.w3c.dom.Document. This document object's tree must then
be "walked" in order to process the different elements. DOM parses the
ENTIRE Document into memory, and then makes it
available to you. The size of the Document you can parse is limited to the
memory available.
The specific parser technology that will be used will be determined by the
requirements of your application. If you need the
entire document represented, you will most likely use DOM builder
implementation. If you only care about parts of the
XML document and/or you only need to parse the document once, you
might be better served using SAX implementation.
Question Can you walk us through the steps necessary to parse XML file? (XML)
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
Answer factory.setValidating(true);
DocumentBuilder domBuilder = factory.newDocumentBuilder();
Document doc = domBuilder.parse(XMLFile);
Answer
A Schema is:
XML Schemas express shared vocabularies and allow machines to carry out
rules made by people. They provide a means for defining the structure,
content and semantics of XML documents.
The current draft of XML Schemas also uses a very different style for
declaring elements and attributes to DTDs. In addition to declaring
elements and attributes individually, developers can create models -
archetypes - that can be applied to multiple elements and refined if
necessary. This provides a lot of the functionality SOX had developed to
support object-oriented concepts like inheritance. Archetype development
and refinement will probably become the mark of the high-end schema
developer, much as the effective use of parameter entities was the mark of
the high-end DTD developer. Archetypes should be easier to model and
use consistently, however.
XML Schemas also support namespaces, a key feature of the W3C’s vision
for the future of XML. While it probably wouldn’t be impossible to integrate
DTDs and namespaces, the W3C has decided to move on, supporting
namespaces in its newer developments and not retrofitting XML 1.0. In
many cases, provided that namespace-prefixes don’t change or simply
aren’t used, DTD’s can work just fine with namespaces, and should be able
to interoperate with namespaces and schema processing that relies on
namespaces. There will be a few cases, however, where namespaces may
force developers to use the newer schemas rather than the older DTDs.