Java Interview Questions -43

Java Interview Questions -43

1.Are Struts’s action classes Thread-safe?

Yes. Action classes are based on “one-instance and many-threads”. This is to conserve resources and to provide the best possible throughput.

2.What are the various Struts Tag libraries?

There are various struts tags. But the most-repeated tags are:

3.What is ActionMapping in struts?

Action mapping defines the flow of one request. The possible sequence is
User -> request -> Form -> Validation -> Business Code -> Forward -> JSP -> response -> User.
The components involved are Action classes, Forms and JSP.

4.What are the advantages of having multiple struts-config in the same application?

The implementation with many struts-config is to organize the development work, so that many people may be involved and it is some organized way of doing things. But this would result in some compromise in performance(speed). Technically there is no any difference between single and multiple struts-config files.

5.What are the ways in which resource file can be used in struts?

Defining message resources in struts-config file.
Programmatically using resource files in Java classes or in JSP files.

6.Explain the term ‘architecture of the application’?

Architecture is the set of rules (or framework) to bring in some common way of assembling or using J2EE components in the application. This helps in bringing consistency between codes developed by various developers in the team.

7.Which is the architecture followed by struts?

Struts follows MVC architecture.

8.What are components corresponding o M, V and C in struts?

Model : The model represents the data of an application. Anything that an application will persist becomes a part of model. The model also defines the way of accessing this data ( the business logic of application) for manipulation. It knows nothing about the way the data will be displayed by the application. It just provides service to access the data and modify it. Here ‘Form Bean’ represents Model layer.
View : The view represents the presentation of the application. The view queries the model for its content and renders it. The way the model will be rendered is defined by the view. The view is not dependent on data or application logic changes and remains same even if the business logic undergoes modification. JSP represents View Layer.
Controller : All the user requests to the application go through the controller. The controller intercepts the requests from view and passes it to the model for appropriate action. Based on the result of the action on data, the controller directs the user to the subsequent view. Action classes (action servlets) represent Controller layer.

9.Differentiate between the terms ‘Design Patterns’, ‘Framework’ and ‘Architecture’.

Design Pattern: The various solutions arrived at for the known problem. This helps to avoid re-inventing the wheel. The risk-free solution can be easily used by others. For example, singleton is the design pattern that you can use instantly to enfore one object per class. You do not need to think of this on your own.
Framework: A framework is a structure or set of rules, used to solve or address complex issues. It is basically a reusable designf for the J2EE applications. For example, Struts, JSF,etc., are the frameworks. You can use these frameworks based on the requirements of your application and each has its own set of advantages.
Architecture: It is a design that describes how the various components in the application fit together. For example, MVC is an architecture which is helpful to define how the components interact within the application.

10.What is the difference between ActionForm and DynaActionForm?

In action form, you need to define the form class that extends ActionForm explicitly, whereas you can define the form dynamically inside the struts-config file when using DynaActionForm.

11.How can you use Validator framework in struts?

Validator Frameworks are helpful when the application needs server-side validation such that the particular set of validations occur very frequently within the same application. This avoids writing complex code in validation() method in every form bean. Using validator framework, there are different pre-written validations in place. You can customize these validations in XML file.

12.What are client-side and server-side vaidations?

Client-side validations: These are the validations that id done using javascripts. There is always a danger involved that the user can get through (crack-through) these validations. But for some simple validations, like converting lower-case to upper-case or date validations can be done, you can use javascripts.
Server-side validations: These are the validations done in server-side using Java components (Form bean or in business logics) where the user has no chance to crookedly get through the system.

13.Define the terms authentication and authorisation.

Authentication is the process/rule that validates if the user is allowed to access the system or not.
Authorization is the process/rule that validates if the user is allowed to access the particular part of the system or not. This occurs after user’s successful authentication.

14.What are the components provided in J2EE to perform authentication and authorization?

Authentication – RequestProcessor and/or Filter.
Authorization – DTO, JDO or Java or Action classes.

15.Give the difference between between ‘DispatchAction’ and ‘Action’.

A DispatchAction contains various different methods other than the standard execute() method in Action classes. These methods are executed based on some request parameter. For example, you can code in such a way that three buttons (namely Insert, Delete, Update) buttons correspond to different methods such as insert(), delete() and udpate(). The submit button in JSP would have the property that has the value which matches to any one of the methods defined in DispatchAction class.

