Vous êtes sur la page 1sur 21

Java

J2EE
JSP
JavaScript
PL/SQL
Struts
SAX Parser
Logger
Spring
MVC
Java
====
* Java is a high-level programming language originally developed by Sun Microsys
tems and released in 1995. Java runs on a variety of platforms, such as Windows,
Mac OS, and the various versions of UNIX.
* Java Platforms:
Java runs on a variety of platforms, such as Windows, Mac OS, and the va
rious versions of UNIX/Linux like HP-Unix, Sun Solaris, Redhat Linux, Ubuntu, Ce
ntOS, etc.
* Features:
Object Oriented
Platform Independent
Robust
Interpreted
Multi-threaded
*Why Architectural Neutral?
It s compiler generates an architecture-neutral object file format, which
makes the compiled code to be executable on many processors, with the presence o
f Java runtime system.
* How High Performace?
Java uses Just-In-Time compiler to enable high performance.
Just-In-Time compiler is a program that turns Java bytecode, which is a
program that contains instructions that must be interpreted into instructions th
at can be sent directly to the processor.
* Why dynamic?
It is designed to adapt to an evolving environment.
Java programs can carry extensive amount of run-time information that ca
n be used to verify and resolve accesses to objects on run-time
* Java Virtual Machine and Platform independency
When Java is compiled, it is not compiled into platform specific machine
, rather into platform independent byte code.
This byte code is distributed over the web and interpreted by virtual Ma
chine (JVM) on whichever platform it is being run
* JAva IDEs:
Netbeans, Eclipse, etc.
* Java Keywords:
import, super, finally, etc.
* Object:
Object is a runtime entity and it s state is stored in fields and behavior
is shown via methods.
Methods operate on an object's internal state and serve as the primary m
echanism for object-to-object communication.
* Class:
A class is a blue print from which individual objects are created.
A class can contain fields and methods to describe the behavior of an ob
ject.
* Class Variables
A class consist of Local variable, instance variables and class variable

s.
* Local variables
Variables defined inside methods, constructors or blocks are called loca
l variables.
The variable will be declared and initialized within the method and it w
ill be destroyed when the method has completed.
* Instance Variables
Instance variables are variables within a class but outside any method.
These variables are instantiated when the class is loaded.
* Class Variables
These are variables declared with in a class, outside any method, with t
he static keyword.
* Singleton Class
Singleton class control object creation, limiting the number to one but
allowing the flexibility to create more objects if the situation changes.
* Contructor
Constructor gets invoked when a new object is created.
Every class has a constructor.
If we do not explicitly write a constructor for a class the java compile
r builds a default constructor for that class
* Creating Object of a class
An Object is first declared, then instantiated and then it is initialize
d.
* Default values:
byte :0
float:0.0f
double: 0.0d
* Using byte:
This data type is used to save space in large arrays, mainly in place of
integers, since a byte is four times smaller than an int.
* Static Variables
Class variables also known as static variables are declared with the sta
tic keyword in a class, but outside a method, constructor or a block.
* Access Specifiers:
Java provides access modifiers to set access levels for classes, variabl
es, methods and constructors.
A member has package or default accessibility when no accessibility modi
fier is specified.
* Protected Access Speciifers:
Variables, methods and constructors which are declared protected in a su
perclass can be accessed only by the subclasses in other package or any class wi
thin the package of the protected members' class.
* Synchronized non access Modifiers
Java provides these modifiers for providing functionalities other than A
ccess Modifiers, synchronized used to indicate that a method can be accessed by
only one thread at a time
* Java Operator Precedence
Postfix operators i.e () [] . is at the highest precedence.
* switch variabe types:
Variables used in a switch statement can only be a byte, short, int, or
char.
* parseInt()
This method is used to get the primitive data type of a certain String.
* Immutable String :
The String class is immutable, so that once it is created a String objec

