You are on page 1of 6

1. What are the principle concepts of OOP?

There are four principle concepts upon which object oriented design and programming rest. They
are:
1. Abstraction
2. Polymorphism
3. Inheritance
4. Encapsulation

2. What is the difference between and statement and a prepare statement in JDBC? Does the
prepared statement do anything other than allow us to have parameters (multiple uses)? How
is this different than a callable statement (used to call stored procedures)?

Statement object is used to run static SQL queries as it cannot accept the parameters.
Prepared Statement object is used to run dynamic SQL queries as it can accept parameters
at runtime.
When Statement object is used, the SQL query is not precompiled. In case of Prepared
Statement, the query is supplied to the object when it is created and it is precompiled at
that time. So it is used when the query needs to be executed many times.
It is the basic type of interface provided in java to run SQL queries. Prepared Statement
extends the Statement interface and thus provides all the features of Statement and also
the above mentioned advantages over the same.

prepared statement is compiled only once and executed many times with different
parameters avoiding delay of compilation for every retrival (execution).In prepared
statements the date formats and number formats are taken care of. Also it takes care if we
have a string with apostrophe, which otherwise needs to be escaped everytime.

Callable statement is used for SQL statements already built inside database (PL/SQL procedures
etc.) which are permanently precompiled in database

3. What is Spring?

Spring is an open source framework created to address the complexity of enterprise application
development. One of the chief advantages of the Spring framework is its layered architecture, which
allows you to be selective about which of its components you use while also providing a cohesive
framework for J2EE application development.

1. What are the advantages of Spring framework?

The advantages of Spring are as follows:

1. Spring has layered architecture. Use what you need and leave you don't need now.
2. Spring Enables POJO Programming. There is no behind the scene magic here. POJO programming
enables continuous integration and testability.
3. Dependency Injection and Inversion of Control Simplifies JDBC
4. Open source and no vendor lock-in.
2. What are some of the modules in Spring?

Spring comprises of seven modules:

1. The core container: The core container provides the essential functionality of the Spring
framework. A primary component of the core container is the BeanFactory, an implementation of the
Factory pattern. The BeanFactory applies the Inversion of Control (IOC) pattern to separate an
application's configuration and dependency specification from the actual application code.

2. Spring context: The Spring context is a configuration file that provides context information to the
Spring framework. The Spring context includes enterprise services such as JNDI, EJB, e-mail,
internalization, validation, and scheduling functionality.

3. Spring AOP: The Spring AOP module integrates aspect-oriented programming functionality directly
into the Spring framework, through its configuration management feature. As a result you can easily
AOP-enable any object managed by the Spring framework. The Spring AOP module provides transaction
management services for objects in any Spring-based application. With Spring AOP you can incorporate
declarative transaction management into your applications without relying on EJB components.

4. Spring DAO: The Spring JDBC DAO abstraction layer offers a meaningful exception hierarchy for
managing the exception handling and error messages thrown by different database vendors. The
exception hierarchy simplifies error handling and greatly reduces the amount of exception code you
need to write, such as opening and closing connections. Spring DAO's JDBC-oriented exceptions comply
to its generic DAO exception hierarchy.

5. Spring ORM: The Spring framework plugs into several ORM frameworks to provide its Object
Relational tool, including JDO, Hibernate, and iBatis SQL Maps. All of these comply to Spring's generic
transaction and DAO exception hierarchies.

6. Spring Web module: The Web context module builds on top of the application context module,
providing contexts for Web-based applications. As a result, the Spring framework supports integration
with Jakarta Struts. The Web module also eases the tasks of handling multi-part requests and binding
request parameters to domain objects.

7. Spring MVC framework: The Model-View-Controller (MVC) framework is a full-featured MVC


implementation for building Web applications. The MVC framework is highly configurable via strategy
interfaces and accommodates numerous view technologies including JSP, Velocity, Tiles, iText, and POI.

3. Why do you need ORM tools like hibernate?

The main advantage of ORM like hibernate is that it shields developers from messy SQL. Apart from this,
ORM provides following benefits:

1. Improved productivity
i. High-level object-oriented API
ii. Less Java code to write
iii. No SQL to write
2. Improved performance
i. Sophisticated caching
ii. Lazy loading
iii. Eager loading

3. Improved maintainability
i. A lot less code to write

4. Improved portability
i. ORM framework generates database-specific SQL for you

4. What is differences between RESTful web services and SOAP web services?

Ans: Though both RESTful web series and SOAP web service can operate cross platform they are
architecturally different to each other, here is some of differences between REST and SOAP:
1) REST is more simple and easy to use than SOAP. REST language is based on use of nouns and verbs
(better readability)
2) REST uses HTTP protocol for producing or consuming web services while SOAP uses XML.

The SOAP WS is transport protocol neutral. Supports multiple protocols like HTTP(S), Messaging,
TCP, UDP SMTP, etc.

The REST is transport protocol specific. Supports only HTTP or HTTPS protocols.

3) REST is lightweight as compared to SOAP and preferred choice in mobile devices and PDAs. REST
does not need XML parsing, no message header (to and from), hence less bandwidth
4) REST supports different format like text, JSON and XML while SOAP only support XML.