16.What is pagination technique? How can you design them in struts?

Pagination is the technique where the bulk of results are split into different pages and only the information where the user can conveniently see are displayed in a page. (Like in Goooooogle). This can be achieved in many ways, but the simplest method is to have a query string (say http://www.testwebsite?pageNumber=2) would lead to information corresponding to resultset rows from 11 to 20. Assuming that you want to display 10 related rows of information, you can set the formula as follows:
Starting row = (pageNumber-1) * + 1 which is equal to 11.
Ending row = Starting row + which is equal to 20.

17.How can you populate the drop-down list using form properties?

There are many ways for this. But the best method is to use which defines collection that needs to be used to populate the drop-down list, the property to store the selected value and the collection that is used to display the labels (what we see in JSP page). For Example,
html:options collection=”form-collection-property”

18.What is the XML parser provided in struts? Can you use it for other purposes?

‘Digester’ framework. Yes we can use for our applications to store and parse our application-related data.

19.Difference between Struts 1.0 and 1.1

Perform() method was replaced by execute()
DynaActionForms are introduced.
Tiles Concept is introduced
We can write our own Controller by Inheriting RequestProcessor

20.What are the differences between setMaxRows(int) and SetFetchSize(int)?

The difference between setFetchSize and setMaxRow are:
setFetchSize(int) defines the number of rows that will be read from the database when the ResultSet needs more rows whereas setMaxRows(int) method of the ResultSet specifies how many rows a ResultSet can contain at a time.
In setFetchSize(int), method in the java.sql.Statement interface will set the ‘default’ value for all the ResultSet derived from that Statement whereas in setMaxRow(int) default value is 0, i.e. all rows will be included in the ResultSet.
the setMaxRows affects the client side JDBC object while the setFetchSize affects how the database returns the ResultSet data.

21.How can I manage special characters when I execute an INSERT query?

The special characters meaning in SQL can be preceded with a special escape character in strings, e.g. “”. In order to specify the escape character used to quote these characters, include the following syntax on the end of the query:
{escape ‘escape-character’}
For example, the query
finds identifier names that begin with an underscore.

22.What is the benefit of having JdbcRowSet implementation? Why do we need a JdbcRowSet like wrapper around ResultSet?

The JdbcRowSet implementation is a wrapper around a ResultSet object has following advantages over ResultSet:
i.It makes possible to use the ResultSet object as a JavaBeans component.
ii.A JdbcRowSet can be used as a JavaBeans component, thus it can be created and configured at design time and executed at run time.
iii.It can be used to make a ResultSet object scrollable and updatable. All RowSet objects are by default scrollable and updatable.

23.Explain Basic Steps in writing a Java program using JDBC.

JDBC makes the interaction with RDBMS simple and intuitive. When a Java application needs to access database :
i.Load the RDBMS specific JDBC driver because this driver actually communicates with the database.
ii.Open the connection to database, for sending SQL statements and get results back.
iii.Create JDBC Statement object containing SQL query.
iv.Execute statement which returns result set. ResultSet contains the tuples of database table as a result of SQL query.
v.Process the result set.
vi.Close the connection.

24.I have the choice of manipulating database data using a byte[] or a java.sql.Blob. Which has best performance?

We use java.sql.Blob, because of following reason:
It does not extract any data from the database until we trigger a query to the databse.
We use byte[] for inserting data in the database when data is not upload in the database till yet.
java.sql.Blob is used when extraction of the data is performed.

25.What are DML and DDL?

Data Manipulation Language (DDL) this portion of the SQL standard is concerned with manipulating the data in a database as opposed to the structure of a database. The DML deals with the SELECT, INSERT, DELETE, UPDATE, COMMIT and ROLLBACK.
Data Definition Language (DDL) this portion of the SQL standard is concerned with the creation, deletion and modification of database objects like tables, indexes and views. The core verbs for DDL are CREATE, ALTER and DROP. While most DBMS engines allow DDL to be used dynamically, it is often not supported in transactions.

26.How can you load the drivers?

It is very simple and involves just one line of code to load the driver or drivers we want to use.

For example, We want to use the JDBC-ODBC Bridge driver, the following code will load it:
Driver documentation will give you the class name to use. For instance, if the class name is jdbc.DriverHELLO, you would load the driver with the following line of code:

27.How do I insert an image file (or other raw data) into a database?

All raw data types should be read and uploaded to the database as an array of bytes, byte[].
1.Originating from a binary file.
2.Read all data from the file using a FileInputStream.
3.Create a byte array from the read data.
4.Use method setBytes(int index, byte[] data); of java.sql.PreparedStatement to upload the data.

28.What causes No suitable driver error?

“No suitable driver” is occurs during a call to the DriverManager.getConnection method, may be of any of the following reason:
1.Due to failing to load the appropriate JDBC drivers before calling the getConnection method.
2.It can be specifying an invalid JDBC URL, one that is not recognized by JDBC driver.
3.This error can occur if one or more the shared libraries needed by the bridge cannot be loaded

29.What does setAutoCommit do?

setAutoCommit() invoke the commit state query to the database. To perform batch updation we use the setAutoCommit() which enable us to execute more than one statement together, which in result minimize the database call and send all statement in one batch.
setAutoCommit() allowed us to commit the transaction commit state manually the default values of the setAutoCommit() is true.

30.Why Prepared Statements are faster?

Prepared execution is faster than direct execution for statements executed more than three or four times because the statement is compiled only once. Prepared statements and JDBC driver are linked with each other. We can bind drivers with columns by triggering the query into the database. When we execute Connection.prepareStatement(), all the columns bindings take place, in oder to reduce the time.

31.What restrictions are placed on method overriding?

The restriction on method overloading is the signature of the method.
i.The signature is the number, type, and order of the arguments passed to a method.
ii.Overridden methods must have the same name, argument list, and return type.
iii.Any method which has the same name cannot have the same signature.
iv.They can have the same return types in the same scope.
v.The compiler uses the signature to detect which overloaded method to refer when a overloaded method is called.
vi.If two methods have the same name and signature the compiler will throw a runtime error.

32.What are derived properties?

The properties that are not mapped to a column, but calculated at runtime by evaluation of an expression are called derived properties. The expression can be defined using the formula attribute of the element.

33.Define HibernateTemplate?

org.springframework.orm.hibernate.HibernateTemplate is a helper class which provides different methods for querying/retrieving data from the database. It also converts checked HibernateExceptions into unchecked DataAccessExceptions.

34.What are the benefits does HibernateTemplate provide?

The benefits of HibernateTemplate are :
HibernateTemplate, a Spring Template class simplifies interactions with Hibernate Session.
Common functions are simplified to single method calls.
Sessions are automatically closed.
Exceptions are automatically caught and converted to runtime exceptions.

35.What is Hibernate proxy?

Mapping of classes can be made into a proxy instead of a table. A proxy is returned when actually a load is called on a session. The proxy contains actual method to load the data. The proxy is created by default by Hibernate, for mapping a class to a file. The code to invoke JDBC is contained in this class.

36. What is lazy fetching in hibernate ?

Lazy fetching is associated with child objects loading for its parents. While loading the parent, the selection of loading a child object is to be specified / mentioned in the hbm.xml file. Hibernate does not load the whole child objects by default. Lazy=true means not to load the child objects.

37.Explain the difference between transient and detached objects in hibernate ?

Transient objects do not have association with the databases and session objects. They are simple objects and not persisted to the database. Once the last reference is lost, that means the object itself is lost. And of course , garbage collected. The commits and rollbacks will have no effects on these objects. They can become into persistent objects through the save method calls of Session object.
The detached object have corresponding entries in the database. These are persistent and not connected to the Session object. These objects have the synchronized data with the database when the session was closed. Since then, the change may be done in the database which makes this object stale. The detached object can be reattached after certain time to another object in order to become persistent again.

38. What are the core interfaces of Hibernate framework ?

Session Interface: The basic interface for all hibernate applications. The instances are light weighted and can be created and destroyed without expensive process.
SessionFactory interface: The delivery of session objects to hibernate applications is done by this interface. For the whole application, there will be generally one SessionFactory and can be shared by all the application threads.
Configuration Interface: Hibernate bootstrap action is configured by this interface. The location specification is specified by specific mapping documents, is done by the instance of this interface.
Transaction Interface: This is an optional interface. This interface is used to abstract the code from a transaction that is implemented such as a JDBC / JTA transaction.
Query and Criteria interface: The queries from the user are allowed by this interface apart from controlling the flow of the query execution.

39.What are the different types of caches in Hibernate ?

Hibernate uses two different caches for objects: first-level cache and second-level cache. First-level cache is associated with the Session object, while second-level cache is associated with the SessionFactory object. By default, Hibernate uses first-level cache on a per-transaction basis. Hibernate uses this cache mainly to reduce the number of SQL queries it needs to generate within a given transaction.

40.How does the hibernate second-level cache work ?

Hibernate always tries to first retrieve objects from the session and if this fails it tries to retrieve them from the second-level cache. If this fails again, the objects are directly loaded from the database. Hibernate’s static initialize() method, which populates a proxy object, will attempt to hit the second-level cache before going to the database. The Hibernate class provides static methods for manipulation of proxies.

41.What is a query cache in Hibernate ?

The query cache is responsible for caching the results and to be more precise the keys of the objects returned by queries. Let us have a look how Hibernate uses the query cache to retrieve objects. In order to make use of the query cache we have to modify the person loading example as follows.

Query query = session.createQuery(“from Order as o where o.status=?”);
query.setInt(0, “Active”);
query.setCacheable(true); // the query is cacheable
List l = query.list();

42.What is callback interfaces in hibernate?

Callback interfaces of hibernate are useful in receiving event notifications from objects. For example, when an object is loaded or deleted, an event is generated and notification is sent using callback interfaces.

43.What is the difference between and merge and update ?

Use update() if you are sure that the session does not contain an already persistent instance with the same identifier, and merge() if you want to merge your modifications at any time without consideration of the state of the session.

44.What is the difference between and load() and get() ?

Load() method:Only use the load() method if you are sure that the object exists.
load() method will throw an exception if the unique id is not found in the database.
load() just returns a proxy by default and database won’t be hit until the proxy is first invoked.
Get() method:If you are not sure that the object exists, then use one of the get()methods.
get() will hit the database immediately.
get() method will return null if the unique id is not found in the database.

45.What are the different caching strategies ?

Read-only: This strategy is useful for data that is read frequently but never updated. This is by far the simplest and best-performing cache strategy.
Read/write: Read/write caches may be appropriate if your data needs to be updated. They carry more overhead than read-only caches. In non-JTA environments, each transaction should be completed when Session.close() or Session.disconnect() is called.
Nonstrict read/write: This strategy does not guarantee that two transactions won’t simultaneously modify the same data. Therefore, it may be most appropriate for data that is read often but only occasionally modified.
Transactional: This is a fully transactional cache that may be used only in a JTA environment.

46.What are the different fetching strategy in Hibernate ?

Hibernate defines the following fetching strategies:
Join fetching – Hibernate retrieves the associated instance or collection in the same SELECT, using an OUTER JOIN.
Select fetching – a second SELECT is used to retrieve the associated entity or collection. Unless you explicitly disable lazy fetching by specifying lazy=”false”, this second select will only be executed when you actually access the association.
Subselect fetching – a second SELECT is used to retrieve the associated collections for all entities retrieved in a previous query or fetch. Unless you explicitly disable lazy fetching by specifying lazy=”false”, this second select will only be executed when you actually access the association.Batch fetching – an optimization strategy for select fetching – Hibernate retrieves a batch of entity instances or collections in a single SELECT, by specifying a list of primary keys or foreign keys.

47.What is version checking in Hibernate ?

version checking used in hibernate when more then one thread trying to access same data.
For example :
User A edit the row of the TABLE for update ( In the User Interface changing data This is user thinking time) and in the same time User B edit the same record for update and click the update. Then User A click the Update and update done. Chnage made by user B is gone. In hibernate you can perevent slate object updatation using version checking.
Check the version of the row when you are upding the row. Get the version of the row when you are fetching the row of the TABLE for update. On the time of updation just fetch the version number and match with your version number ( on the time of fetching).

48.Difference between getCurrentSession() and openSession() in Hibernate ?

getCurrentSession():The “current session” refers to a Hibernate Session bound by Hibernate behind the scenes, to the transaction scope. A Session is opened when getCurrentSession() is called for the first time and closed when the transaction ends.
openSession():If you decide to use manage the Session yourself the go for sf.openSession(), you have to flush() and close() it. It does not flush and close() automatically.

49.What does session.refresh() do ?


50.How to get JDBC connections in hibernate ?

User Session.connection() method to get JDBC Connection.

51.What’s the use of session.lock() in hibernate ?

session.lock() method of session class is used to reattach an object which has been detached earlier. This method of reattaching doesn’t check for any data synchronization in database while reattaching the object and hence may lead to lack of synchronization in data.

52. What is the difference between the session.update() method and the session.lock() method ?

Both of these methods and saveOrUpdate() method are intended for reattaching a detached object. The session.lock() method simply reattaches the object to the session without checking or updating the database on the assumption that the database in sync with the detached object. It is the best practice to use either session.update(..) or session.saveOrUpdate(). Use session.lock() only if you are absolutely sure that the detached object is in sync with your detached object or if it does not matter because you will be overwriting all the columns that would have changed later on within the same transaction.

53.What is a SessionFactory?

The SessionFactory is the concept that is a single data store and thread safe. Because of this feature, many threads can access this concurrently and the sessions are requested, and also the cache that is immutable of compiled mappings for a specific database. A SessionFactory will be built only at the time of its startup. In order to access it in the application code, it should be wrapped in singleton. This wrapping makes the easy accessibility to it in an application code.

54.Explain about session interface?

This represents hibernate session which perform the manipulation on the database entities. Some of the activities performed by session interface are as follows they are managing the persistence state, fetching persisted ones and management of the transaction demarcation.

55.Explain about the dirty checking feature of Hibernate?

Dirty checking feature of the Hibernate allows users or developers to avoid time consuming data base write actions. This feature makes necessary updations and changes to the fields which require a change, remaining fields are left unchanged or untouched.

56. Explain the steps involved in creating database applications with Java using Hibernate?

Creating Database applications with Java is made simpler with Hibernate. First Plain old java object needs to be written, XML mapping file should be created which shows relationship between database and class attributes. Hibernate APIs can be used to store persistent objects.

57.Explain about hibernate.cfg.xml?

Hibernate can be configured with two types of files out of which hibernate.cfg.xmlis widely used and popular feature. Hibernate consults hibernate.cfg.xml file for its operating properties such as database dialect, connection string and mapping files. These files are searched on class path.

58. Explain about mapping description file?

Mapping description file is the second file which Hibernate uses to configure its functions. This mapping file has an extension *.hbm which instructs mapping between Java class and database tables. The usage of mapping description file rests entirely upon the business entity.

59. Explain about transaction file?

Transactions denote a work file which can save changes made or revert back the changes. A transaction can be started by session.beginTransaction() and it uses JDBC connection, CORBA or JTA. When this session starts several transactions may occur.

60. Explain about mapping files in Hibernate?

Mapping files forms the core of any database mapping tools. These files contain field to field mapping, usually this mapping occurs between classes and attributes. After mapping files they can be persist to the database. Tags can be used to indicate the presence of a primary key.

61. What is the effect when a transient mapped object is passed onto a Sessions save?

When a ) is passed to a transient mapped object it makes the method to become more persistent. Garbage collection and termination of the Java virtual machine stays as long as it is deleted explicitly. It may head back to its transient state.