t cannot be changed.
Since String is immutable it can safely be shared between many threads ,
which is considered very important for multithreaded programming.
* Mutable StringBuffer
The String class is considered as immutable, so that once it is created
a String object cannot be changed.
If there is a necessity to make alot of modifications to Strings of char
acters then StringBuffer should be used.
* StringBuffer and StringBuilder
Use StringBuilder whenever possible because it is faster than StringBuff
er.
But, if thread safety is necessary then use StringBuffer objects.
* Regualr experssion Pattern Match :java.util.regex package is used for this pur
pose.
* finalize():
It is possible to define a method that will be called just before an obj
ect's final destruction by the garbage collector. This method is called finalize
( ), and it can be used to ensure that an object terminates cleanly.
*Exception :
An exception is a problem that arises during the execution of a program.
Exceptions are caught by handlers positioned along the thread's method invocati
on stack.
* Checked Exception :
It is an exception that is typically a user error or a problem that cann
ot be foreseen by the programmer.
For example, if a file is to be opened, but the file cannot be found, an
exception occurs.
These exceptions cannot simply be ignored at the time of compilation.
* Runtime Exception:
It is an exception that occurs that probably could have been avoided by
the programmer. As opposed to checked exceptions, runtime exceptions are ignored
at the time of compliation.
* Subclass of Exception :
The Exception class has two main subclasses : IOException class and Runt
imeException Class.
* throws Keyword:
If a method does not handle a checked exception, the method must declare
it using the throwskeyword.
The throws keyword appears at the end of a method's signature.
* throw Keyword:
An exception can be thrown, either a newly instantiated one or an except
ion that you just caught, by using throw keyword.
* finally used in Exception handling:
The finally keyword is used to create a block of code that follows a try
block.
A finally block of code always executes, whether or not an exception has
occurred.
* While creating your own exception All exceptions must be a child of Throwable.
If you want to write a checked exception that is automatically enforced
by the Handle or Declare Rule, you need to extend the Exception class.
You want to write a runtime exception, you need to extend the RuntimeExc
eption class.
* Inheritance:
It is the process where one object acquires the properties of another.
With the use of inheritance the information is made manageable in a hier
archical order.
* super keyword:

If the method overrides one of its superclass's methods, overridden meth


od can be invoked through the use of the keyword super. It can be also used to r
efer to a hidden field.
*Polymorphism:
Polymorphism is the ability of an object to take on many forms.
The most common use of polymorphism in OOP occurs when a parent class re
ference is used to refer to a child class object.
* Abstraction:
It refers to the ability to make a class abstract in OOP.
It helps to reduce the complexity and also improves the maintainability
of the system
* Abstract Class:
These classes cannot be instantiated and are either partially implemente
d or not at all implemented.
This class contains one or more abstract methods which are simply method
declarations without a body.
* When abstract method?
If you want a class to contain a particular method but you want the actu
al implementation of that method to be determined by child classes, you can decl
are the method in the parent class as abstract.
* Encapsulation :
t is the technique of making the fields in a class private and providing
access to the fields via public methods.
If a field is declared private, it cannot be accessed by anyone outside
the class, thereby hiding the fields within the class.
Therefore encapsulation is also referred to as data hiding.
* Benefit of Encapsulation :
The main benefit of encapsulation is the ability to modify our implement
ed code without breaking the code of others who use our code. With this Encapsul
ation gives maintainability, flexibility and extensibility to our code.
* Interface :
An interface is a collection of abstract methods.
A class implements an interface, thereby inheriting the abstract methods
of the interface.
Features:
Interface cannot be instantiated
An interface does not contain any constructors.
All of the methods in an interface are abstract.
An Interface can inherit another Interface, for that matter an Interface
can extend more than one Interface.
* Multithreaded programing;
A multithreaded program contains two or more parts that can run concurre
ntly. Each part of such a program is called a thread, and each thread defines a
separate path of execution.
* two ways to create thread:
Thread can be created by: implementing Runnable interface, extending the
Thread class.
* Applet :
An applet is a Java program that runs in a Web browser.
An applet can be a fully functional Java application because it has the
entire Java API at its disposal.
An applet extends java.applet.Applet class.
* Garbage Collection :

It uses garbage collection to free the memory.


