Académique Documents
Professionnel Documents
Culture Documents
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:
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.
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.
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.
* 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.
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.
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.
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.