62. Explain about version field?

Application level data integrity constants are important if you are making changes to offline information which is again backed by database. Higher level locking or versioning protocol is required to support them. Version field usage comes at this stage but the design and implementation process is left to the developer.

63. Explain State some advantages of hibernate?

Some of the advantages which a developer can get from Hibernate are as follows:
i.Mapping of one POJO table to one table is not required in hibernate.
ii.It supports inheritance relationships and is generally a fast tool. Portability is necessary the greater benefit from hibernate. POJOs can be used in other applications where they are applicable.

64.Explain about addClass function?

This function translates a Java class name into file name. This translated file name is then loaded as an input stream from the Java class loader. This addclass function is important if you want efficient usage of classes in your code.

65. Explain about addjar() and addDirectory() methods?

These methods are the most convenient to use in hibernate. These methods allow you to load all your Hibernate documents at a time. These methods simplify code configuration, refactoring, layout, etc. These functions help you to add your hibernate mapping to Hibernate initialization files.

66. Explain about the id field?

This id field corresponds to the surrogate key which is generated by the database. These fields are handled by the id field. Name attribute is used to specify the names of the field and it should correspond to the method name of getid. This also should correspond to long type and the values should be stored I the database in the long column.

67. What are the most common methods of Hibernate configuration ?

The most common methods of Hibernate configuration are:
Programmatic configuration
XML configuration (hibernate.cfg.xml)