By cleaning those objects that is no longer reference by any of the prog
ram.
* Comparable :
t is used to sort collections and arrays of objects using the collection
s.sort() and java.utils. The objects of the class implementing the Comparable in
terface can be ordered.
* TreeSet :
It is a Set implemented when we want elements in a sorted order.
* throws and throw :
Throw is used to trigger an exception where as throws is used in declara
tion of exception.
Without throws, Checked exception cannot be handled where as checked exc
eption can be propagated with throws.
* JRE :
Java Runtime Environment is an implementation of the Java Virtual Machin
e which executes Java programs.
It provides the minimum requirements for executing a Java application.
* JAR :
JAR files is Java Archive fles and it aggregates many files into one.
It holds Java classes in a library.
JAR files are built on ZIP file format and have .jar file extension.
* WAR :
This is Web Archive File and used to store XML, java classes, and JavaSe
rver pages. which is used to distribute a collection of JavaServer Pages, Java S
ervlets, Java classes, XML files, static Web pages etc.
* JIT Compiler :
It improves the runtime performance of computer programs based on byteco
de.
* OOP and Object based Programing :
Object based programming languages follow all the features of OOPs excep
t Inheritance.
JavaScript is an example of object based programming languages.
* Statc Block :
It is used to initialize the static data member, It is excuted before ma
in method at the time of classloadin
* Composition :
Holding the reference of the other class within some other class is know
n as composition.
* Function OverLoading
If a class has multiple functions by same name but different parameters,
it is known as Method Overloading.
* Over riding :
If a subclass provides a specific implementation of a method that is alr
eady provided by its parent class, it is known as Method Overriding.
* Final class :
Final classes are created so the methods implemented by that class canno
t be overridden. It can t be inherited.
* Null Pointer Exception :
A NullPointerException is thrown when calling the instance method of a n
ull object, accessing or modifying the field of a null object etc.
*Thread waiting stage :
A thread can enter the waiting state by invoking its sleep() method, by
blocking on IO, 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.
* The FileNoFoundException is inherited from the IOException. Exception's subcla
sses have to be caught first.
* The operating system's task scheduler allocates execution time to multiple tas
ks. By quickly switching between executing tasks, it creates the impression that
tasks execute sequentially.
* threads run method invocation :
After a thread is started, via its start() method of the Thread class, t
he JVM invokes the thread's run() method when the thread is initially executed.
* Wrapper Classes
These are classes that allow primitive types to be accessed as objects.
Example: Integer, Character, Double, Boolean etc.
* Static ans NonStatic :
A static variable is associated with the class as a whole rather than wi
th specific instances of a class. Non-static variables take on unique values wit
h each object instance.
* Serialization :
Serialization is the process of writing the state of an object to a byte
stream. Deserialization is the process of restoring these objects.
* Transient Variable :
A transient variable is a variable that may not be serialized during Ser
ialization and which is initialized by its default value during de-serialization
,
* Synchronizaion :
Synchronization is the capability to control the access of multiple thre
ads to shared resources. synchronized keyword in java provides locking which ens
ures mutual exclusive access of shared resource and prevent data race.
* Primitive Java type :
The eight primitive types are byte, char, short, int, long, float, doubl
e, and boolean.
* Class Loader :
A class loader is an object that is responsible for loading classes. The
class ClassLoader is an abstract class.
* Interfaace and Absract Class :
An abstract class can have instance methods that implement a default beh
avior.
An Interface can only declare constants and instance methods, but cannot
implement default behavior and all methods are implicitly abstract.
An interface has all public members and no implementation.
* Need of Wrapperr Classes :
We can pass them around as method parameters where a method expects an o
bject. It also provides utility methods.
* Error and Exception :
An error is an irrecoverable condition occurring at runtime. Such as Out
OfMemory error. Exceptions are conditions that occur because of bad input etc. e
.g. FileNotFoundException will be thrown if the specified file does not exist.
* try, catch ad finally :
It is not necessary that each try block must be followed by a catch bloc
k. It should be followed by either a catch block or a finally block.
* dot Operator :
The dot operator(.) is used to access the instance variables and methods

of class objects.It is also used to access classes and sub-packages from a pack
age.
* Path and Class Path :
Path and Classpath are operating system level environment variales.
Path is defines where the system can find the executables(.exe) files an
d classpath is used to specify the location of .class files.
Struts
======
* Struts is nothing but open source framework mostly used for making web applica
tion
Framework means it comprises JSP ,servlet ,custom tags message resources
all in one bundle which makes developer task very easy.
Its is based on MVC pattern which is model view Controller pattern.
*why we use Struts?
Main reason is if we go with servlet all HTML code which is related with
design part mostly will come inside java code which makes code unmaintainable a
nd complex similarly if use
JSP,all java code related with business come inside design part which ag
ain make code complex, that s why MVC pattern come into existence and which separa
te the business,
design and controller and struts was made based upon this pattern and ea
sy to develop web application
MVC design pattern, Front Controller Pattern and better flow management
*Main Classes:
Action servlet: it s a back-bone of web application it s a controller class
responsible for handling the entire request.
Action class: using Action classes all the business logic is developed u
s call model of the application also.
Action Form: it s a java bean which represents our forms and associated wi
th action mapping.
And it also maintains the session state its object is autom
atically populated on the server side with data entered from a form on the clien
t side.
Action Mapping: using this class we do the mapping between object and Ac
tion.
ActionForward: this class in Struts is used to forward the result from c
ontroller to destination.
* Exception Handling :
<exception
key="stockdataBase.error.invalidCurrencyType"
path="/AvailbleCurrency.jsp"
type="Stock.account.illegalCurrencyTypeException">
</exception>
Key: The key represent the key present in MessageResource.properties fil
e to describe the exception.
Type: The class of the exception occurred.
Path: The page where the controls are to be followed is case exception o
ccurred.
* Validation
In struts validation is performed using validator framework, Validator F
ramework in Struts consist of two XML configuration files.
1. validator-rules.xml file: which contains the default struts pluggable
validator definitions. You can add new validation rules by adding an entry in t
his file.
This was the original beauty of struts which makes it highly configur
able.

