--Explain about stored procedures
--I/O Filter
--Two types of multi-tasking
--Explain lazy activation
--How can a dead thread be started
--What is meant by flickering
--How do you load an Image in a Servlet ?
--What is meant by class loader ? How many types are there? When will we use them ?
---Why there are some null interface in java ? What does it mean ? Give me some null interfaces in JAVA ?
--Write a program on RMI and JDBC using StoredProcedure ?
--Have you used threads in Servelet ?
--How do you invoke a Servelt?
--How will you pass parameters in RMI ?
--
--
posted @
2007-07-12 15:26 Sun River|
编辑 收藏
--Question: What is similarities/difference between an Abstract class and Interface?
Answer: Differences are as follows:
- Interfaces provide a form of multiple inheritance. A class can extend only one other class.
- Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc.
- A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class.
- Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class. Abstract classes are fast.
Similarities:
- Neither Abstract classes or Interface can be instantiated.
--Question:
What do you understand by Synchronization?
Answer: Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access one resource at a time. In non synchronized multithreaded application, it is possible for one thread to modify a shared object while another thread is in the process of using or updating the object's value. Synchronization prevents such type of data corruption.
E.g. Synchronizing a function:
public synchronized void Method1 () {
// Appropriate method-related code.
}
E.g. Synchronizing a block of code inside a function:
public myFunction (){
synchronized (this) {
// Synchronized code here.
}
}
--Question: What is Collection API?
Answer: The Collection API is a set of classes and interfaces that support operation on collections of objects. These classes and interfaces are more flexible, more powerful, and more regular than the vectors, arrays, and hashtables if effectively replaces.
Example of classes: HashSet
, HashMap
, ArrayList
, LinkedList
, TreeSet
and TreeMap
.
Example of interfaces: Collection
, Set
, List
and Map.
--
Question: Describe the principles of OOPS.
Answer: There are three main principals of oops which are called Polymorphism, Inheritance and Encapsulation.
Question: Explain the Encapsulation principle.
Answer: Encapsulation is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. One way to think about encapsulation is as a protective wrapper that prevents code and data from being arbitrarily accessed by other code defined outside the wrapper.
Question: Explain the Inheritance principle.
Answer: Inheritance is the process by which one object acquires the properties of another object.
Question: Explain the Polymorphism principle.
Answer: The meaning of Polymorphism is something like one name many forms. Polymorphism enables one entity to be used as as general category for different types of actions. The specific action is determined by the exact nature of the situation. The concept of polymorphism can be explained as "one interface, multiple methods".
Question: Explain the different forms of Polymorphism.
Answer: From a practical programming viewpoint, polymorphism exists in three distinct forms in Java:
- Method overloading
- Method overriding through inheritance
- Method overriding through the Java interface
--Question: What do you understand by final value?
Answer: FINAL for a variable: value is constant. FINAL for a method: cannot be overridden. FINAL for a class: cannot be derived.
--Question: How to convert String to Number in java program?
Answer: The valueOf() function of Integer class is is used to convert string to Number. Here is the code example:
String strId = "10"; int id=Integer.valueOf(strId);
posted @
2007-07-12 03:00 Sun River|
编辑 收藏
摘要:
---Which of the following methods can be called to change the state of the CMP entity bean from pooled to the ready state?
ejbStore()
ejbCreate()
ejbActivate()
ejbFind...
阅读全文
posted @
2007-07-09 16:36 Sun River|
编辑 收藏
A
message-driven bean is an enterprise bean that allows J2EE applications to process messages asynchronously. It acts as a JMS message listener, which is similar to an event listener except that it receives messages instead of events.
Message-driven beans currently process only JMS messages, but in the future they may be used to process other kinds of messages. The most visible difference between message-driven beans and session and entity beans is that clients do not access message-driven beans through interfaces.
When a message arrives, the container calls the message-driven bean's onMessage
method to process the message. The onMessage
method normally casts the message to one of the five JMS message types and handles it in accordance with the application's business logic. The onMessage
method may call helper methods, or it may invoke a session or entity bean to process the information in the message or to store it in a database.
A message may be delivered to a message-driven bean within a transaction context, so that all operations within the onMessage
method are part of a single transaction. If message processing is rolled back, the message will be redelivered.
Session beans and entity beans allow you to send JMS messages and to receive them synchronously, but not asynchronously. To avoid tying up server resources, you may prefer not to use blocking synchronous receives in a server-side component. To receive messages asynchronously, use a message-driven bean.
posted @
2007-07-09 14:35 Sun River|
编辑 收藏
--
Inner Join
Definition: An inner join is a join that selects only those records from both database tables that have matching values. Records with values in the joined field that do not appear in both of the database tables will be excluded from the query. One or more fields can serve as the join fields.
---Outer Join
Definition: An outer join selects all of the records from one database table and only those records in the second table that have matching values in the joined field. In a left outer join, the selected records will include all of the records in the first database table. In a right outer join, the selected records will include all records of the second database table. One or more fields can serve as the join fields.
posted @
2007-07-09 13:58 Sun River|
编辑 收藏
A
JavaBean is a POJO that is
serializable, has a no-argument constructor, and allows access to properties using getter and setter methods. An
Enterprise JavaBean is not a single class but an entire component model (again,
EJB 3 reduces the complexity of Enterprise JavaBeans).
posted @
2007-07-06 22:27 Sun River|
编辑 收藏
---SOA: A service-oriented architecture is essentially a collection of services. These services communicate with each other. The communication can involve either simple data passing or it could involve two or more services coordinating some activity. Some means of connecting services to each other is needed.
---
Service:
A service is a function that is well-defined, self-contained, and does not depend on the context or state of other services.A service is the endpoint of a connection.
---
Web Services refers to the technologies that allow for making connections.
---Questions:
Are you familiar with SOA?
What is SOA?
What is a Web Service?
What is the difference between SOA and Web Services?
What is the difference between Web Services and SOAP?
What is the difference between SOAP and SOA?
---
Most services are built on tools that provide the following components:
Application and Service Components: Workflow, Business Process Execution, Orchestration
Service Buses: Connectors, Caching, Policies, Scripting, Messaging
Infrastructure Components: SOAP bindings, XML parsers, Message service bindings, clustering, replication and high availability
--ESB:
An enterprise service bus (ESB) is a pattern of middleware that unifies and connects services, applications and resources within a business. it's a new way of looking at how to integrate applications, coordinate resources and manipulate information,
the ESB pattern enables the connection of software running in parallel on different platforms, written in different programming languages and using different programming models.
posted @
2007-07-03 13:09 Sun River|
编辑 收藏
---How do you call a state of an entity object that is never persisted and not associated with any Session?
A: transient
---Transient instances may be made persistent by calling which of the Session method (Choose all that apply)?
A: Save, Update, Persist, Write, SaveOrUpdate.
Transient instances may be made persistent by calling save, persist or saveOrUpdate. There is no such method like write and update - updates the persistent instance with the identifier of the given detached instance not transient.
---Is there a difference between
Pet pet = (Pet) session.get(Pet.class, petId);
and
Pet pet = (Pet) session.load(Pet.class, petId);
?
A: There is a difference - if session.load can't find the object in the cache or database it throws an exception, while session.get just returns null.
---Which of the following LockMode always increments version for versioned entities.
|
|
READ
|
|
|
WRITE
|
|
+
|
FORCE
|
|
|
UPGRADE
|
|
|
INCREMENT
|
---
What kind of hibernate inheritance mapping strategies represents the hibernate mapping file (Person.hbm.xml)?
<hibernate-mapping>
<class
name="Person"
table="PERSON"
>
<id
name="id"
column="id"
type="long"
>
<generator class="increment"/>
</id>
<property name="name" column="name"/>
<joined-subclass
name="Worker"
table="WORKER"
>
<key column="id"/>
<property name="salary" column="salary"/>
</joined-subclass>
<joined-subclass
name="Student"
table="STUDENT"
>
<key column="id"/>
<property name="grade" column="salary"/>
</joined-subclass>
</class>
</hibernate-mapping>
+
|
Table per subclass
|
|
Table per class hierarchy
|
|
Table per concrete class
|
|
implicit polymorphism
|
---Assume that you want to see what SQL queries are used by Hibernate during the execution of the HQL commands. Fill the gap in order to enable the underlaying SQL commands logging.
<property name="__show_sql ___">true</property>
--- Given:
@Entity
public class Foo {
@Id
private int id;
....
}
Choose correct statement.
+
|
It's a valid example of the @Id annotation usage.
|
|
It's not valid as @Id should be associated with a getter method (getId()) not a field.
|
|
It's not valid as @Id should be associated with both a field and a getter (getId()) method.
|
|
It's not valid as @Id should be associated with both a field and a setter (setId()) method.
|
---Hibernate provides <native>
inheritance strategy indicating that we want to use native SQL inheritance mechanism. (F)
SQL does not provide inheritance - that is one of the Object/Relation mismatches.
---Object Relational Mapping of hibernate is used to select, insert, update and delete the records form the underlying table. (T)
---Consider the following snippet:
<set name="foos" ______="joinPoint">
<key column="keyCol" />
<many-to-many class="Foo" />
</set>
Fill the gap in order to make the snippet above valid.
A: table
Many-to-many relationships requires setting the name of the table used to perform the join.
---Hibernate doesn't provide its own connection pooling facility i.e. you have to use some third parties pooling implementation like DBCP.(F)
EX: Hibernate provides its own internal connection pooling facility. However the latter is intended to be used during a development phase - third party solutions are recommended to be used in the production.
---Collection can be used as a key type for a Hibernate map.(F)
Ex: Keys of Hibernate maps can be of any type (including composite type) except the collection types.
---Hibernate provides its own connection pooling facility. The latter is recommended to be used in the production instead of the third parties pooling implementation like DBCP.
The last sentence is true. (F)
Hibernate provides its own internal connection pooling facility. However the latter is intended to be used during a development phase - third party solutions are recommended to be used in the production.
---How many table(s) in a database represents the hibernate mapping file (Person.hbm.xml)?
<hibernate-mapping>
<class name="Person">
<id name="id">
<generator class="increment"/>
</id>
<discriminator column="PERSON_TYPE" type="string"/>
<property name="name"/>
<subclass name="Worker">
<property name="salary" column="SALARY"/>
</subclass>
<subclass name="Student">
<property name="grade" column="GRADE"/>
</subclass>
</class>
</hibernate-mapping>
One table (PERSON) (T)
|
Three tables (PERSON, WORKER, STUDENT)
|
The quantity of tables depends of the type of database to which hibernate is connected
|
Ex:The mapping file represents the table per class hierarchy inheritance strategy and there is only one table for class hierarchy.
---Is it possible using annotations to declare readable name of a foreign key constraint in joined inheritance type ? (T)
---Consider the following code:
Session session;
PersistedEntity entity = session.get(PersistedEntity.class, new Integer(1));
entity.setValue("New Value");
session.saveOrUpdate(entity);
session.close();
If there is record in database for class PersistedEntity with ID of 1, the changes to the property 'value' will be correctly saved in the database. (F)
Ex: The Hibernate framework has already associated the id 1 with the entity. When you try to saveOrUpdate it, it will complain that the object already exist in the session by throwing an HibernateException.
---Which of the following scopes of identity are defined in Hibernate? (all true)
No identity scope(def) : a database row can be represented as two java objects ..this is not supported as two objects can modify a record...
|
Transacion scoped identity:In the context of a transaction a single object instance that represents a database row. Allows some caching to be done at transaction level.
|
process scoped identity :one instance per row in whole jvm.
|
---Select all valid Hibernate queries.
|
|
select emp from Employee emp |
|
|
select emp.id from Employee emp where exists ( from Education where name like 'Foo' and emp.id = employee.id ) |
|
|
select emp.id from Employee emp where exists ( from Education edu where edu.name like 'Foo' and emp.id = employee.id ) |
|
|
select * from Employee as emp where exists ( from Education as edu where edu.name like 'Foo' and emp.id = employee.id ) |
|
|
from Employee as emp where exists ( from Education where name like 'Foo' and emp.id = employee.id ) |
explanation |
The use of select * is not allowed in HQL. As an alternative you can leave out select * or use (in this case) select emp . |
---In Hibernate which of the following properties of persistent class mapping have to be added (separately) to enable optimistic locking? (Choose all that apply)
+
|
<timestamp>
|
|
<lock>
|
|
<optimistic-locking>
|
+
|
<version>
|
Ex::Optimistic locking is enabled when you add a <version> or a <timestamp> property to a persistent class mapping.
---Select the right lock levels that may be acquired by Hibernate.
+
|
LockMode.WRITE
|
+
|
LockMode.READ
|
|
LockMode.READ_WRITE
|
+
|
LockMode.UPGRADE
|
+
|
LockMode.UPGRADE_NOWAIT
|
+
|
LockMode.NONE
|
There is no LockMode.READ_WRITE.
---By default, Hibernate works in the autocommit mode i.e. starts and commits the transaction after each operation like load or save. (F)
Ex:You have to flush the session or commit the transaction explicitly.
---One of the Hibernate supported inheritance mapping strategies is
table per class hierarchy (An entire class hierarchy can be mapped to a single table).
Disadvantage of the strategy is that columns for properties declared by subclasses must be declared to be nullable. (T)
---What's the state of a newly created object?
+
|
Transient.
|
|
Persistent.
|
|
Detached.
|
Ex: Objects created with a new operator are transient (are not associated with a database).
---Which is default cache service in Hibernate 3?
+
|
EHCache
|
|
OSCache
|
|
TreeCache
|
|
SwarmCache
|
Default cache service in Hibernate 3 is EHCache
---Assume, that U have two persistent classes with the same
unqualified name, for example
com.jbb.JBB
and
org.jbb.JBB
.Hibernate will throw an exception if you attempt to assign two classes to the same unqualified name when
auto-import
attribute set to "false".
(F)
If you have two persistent classes with the same (unqualified) name, you should set auto-import="false". Hibernate will throw an exception if you attempt to assign two classes to the same "imported" name
posted @
2007-06-15 15:11 Sun River|
编辑 收藏
Here are some XML processing examples in Javascript. If you've got some XML data with XMLHttpRequest (there is actually no XMLHttpRequest in the examples - we create the XML object from a string - can be handy too) you need to read/convert etc. it to some other format and do something with it. Traversing a DOM/XML tree can be tricky, so have a look at these examples:
Example #1:
Using getElementsByTagName, we iterate thru the XML tree and read the numerous children/sibling.
<html>
<body>
<script>
var xmlstring = '<?xml version=\"1.0\"?>\
<shoppingcart date="14-10-2005" total="123.45">\
<item code="12345">\
<name>Widget</name>\
<quantity>1</quantity>\
</item>\
<item code="54321">\
<name>Another Widget</name>\
<quantity>2</quantity>\
</item>\
</shoppingcart>';
// convert the string to an XML object
var xmlobject = (new DOMParser()).parseFromString(xmlstring, "text/xml");
// get the XML root item
var root = xmlobject.getElementsByTagName('shoppingcart')[0];
var date = root.getAttribute("date");
alert("shoppingcart date=" + date);
var items = root.getElementsByTagName("item");
for (var i = 0 ; i < items.length ; i++) {
// get one item after another
var item = items[i];
// now we have the item object, time to get the contents
// get the name of the item
var name = item.getElementsByTagName("name")[0].firstChild.nodeValue;
// get the quantity
var quantity = item.getElementsByTagName("quantity")[0].firstChild.nodeValue;
alert("item #" + i + ": name=" + name + " quantity=" + quantity);
}
</script>
</body>
</html>
Example #2:
Here is a more universal example with the method "childNodes".
<html>
<body>
<script>
var xmlstring = '<?xml version="1.0"?>\
<root>\
<data>\
<row>\
<cell>Admiral</cell>\
<cell>Melon</cell>\
<cell>Carrot</cell>\
</row>\
<row>\
<cell>Captain</cell>\
<cell>Banana</cell>\
<cell>Zucchini</cell>\
</row>\
</data>\
<data>\
<row>\
<cell>Midshipman</cell>\
<cell>Orange</cell>\
<cell>Potatoe</cell>\
</row>\
</data>\
</root>';
// convert the string to an XML object
var xmlobject = (new DOMParser()).parseFromString(xmlstring, "text/xml");
// get the XML root item
var root = xmlobject.getElementsByTagName('root')[0];
for (var iNode = 0; iNode < root.childNodes.length; iNode++) {
var node = root.childNodes.item(iNode);
for (i = 0; i < node.childNodes.length; i++) {
var sibling = node.childNodes.item(i);
for (x = 0; x < sibling.childNodes.length; x++) {
var sibling2 = sibling.childNodes.item(x);
if (sibling2.childNodes.length > 0) {
var sibling3 = sibling2.childNodes.item(0);
alert(sibling3.data);
}
}
}
}
</script>
</body>
</html>
posted @
2007-06-14 06:40 Sun River|
编辑 收藏
---Is there any way that an AJAX object can get back a record set?
Answer
You could build an XML document out of your recordset and send that back to the server, say you had a redord set for a "user" with the following details (name, surname, age, email), you could build an xml document like this:
Code:
<recordset>
<user>
<name>Byron</name>
<surname>Tymvios</surname>
<age>25</age>
<email>email@address.com</email>
</user>
<user>
<name>User</name>
<surname>Someone</surname>
<age>39</age>
<email>myAddy@address.com</email>
</user>
</recordset>
You can add as many records as you have in your recordset, then once the client has received it you can use javascript to iterate over the <user>'s in the xml.
---Is it possible to set session variables from javascript? It's not possible to set any session variables directly from javascript as it is purely a client side technology. You can use AJAX though to asyncronously send a request to a servlet running on the server and then add the data to the session from within the servlet. So you wouldn't be using javascript to do the actual setting of session variables but it would look like it is.
I've been developing a sliding navigational menu. Here is how I save the state across pages:
var saveState = true;
if(saveState)
{
// This AJAX call will save the Navigator's state to session.
// We don't need a callback function because nothing happens
// once said state is saved.
var url = "AJAX_Servlet.aspx?function=saveNavigatorState&control=" + id + "&class=" + section.className + "";
req = new ActiveXObject("Microsoft.XMLHTTP");
req.open("POST", url, true);
req.send();
}
Note that id is set to the Id of the submenu table (which is hidden / shown by other code which sets the className of the table. My stylesheet has css for each class.) earlier in the overal function.
Here is the codebehind for my AJAX_Servlet.aspx, which could easily be a web service:
private void Page_Load(object sender, System.EventArgs e)
{
if(Request.QueryString["function"] != null)
{
if(Request.QueryString["function"] == "saveNavigatorState")
SaveNavigatorState();
}
}
private void SaveNavigatorState()
{
if(Request.QueryString["control"] != null && Request.QueryString["class"] != null)
{
string controlID = Request.QueryString["control"].ToString();
string className = Request.QueryString["class"].ToString();
Session[controlID] = className;
}
}
Then on my navigator codebehind, I just check for session data on load.
posted @
2007-06-14 06:26 Sun River|
编辑 收藏