68.Define cascade and inverse option in one-many mapping ?

cascade – enable operations to cascade to child entities.
inverse – mark this collection as the “inverse” end of a bidirectional association.

69. Explain Criteria API ?

Criteria is a simplified API for retrieving entities by composing Criterion objects. This is a very convenient approach for functionality like “search” screens where there is a variable number of conditions to be placed upon the result set.
Example :
List employees = session.createCriteria(Employee.class)
.add(“name”, “a%”) )
.add(“address”, “Boston”))
.addOrder(Order.asc(“name”) )

70.. How can a whole class be mapped as immutable ?

Mark the class as mutable=”false” (Default is true),. This specifies that instances of the class are (not) mutable. Immutable classes, may not be updated or deleted by the application.

71. What  is hibernate tuning ?

The key to obtain better performance in any hibernate application is to employ SQL Optimization, session management, and Data caching.

72. What is HQL ?

HQL stands for Hibernate Query Language. Hibernate allows the user to express queries in its own portable SQL extension and this is called as HQL. It also allows the user to express in native SQL.

73. How to Execute Stored procedure in Hibernate ?

<sql-query name=”selectAllEmployees_SP” callable=”true”>
<return alias=”emp” class=”employee”>
<return-property name=”empid” column=”EMP_ID”/>
<return-property name=”name” column=”EMP_NAME”/>
<return-property name=”address” column=”EMP_ADDRESS”/>
{ ? = call selectAllEmployees() }
SQLQuery sq = (SQLQuery) session.getNamedQuery(“selectAllEmployees_SP”);
List results = sq.list();