2. Validation.xml files which contain details regarding the validation r


outines that are applied to the different Form Beans.
These two configuration file in Struts should be place somewhere inside
the /WEB-INF folder of the application to keep it safe from client and make it a
vailable in Classpath.
* validate() :
validate method is Used to validate properties after they have been pop
ulated, and this ,method is Called before FormBean is passed to Action.
Returns a collection of ActionError as ActionErrors.
public ActionErrors validate(ActionMapping mapping, HttpServletRequest r
equest)
* reset():
reset() method is called by Struts Framework with each request that uses
the defined ActionForm.
The purpose of this method is to reset all of the ActionForm's data memb
ers prior to the new request values being set.
public void reset(ActionMapping mapping, HttpServletRequest request) {
* Message Resources Definitions file are simple .properties files and these file
s contains the messages that can be used in the struts project.
Message Resources Definitions files can be added to the struts-config.xml file
through < message-resources / > tag
* ApplicationResources.properties and struts-config.xml these two files are used
to between the Controller and the Model.
* Struts WorkFlow :
1) A request comes in from a Java Server Page into the ActionServlet.
2) The ActionServlet having already read the struts-config.xml file, kno
ws which form bean relates to this JSP, and delegates work to the validate metho
d of that form bean.
3) The form bean performs the validate method to determine if all requir
ed fields have been entered, and performs whatever other types of field validati
ons that need to be performed.
4) If any required field has not been entered, or any field does not pas
s validation, the form bean generates ActionErrors, and after checking all field
s returns back to the ActionServlet.
5) The ActionServlet checks the ActionErrors that were returned from the
form beans validate method to determine if any errors have occurred.
If errors have occurred, it returns to the originating JSP displaying
the appropriate errors.
6) If no errors occurred in the validate method of the form bean, the Ac
tionServlet passes control to the appropriate Action class.
7) The Action class performs any necessary business logic, and then forw
ards to the next appropriate action (probably another JSP).
* The various Struts tag libraries are:
HTML Tags: used to create the struts input forms and GUI of web page.
Bean Tags: used to access bean and their properties.
Logic Tags: used to perform the logical operation like comparison
Template Tags: used to changes the layout and view.
Nested Tags: used to perform the nested functionality
Tiles Tags: used to manages the tiles of the application
*The lifecycle of ActionForm is as follows:

Retrieve or Create Form Bean associated with Action


"Store" FormBean in appropriate scope (request or session)
Reset the properties of the FormBean
Populate the properties of the FormBean
Validate the properties of the FormBean
Pass FormBean to Action
* The drawbacks of Struts are following:
Absence of backward flow mechanism.
Only one single controller Servlets is used.
Bigger learning curve
Worst documentation
No exception present in this framework
Less transparent
Rigid approach.
With struts 1, embedding application into JSP can t be prevented.
Non-XML compliance of JSP syntax
* Difference between HTML tag and Struts specific HTLM tags are:
HTML tags are static in nature but Struts specific HTML tags are dynamic
in nature.
HTML tags are not User Defined whereas Struts tags can be user defined.
HTML tags provide the different templates and themes to the programmer w
hereas Struts specific HTML tag provides the integrating the property value with
the Formbean properties.
HTML tags are integral part of Struts whereas Struts have HTML tag libra
ries.
*ActonMapping :
In action mapping is the mapping of the action performed by the user or
client on the application.
-We specify the action class for a specific user s action. Like we provide
the path or URL and different view based on user event.
-We can also define where control of the page deviate in case of validat
ion error in the form.
-We can include ActionMapping in code like this:
<action-mappings>
<action path="/a" type=myclasse.A name="myForm">
<forward name="Login" path="/login.jsp"/>
<forward name="error" path="/error.jsp"/>
</action-mappings>
*Action Class:
An Action class in the struts application is used to handle the request.
It acts as interface or communication medium between the HTTP request co
ming to it and business logic used to develop the application.
Action class consists of RequestProcessor which act as controller. This
controller will choose the best action for each incoming request, generate the i
nstance of that action and execute that action.
This should be in thread-safe manner, because RequestProcessor uses the
same instance for no. of requests at same time.
*The submission form can be duplicated by the any of the following ways:
Using refresh button.

By clicking
response.
By clicking
The browser
By clicking

submit button more than once before the server sent back the
back navigation button present in browser.
is restores to submit the form again.
multiple times on a transaction that is delayed than usual.

* Inner class: classes that are defined within other classes.