The SOAP WS permits only XML data format. You define operations, which tunnels through the
POST. The focus is on accessing the named operations and exposing the application logic as a service.

The REST permits multiple data formats like XML, JSON data, text, HTML, etc. Any browser can be
used because the REST approach uses the standard GET, PUT, POST, and DELETE Web operations. The
focus is on accessing the named resources and exposing the data as a service. REST has AJAX support. It
can use the XMLHttpRequest object. Good for stateless CRUD (Create, Read, Update, and Delete)
operations

1. What happens if RestFull resources are accessed by multiple clients? Do you need to make it
thread-safe?

Ans: Since a new Resource instance is created for every incoming Request there is no need to make it
thread-safe or add synchronization. Multiple clients can safely access RestFull resources concurrently.

2. What are the differences between GET and POST in RESTfull Web Services?
Retrieve information. GET requests must be safe and idempotent, meaning regardless of how many
times it repeats with the same parameters, the results are the same.
POST is used to create a new entity, but it can also be used to update an entity.
3. What are the diff design approaches to create SOAP based Web Services?
Ans: Top-Down and Bottom-Up design approaches. They call it as Contract First or Contract Last.

4. What are diff ways we can use application context?


ClassPathXmlApplicationContext
FileSystemXmlApplicationContext
XmlWebApplicationContext

5. Diff between Bean factory and Application Context?


Ans:
The core modules BeanFactory makes Spring a container, but the context module is what makes it a
framework. This module extends the concept of Bean-Factory, adding support for
internationalization (I18N) messages, application life cycle events, and validation.

In addition, this module supplies many enterprise services such as e-mail, JNDI access, EJB
integration, remoting, and scheduling.
Application Context Support for integration with templating frameworks such as Velocity and
FreeMarker.

6. How do you enable spring transactions?


Using Annotation and XML.

7. How many ways to initiate Spring transactions?


Ans: Programatic and Declarative.

8. What is a criterion API?


Ans: The Criterion API provides a type-safe and object-oriented way to retrieve persistent objects. This
provides a simplified API to build queries dynamically at runtime, as an alternative to HQL.

Criterion API is more helpful when we have variable number of conditions in a query. The
org.hibernate.Criteria is the basic interface of criterion API for building queries.

9. What is restriction and projection?


Ans: To narrow the results of the criterion query we want to add restrictions to the query.
We use add() method of Criteria object to add restrictions.

Projections are used to implement aggregate functions or grouping functions


Projection is used to specify the output type, that is, the type of objects or values to be selected. That
means a projection in criterion API enables us to select specific columns of entity or its associated
entities. We use setProjection() method of Criteria object to set the projection.

Criteria.setProjection(Projections.Count())
Criteria.setProjection(Projections.property(userid))
10. What are the different level CACHE levels in Hibernate?
Ans: Fist Level cache & Second level cache
11. What are the different fetch strategies?
There are 4 types of fetching strategies
Fetchmode.Join (Fetch eagerly using an outer join. Equivalent to fetch="join".)
Fetchmode.Select (Fetch Lazily, using a separate select. Equivalent to fetch="select". )
Fetchmode.Subselect (Group its collection into a sub select statement
batch-size= N (Fetching up to N collections or entities)

12. What the Ordered collection and sorted collection in Hibernate?


A sorted collection is sorted by utilizing the sorting features provided by the Java collections framework.
The sorting occurs in the memory of JVM which running Hibernate, after the data being read from
database using java comparator.
The efficiency depends on the size of the collection.
Ordered collection is sorted by specifying the order-by clause for sorting this collection when retrieval.
This is an efficient way to sort larger collections.

13. What is transient variable do in JAVA?


Transient is the modifier applicable only for variables but not for methods and classes.
At the time of serialization if we dont want to serialize the value of a particular variable
to meet the security constraints then we should declare that variable with transient
modifier.
At the time of serialization jvm ignores the original value of the transient variable and
save default value that is transient means not to serialize.
Static variables are not part of object state hence serialization concept is not applicable
for static variables duo to this declaring a static variable as transient there is no use.
Final variables will be participated into serialization directly by their values due to this
declaring a final variable as transient there is no impact.

14. What is volatile key word?


Volatile is the modifier applicable only for variables but not for classes and methods.
If the value of variable keeps on changing such type of variables we have to declare with
volatile modifier.
If a variable declared as volatile then for every thread a separate local copy will be
created by the jvm, all intermediate modifications performed by the thread will takes
place in the local copy instead of master copy.
Once the value got finalized before terminating the thread that final value will be
updated in master copy.
The main advantage of volatile modifier is we can resolve data inconsistency problems,
but creating and maintaining a separate copy for every thread increases complexity of
the programming and effects performance of the system. Hence if there is no specific
requirement never recommended to use volatile modifier and its almost outdated.
Volatile means the value keep on changing where as final means the value never changes
hence final volatile combination is illegal for variables.

15. How do you make sure you application code thread safe?

16. Read about diff types of logs in threads?

LOG.INFO
LOG.WARNING
LOG.CONFIG
LOG.WARNING
LOG.SEVERE

You might also like