74. What is a meant by light object mapping?

The entities are represented as classes that are mapped manually to the relational tables. The code is hidden from the business logic using specific design patterns. This approach is successful for applications with a less number of entities, or applications with common, metadata-driven data models.

75. What’s the difference between load() and get() method in hibernate?

Load() methods results in an exception if the required records isn’t found in the database while get() method returns null when records against the id isn’t found in the database.
So, ideally we should use Load() method only when we are sure about existence of records against an id.

76. What’s the use of version property in hibernate?

Version property is used in hibernate to know whether an object is in transient state or in detached state.

77. What is attribute oriented programming?

In Attribute oriented programming, a developer can add Meta data (attributes) in the java source code to add more significance in the code. For Java (hibernate), attribute oriented programming is enabled by an engine called XDoclet.

78. What’s the use of session.lock() in hibernate?


79. Does hibernate support polymorphism?

Yes, hibernate fully supports polymorphism. Polymorphism queries and polymorphism associations are supported in all mapping strategies of hibernate.

80. What the three inheritance models are of hibernate?

Hibernate has following three inheritance models:
a. Tables Per Concrete Class
b. Table per class hierarchy
c. Table per sub-class

81. How can we map the classes as immutable?

If we don’t want an application to update or delete objects of a class in hibernate, we can make the class as immutable by setting mutable=false