The nesting is a relationship performed between two different classes.
An inner class can access private members and data.
Inner classes have clearly two benefits:
o Name control
o Access control.
Anonymous class: Anonymous class is a class defined inside a method without a n
ame.
It is instantiated and declared in the same method.
It does not have explicit constructors.
* The struts.devMode is used to make sure that framework is running in developme
nt mode or production mode by setting true or false.
struts.devMode is set to false in production phase to reduce impact of performa
nce. By default it is "false".
It is used because of the following reasons:
Resource Reloading: Resource bundle reload on every request
Modification: struts.xml can be modified without restarting or redeployi
ng the application
Error Handling: The error occurs in the application will be reported, as
oppose to production mode.
* Action error:
When user or client submits the incorrect or invalid data in the applica
tion, then these errors are known as Action error.
Action errors are generated by the clients.
Action error should be determined as soon as possible.
The impacts of such Action Error are:
Wastage of server time and resources.
Negative impact on code quality.

J2EE
====
* J2EE means Java 2 Enterprise Edition.
The functionality of J2EE is developing multitier web-based applications .
The J2EE platform consists of a set of services, application programming inter
faces (APIs), and protocols.
* J2EE Componenets :
Application clients components.
Servlet and JSP technology are web components.
Business components (JavaBeans).
Resource adapter components
* J2EE Clients :
Applets
Application clients
Java Web Start-enabled clients, by Java Web Start technology.

Wireless clients, based on MIDP technology.


* Web Components :
Java Servlet and Java Server Pages technology components are web compone
nts.
Servlets are Java programming language that dynamically receive requests
and make responses.
JSP pages execute as servlets but allow a more natural approach to creat
ing static content
* JSF :
JavaServer Faces (JSF) is a user interface (UI) designing framework for
Java web applications.
JSF provide a set of reusable UI components, standard for web applicatio
ns.
JSF is based on MVC design pattern.
It automatically saves the form data to server and populates the form da
ta when display at client side.
* HashTable :
HashTable is just like Hash Map,Collection having key(Unique),value pair
s.
Hashtable is a collection Synchronozed object .
It does not allow duplicate values but it allows null values
* Hibernate :
Hibernate is a open source object-relational mapping and query service.
In hibernate we can write HQL instead of SQL which save developers to sp
end more time on writing the native SQL.
Hibernate has more powerful association, inheritance, polymorphism, comp
osition, and collections.
It is a beautiful approach for persisting into database using the java o
bjects.
Hibernate also allows you to express queries using java-based criteria .
Limitations :
Slower in executing the queries than queries are used directly.
Only query language support for composite keys.
No shared references to value types
Advantages :
Hibernate is portable i mean database independent, Vendor indep
endence.
Standard ORM also supports JPA
Mapping of Domain object to relational database.
Hibernate is better then plain JDBC.
JPA provider in JPA based applications.
* ORM :
ORM stands for Object-Relational mapping.
The objects in a Java class which is mapped in to the tables of a relati
onal database using the metadata that describes the mapping between the objects
and the database.
It works by transforming the data from one representation to another.
Benefits :
Productivity
Maintainability
Performance
Vendor independence

* save()
This method in hibernate is used to stores an object into the database
. It insert an entry if the record doesn t exist, otherwise not.
* saveorupdate () -This method in the hibernate is used for updating the object
using identifier. If the identifier is missing this method calls save().
If the identifier exists, it will call update method.
* load() can t find the object from cache or database, an exception is thrown and
the load() method never returns null.
get() method returns null if the object can t be found.
The load() method may return a proxy instead of a real persistent instance ge
t() never returns a proxy.
* invoking stored procedure :
{ ? = call thisISTheProcedure() }
* Interface of Hibernate :
Session Interface
SessionFactory Interface
Configuration Interface
Transaction Interface
Query and Criteria Interface
* Hibernate mapping file :
The name of the file should be like this : filename.hbm.xml
* Hibernate configuration file :
The name of the file should be like this : hibernate.cfg.xml
* DataBase independence of Hibernate :
Only changing the property
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect<
/property> and
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.Or
acleDriver</property>
full database can be replaced.
* Connection Pooling :
Connection pooling is a mechanism reuse the connection.which contains th
e number of already created object connection.
So whenever there is a necessary for object, this mechanism is used to d
irectly get objects without creating it.
* HQL :
HQL stands for Hibernate Query Language.
Hibernate allows to 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.
* ear, jar and war :
.jar files: These files are with the .jar extenstion. The .jar files con
tains the libraries, resources and accessories files like property files.
.war files: These files are with the .war extension. The .war file conta
ins jsp, html, javascript and other files for necessary for the development of w
eb applications.
.ear files: The .ear file contains the EJB modules of the application.
* JSP tags :
In JSP tags can be divided into 4 different types.

