Sun River
Topics about Java SE, Servlet/JSP, JDBC, MultiThread, UML, Design Pattern, CSS, JavaScript, Maven, JBoss, Tomcat, ... |
--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 ?
--
--
--Question: What is similarities/difference between an Abstract class and Interface? Similarities:
--Question:
Answer: Differences are as follows:
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. --Question: What do you understand by final value?
Answer: From a practical programming viewpoint, polymorphism exists in three distinct forms in Java:
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);
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.
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.
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). ---SOA: 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.
Pet pet = (Pet) session.get(Pet.class, petId);
andPet pet = (Pet) session.load(Pet.class, petId);
?
|
READ |
|
|
WRITE |
|
|
FORCE |
|
|
UPGRADE |
|
|
INCREMENT |
+ |
Table per subclass |
|
Table per class hierarchy |
|
Table per concrete class |
|
implicit polymorphism |
<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;
// initialize the Session object properly
// for example using sessionFactory.openSession()
// ...
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 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 . |
+ |
<timestamp> |
|
<lock> |
|
<optimistic-locking> |
+ |
<version> |
+ |
LockMode.WRITE |
+ |
LockMode.READ |
|
LockMode.READ_WRITE |
+ |
LockMode.UPGRADE |
+ |
LockMode.UPGRADE_NOWAIT |
+ |
LockMode.NONE |
+ |
Transient. |
|
Persistent. |
|
Detached. |
+ |
EHCache |
|
OSCache |
|
TreeCache |
|
SwarmCache |
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". <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>
---Is there any way that an AJAX object can get back a record set?
AnswerYou 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.
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();
}
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;
}
}