82. What’s general hibernate flow using RDBMS?

General hibernate flow involving RDBMS is as follows:
a. Load configuration file and create object of configuration class.
b. Using configuration object, create sessionFactory object.
c. From sessionFactory, get one session.
d. Create HQL query.
e. Execute HQL query and get the results. Results will be in the form of a list.

83. What is Light Object Mapping?

Light Object Mapping is one of the levels of ORM quality in which all entities are represented as classes and they are mapped manually.

84. What’s difference between managed associations and hibernate associations?

Managed associations relate to container management persistence and are bi-directional while hibernate associations are unidirectional.

85.What is auto wiring ?

The Spring container provides the functionality of connecting beans with each other automatically called autowiring . Rather we inject one bean into the other using ref attribute,  Spring can look into the BeanFactory and decide how to inject one bean into the other.

86.What are the different bean scopes in Spring ? Explain with an example ?

In Spring, creation of beans can be controlled by defining the scope of bean.  To define scope attribute ‘scope’ of <bean> tag is used. There are five types of bean scopes in Spring.

87.What is Aspect Oriented programming (AOP) ? Explain with an example ?

AOP is a programming technique used to manage cross-cutting concerns like logging, security and transaction management. To implement AOP we need to create aspects (classes) which contains cross-cutting functionality .