Directives
Declarations
Scriplets
Expressions
* Access web.xml init parametrs from JSP :
For example, if you have:
<context-param> <param-name>Id</param-name> <param-value>this is the val
ue</param-value></context-param>
You can access this parameter
Id: <h:outputText value= #{initParam[ Id ]} />
* JSP Directives :
1.page Directives <%@page language= java %>
2. include Directives: <%@ include file= /header.jsp
3. taglib Directives <%@ taglib uri= tlds/taglib.tld

%>
prefix= html

%>

* EAR file :
An EAR file is a JAR file with an .ear extension. A J2EE application wit
h all of its modules is delivered in EAR file.
* Spring :
Spring is a light weight open source framework for the development of e
nterprise application that resolves the complexity of enterprise application dev
elopment also providing a cohesive framework for J2EE application development.
Which is primarily based on IOC (inversion of control) or DI (dependency
injection) design pattern.
There are seven core modules in spring
The Core container module
O/R mapping module (Object/Relational)
DAO module
Application context module
Aspect Oriented Programming
Web module
MVC module
* BeanFactory :
XmlBeanFactory is one of the implementation of bean Factory org.springfr
amework.beans.factory.xml.XmlBeanFactory is used to creat bean instance defined
in our xml file.
BeanFactory factory = new XmlBeanFactory(new FileInputStream("beans.xml"
));
Or
ClassPathResource resorce = new ClassPathResource("beans.xml");
XmlBeanFactory factory = new XmlBeanFactory(resorce);
* Functionality of ActionServlet and RequestProcessor?
Receiving the HttpServletRequest
Populating JavaBean from the request parameters
Displaying response on the web page Issues
Content type issues handling
Provide extension points
* Default scope in Spring : Singleton.
* Advantages of Spring usage?
Pojo based programming enables reuse component.

Improve productivity and subsequently reduce development cost.


Dependency Injection can be used to improve testability.
Spring required enterprise services without a need of expensive applicat
ion server.
It reduces coupling in code and improves maintainability.
* Benefits Spring Framework ?
Light weight container
Spring can effectively organize your middle tier objects
Initialization of properties is easy ? no need to read from properties f
ile
application code is much easier to unit test
Objects are created Lazily , Singleton
configuration
Spring s configuration management services can be used in any architectura
l layer, in whatever runtime environment
* Servlets :
Servlets is a server side components that provide a powerful mechanism f
or developing server side programs.
Servlets is a server as well as platform-independent and Servlets are de
signed for a various protocols.
Most commonly used HTTP protocols.
Servlets uses the classes in the java packages javax.servlet, javax.serv
let.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servl
et.http.HttpSession;.
All servlets must implement the Servlet interface, which defines life-cy
cle methods.
* The life cycle of a servlet consists of the following phases:
Servlet class loading
Servlet instantiation
the init method
Request handling (call the service method)
Removal from service (call the destroy method)
* The Servlet Interface must be implemented by all servlets
XML
===
* XML stands for eXtensible Markup Language.
It is a simple and flexible markup language.
It is known as universal language for data on the web because XML docume
nts can be created and used in any language.
It is universal standard for information interchange.
* Why xml?
Platform Independent and Language Independent: The main benefit of xml i
s that you can use it to take data from a program like Microsoft SQL, convert it
into XML then share that XML with other programs and platforms. You can communi
cate between two platforms which are generally very difficult.
The main thing which makes XML truly powerful is its international accep
tance. Many corporation use XML interfaces for databases, programming, office ap
plication mobile phones and more. It is due to its platform independent feature.
* Benefits :
These are the main benefits of using XML.

Simplicity: Very easy to read and understand the information coded in XM


L.
Openness: It is a W3C standard, endorsed by software industry market lea
ders.
Extensibility: It is extensible because it has no fixed set of tags. You
can define them as you need.
Self-descriptive: XML documents do not need special schema set-up like t
raditional databases to store data. XML documents can be stored without such def
initions, because they contain metadata in the form of tags and attributes.
Scalable: XML is not in binary format so you can create and edit files w
ith anything and it is also easy to debug.
Fast access: XML documents are arranged in hierarchical form so it is co
mparatively faster.
* DOM
DOM stands for Document Object Model which is used to describe the logic
al structure of XML document.
It is a hierarchical model that provides a way to access and manipulate
an XML document.
DOM methods and objects can be used with any languages like C#, VB, Java
Script and VB Script.
* SAX
SAX stands for Simple API for XML. It is a sequential access parser.
It is a simple API for XML which provides a mechanism for reading data f
rom an XML document.
It is an alternative of DOM. DOM operates on the documents as whole, SAX
parsers operate on each piece of the XML document sequentially.
SAX has no formal specification like DOM and consumes less memory. But i
t can be used to read the XML document only not write.
* DOM vs SAX
DOM parser is a tree-based API.
A tree-based API is centered around a tree structure and therefore provi
des interfaces on components of a tree (which is a DOM document) such as Documen
t interface,Node interface, NodeList interface, Element interface, Attr interfac
e and so on.
A DOM parser creates a tree structure in memory from the input document
and then waits for requests from client.
A DOM parser always serves the client application with the entire docume
nt no matter how much is actually needed by the client.
With DOM parser, method calls in client application have to be explicit
and forms a kind of chained method calls.
SAX parser is a event-based API.
Usually an event-based API provides interfaces on handlers.
There are four handler interfaces, ContentHandler interface, DTDHandler
interface, EntityResolver interface and ErrorHandler interface.
SAX parser does not create any internal structure.
Instead, it takes the occurrences of components of a input document as e

