A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
What is an abstract method?
abstract class can not be final
Can there be an abstract class with no abstract methods in it? -Yes
access modifiers : private, public, ...
anonymous class: Can an anonymous class be declared as implementing an interface and extending a class?
ActionEvent - event results from the clicking of a button.
elements of a BorderLayout
default value of the boolean type is false
Capability Maturity Model (CMM)
Cut & Paste: How you restrict a user to cut and paste from the html page?
What is the relationship between the Canvas class and the Graphics class?
Serialization and deserialization
constructors of its superclass
design information about an object - Class class
Is a class a subclass of itself - yes
clicking of a button event is ActionEvent
clipping and repainting
Superclass of the Container class - Component
Checkbox is checked
What is casting?
Choice vs a List
Object and Class classes
request.getRequestDispatcher() and context.getRequestDispatcher()
Cookie delete within a JSP
EJB Context
What Class.forName will do while loading drivers?
What are cursors? Explain different types of cursors.
Default Layout: Which containers use a border layout as their default layout?
package is always imported by default - java.lang
design information about an object - Class class
How to delete duplicate rows?
highest-level event class of the event-delegation
event-listener interface and an event-adapter class
Can an exception be rethrown - Yes?
session vs entity beans
advantage of using Entity bean for database operations, over directly using JDBC
What does the "final" keyword mean in front of a variable? A method? A class?
Flow Layout: Which containers use a FlowLayout as their default layout?
finalyze: Can an object's finalize() method be invoked while it is reachable?
finalyze: How many times may an object's finalize() method be invoked by the garbage collector?
unreachable object become reachable again after finalize
finally: What is the purpose of the finally clause of a try-catch-finally statement?
Window vs Frame
Font and FontMetrics
File vs RandomAccessFile
first character of an identifier
field variable vs local variable
Difference between a "where" clause and a "having" clause.
diffrence between inner class and nested class
Local inner class modifiers - final or abstract
first character of an identifier
Can we implement an interface in a JSP?-No
What modifiers may be used with an interface declaration
What are the legal operands of the instanceof operator?
if statement and a switch statement
Can an Interface be final?- No
Can we define private and protected modifiers for variables in interfaces? - No
include and jsp include
mix JSP and SSI #include
object's lock
Layout: Specify a container's layout
field variable vs local variable
return type of a program's main() -void
What modifiers may be used with a top-level class?
Message Driven Bean
Null: Is null a keyword?
diffrence between inner class and nested class
object's lock
What restrictions are placed on method overriding?
ObjectInputStream-read objects directly from a stream
Object and Class classes
painting: Name three Component subclasses that support painting.
ServletContext and PageContext
readLine: What value does readLine() return when it has reached the end of a file?
read objects directly from a stream-ObjectInputStream
read() method returns -1 when it has reached the end of a file.
Resource Bundle class
File vs RandomAccessFile
clipping and repainting
Can an exception be rethrown - Yes?
Method implemented by all threads - run
request.getRequestDispatcher() and context.getRequestDispatcher()
RequestDispatcher and sendRedirect
remove method in both EJBHome and EJBObject
Rational Unified Process (RUP)
session vs entity beans
Sizeof: Is sizeof a keyword?
Superclass of the Container class - Component
Serialization and deserialization
serialization in EJB
synchronization primitives be used on EJB bean methods
this() and super()
Simple Time Zone class
constructors of its superclass
System class
set TextComponent read-only - SetEditable()
if statement and a switch statement
ServletContext and PageContext
RequestDispatcher and sendRedirect
What information is needed to create a TCP Socket?
How to Retrieve SQLWarnings?
Thread block : Why do threads block on I/O?
Threads may be defined as a subclass of Thread, or implement Runnable interface
Thread start: What invokes a thread's run() method?
Which Swing methods are thread-safe?
State for a thread in when it is executing? - running
Method implemented by all threads - run
What are the high-level thread states?
this() and super()
set TextComponent read-only - SetEditable()
default transaction attribute for an EJB
unreachable object become reachable again after finalize
primary key vs unique key
Extreme Programming (XP)
What is a transient variable?
A transient variable is a variable that may not be serialized.
Which containers use a border layout as their default layout?
The window, Frame and Dialog classes use a border layout as their default layout.
Threads block on i/o (that is enters the waiting state) so that other threads may execute while the i/o
Operation is performed.
How are Observer and Observable used?
Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.
What is synchronization and why is it important?
With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object's value. This often leads to significant errors.
Can a lock be acquired on a class?
Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object.
What is an object's lock and which object's have locks?
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 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.
What's new with the stop(), suspend() and resume() methods in JDK 1.2?
The stop(), suspend() and resume() methods have been deprecated in JDK 1.2.
The null value is not a keyword.
What method is used to specify a container's layout?
The setLayout() method is used to specify a container's layout.
Which containers use a FlowLayout as their default layout?
The Panel and Applet classes use the FlowLayout as their default layout.
What is the Collections API?
The Collections API is a set of classes and interfaces that support operations on collections of objects.
Which characters may be used as the second character of an identifier,
but not as the first character of an identifier?
The digits 0 through 9 may not be used as the first character of an identifier but they may be used after the first character of an identifier.
What is the List interface?
The List interface provides support for ordered collections of objects.
How does Java handle integer overflows and underflows?
It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.
What is the Vector class?
The Vector class provides the capability to implement a growable array of objects
What modifiers may be used with an inner class that is a member of an outer class?
A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.
What is an Iterator interface?
The Iterator interface is used to step through the elements of a Collection.
How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?
Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns.
What is the difference between yielding and sleeping?
When a task invokes its yield() method, it returns to the ready state. When a task invokes its sleep() method, it returns to the waiting state.
Which java.util classes and interfaces support event handling?
The EventObject class and the EventListener interface support event processing.
The sizeof operator is not a keyword.
What are wrapped classes?
Wrapped classes are classes that allow primitive types to be accessed as objects.
Can an object's finalize() method be invoked while it is reachable?
An object's finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object's finalize() method may be invoked by other objects.
Under what conditions is an object's finalize() method invoked by the garbage collector?
The garbage collector invokes an object's finalize() method when it detects that the object has become unreachable.
What is the immediate superclass of the Applet class?
Panel
Name three Component subclasses that support painting.
The Canvas, Frame, Panel, and Applet classes support painting.
What value does readLine() return when it has reached the end of a file?
The readLine() method returns null when it has reached the end of a file.
What is the immediate superclass of the Dialog class?
Window
Can a for statement loop indefinitely?
Yes, a for statement can loop indefinitely. For example, consider the following:
for(;;) ;
What class is the top of the AWT event hierarchy?
The java.awt.AWTEvent class is the highest-level class in the AWT event-class hierarchy.
Can an anonymous class be declared as implementing an interface and extending a class?
An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.
What is the immediate superclass of Menu?
MenuItem
What is the purpose of finalization?
The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.
Which class is the immediate superclass of the MenuComponent class.
Object
What invokes a thread's run() method?
After a thread is started, via its start() method or that of the Thread class, the JVM invokes the thread's run() method when the thread is initially executed.
Name three subclasses of the Component class.
Box.Filler, Button, Canvas, Checkbox, Choice, Container, Label, List, Scrollbar, or TextComponent
What is the purpose of the Runtime class?
The purpose of the Runtime class is to provide access to the Java runtime system.
How many times may an object's finalize() method be invoked by the garbage collector?
An object's finalize() method may only be invoked once by the garbage collector.
What is the purpose of the finally clause of a try-catch-finally statement?
The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.
When is the finally clause of a try-catch-finally statement executed?
The finally clause of the try-catch-finally statement is always executed unless the thread of execution terminates or an exception occurs within the execution of the finally clause.
The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.
Can a double value be cast to a byte?
Yes, a double value can be cast to a byte.
What is the difference between a break statement and a continue statement?
A break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.
Name two subclasses of the TextComponent class.
TextField and TextArea
What is the advantage of the event-delegation model over the earlier event-inheritance model?
The event-delegation model has two advantages over the event-inheritance model. First, it enables event handling to be handled by objects other than the ones that generate the events (or their containers). This allows a clean separation
between a component's design and its use. The other advantage of the event-delegation model is that it performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to repeatedly process unhandled events, as is the case of the event-inheritance
model.
Which containers may have a MenuBar?
Frame
What is the purpose of the wait(), notify(), and notifyAll() methods?
The wait(),notify(), and notifyAll() methods are used to provide an efficient way for threads to wait for a shared resource. When a thread executes an object's wait() method, it enters the waiting state. It only enters the ready state after another thread invokes the object's notify() or notifyAll() methods.
An abstract method is a method whose implementation is deferred to a subclass.
What is the relationship between the Canvas class and the Graphics class?
A Canvas object provides access to a Graphics object via its paint() method.
What are the high-level thread states?
The high-level thread states are ready, running, waiting, and dead.
What value does read() return when it has reached the end of a file?
The read() method returns -1 when it has reached the end of a file.
What is the difference between a static and a non-static inner class?
A non-static inner class may have object instances that are associated with instances of the class's outer class. A static inner class does not have any object instances.
What is the difference between the String and StringBuffer classes?
String objects are constants. StringBuffer objects are not.
If a variable is declared as private, where may the variable be accessed?
A private variable may only be accessed within the class in which it is declared.
What is the Dictionary class?
The Dictionary class provides the capability to store key-value pairs.
How are the elements of a BorderLayout organized?
The elements of a BorderLayout are organized at the borders (North, South, East, and West) and the center of a container.
What is the difference between a Window and a Frame?
The Frame class extends Window to define a main application window that can have a menu bar.
What is the difference between the Font and FontMetrics classes?
The FontMetrics class is used to define implementation-specific properties, such as ascent and descent, of a Font object.
What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.
What is the SimpleTimeZone class?
The SimpleTimeZone class provides support for a Gregorian calendar.
What is the Map interface?
The Map interface replaces the JDK 1.1 Dictionary class and is used associate keys with values.
Does a class inherit the constructors of its superclass?
A class does not inherit constructors from any of its superclasses.
For which statements does it make sense to use a label?
The only statements for which it makes sense to use a label are those statements that can enclose a break or continue statement.
What is the purpose of the System class?
The purpose of the System class is to provide access to system resources.
Which TextComponent method is used to set a TextComponent to the read-only state?
setEditable()
How are the elements of a CardLayout organized?
The elements of a CardLayout are stacked, one on top of the other, like a deck of cards.
Name the eight primitive Java types.
The eight primitive types are byte, char, short, int, long, float, double, and boolean.
Which class should you use to obtain design information about an object - Class class?
The Class class is used to obtain information about an object's design.
What is the relationship between clipping and repainting?
When a window is repainted by the AWT painting thread, it sets the clipping regions to the area of the window that requires repainting.
What is the relationship between an event-listener interface and an event-adapter class?
An event-listener interface defines the methods that must be implemented by an event handler for a particular kind of event. An event adapter provides a default implementation of an event-listener interface.
What restrictions are placed on the values of each case of a switch statement?
During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value.
What modifiers may be used with an interface declaration?
An interface may be declared as public or abstract.
What is the highest-level event class of the event-delegation model?
The java.util.EventObject class is the highest-level class in the event-delegation class hierarchy.
How are the elements of a GridBagLayout organized?
The elements of a GridBagLayout are organized according
to a grid. However, the elements are of different sizes and may occupy more
than one row or column of the grid. In addition, the rows and columns may have
different sizes.
What is the Collection interface?
The Collection interface provides support for the implementation of a mathematical bag - an unordered collection of objects that may contain duplicates.
What is the difference between static and non-static variables?
A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.
If your method doesn't use an object of the class it is defined in, but does
some work only on it's parameters, then you can declare the method to be
static
. Except for some utility methods and
main(...)
, you should probably not be using static methods. A good
example of a static methods in Java is the Math or Character classes. For
example, the Math.cos(x)
method calls the cosine method in the Math
class. Cosine takes only one (primitive) parameter, and it doesn't work on any
object. Make a call to a static method by putting a class name and a dot in
front of the method call.
What is the difference between the paint() and repaint() methods?
The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() to be invoked by the AWT painting thread.
If a method is declared as protected, where may the method be accessed?
A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.
How can the Checkbox class be used to create a radio button?
By associating Checkbox objects with a CheckboxGroup.
Which non-Unicode letter characters may be used as the first character of an identifier?
The non-Unicode letter characters $ and _ may appear as the first character of an identifier
There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte
values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.
Name four Container classes.
Window, Frame, Dialog, FileDialog, Panel, Applet, or ScrollPane
What is the difference between a Choice and a List?
A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices. Only one item may be selected from a Choice. A List may be displayed in such a way that several List items are visible. A List supports the selection of one or more List items.
What is the difference between a field variable and a local variable?
A field variable is a variable that is declared as a member of a class. A local variable is a variable that is declared local to a method.
What Checkbox method allows you to tell if a Checkbox is checked?
getState()
What are the legal operands of the instanceof operator?
The left operand is an object reference or null value and the right operand is a class, interface, or array type.
Which package is always imported by default - java.lang ?
The java.lang package is always imported by default.
What is the difference between method overriding and overloading? (CoreJava)
Overriding is a method with the same name and arguments as in a parent, whereas overloading is the same method name but different arguments
What restrictions are placed on method overriding?
Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides. The overriding method may not throw any exceptions that may not be thrown by the overridden method.
What restrictions are placed on method overloading?
Two methods may not have the same name and argument list but different return types.
What is a layout manager?
A layout manager is an object that is used to organize components in a container.
What advantage do Java's layout managers provide over traditional windowing systems?
Java uses layout managers to lay out components in a consistent manner across all windowing platforms. Since Java's layout managers aren't tied to absolute sizing and positioning, they are able to accomodate platform-specific differences among windowing systems.
What is the difference between the prefix and postfix forms of the ++ operator?
The prefix form performs the increment operation and returns the value of the increment operation. The postfix form returns the current value all of the expression and then performs the increment operation on that value.
What modifiers may be used with a top-level class?
A top-level class may be public, abstract, or final.
What are the Object and Class classes used for?
The Object class is the highest-level class in the Java class hierarchy. The Class class is used to represent the classes and interfaces that are loaded by a Java program.
What are synchronized methods and synchronized statements?
Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.
What is the difference between an if statement and a switch statement?
The if statement is used to select among two alternatives. It uses a boolean expression to decide which alternative should be executed. The switch statement is used to select among multiple alternatives. It uses an int expression to determine which alternative should be executed.
Can an Interface have an inner class? (CoreJava)
Yes public interface abc { static int i=0; void dd(); class a1 { a1() { int j; System.out.println("in interfia"); }; public static void main(String a1[]) { System.out.println("in interfia"); } } }
What is Externalizable? (CoreJava)
Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in)
What is the difference between ServletContext and PageContext? (JSP)
ServletContext: Gives the information about the container
PageContext: Gives the information about the Request
What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()? (JSP)
request.getRequestDispatcher(path): In order to create it we need to give
the relative path of the resource
context.getRequestDispatcher(path): In order to create it we need to give
the absolute path of the resource.
What is the difference between directive include and jsp include? (JSP)
<%@ include>
: Used to include static resources during translation time.
How to pass information from JSP to included JSP? (JSP)
Using <%jsp:param> tag.
What is the difference between RequestDispatcher and sendRedirect? (JSP)
RequestDispatcher: server-side redirect with request and response objects.
sendRedirect : Client-side redirect with new request and response objects.
How does JSP handle runtime exceptions? (JSP)
Using errorPage attribute of page directive and also we need to specify isErrorPage=true if the current page is intended to URL redirecting of a JSP.
How do you delete a Cookie within a JSP? (JSP)
Cookie mycook = new Cookie("name","value"); response.addCookie(mycook);
Cookie killmycook = new Cookie("mycook","value"); killmycook.setMaxAge(0);
killmycook.setPath("/"); killmycook.addCookie(killmycook);
How do I mix JSP and SSI #include? (JSP)
If you're
just including raw HTML, use the #include directive as usual inside your .jsp
file.
<!--#include file="data.inc"-->
But it's a little trickier if you want the server to evaluate any JSP code
that's inside the included file. Ronel Sumibcay (ronel@LIVESOFTWARE.COM)
says: If your data.inc file contains jsp code you will have to use
<%@ vinclude="data.inc" %>
The <!--#include file="data.inc"--> is used for including non-JSP files.
Are enterprise beans allowed to use Thread.sleep()? (EJB)
Enterprise beans make use of the services provided by the EJB container, such as life-cycle management. To avoid conflicts with these services, enterprise beans are restricted from performing certain operations: Managing or synchronizing threads
Is it possible to write two EJB's that share the same Remote and Home 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 implementations for CheckingAccount and SavingsAccount, one of which was CMP and one of which was BMP.
Is it possible to specify multiple JNDI names when deploying an EJB? (EJB)
No. To achieve this you have to deploy your EJB multiple times each specifying a different JNDI name.
Is there a guarantee of uniqueness for entity beans? (EJB)
There is no such guarantee. The server (or servers) can instantiate as many instances of the same underlying Entity Bean (with the same PK) as it wants. However, each instance is guaranteed to have up-to-date data values, and be transactionally consistent, so uniqueness is not required. This allows the server to scale the system to support multiple threads, multiple concurrent requests, and multiple hosts.
What's new in the EJB 2.0 specification? (EJB)
Following are the main features supported in EJB 2.0 * Integration of EJB with JMS * Message Driven Beans * Implement additional Business methods in Home interface which are not specific for bean instance. * EJB QL.
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 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.
What are the different identifier states of a Thread? (CoreJava)
The
different identifiers of a Thread are:
R - Running or runnable thread
S - Suspended thread
CW - Thread waiting on a condition variable
MW - Thread waiting on a monitor lock
MS - Thread suspended waiting on a monitor lock
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 responsabilities between the two interfaces.
The home interface is your way to communicate with the container, that is
who is responsable of creating, locating even removing one or more beans.
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.
What is the advantage of using Entity bean for database operations, over directly using JDBC API to do database operations? When would I use one over the other? (EJB)
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 role of serialization in EJB? (EJB)
A big part
of EJB is that it is a framework for underlying RMI: remote method
invocation. You're invoking methods remotely from JVM space 'A' on objects
which are in JVM space 'B' -- possibly running on another machine on the
network.
To make this happen, all arguments of each method call must have their
current state plucked out of JVM 'A' memory, flattened into a byte stream
which can be sent over a TCP/IP network connection, and then deserialized
for reincarnation on the other end in JVM 'B' where the actual method call
takes place.
If the method has a return value, it is serialized up for streaming back to
JVM A. Thus the requirement that all EJB methods arguments and return values
must be serializable. The easiest way to do this is to make sure all your
classes implement java.io.Serializable.
What is EJB QL? (EJB)
EJB QL is a Query Language provided for navigation across a network of enterprise beans and dependent objects defined by means of container managed persistence. EJB QL is introduced in the EJB 2.0 specification. The EJB QL query language defines finder methods for entity beans with container managed persistenceand is portable across containers and persistence managers. EJB QL is used for queries of two types of finder methods: Finder methods that are defined in the home interface of an entity bean and which return entity objects. Select methods, which are not exposed to the client, but which are used by the Bean Provider to select persistent values that are maintained by the Persistence Manager or to select entity objects that are related to the entity bean on which the query is defined.
Whats the difference between notify() and notifyAll()? (CoreJava)
notify() is used to unblock one waiting thread; notifyAll() is used to unblock all of them. Using notify() is preferable (for efficiency) when only one blocked thread can benefit from the change (for example, when freeing a buffer back into a pool). notifyAll() is necessary (for correctness) if multiple threads should resume (for example, when releasing a "writer" lock on a file might permit all "readers" to resume).
How can I implement a thread-safe JSP page? (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.
What is the default transaction attribute for an EJB? (EJB)
There is no default transaction attribute for an EJB. Section 11.5 of EJB v1.1 spec says that the deployer must specify a value for the transaction attribute for those methods having container managed transaction. In weblogic, the default transaction attribute for EJB is SUPPORTS.
What is the difference between session and entity beans? When should I 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 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)
Why is ejbFindByPrimaryKey mandatory? (EJB)
An Entity Bean represents persistent data that is stored outside of the EJB Container/Server. The ejbFindByPrimaryKey is a method used to locate and load an Entity Bean into the container, similar to a SELECT statement in SQL. By making this method mandatory, the client programmer can be assured that if they have the primary key of the Entity Bean, then they can retrieve the bean without having to create a new bean each time - which would mean creating duplications of persistent data and break the integrity of EJB.
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 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.
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 Home Interface of the other bean, then acquire an instance reference, and so forth.
What is an EJB Context? (EJB)
EJBContext is an interface that is implemented by the container, and it is also a part of the bean-container contract. Entity beans use a subclass of EJBContext called EntityContext. Session beans use a subclass called SessionContext. These EJBContext objects provide the bean class with information about its container, the client using the bean and the bean itself. They also provide other functions. See the API docs and the spec for more details.
Should synchronization primitives be used on bean methods? (EJB)
No. The EJB specification specifically states that the enterprise bean is not allowed to use thread primitives. The container is responsible for managing concurrent access to beans at runtime
What is a Message Driven Bean, What functions does a message driven bean have and how do they work in collaboration with JMS? (EJB)
Message
driven beans are the latest addition to the family of component bean types
defined by the EJB specification. The original bean types include session
beans, which contain business logic and maintain a state associated with
client sessions, and entity beans, which map objects to persistent data.
Message driven beans will provide asynchrony to EJB based applications by
acting as JMS message consumers. A message bean is associated with a JMS
topic or queue and receives JMS messages sent by EJB clients or other beans.
Unlike entity beans and session beans, message beans do not have home or
remote interfaces. Instead, message driven beans are instantiated by the
container as required. Like stateless session beans, message beans maintain
no client-specific state, allowing the container to optimally manage a pool
of message-bean instances.
Clients send JMS messages to message beans in exactly the same manner as
they would send messages to any other JMS destination. This similarity is a
fundamental design goal of the JMS capabilities of the new specification.
To receive JMS messages, message driven beans implement the
javax.jms.MessageListener interface, which defines a single "onMessage()"
method.
When a message arrives, the container ensures that a message bean
corresponding to the message topic/queue exists (instantiating it if
necessary), and calls its onMessage method passing the client's message as
the single argument. The message bean's implementation of this method
contains the business logic required to process the message.
Note that session beans and entity beans are not allowed to function as
message beans.
thread-safe
In computer programming, thread-safe describes a program portion or routine that
can be called from multiple programming threads without unwanted interaction
between the threads.
What is the advantage of putting an Entity Bean instance from the "Ready State" to "Pooled state"? (EJB)
The idea of
the "Pooled State" is to allow a container to maintain a pool of entity
beans that has been created, but has not been yet "synchronized" or assigned
to an EJBObject. This mean that the instances do represent entity beans, but
they can be used only for serving Home methods (create or findBy), since
those methods do not relay on the specific values of the bean. All these
instances are, in fact, exactly the same, so, they do not have meaningful
state. Jon Thorarinsson has also added: It can be looked at it this way:
If no client is using an entity bean of a particular type there is no need
for cachig it (the data is persisted in the database).
Therefore, in such cases, the container will, after some time, move the
entity bean from the "Ready State" to the "Pooled state" to save memory.
Then, to save additional memory, the container may begin moving entity beans
from the "Pooled State" to the "Does Not Exist State", because even though
the bean's cache has been cleared, the bean still takes up some memory just
being in the "Pooled State".
Can a Session Bean be defined without ejbCreate() method? (EJB)
The
ejbCreate() methods is part of the bean's lifecycle, so, the compiler will
not return an error because there is no ejbCreate() method.
However, the J2EE spec is explicit:
the home interface of a Stateless Session Bean must have a single create()
method with no arguments, while the session bean class must contain exactly
one ejbCreate() method, also without arguments.
Stateful Session Beans can have arguments (more than one create method)
stateful beans can contain multiple ejbCreate() as long as they match with
the home interface definition
You need a reference to your EJBObject to startwith. For that Sun insists on
putting a method for creating that reference (create method in the home
interface). The EJBObject does matter here. Not the actual bean.
Is it possible to share an HttpSession between a JSP and EJB? What happens when I change a value in the HttpSession from inside an EJB? (EJB)
You can pass the HttpSession as parameter to an EJB method, only if all objects in session are serializable.This has to be consider as "passed-by-value", that means that it's read-only in the EJB. If anything is altered from inside the EJB, it won't be reflected back to the HttpSession of the Servlet Container.The "pass-by-reference" can be used between EJBs Remote Interfaces, as they are remote references. While it IS possible to pass an HttpSession as a parameter to an EJB object, it is considered to be "bad practice (1)" in terms of object oriented design. This is because you are creating an unnecessary coupling between back-end objects (ejbs) and front-end objects (HttpSession). Create a higher-level of abstraction for your ejb's api. Rather than passing the whole, fat, HttpSession (which carries with it a bunch of http semantics), create a class that acts as a value object (or structure) that holds all the data you need to pass back and forth between front-end/back-end. Consider the case where your ejb needs to support a non-http-based client. This higher level of abstraction will be flexible enough to support it. (1) Core J2EE design patterns (2001)
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 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.
What is the difference between a "Coarse Grained" Entity Bean and a "Fine Grained" Entity Bean? (EJB)
A 'fine
grained' entity bean is pretty much directly mapped to one relational table,
in third normal form.
A 'coarse grained' entity bean is larger and more complex, either because
its attributes include values or lists from other tables, or because it
'owns' one or more sets of dependent objects. Note that the coarse grained
bean might be mapped to a single table or flat file, but that single table
is going to be pretty ugly, with data copied from other tables, repeated
field groups, columns that are dependent on non-key fields, etc.
Fine grained entities are generally considered a liability in large systems
because they will tend to increase the load on several of the EJB server's
subsystems (there will be more objects exported through the distribution
layer, more objects participating in transactions, more skeletons in memory,
more EJB Objects in memory, etc.) The other side of the coin is that the 1.1
spec doesn't mandate CMP Error! No index entries found.support for dependent
objects (or even indicate how they should be supported), which makes it more
difficult to do coarse grained objects with CMP. The EJB 2.0 specification
improves this in a huge way.
What is EJBDoclet? (EJB)
EJBDoclet is an open source JavaDoc doclet that generates a lot of the EJB related source files from custom JavaDoc comments tags embedded in the EJB source file.
Wha is the output from System.out.println("Hello"+null); (CoreJava)
Hellonull
Can we use the constructor, instead of init(), to initialize servlet? (Servlets)
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 database? (Servlets)
You can use a client-side Refresh or Server Push
The code in a finally clause will never fail to execute, right? (Servlets)
Using System.exit(1); in try block will not allow finally code to execute.
Why are there no global variables in Java? (CoreJava)
Global
variables are considered bad form for a variety of reasons:
╥ Adding state variables breaks referential transparency (you no longer can
understand a statement or expression on its own: you need to understand it
in the context of the settings of the global variables).
╥ State variables lessen the cohesion of a program: you need to know more to
understand how something works. A major point of Object-Oriented programming
is to break up global state into more easily understood collections of local
state.
╥ When you add one variable, you limit the use of your program to one
instance. What you thought was global, someone else might think of as local:
they may want to run two copies of your program at once.
For these reasons, Java decided to ban global variables.
What does it mean that a class or member is final? (CoreJava)
A final class can no longer be subclassed. Mostly this is done for security
reasons with basic classes like String and Integer. It also allows the compiler
to make some optimizations, and makes thread safety a little easier to achieve.
Methods may be declared final as well. This means they may not be overridden
in a subclass.
Fields can be declared final, too. However, this has a completely different
meaning. A final field cannot be changed after it's initialized, and it must
include an initializer statement where it's declared. For example,
public final double c = 2.998;
It's also possible to make a static field final to get the effect of C++'s
const statement or some uses of C's #define, e.g.
public static final double c = 2.998;
How may messaging models do JMS provide for and what are they? (JMS)
JMS provide for two messaging models, publish-and-subscribe and point-to-point queuing
What information is needed to create a TCP Socket? (Networking)
The Local System?s IP Address and Port Number. And the Remote System's IPAddress and Port Number.
What Class.forName will do while loading drivers? (JDBC)
It is used to create an instance of a driver and register it with the DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS.
How to Retrieve SQLWarnings? (JDBC)
SQLWarning
objects are a subclass of SQLException that deal with database access
warnings. Warnings do not stop the execution of an application, as
exceptions do; they simply alert the user that something did not happen as
planned. A warning can be reported on a Connection object, a Statement
object (including PreparedStatement and CallableStatement objects), or a
ResultSet object. Each of these classes has a getWarnings method, which you
must invoke in order to see the first warning reported on the calling object
E.g.
SQLWarning warning = stmt.getWarnings();
if (warning != null) {
while (warning != null) {
System.out.println("Message: " + warning.getMessage());
System.out.println("SQLState: " + warning.getSQLState());
System.out.print("Vendor error code: ");
System.out.println(warning.getErrorCode());
warning = warning.getNextWarning();
}
}
How many JSP scripting elements are there and what are they? (JSP)
There are
three scripting language elements:
declarations
scriptlets
expressions
What is the difference amongst JVM Spec, JVM Implementation, JVM Runtime ? (CoreJava)
The JVM spec is the blueprint for the JVM generated and owned by Sun. The JVM implementation is the actual implementation of the spec by a vendor and the JVM runtime is the actual running instance of a JVM implementation
Describe what happens when an object is created in Java? (CoreJava)
Several
things happen in a particular order to ensure the object is constructed
properly:
1. Memory is allocated from heap to hold all instance variables and
implementation-specific data of the object and its superclasses.
Implemenation-specific data includes pointers to class and method data.
2. The instance variables of the objects are initialized to their default
values.
3. The constructor for the most derived class is invoked. The first thing a
constructor does is call the consctructor for its superclasses. This process
continues until the constrcutor for java.lang.Object is called, as
java.lang.Object is the base class for all objects in java.
4. Before the body of the constructor is executed, all instance variable
initializers and initialization blocks are executed. Then the body of the
constructor is executed. Thus, the constructor for the base class completes
first and constructor for the most derived class completes last.
What does the "final" keyword mean in front of a variable? A method? A class? (CoreJava)
FINAL for a
variable : value is constant
FINAL for a method : cannot be overridden
FINAL for a class : cannot be derived
What is the difference between instanceof and isInstance? (CoreJava)
instanceof
is used to check to see if an object can be cast into a specified type
without throwing a cast class exception.
isInstance()
Determines if the specified Object is assignment-compatible with the object
represented by this Class. This method is the dynamic equivalent of the Java
language instanceof operator. The method returns true if the specified
Object argument is non-null and can be cast to the reference type
represented by this Class object without raising a ClassCastException. It
returns false otherwise.
Which Swing methods are thread-safe? (Swing)
The only thread-safe methods are repaint(), revalidate(), and invalidate()
Why won?t the JVM terminate when I close all the application windows? (Swing)
The AWT event dispatcher thread is not a daemon thread. You must explicitly call System.exit to terminate the JVM.
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.
If the access modifier of the inner class is static, then it becomes nested
class.
What is a design pattern? (General)
A design pattern systematically names, motivates, and explains a general design that addresses a recurring design problem.
What JSP lifecycle methods can I override? (JSP)
You cannot
override the _jspService() method within a JSP page. You can however,
override the jspInit() and jspDestroy() methods within a JSP page. jspInit()
can be useful for allocating resources like database connections, network
connections, and so forth for the JSP page. It is good programming practice
to free any allocated resources within jspDestroy().
The jspInit() and jspDestroy() methods are each executed just once during
the lifecycle of a JSP page and are typically declared as JSP declarations:
<%!
public void jspInit() {
. . .
}
%>
<%!
public void jspDestroy() {
. . .
}
%>
How do I include static files within a JSP page? (JSP)
Static
resources should always be included using the JSP include directive. This
way, the inclusion is performed just once during the translation phase. The
following example shows the syntax:
<%@ include file="copyright.html" %>
Do note that you should always supply a relative URL for the file attribute.
Although you can also include static resources using the action, this is not
advisable as the inclusion is then performed for each and every request.
How do I perform browser redirection from a JSP page? (JSP)
You can use
the response implicit object to redirect the browser to a different
resource, as:
response.sendRedirect("http://www.foo.com/path/error.html");
You can also physically alter the Location HTTP header attribute, as shown
below:
<%
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
String newLocn = "/newpath/index.html";
response.setHeader("Location",newLocn);
%>
You can also use the: <jsp:forward page="/newpage.jsp" /> Also note that you
can only use this before any output has been sent to the client. I beleve
this is the case with the response.sendRedirect() method as well.
If you want to pass any paramateres then you can pass using <jsp:forward
page="/servlet/login"> <jsp:param name="username" value="jsmith" /> </jsp:forward>>
Can a JSP page instantiate a serialized bean? (JSP)
No problem!
The useBean action specifies the beanName attribute, which can be used for
indicating a serialized bean. For example:
<jsp:useBean id="shop" type="shopping.CD" beanName="CD" /> <jsp:getProperty
name="shop" property="album" />
A couple of important points to note. Although you would have to name your
serialized file "filename.ser", you only indicate "filename" as the value
for the beanName attribute. Also, you will have to place your serialized
file within the WEB-INF\jsp\beans directory for it to be located by the JSP
engine.
Can you make use of a ServletOutputStream object from within a JSP page? (JSP)
No. You are
supposed to make use of only a JSPWriter object (given to you in the form of
the implicit object out) for replying to clients. A JSPWriter can be viewed
as a buffered version of the stream object returned by response.getWriter(),
although from an implementational perspective, it is not. A page author can
always disable the default buffering for any page using a page directive as:
<%@ page buffer="none" %>
What's a better approach for enabling thread-safe servlets and JSPs? SingleThreadModel Interface or Synchronization? (JSP)
Although the
SingleThreadModel technique is easy to use, and works well for low volume
sites, it does not scale well. If you anticipate your users to increase in
the future, you may be better off implementing explicit synchronization for
your shared data. The key however, is to effectively minimize the amount of
code that is synchronzied so that you take maximum advantage of
multithreading.
Also, note that SingleThreadModel is pretty resource intensive from the
server's perspective. The most serious issue however is when the number of
concurrent requests exhaust the servlet instance pool. In that case, all the
unserviced requests are queued until something becomes free - which results
in poor performance. Since the usage is non-deterministic, it may not help
much even if you did add more memory and increased the size of the instance
pool.
Can I stop JSP execution while in the midst of processing a request? (JSP)
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 developing JSP pages? (JSP)
With JSWDK
1.0, set the following servlet initialization property within the \WEB-INF\servlets.properties
file for your application:
jsp.initparams=sendErrToClient=true
This will cause any compilation/parsing errors to be sent as part of the
response to the client.
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 "this", and returns a reference to the servlet generated by the JSP page.
How do I instantiate a bean whose constructor accepts parameters using the useBean tag? (JSP)
Consider the
following bean: package bar;
public class FooBean {
public FooBean(SomeObj arg) {
...
}
//getters and setters here
}
The only way you can instantiate this bean within your JSP page is to use a
scriptlet. For example, the following snippet creates the bean with session
scope:
&l;% SomeObj x = new SomeObj(...);
bar.FooBean foobar = new FooBean(x);
session.putValue("foobar",foobar);
%> You can now access this bean within any other page that is part of the
same session as: &l;%
bar.FooBean foobar = session.getValue("foobar");
%>
To give the bean "application scope", you will have to place it within the
ServletContext as:
&l;%
application.setAttribute("foobar",foobar);
%>
To give the bean "request scope", you will have to place it within the
request object as:
&l;%
request.setAttribute("foobar",foobar);
%>
If you do not place the bean within the request, session or application
scope, the bean can be accessed only within the current JSP page (page
scope).
Once the bean is instantiated, it can be accessed in the usual way:
jsp:getProperty name="foobar" property="someProperty"/ jsp:setProperty
name="foobar" property="someProperty" value="someValue"/
Can I invoke a JSP error page from a servlet? (JSP)
Yes, you can
invoke the JSP error page and pass the exception object to it from within a
servlet. The trick is to create a request dispatcher for the JSP error page,
and pass the exception object as a javax.servlet.jsp.jspException request
attribute. However, note that you can do this from only within controller
servlets. If your servlet opens an OutputStream or PrintWriter, the JSP
engine will throw the following translation error:
java.lang.IllegalStateException: Cannot forward as OutputStream or Writer
has already been obtained
The following code snippet demonstrates the invocation of a JSP error page
from within a controller servlet:
protected void sendErrorRedirect(HttpServletRequest request,
HttpServletResponse response, String errorPageURL, Throwable e) throws
ServletException, IOException {
request.setAttribute ("javax.servlet.jsp.jspException", e);
getServletConfig().getServletContext().
getRequestDispatcher(errorPageURL).forward(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
{
try {
// do something
} catch (Exception ex) {
try {
sendErrorRedirect(request,response,"/jsp/MyErrorPage.jsp",ex);
} catch (Exception e) {
e.printStackTrace();
}
}
}
What is a compilation unit? (CoreJava)
A compilation unit is a Java source code file.
What restrictions are placed on method overriding? (CoreJava)
Overridden
methods must have the same name, argument list, and return type.
The overriding method may not limit the access of the method it overrides.
The overriding method may not throw any exceptions that may not be thrown by
the overridden method.
How can a dead thread be restarted? (CoreJava)
A dead thread cannot be restarted.
What happens if an exception is not caught? (CoreJava)
An uncaught exception results in the uncaughtException() method of the thread's ThreadGroup being invoked, which eventually results in the termination of the program in which it is thrown.
Which arithmetic operations can result in the throwing of an ArithmeticException? (CoreJava)
Integer / and % can result in the throwing of an ArithmeticException
Can an abstract class be final? (CoreJava)
An abstract class may not be declared as final
What happens if a try-catch-finally statement does not have a catch clause to handle an exception that is thrown within the body of the try statement? (CoreJava)
The exception propagates up to the next higher level try-catch statement (if any) or results in the program's termination
What is numeric promotion? (CoreJava)
Numeric promotion is the conversion of a smaller numeric type to a larger numeric type, so that integer and floating-point operations may take place. In numerical promotion, byte, char, and short values are converted to int values. The int values are also converted to long values, if necessary. The long and float values are converted to double values, as required
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 may not be accessed outside of its package.
To what value is a variable of the boolean type automatically initialized? (CoreJava)
The default value of the boolean type is false
Can try statements be nested? (CoreJava)
Yes
What is the difference between the prefix and postfix forms of the ++ 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 of the expression and then performs the increment operation on that value.
What is the purpose of a statement block? (CoreJava)
A statement block is used to organize a sequence of statements as a single statement group
What is a Java package and how is it used? (CoreJava)
A Java package is a naming context for classes and interfaces. A package is used to create a separate name space for groups of classes and interfaces. Packages are also used to organize related classes and interfaces into a single API unit and to control accessibility to these classes and interfaces.
What modifiers may be used with a top-level class? (CoreJava)
A top-level class may be public, abstract, or final.
What are the Object and Class classes used for? (CoreJava)
The Object class is the highest-level class in the Java class hierarchy. The 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 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 appear. The first catch clause that is capable of handling the exception is executed. The remaining catch clauses are ignored.
What are synchronized methods and synchronized statements? (CoreJava)
Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.
What is the difference between an if statement and a switch statement? (CoreJava)
The if statement is used to select among two alternatives. It uses a boolean expression to decide which alternative should be executed. The switch statement is used to select among multiple alternatives. It uses an int expression to determine which alternative should be executed.
which containers use a border Layout as their default layout? (AWT)
The window, Frame and Dialog classes use a border layout as their default layout
What is the preferred size of a component? (AWT)
The preferred size of a component is the minimum component size that will allow the component to display normally
Which containers use a FlowLayout as their default layout? (AWT)
The Panel and Applet classes use the FlowLayout as their default layout
What is the immediate superclass of the Applet class? (AWT)
Panel
Name three Component subclasses that support painting (AWT)
The Canvas, Frame, Panel, and Applet classes support painting
What is the immediate superclass of the Dialog class? (AWT)
Window
What is clipping? (AWT)
Clipping is the process of confining paint operations to a limited area or shape
What is the difference between a MenuItem and a CheckboxMenuItem? (AWT)
The CheckboxMenuItem class extends the MenuItem class to support a menu item that may be checked or unchecked
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-class hierarchy
In which package are most of the AWT events that support the event-delegation model defined? (AWT)
Most of the AWT-related events of the event-delegation model are defined in the java.awt.event package. The AWTEvent class is defined in the java.awt package.
Which class is the immediate superclass of the MenuComponent class (AWT)
Object
Which containers may have a MenuBar? (AWT)
Frame
What is the relationship between the Canvas class and the Graphics class? (AWT)
A Canvas object provides access to a Graphics object via its paint() method.
How are the elements of a BorderLayout organized? (AWT)
The elements of a BorderLayout are organized at the borders (North, South, East, and West) and the center of a container.
What is the difference between a Window and a Frame? (AWT)
The Frame class extends Window to define a main application window that can have a menu bar.
What is the difference between the Font and FontMetrics classes? (AWT)
The FontMetrics class is used to define implementation-specific properties, such as ascent and descent, of a Font object.
How are the elements of a CardLayout organized? (AWT)
The elements of a CardLayout are stacked, one on top of the other, like a deck of cards.
What is the relationship between clipping and repainting? (AWT)
When a window is repainted by the AWT painting thread, it sets the clipping regions to the area of the window that requires repainting.
What is the relationship between an event-listener interface and an event-adapter class? (AWT)
An event-listener interface defines the methods that must be implemented by an event handler for a particular kind of event. An event adapter provides a default implementation of an event-listener interface.
How can a GUI component handle its own events? (AWT)
A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener.
How are the elements of a GridBagLayout organized? (AWT)
The elements of a GridBagLayout are organized according to a grid. However, the elements are of different sizes and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.
What advantage do Java's layout managers provide over traditional windowing systems? (AWT)
Java uses layout managers to lay out components in a consistent manner across all windowing platforms. Since Java's layout managers aren't tied to absolute sizing and positioning, they are able to accomodate platform-specific differences among windowing systems.
What is the difference between the paint() and repaint() methods? (AWT)
The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() to be invoked by the AWT painting thread.
How can the Checkbox class be used to create a radio button? (AWT)
By associating Checkbox objects with a CheckboxGroup
What is the difference between a Choice and a List? (AWT)
A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices. Only one item may be selected from a Choice. A List may be displayed in such a way that several List items are visible. A List supports the selection of one or more List items.
What interface is extended by AWT event listeners? (AWT)
All AWT event listeners extend the java.util.EventListener interface.
What is a layout manager? (AWT)
A layout manager is an object that is used to organize components in a container
Which Component subclass is used for drawing and painting? (AWT)
Canvas
What are the problems faced by Java programmers who dont use layout managers? (AWT)
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
What is the difference between a Scrollbar and a ScrollPane? (Swing)
A Scrollbar is a Component, but not a Container. A ScrollPane is a Container. A ScrollPane handles its own events and performs its own scrolling
What is the Collections API? (JavaUtil)
The Collections API is a set of classes and interfaces that support operations on collections of objects
What is the List interface? (JavaUtil)
The List interface provides support for ordered collections of objects.
What is the Vector class? (JavaUtil)
The Vector class provides the capability to implement a growable array of objects
What is an Iterator interface? (JavaUtil)
The Iterator interface is used to step through the elements of a Collection
Which java.util classes and interfaces support event handling? (JavaUtil)
The EventObject class and the EventListener interface support event processing
What is the GregorianCalendar class? (JavaUtil)
The GregorianCalendar provides support for traditional Western calendars
What is the Locale class? (JavaUtil)
The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region
What is the SimpleTimeZone class? (JavaUtil)
The SimpleTimeZone class provides support for a Gregorian calendar
What is the Map interface? (JavaUtil)
The Map interface replaces the JDK 1.1 Dictionary class and is used associate keys with values
What is the highest-level event class of the event-delegation model? (JavaUtil)
The java.util.EventObject class is the highest-level class in the event-delegation class hierarchy
What is the Collection interface? (JavaUtil)
The Collection interface provides support for the implementation of a mathematical bag - an unordered collection of objects that may contain duplicates
What is the Set interface? (JavaUtil)
The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements
What is the purpose of the enableEvents() method? (JavaUtil)
The enableEvents() method is used to enable an event for a particular object. Normally, an event is enabled when a listener is added to an object for a particular event. The enableEvents() method is used by objects that handle events by overriding their event-dispatch methods.
What is the ResourceBundle class? (JavaUtil)
The ResourceBundle class is used to store locale-specific resources that can be loaded by a program to tailor the program's appearance to the particular locale in which it is being run.
What is the difference between yielding and sleeping? (Threads)
When a task invokes its yield() method, it returns to the ready state. When a task invokes its sleep() method, it returns to the waiting state.
When a thread blocks on I/O, what state does it enter? (Threads)
A thread enters the waiting state when it blocks on I/O.
When a thread is created and started, what is its initial state? (Threads)
A thread is in the ready state after it has been created and started.
What invokes a thread's run() method? (Threads)
After a thread is started, via its start() method or that of the Thread class, the JVM invokes the thread's run() method when the thread is initially executed.
What method is invoked to cause an object to begin executing as a separate thread? (Threads)
The start() method of the Thread class is invoked to cause an object to begin executing as a separate thread.
What is the purpose of the wait(), notify(), and notifyAll() methods? (Threads)
The wait(),notify(), and notifyAll() methods are used to provide an efficient way for threads to wait for a shared resource. When a thread executes an object's wait() method, it enters the waiting state. It only enters the ready state after another thread invokes the object's notify() or notifyAll() methods.
What are the high-level thread states? (Threads)
The high-level thread states are ready, running, waiting, and dead
What happens when a thread cannot acquire a lock on an object? (Threads)
If a thread attempts to execute a synchronized method or synchronized statement and is unable to acquire an object's lock, it enters the waiting state until the lock becomes available.
How does multithreading take place on a computer with a single CPU? (Threads)
The operating system's task scheduler allocates execution time to multiple tasks. By quickly switching between executing tasks, it creates the impression that tasks execute sequentially.
What happens when you invoke a thread's interrupt method while it is sleeping or waiting? (Threads)
When a task's interrupt() method is executed, the task enters the ready state. The next time the task enters the running state, an InterruptedException is thrown.
What state is a thread in when it is executing? (Threads)
An executing thread is in the running state
What are three ways in which a thread can enter the waiting 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 by invoking an object's wait() method. It can also enter the waiting state by invoking its (deprecated) suspend() method.
What method must be implemented by all threads? (Threads)
All tasks must implement the run() method, whether they are a subclass of Thread or implement the Runnable interface.
What are the two basic ways in which classes that can be run as threads may be defined? (Threads)
A thread class may be declared as a subclass of Thread, or it may implement the Runnable interface.
How can you store international / Unicode characters into a cookie? (JSP)
One way is,
before storing the cookie URLEncode it.
URLEnocder.encoder(str);
And use URLDecoder.decode(str) when you get the stored cookie.
What is the difference between URL instance and URLConnection instance? (Networking)
A URL instance represents the location of a resource, and a URLConnection instance represents a link for accessing or communicating with the resource at the location.
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 the sockets. getInputStream() and getOutputStream() are the two methods available in Socket class.
How to call a Stored Procedure from JDBC? (JDBC)
The first
step is to create a CallableStatement object. As with Statement an and
PreparedStatement objects, this is done with an open Connection object. A
CallableStatement object contains a call to a stored procedure.
E.g.
CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
ResultSet rs = cs.executeQuery();
What are the implicit objects? (JSP)
Implicit
objects are objects that are created by the web container and contain
information related to a particular request, page, or application. They are:
request
response
pageContext
session
application
out
config
page
exception
Is JSP technology extensible? (JSP)
YES. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries
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, which is specific to a particular operating system, the code platform specific machine code is generated thus making java platform independent.
What are the four corner stones of OOP ? (CoreJava)
Abstraction, Encapsulation, Polymorphism and Inheritance
Difference between a Class and an Object ? (CoreJava)
A class is a definition or prototype whereas an object is an instance or living representation of the prototype
What is a "stateless" protocol ? (CoreJava)
Without getting into lengthy debates, it is generally accepted that protocols like HTTP are stateless i.e. there is no retention of state between a transaction which is a single request response combination
What is constructor chaining and how is it achieved in Java ? (CoreJava)
A child object constructor always first needs to construct its parent (which in turn calls its parent constructor.). In Java it is done via an implicit call to the no-args constructor as the first statement.
What is passed by ref and what by value ? (CoreJava)
All Java method arguments are passed by value. However, Java does manipulate objects by reference, and all object variables themselves are references
Can RMI and Corba based applications interact ? (RMI)
Yes they can. RMI is available with IIOP as the transport protocol instead of JRMP.
You can create a String object as String str = "abc"; Why cant a button 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 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 does the "abstract" keyword mean in front of a method? A class? (CoreJava)
Abstract
keyword declares either a method or a class. If a method has a abstract
keyword in front of it,it is called abstract method.Abstract method hs no
body.It has only arguments and return type.Abstract methods act as
placeholder methods that are implemented in the subclasses.
Abstract classes can't be instantiated.If a class is declared as abstract,no
objects of that class can be created.If a class contains any abstract method
it must be declared as abstract
How many methods do u implement if implement the Serializable Interface? (CoreJava)
The
Serializable interface is just a "marker" interface, with no methods of its
own to implement. Other 'marker' interfaces are
java.rmi.Remote
java.util.EventListener
What are the practical benefits, if any, of importing a specific class rather 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 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.
What is the difference between logical data independence and physical data independence? (CoreJava)
Logical Data Independence - meaning immunity of external schemas to changeds in conceptual schema. Physical Data Independence - meaning immunity of conceptual schema to changes in the internal schema.
What is user defined exception ? (CoreJava)
Apart from the exceptions already defined in Java package libraries, user can define his own exception classes by extending Exception class.
Describe the visitor design pattern (General)
Represents
an operation to be performed on the elements of an object structure. Visitor
lets you define a new operation without changing the classes of the elements
on which it operates.
The root of a class hierarchy defines an abstract method to accept a
visitor. Subclasses implement this method with visitor.visit(this). The
Visitor interface has visit methods for all subclasses of the baseclass in
the hierarchy.
How can I implement a thread-safe JSP page? What are the advantages 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 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
How does JSP handle run-time exceptions? (JSP)
You can use
the errorPage attribute of the page directive to have uncaught run-time
exceptions automatically forwarded to an error processing page. For example:
<%@ page errorPage="error.jsp" %>
redirects the browser to the JSP page error.jsp if an uncaught exception is
encountered during request processing. Within error.jsp, if you indicate
that it is an error-processing page, via the directive:
<%@ page isErrorPage="true" %>
the Throwable object describing the exception may be accessed within the
error page via the exception implicit object.
Note: You must always use a relative URL as the value for the errorPage
attribute.
How do I prevent the output of my JSP or Servlet pages from being cached by the browser? (JSP)
You will
need to set the appropriate HTTP header attributes to prevent the dynamic
content output by the JSP page from being cached by the browser. Just
execute the following scriptlet at the beginning of your JSP pages to
prevent them from being cached at the browser. You need both the statements
to take care of some of the older browser versions.
<%
response.setHeader("Cache-Control","no-store"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy
server
%>
How do I use comments within a JSP page? (JSP)
You can use
"JSP-style" comments to selectively block out code while debugging or simply
to comment your scriptlets. JSP comments are not visible at the client. For
example:
<%-- the scriptlet is now commented out
<%
out.println("Hello World");
%>
--%>
You can also use HTML-style comments anywhere within your JSP page. These
comments are visible at the client. For example:
<!-- (c) 2004 javagalaxy.com -->
Of course, you can also use comments supported by your JSP scripting
language within your scriptlets. For example, assuming Java is the scripting
language, you can have:
<%
//some comment
/**
yet another comment
**/
%>
Response has already been commited error. What does it mean? (JSP)
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 do I use a scriptlet to initialize a newly instantiated bean? (JSP)
A
jsp:useBean action may optionally have a body. If the body is specified, its
contents will be automatically invoked when the specified bean is
instantiated. Typically, the body will contain scriptlets or jsp:setProperty
tags to initialize the newly instantiated bean, although you are not
restricted to using those alone.
The following example shows the "today" property of the Foo bean initialized
to the current date when it is instantiated. Note that here, we make use of
a JSP expression within the jsp:setProperty action.
<jsp:useBean id="foo" class="com.Bar.Foo" >
<jsp:setProperty name="foo" property="today" value="<%=java.text.DateFormat.getDateInstance().format(new
java.util.Date()) %>"/ >
<%-- scriptlets calling bean setter methods go here --%>
</jsp:useBean >
How can I enable session tracking for JSP pages if the browser has disabled cookies? (JSP)
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());
How can I declare methods within my JSP page? (JSP)
You can
declare methods for use within your JSP page as declarations. The methods
can then be invoked within any other methods you declare, or within JSP
scriptlets and expressions.
Do note that you do not have direct access to any of the JSP implicit
objects like request, response, session and so forth from within JSP
methods. However, you should be able to pass any of the implicit JSP
variables as parameters to the methods you declare. For example:
<%!
public String whereFrom(HttpServletRequest req) {
HttpSession ses = req.getSession();
...
return req.getRemoteHost();
}
%>
<%
out.print("Hi there, I see that you are coming in from ");
%>
<%= whereFrom(request) %>
Another Example
file1.jsp:
<%@page contentType="text/html"%>
<%!
public void test(JspWriter writer) throws IOException{
writer.println("Hello!");
}
%>
file2.jsp
<%@include file="file1.jsp"%>
<html>
<body>
<%test(out);% >
</body>
</html>
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
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.
How can I set a cookie and delete a cookie from within a JSP page? (JSP)
A cookie,
mycookie, can be deleted using the following scriptlet:
<%
//creating a cookie
Cookie mycookie = new Cookie("aName","aValue");
response.addCookie(mycookie);
//delete a cookie
Cookie killMyCookie = new Cookie("mycookie", null);
killMyCookie.setMaxAge(0);
killMyCookie.setPath("/");
response.addCookie(killMyCookie);
%>
How does a servlet communicate with a JSP page? (JSP)
The
following code snippet shows how a servlet instantiates a bean and
initializes it with FORM data posted by a browser. The bean is then placed
into the request, and the call is then forwarded to the JSP page, Bean1.jsp,
by means of a request dispatcher for downstream processing.
public void doPost (HttpServletRequest request, HttpServletResponse
response) {
try {
govi.FormBean f = new govi.FormBean();
String id = request.getParameter("id");
f.setName(request.getParameter("name"));
f.setAddr(request.getParameter("addr"));
f.setAge(request.getParameter("age"));
//use the id to compute
//additional bean properties like info
//maybe perform a db query, etc.
// . . .
f.setPersonalizationInfo(info);
request.setAttribute("fBean",f);
getServletConfig().getServletContext().getRequestDispatcher ("/jsp/Bean1.jsp").forward(request,
response);
} catch (Exception ex) {
. . .
}
}
The JSP page Bean1.jsp can then process fBean, after first extracting it
from the default request scope via the useBean action.
jsp:useBean id="fBean" class="govi.FormBean" scope="request"/
jsp:getProperty name="fBean" property="name" / jsp:getProperty name="fBean"
property="addr" / jsp:getProperty name="fBean" property="age" /
jsp:getProperty name="fBean" property="personalizationInfo" /
How do I have the JSP-generated servlet subclass my own custom servlet class, instead of the default? (JSP)
One should
be very careful when having JSP pages extend custom servlet classes as
opposed to the default one generated by the JSP engine. In doing so, you may
lose out on any advanced optimization that may be provided by the JSP
engine. In any case, your new superclass has to fulfill the contract with
the JSP engine by:
Implementing the HttpJspPage interface, if the protocol used is HTTP, or
implementing JspPage otherwise Ensuring that all the methods in the Servlet
interface are declared final Additionally, your servlet superclass also
needs to do the following:
The service() method has to invoke the _jspService() method
The init() method has to invoke the jspInit() method
The destroy() method has to invoke jspDestroy()
If any of the above conditions are not satisfied, the JSP engine may throw a
translation error.
Once the superclass has been developed, you can have your JSP extend it as
follows:
<%@ page extends="packageName.ServletName" %<
How can I prevent the word "null" from appearing in my HTML input text 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;
}
%>
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 JSP page? (JSP)
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("
");
%>
How do you pass an InitParameter to a JSP? (JSP)
The JspPage
interface defines the jspInit() and jspDestroy() method which the page
writer can use in their pages and are invoked in much the same manner as the
init() and destory() methods of a servlet. The example page below enumerates
through all the parameters and prints them to the console.
<%@ page import="java.util.*" %>
<%!
ServletConfig cfg =null;
public void jspInit(){
ServletConfig cfg=getServletConfig();
for (Enumeration e=cfg.getInitParameterNames(); e.hasMoreElements();) {
String name=(String)e.nextElement();
String value = cfg.getInitParameter(name);
System.out.println(name+"="+value);
}
}
%>
How can my JSP page communicate with an EJB Session Bean? (JSP)
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...
%>
In Java, what is the difference between an Interface and an Abstract class?
A: An Abstract class declares have at least one instance method that is declared abstract which will be implemented by the subclasses. An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior.
Can you have virtual functions in Java? Yes or No. If yes, then what are virtual functions?
A: Yes, Java class functions are virtual by default. Virtual functions are functions of subclasses that can be invoked from a reference to their superclass. In other words, the functions of the actual object are called when a function is invoked on the reference to that object.
Write a function to reverse a linked list p in C++?
A:
Link* reverse_list(Link* p)
{
if (p == NULL)
return NULL;
Link* h = p;
p = p->next;
h->next = NULL;
while (p != null)
{
Link* t = p->next;
p->next = h;
h = p;
p = t;
}
return h;
}
In C++, what is the usefulness of Virtual destructors?
A:Virtual destructors are neccessary to reclaim memory that were allocated for objects in the class hierarchy. If a pointer to a base class object is deleted, then the compiler guarantees the various subclass destructors are called in reverse order of the object construction chain.
What are mutex and semaphore? What is the difference between them?
A:A mutex is a synchronization object that allows only one process or thread to access a critical code block. A semaphore on the other hand allows one or more processes or threads to access a critial code block. A semaphore is a multiple mutex.
Database
What is JServer and what is it used for?
Oracle JServer Option is a Java Virtual Machine (Java VM) which runs within the Oracle database server’s address space. Oracle also provides a JServer Accelerator to compile Java code natively. This speeds up the execution of Java code by eliminating interpreter overhead.
Why does one need to publish Java in the database?
Publishing Java classes on the database makes it visible on a SQL and PL/SQL level. It is important to publish your code before calling it from SQL statements or PL/SQL code.
What is JDBC and what is it used for?
JDBC is a set of classes and interfaces written in Java to allow other Java programs to send SQL statements to a relational database management system. Oracle provides three categories of JDBC drivers: (a) JDBC Thin Driver (No local Net8 installation required/ handy for applets), (b) JDBC OCI for writing stand-alone Java applications, © JDBC KPRB driver (default connection) for Java Stored Procedures and Database JSP’s.
How does one connect with the JDBC Thin Driver?
The the JDBC thin driver provides the only way to access Oracle from the Web
(applets). It is smaller and faster than the OCI drivers, and doesn’t
require a pre-installed version of the JDBC drivers.
import java.sql.*;
class dbAccess {
public static void main (String args []) throws SQLException
{
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@hostname:1526:orcl", "scott", "tiger");
// @machineName:port:SID, userid, passwordStatement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
while (rset.next())
System.out.println (rset.getString(1)); // Print col 1
stmt.close();
}
}
How does one connect with the JDBC OCI Driver?
One must have Net8
(SQL*Net) installed and working before attempting to use one of the OCI
drivers.
import java.sql.*;
class dbAccess {
public static void main (String args []) throws SQLException
{
try {
Class.forName ("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci8:@hostname_orcl", "scott", "tiger");
// or oci7 @TNSNames_Entry, userid, passwordStatement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
while (rset.next())
System.out.println (rset.getString(1)); // Print col 1
stmt.close();
}
}
How does one connect with the JDBC KPRB Driver?
One can obtain a
handle to the default or current connection (KPRB driver) by calling the
OracleDriver.defaultConenction() method. Please note that you do not need to
specify a database URL, username or password as you are already connected to
a database session. Remember not to close the default connection. Closing
the default connection might throw an exception in future releases of
Oracle.
import java.sql.*;
class dbAccess {
public static void main (String args []) throws SQLException
{
Connection conn = (new oracle.jdbc.driver.OracleDriver()).defaultConnection();
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
while (rset.next())
System.out.println (rset.getString(1)); // Print col 1
stmt.close();
}
}
What is SQLJ and what is it used for?
SQLJ is an ANSI standard way of coding SQL access in Java. It provides a Java precompiler that translates SQLJ call to JDBC calls. The idea is similar to that of other Oracle Precompilers.
How does one deploy SQLJ programs?
Use the sqlj compiler to compile your *.sqlj files to *.java and *.ser files. The *.ser files contain vendor specific database code. Thereafter one invokes the javac compiler to compile the .java files to *.class files. The *.class and *.ser files needs to be deployed.
What is InfoBus DAC and what is it used for?
InfoBus DAC (Data Aware Controls) is a standard Java extension used in JDeveloper to create data aware forms. It replaced the JBCL interface that were used in JDeveloper V1 and V2.
What is a JSP and what is it used for?
Java Server Pages (JSP) is a platform independent presentation layer technology that comes with SUN’s J2EE platform. JSPs are normal HTML pages with Java code pieces embedded in them. JSP pages are saved to *.jsp files. A JSP compiler is used in the background to generate a Servlet from the JSP page.
What is the difference between ASP and JSP?
Active Server Pages (ASP) is a Microsoft standard, which is easier to develop than Java Server Pages (JSP). However ASP is a proprietary technology and is less flexible than JSP. For more information about ASP, see the Oracle ASP FAQ.
How does one invoke a JSP?
A JSP gets invoked when you call a *.jsp file from your Web Server like you would call a normal *.html file. Obviously your web server need to support JSP pages and must be configured properly to handle them.
How does a JSP gets executed?
The first time you call a JSP, a servlet (*.java) will be created and compiled to a .class file. The class file is then executed on the server. Output produced by the servlet is returned to the web browser. Output will typically be HTML or XML code.
What is a Java Stored Procedure/ Trigger?
A Java Stored Procedure is a procedure coded in Java (as opposed to PL/SQL) and stored in the Oracle database. Java Stored procedures are executed by the database JVM in database memory space. Java Stored Procedures can be developed in JDBC or SQLJ. Interfacing between PL/SQL and Java are extremely easy. Please note that Java Stored procedures are by default executed with invokers rights. PL/SQL procedures are by default executed with defines rights.
Java Swing interview questions
1) Can a class be it’s own event handler? Explain how to implement this.
Answer: Sure. an example could be a class that extends Jbutton and implements ActionListener. In the actionPerformed method, put the code to perform when the button is pressed.
2) Why does JComponent have add() and remove() methods but Component does not?
Answer: because JComponent is a subclass of Container, and can contain other components and jcomponents.
3) How would you create a button with rounded edges?
Answer: there’s 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 (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.
4) If I wanted to use a SolarisUI for just a JTabbedPane, and the Metal UI for everything else, how would I do that?
Answer: in the UIDefaults table, override the entry for tabbed pane and put in the SolarisUI delegate. (I don’t know it offhand, but I think it’s "com.sun.ui.motiflookandfeel.MotifTabbedPaneUI" - anything simiar is a good answer.)
5) What is the difference between the ‘Font’ and ‘FontMetrics’ class?
Answer: The Font Class is used to render ‘glyphs’ - the characters you see on the screen. FontMetrics encapsulates information about a specific font on a specific Graphics object. (width of the characters, ascent, descent)
6) What class is at the top of the AWT event hierarchy?
Answer: java.awt.AWTEvent. if they say java.awt.Event, they haven’t dealt with swing or AWT in a while.
7) Explain how to render an HTML page using only Swing.
Answer: Use a JEditorPane or JTextPane and set it with an HTMLEditorKit, then load the text into the pane.
8) How would you detect a keypress in a JComboBox?
Answer: This is a trick. most people would say ‘add a KeyListener to the JComboBox’ - but the right answer is ‘add a KeyListener to the JComboBox’s editor component.’
9) Why should the implementation of any Swing callback (like a listener) execute quickly?
A: Because callbacks are invoked by the event dispatch thread which will be blocked processing other events for as long as your method takes to execute.
10) In what context should the value of Swing components be updated directly?
A: Swing components should be updated directly only in the context of callback methods invoked from the event dispatch thread. Any other context is not thread safe?
11) Why would you use SwingUtilities.invokeAndWait or SwingUtilities.invokeLater?
A: I want to update a Swing component but I’m not in a callback. If I want the update to happen immediately (perhaps for a progress bar component) then I’d use invokeAndWait. If I don’t care when the update occurs, I’d use invokeLater.
12) If your UI seems to freeze periodically, what might be a likely reason?
A: A callback implementation like ActionListener.actionPerformed or MouseListener.mouseClicked is taking a long time to execute thereby blocking the event dispatch thread from processing other UI events.
13) Which Swing methods are thread-safe?
A: The only thread-safe methods are repaint(), revalidate(), and invalidate()
14) Why won’t the JVM terminate when I close all the application windows?
A: The AWT event dispatcher thread is not a daemon thread. You must explicitly call System.exit to terminate the JVM.
Q1. Describe the three OOO principles?
A1. Encapsulation - It is the way the code and data are confined and are in isolation from the
outside environment of the system.
EXAMPLE : In a car the engine can be thought about as an encapsulated which is controlled by the starter key and the gear.The operation of the engine does not affect the functioning of other parts of car like the headlight and wiper. In JAVA basis of encapsulation is the CLASS.
Inheritence - It is the process by which one object acccquires the properties of another object.
Polymorphism - It is a feature that allows one interface to be used for a general class of actions. The specific action is determined by the exact nature of the situation.
EXAMPLE : In a college cafeteria if an old music is put the students would not like it , but if the latest number of Brittney Spears is put then they would love it.If analysed then we can see that even though the process of listening is the same i.e. for the old song the students listen it from there ears and even for the latest Brittney Spears number they listen it from there ear. But there is a difference by which the students react. This difference can be explained by the concept polymorphism.
Q2. What is meant by Endianness?
A2. Endianness describes how multiple data types such as short , int and long are stored in memory.If it takes two bytes to represent a short, then to predict if the most significant or the least significant comes first.If the most significant byte is first, followed by the least significant one then the machine is said to be big endian. Machines such as the SPARC and Power PC are big-endian, while the Intel x86 series is little-endian.
Q3. How many types of literals are there in JAVA?
A3. There are four types of literals they are Integer literals, Flaoting point literals, Boolean literals and character literals.
Q4. A note on compiling & Executing a JAVA pgm
A4. (i) The name of the sourcefile is called in terms of .java
(ii) A source file is called a compilation unit. This has one or more class definitions.
(iii) The name of the class should be same as that of the file.
(iv) Once compiled the .java file creates a .class file. This is done by the compiler javac
(v) This classfile contains the bytecode version of the program.
What is meant by Garbage collection ?
The technique that automatically destroys the dynamically created objects is called garbage collection. When no reference to an object exists, that object is assumed to be no longer needed , and memory occupied by that object can be reclaimed.
Once an object is garbage collected, it ceases to exist. It can no longer become reachable again.
An object is subject to garbage collection when it becomes unreachable to the program in which it is used.
What are the access modifiers?
There are three types of access modifiers.
(i) Private - Makes a method or a variable accessible only from within its own class.
(ii) Protected - Makes a method or a variable accessible only to classes in the same package or subclasses of the class.
(iii) Public - Makes a class , method or variable accessible from any other class.
A note on PUBLIC , PRIVATE , STATIC , VOID & MAIN.
(i) All Java applications begin execution by calling main ()
(ii) When a class member is defined as public. Then that member may be accessed by code outside the class in which it is declared.
(iii) The opposite of public is private which prevents a member from being used by code defined outside of its class.
(iv) The keyword static allows main() to be called without having to instantiate a particular instance of the class. This is mandatory because main () is called by the Java interpreter before any objects are made.
(v) CASE SENSITIVE : Main () is different from main(). It is important to know that that Main() would be compiled. But the Java interpreter would report an error if it would not find main().
A note on keywords for Error handling.
A8. (i) Catch - Declares the block of code used to handle an exception.
(ii) Finally - Block of code , usually following a typecatch statement, which is executed no matter what program flow occurs when dealing with an exception.
(iii) Throw - Used to pass an exception up to the methhhod that calls this method.
(iv) Throws - Indicates the method will pass an exceptttion to the method that called it.
(v) Try - Block of code that will be tried but which may cause an exception.
(vi) Assert - Evaluates a conditional _expression to vvverify the programmer's assumption.
Q9. How many ways can you represent integer numbers in JAVA?
A9. There are three ways , you can represent integer numbers in JAVA. They are decimal (base 10) , octal (base 8) , and hexadecimal (base 16).
Q10. A note on defining floating point literal ?
A10. A floating point literal is defined as float g = 3576.2115F.
Q11. A note on arrays of object references?
A11. If the array type is CLASS then one can put objects of any subclass of the declared type into the array. The following example on sports explains the above concept :
class sports { }
class football extends sports { }
class hockey extends sports { }
class baseball extends sports { }
sports [ ] mysports = { new football (),
new hockey (),
new baseball ()};
Q12. What is meant by Instance of comparison?
A12. It is used for object reference variables only.You can use it to check wether an object is of a particular type.
Q14. What is meant by Recursion?
A14. It is the process of defining something in terms of itself. Interms of JAVA it is the attribute that allows a method to call itself.The following example of calculating a factorial gives an example of recursion.
class Factorial {
int fact (int n) {
int result;
if (n= 1) return 1;
result = fact(n -1) * n;
return result;
}
}
class Recursion {
Public static void main (string args[ ]) {
Factorial f = new Factorial ();
system.out.println ("Factorial of 10 is " + f.fact(10));
}
}
Q15. A cool example to explain the concept of METHOD in JAVA.
A15. Let us say you are in Mcdonalds and you order for #7 for here with medium coke. The cashier takes your order and punches it on the computer. The folks in the kitchen get the order and they get the crispy chicken and pass it on to the guy who puts a medium fries and finally a medium coke is filled and the order is served to you. In other terms if all this was supposed to be done by a robot then it could have been programmed the following way.
void #7forherewithmediumcoke( )
{
Get (crispy chicken, lattice, butter, fries, coke);
make (sandwich);
fill (coke, fries);
}
What is the main difference between Java platform and other platforms?
The Java platform differs from most other platforms in that it's a software-only platform that runs on top of other hardware-based platforms.
The Java platform has two components: The Java Virtual Machine (Java VM) The Java Application Programming Interface (Java API)
What is the Java Virtual Machine?
The Java Virtual Machine is a software that can be ported onto various hardware-based platforms.
What is the Java API?
The Java API is a large collection of ready-made software components that provide many useful capabilities, such as graphical user interface (GUI) widgets.
What is the package?
The package is a Java namespace or part of Java libraries. The Java API is grouped into libraries of related classes and interfaces; these libraries are known as packages.
What is native code?
The native code is code that after you compile it, the compiled code runs on a specific hardware platform.
Is Java code slower than native code?
Not really. As a platform-independent environment, the Java platform can be a bit slower than native code. However, smart compilers, well-tuned interpreters, and just-in-time bytecode compilers can bring performance close to that of native code without threatening portability.
What is synchronization and why is it important?
With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object's value. This often causes dirty data and leads to significant errors.
What are synchronized methods and synchronized statements?
Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.
What are three ways in which a thread can enter the waiting state?
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 by invoking an object's wait() method. It can also enter the waiting state by invoking its (deprecated) suspend() method.
What method is used to specify a container's layout?
The setLayout() method is used to specify a container's layout.
What state does a thread enter when it terminates its processing?
When a thread terminates its processing, it enters the dead state.
What is the Collections API?
The Collections API is a set of classes and interfaces that support operations on collections of objects.
What is the List interface?
The List interface provides support for ordered collections of objects.
How does Java handle integer overflows and underflows?
It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.
What is the Vector class?
The Vector class provides the capability to implement a growable array of objects
What modifiers may be used with an inner class that is a member of an outer class?
A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.
If a method is declared as protected, where may the method be accessed?
A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.
What is an Iterator interface?
The Iterator interface is used to step through the elements of a Collection.
How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?
Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns.
What is the difference between yielding and sleeping?
When a task invokes its yield() method, it returns to the ready state. When a task invokes its sleep() method, it returns to the waiting state.
Is sizeof a keyword?
The sizeof operator is not a keyword.
What are wrapped classes?
Wrapped classes are classes that allow primitive types to be accessed as objects.
Does garbage collection guarantee that a program will not run out of memory?
No, it doesn't. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection
What is the difference between preemptive scheduling and time slicing?
Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.
Name Component subclasses that support painting.
The Canvas, Frame, Panel, and Applet classes support painting.
What is a native method?
A native method is a method that is implemented in a language other than Java.
How can you write a loop indefinitely?
for(;;)--for loop; while(true)--always true, etc.
Can an anonymous class be declared as implementing an interface and extending a class?
An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.
What is the purpose of finalization?
The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.
Which class is the superclass for every class.
Object
What invokes a thread's run() method?
After a thread is started, via its start() method or that of the Thread class, the JVM invokes the thread's run() method when the thread is initially executed.
What is the difference between the Boolean & operator and the && operator?
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 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.
Operator & has no chance to skip both sides evaluation and && operator does.
If asked why, give details as above.
What is the GregorianCalendar class?
The GregorianCalendar provides support for traditional Western calendars.
What is the SimpleTimeZone class?
The SimpleTimeZone class provides support for a Gregorian calendar.
Which Container method is used to cause a container to be laid out and redisplayed?
validate()
What is the Properties class?
The properties class is a subclass of Hashtable that can be read from or written to a stream. It also provides the capability to specify a set of default values to be used.
What is the purpose of the Runtime class?
The purpose of the Runtime class is to provide access to the Java runtime system.
What is the purpose of the System class?
The purpose of the System class is to provide access to system resources.
What is the purpose of the finally clause of a try-catch-finally statement?
The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.
What is the Locale class?
The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.
What must a class do to implement an interface?
It must provide all of the methods in the interface and identify the interface in its implements clause.
What is the purpose of the wait(), notify(), and notifyAll() methods?
The wait(),notify(), and notifyAll() methods are used to provide an efficient way for threads to communicate each other.
What is an abstract method?
An abstract method is a method whose implementation is deferred to a subclass.
What are the high-level thread states?
The high-level thread states are ready, running, waiting, and dead.
What is the difference between a static and a non-static inner class?
A non-static inner class may have object instances that are associated with instances of the class's outer class. A static inner class does not have any object instances.
What is an object's lock and which object's have locks?
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 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.
When can an object reference be cast to an interface reference?
An object reference be cast to an interface reference when the object implements the referenced interface.
What is the difference between a Window and a Frame?
The Frame class extends Window to define a main application window that can have a menu bar.
What do heavy weight components mean?
Heavy weight components like Abstract Window Toolkit (AWT), depend on the local windowing toolkit. For example, java.awt.Button is a heavy weight component, when it is running on the Java platform for Unix platform, it maps to a real Motif button. In this relationship, the Motif button is called the peer to the java.awt.Button. If you create two Buttons, two peers and hence two Motif Buttons are also created. The Java platform communicates with the Motif Buttons using the Java Native Interface. For each and every component added to the application, there is an additional overhead tied to the local windowing system, which is why these components are called heavy weight.
Which package has light weight components?
javax.Swing package. All components in Swing, except JApplet, JDialog, JFrame and JWindow are lightweight components.
What are peerless components?
The peerless components are called light weight components.
What is the difference between the Font and FontMetrics classes?
The FontMetrics class is used to define implementation-specific properties, such as ascent and descent, of a Font object.
What happens when a thread cannot acquire a lock on an object?
If a thread attempts to execute a synchronized method or synchronized statement and is unable to acquire an object's lock, it enters the waiting state until the lock becomes available.
What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.
What classes of exceptions may be caught by a catch clause?
A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.
If a class is declared without any access modifiers, where may the class be accessed?
A class that is declared without any access modifiers is said to have 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.
What is the Map interface?
The Map interface replaces the JDK 1.1 Dictionary class and is used associate keys with values.
Does a class inherit the constructors of its superclass?
A class does not inherit constructors from any of its superclasses.
Name primitive Java types.
The primitive types are byte, char, short, int, long, float, double, and boolean.
Which class should you use to obtain design information about an object?
The Class class is used to obtain information about an object's design.
How can a GUI component handle its own events?
A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener.
How are the elements of a GridBagLayout organized?
The elements of a GridBagLayout are organized according to a grid. However, the elements are of different sizes and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.
What advantage do Java's layout managers provide over traditional windowing systems?
Java uses layout managers to lay out components in a consistent manner across all windowing platforms. Since Java's layout managers aren't tied to absolute sizing and positioning, they are able to accommodate platform-specific differences among windowing systems.
What are the problems faced by Java programmers who don't use layout managers?
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.
What is the difference between static and non-static variables?
A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.
What is the difference between the paint() and repaint() methods?
The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() to be invoked by the AWT painting thread.
What is the purpose of the File class?
The File class is used to create objects that provide access to the files and directories of a local file system.
How does multithreading take place on a computer with a single CPU?
The operating system's task scheduler allocates execution time to multiple tasks. By quickly switching between executing tasks, it creates the impression that tasks execute sequentially.
What is casting?
There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.
Name Container classes.
Window, Frame, Dialog, FileDialog, Panel, Applet, or ScrollPane
What class allows you to read objects directly from a stream-ObjectInputStream?
The ObjectInputStream class supports the reading of objects from input streams.
How are this() and super() used with constructors?
this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.
How is it possible for two String objects with identical values not to be equal under the == operator?
The == operator compares two objects to determine if they are the same object in memory. It is possible for two String objects to have the same value, but located indifferent areas of memory.
What an I/O filter?
An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.
What is the Set interface?
The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements.
What is the purpose of the enableEvents() method?
The enableEvents() method is used to enable an event for a particular object. Normally, an event is enabled when a listener is added to an object for a particular event. The enableEvents() method is used by objects that handle events by overriding their event-dispatch methods.
What is the difference between the File and RandomAccessFile classes?
The File class encapsulates the files and directories of the local file system. The RandomAccessFile class provides the methods needed to directly access data contained in any part of a file.
What is the ResourceBundle class?
The ResourceBundle class is used to store locale-specific resources that can be loaded by a program to tailor the program's appearance to the particular locale in which it is being run.
What is the difference between a Scrollbar and a ScrollPane?
A Scrollbar is a Component, but not a Container. A ScrollPane is a Container. A ScrollPane handles its own events and performs its own scrolling.
What is Serialization and deserialization?
Serialization is the process of writing the state of an object to a byte
stream.
Deserialization is the process of restoring these objects.
Tunnelling is a route to somewhere. For example, RMI tunnelling is a way to make RMI application get through firewall. In CS world, tunnelling means a way to transfer data.
How you restrict a user to cut and paste from the html page?
Using javascript to lock keyboard keys. It is one of solutions.
SQL> DELETE FROM table_name A WHERE ROWID > (
2 SELECT min(rowid) FROM table_name B
3 WHERE A.key_values = B.key_values);
SQL> create table table_name2 as select distinct * from table_name1;
SQL> drop table_name1;
SQL> rename table_name2 to table_name1;
What is
the difference between an Interface and an Abstract class?
An Abstract
class declares have at least one instance method that is declared abstract
which will be implemented by the subclasses.
An abstract class can have
instance methods that implement a default behavior. An Interface can only
declare constants and instance methods, but cannot implement default
behavior.