88. What is the difference between concerns and cross-cutting concerns ?


89. What is Aspect in Spring AOP? Explain with an example ?

Aspect defines the implementation of cross-cutting concern. We implement a cross-cutting functionality by creating an aspect. Aspect encapsulates our cross-cutting concern.

90.What is Advice in Spring AOP ? Explain with an example ?

Action performed by an aspect at a particular join point is called an Advice. Different types of advice are “around,” “before” ,”after”, “afterreturning” and “afterthrowing”.

91. What is Pointcut in Spring AOP ? Explain with an example ?

A pointcut is an expression/predicate which points to a join point. Pointcut defines where to hook the advice.

92.What is join point ? Explain with an example ?

Join point represents execution of a method where we want to hook the advice into.
Consider execution of a program and during this some methods are called say meth1(), meth2(), meth3().

93.What is Around advice ? Explain with an example ?

This advice is combination of before and after advices. It lets you do something before target method (join point) and some other things after the target method (join point).

94.What is the use of setComment and getComment methods in Cookies ?

setComment:If a user agent (web browser) presents this cookie to a user, the cookie’s purpose will be described using this comment. This is not supported by version zero cookies.
public void setComment(String use)
Returns the comment describing the purpose of this cookie, or null if no such comment has been defined.

95.Why do you need both GET and POST method implementations in Servlet?

A single servlet can be called from differenr HTML pages,so Different method calls can be possible.

96.If you want to modify the servlet,will the Webserver need to be ShutDown.


97.What is the uses Sessions ?

Its a part of the SessionTracking and it is for mainting the client state at server side.

98.What are the advantage of using Sessions over Cookies and URLReWriting?

Sessions are more secure and fast becasue they are stored at serverside. But Sessions has to be used combindly with Cookies or URLReWriting for mainting the client id that is sessionid at client side.
Cookies are stored at client side so some clients may disable cookies so we may not sure that thecookies which we are mainting may work or not but in sessions cookies are disable we can maintain
our sessionid using URLReWriting .In URLReWriting we can’t maintain large data because it leads to network traffic and access may be become slow.Where as in seesions will not maintain the data which we have to maintain instead
we will maintain only the session id.

99. What is session tracking and how do you track a user session in servlets?

Session tracking is a mechanism that servlets use to maintain state about a series requests
from the same user across some period of time. The methods used for session tracking are:
a) User Authentication – occurs when a web server restricts access to some of its resources to only those clients that log in using a recognized username and password
b) Hidden form fields – fields are added to an HTML form that are not displayed in the clientâ€™s browser. When the form containing the fields is submitted, the fields are sent back to the server
c) URL rewriting – every URL that the user clicks on is dynamically modified or rewritten to include extra information. The extra information can be in the form of extra path information, added parameters or some custom, server-specific URL change.
d) Cookies – a bit of information that is sent by a web server to a browser and which can later be read back from that browser.
e) HttpSession- places a limit on the number of sessions that can exist in memory. This limit is set in the session.maxresidents property

100.What is Cookies and what is the use of Cookies ?

Cookies are used to get user agents (web browsers etc) to hold small amounts of state associated with a user’s web browsing.Later that infromation read by server

101.What is the advantage of Servlets over other serverside technologies.

PlatForm independent, so once compiled can be used in any webserver.For different processes different threads will execute inbuilt mutithreaded.

102.What is Server-Side Includes (SSI)?

Server-Side Includes allows embedding servlets within HTML pages using a special servlet tag. In many servlets that support servlets, a page can be processed by the server to include output from servlets at certain points inside the HTML page.
This is accomplished using a special internal SSINCLUDE, which processes the servlet tags. SSINCLUDE servlet will be invoked whenever a file with an. shtml extension is requested.
So HTML files that include server-side includes must be stored with an .shtml extension.

103.What is Single Threaded Model in Servlets and how is it useful give one practical example.

For every single user a differnt copy of this servlet is executed. Credit card transactions.