vents, and tells the client what it reads as it reads through the input document
. SAX parser serves the client application always only with pieces of the docume
nt at any given time. With SAX parser, some custom methods are called [ callback m
ethods ] when some certain events occur during parsing on xml document.
These methods do not have to be called explicitly by the client, though
we could call them explicitly.
DOM (Document Object Model)
SAX
===========================
===========================
Parses entire document
Parses until you tell it to stop
Represents result as a tree
Fires event handlers for each:
Lets you search tree
Start tag
Lets you modify tree
Tag body
End tag
Low level APIs
Good for reading data/configuration files
Good for very large documents, especially if you only care about very small port
ions
of the document.
Ideally a good parser should be fast (time efficient),space efficient, r
ich in functionality and easy to use .
But in reality, none of the main parsers have all these features at the
same time.
For example, a DOM Parser is rich in functionality (because it creates a
DOM tree in memory and allows you to access any part of the document repeatedly
and allows you to modify the DOM tree), but it is space inefficient when the do
cument is huge, and it takes a little bit long to learn how to work with it.
A SAX Parser, however, is much more space efficient in case of big input
document (because it creates no internal structure).
What s more, it runs faster and is easier to learn than DOM Parser because
its API is really simple.
But from the functionality point of view, it provides less functions whi
ch mean that the users themselves have to take care of more, such as creating th
eir own data structures.
* DTD
DTD stands for Document Type Definition.
It defines a leading building block of an XML document.
It defines:
Names of elements
How and where they can be used
Element attributes
Proper nesting
* To apply a DTD to an XML document, you can:
Use the DTD element definition within the XML document itself.
Provide a DTD as a separate file and reference its name in XML document.

*You should consider the following rules to write an XML document.


It should have a root element.
All tags must be closed.
Spaces are not allowed in tag names.
All tags must be nested properly.
XML tags are case sensitive.
Use the attribute values within quotes.
Whitespace is preserved in XML.
* XSL:
XSL stands for Extensible Stylesheet Language.
It is a language for expressing stylesheets.
These stylesheets are like CSS which describes how to display an XML doc
ument of a given type.
SQL
===
* SQL stands for structured query language.
It is a database language used for database creation, deletion, fetching rows
and modifying rows etc.
* Usages of SQL
To execute queries against a database
To retrieve data from a database
To inserts records in a database
To updates records in a database
To delete records from a database
To create new databases
To create new tables in a database
To create views in a database
* The subsets of SQL?
Data definition language (DDL)
Data manipulation language (DML)
Data control language (DCL)
* DDL
Data definition language(DDL) allows you to CREATE, ALTER and DELETE dat
abase objects such as schema, tables, view, sequence etc.
* DML
Data manipulation language makes user able to access and manipulate data
. It is used to perform following operations.
Insert data into database
Retrieve data from the database
Update data in the database
Delete data from the database
* DDL
Data control language allows you to control access to the database. It i
ncludes two commands GRANT and REVOKE.
GRANT: to grant specific user to perform specific task.
REVOKE: to cancel previously denied or granted permissions.
* Type of operators available in SQL?

Arithmetic operators
Logical operators
Comparison operator
* DBMS
The database management system is a collection of programs that enables
user to store, retrieve, update and delete information from a database.
* RDBMS
Relational Database Management system (RDBMS)
ystem (DBMS) that is based on the relational model.
Data from relational database can be accessed
ferent ways without having to reorganize the database
Data from relational database can be accessed
Query Language (SQL).

is a database management s
or reassembled in many dif
tables.
using an API , Structured

* There are mainly two type of indexes in SQL, Clustered index and non clustered
index.
The differences between these two indexes is very important from SQL performan
ce perspective.
1) One table can have only one clustered index but it can have many non
clustered index. (approximately 250).
2) Clustered index determines how data is stored physically in table.
Actually clustered index stores data in cluster, related data is stor
ed together so it makes simple to retrieve data.
3) Reading from a clustered index is much faster than reading from non c
lustered index from the same table.
4) Clustered index sort and store data rows in the table or view based o
n their key value, while non cluster have a structure separate from the data row
.
* Curretn Date :
There is a built in function in SQL called GetDate() which is used to re
turn current timestamp.
* JOIN
Mostly used join is INNER JOIN and (left/right) OUTER JOIN.
Inner Join:
Inner join is the most common type of Join which is used to comb
ine the rows from two tables and create a result set containing only such record
s that are present in both the tables based on the joining condition (predicate)
.
Inner join returns rows when there is at least one match in both
tables
If none of the record matches between two tables, then INNER JOI
N will return a NULL set.
SELECT dept.name DEPARTMENT, emp.name EMPLOYEE
FROM DEPT dept, EMPLOYEE emp
WHERE emp.dept_id = dept.id

Outer Join:
Outer Join, on the other hand, will return matching rows from bo
th tables as well as any unmatched rows from one or both the tables (based on wh
ether it is single outer or full outer join respectively).
Outer Join can be full outer or single outer
SELECT dept.name DEPARTMENT, emp.name EMPLOYEE
FROM DEPT dept, EMPLOYEE emp
WHERE dept.id = emp.dept_id (+)
* JOIN vs UNION
SQL JOIN allows us to
ditions between two tables.

lookup records on other table based on the given con

For example, if we have the department ID of each employee, then we can


use this department ID of the employee table to join with the department ID of d
epartment table to lookup department names.
UNION operation allows us to add 2 similar data sets to create resulting
data set that contains all the data from the source data sets.
Union does not require any condition for joining.
For example, if you have 2 employee tables with same structure, you can
UNION them to create one result set that will contain all the employees from bot
h of the tables
* UNION and UNION ALL
UNION and UNION ALL both unify for add two structurally similar data set
s,
but UNION operation returns only the unique records from the resulting d
ata set whereas
UNION ALL will return all the rows, even if one or more rows are duplica
ted to each other.
* WHERE clause and HAVING clause
WHERE and HAVING both filters out records based on one or more condition
s.
The difference is, WHERE clause can only be applied on a static non-aggr
egated column whereas we will need to use HAVING for aggregated columns.
Eg:
SELECT * FROM DEPT WHERE ID > 3
SELECT dept.name DEPARTMENT, avg(emp.sal) AVG_SAL
FROM DEPT dept, EMPLOYEE emp
WHERE dept.id = emp.dept_id (+)
GROUP BY dept.name
HAVING AVG(emp.sal) > 80
* UNION combines the results from 2 tables and eliminates duplicate records from
the result set.
MINUS operator when used between 2 tables, gives us all the rows from the firs
t table except the rows which are present in the second table.

INTERSECT operator returns us only the matching or common rows between 2 resul
t sets.
* Stored Procedure vs Function
A Stored Procedure can return zero, single or multiple values. But, a fu
nction must return a single value.
A Stored Procedure can have both input and output parameters whereas Fun
ctions can have only input parameters.
Functions allow only a SELECT command whereas a Stored Procedure allows
SELECT and other DML commands (INSERT, UPDATE and DELETE).
A Stored Procedure can call a function, but a function can't call a Stor
ed Procedure.
A Stored Procedure can use try-catch block to handle exceptions. But try
-catch is not allowed in functions.
Functions can be used in a SELECT statement, but procedures are not allo
wed in a select-statement.
SQL transactions can be used in Stored Procedures but not in Functions.
* SQL Triggers :
Trigger allows you to execute a batch of SQL code when an insert, update
or delete command is executed against a specific table.
Actually triggers are special type of stored procedures that are defined
to execute automatically in place or after data modifications.
* Self Join
Self join is often very useful to convert a hierarchical structure to a
flat structure.
It is used to join a table to itself as like if that is the second table
.
* Set Operators :
Union, intersect or minus operators are called set operators.
* Constrainsts:
Constraints are representators of a column to enforce data entity and co
nsistency. There are two levels :
column level constraint
table level constraint
* ACID :
ACID property is used to ensure that the data transactions are processed
reliably in a database system.
A single logical operation of a data is called transaction.
ACID is an acronym for Atomicity, Consistency, Isolation, Durability.
Atomicity: it requires that each transaction is all or nothing. It means
if one part of the transaction fails, the entire transaction fails and the data
base state is left unchanged.
Consistency: the consistency property ensure that the data must meet all
validation rules. In simple words you can say that your transaction never leave
s your database without completing its state.

Isolation: this property ensure that the concurrent property of executio


n should not be met. The main goal of providing isolation is concurrency control
.
Durability: durability simply means that once a transaction has been com
mitted, it will remain so, come what may even power loss, crashes or errors

Vous aimerez peut-être aussi