Escolar Documentos
Profissional Documentos
Cultura Documentos
{
1. Data
// variables/fields/properties
Variable
int x
dou
Object
Strin
Instance
g=
Declaration
int x
Initialization
x=
g=
g=
in h
Instantiation
g=
Method signature :
1. method name
2. method params (no.of.params, and datatypes)
3. access modifier/specifiers
4. return type
5. exceptions it throws
parameter - variables that receive values. Public void foo(int x, float y)
argument - values that are passed (pass by value not by reference) to a
method. foo(6, 4.4)
Access Specifiers :
Volatile
Tran
JVM assigns unique hashcode value to each object when they are
created in memory
It is not necessary that two different object must have different
hashcode values. it might be possible that they share common hash
bucket.
If two objects are same then they must return same value in
hashcode() and equals() method whenever invoked.
Data Abstraction
Encapsulation
Inheritance
Polymorphism
Overloading
Overridin
Class
Abstract class
The life cycle of the thread in java is controlled by JVM. The java thread
states are as follows:
New
Runnable
Running
Non-Runnable (Blocked)
Terminated
Thread scheduler in java is the part of the JVM that decides which thread
should run.
Under preemptive scheduling, the highest priority task executes until it
enters the waiting or dead states or a higher priority task comes into
existence.
Under time slicing, a task executes for a predefined slice of time and then
reenters the pool of ready tasks.
No. After starting a thread, it can never be started again. If you does so, an
IllegalThreadStateException is thrown.
Each thread starts in a separate call stack. Invoking the run() method from
main thread, the run() method goes onto the current call stack rather than at
the beginning of a new call stack.
The join() method waits for a thread to die. In other words, it causes the
currently running threads to stop executing until the thread it joins
with completes its task.
t1.join();
t2.start();
t3.start();
As you can see in the above example,when t1 completes its task then t2
and t3 starts executing.
t1.join(1500);
Java Thread pool represents a group of worker threads that are waiting
for the job and reuse many times.
In case of thread pool, a group of fixed size threads are created. A thread
from the thread pool is pulled out and assigned a job by the service provider.
After completion of the job, thread is contained in the thread pool again.
Advantage of Java Thread Pool is,
Better performance It saves time because there is no need to create new
thread. Real time usage is,
It is used in Servlet and JSP where container creates a thread pool to process
the request.
There are two types of thread synchronization mutual exclusive and interthread communication.
Mutual Exclusive - helps keep threads from interfering with one another while
sharing data. This can be done by three ways in java:
-Synchronized method.
If you declare any method as synchronized, it is known as synchronized
method.
-Synchronized block.
Suppose you have 50 lines of code in your method, but you want to
synchronize only 5 lines, you can use synchronized block.
-static synchronization.
If you make any static method as synchronized, the lock will be on the class
not on object.
wait()
Causes current thread to release the lock and wait until either another
thread invokes the notify() method or the notifyAll() method for this object,
or a specified amount of time has elapsed.
The current thread must own this object's monitor, so it must be called from
the synchronized method only otherwise it will throw exception.
notify()
Wakes up a single thread that is waiting on this object's monitor. If any
threads are waiting on this object, one of them is chosen to be awakened.
The choice is arbitrary and occurs at the discretion of the implementation.
notifyAll()
Wakes up all threads that are waiting on this object's monitor.
Suppose there are two objects of a shared class(e.g. Table) named object1
and object2.
In case of synchronized method and synchronized block there cannot be
interference between t1 and t2 or t3 and t4 because t1 and t2 both refers to
a common object that have a single lock.
But there can be interference between t1 and t3 or t2 and t4 because t1
acquires another lock and t3 acquires another lock.I want no interference
between t1 and t3 or t2 and t4.
Static synchronization solves this problem.
Wait()
Slee
wait(), sleep() and join() will make thread leave Running state.
String
StringBuffer
Storage Area
Stack
Heap
Mutation
Immutable
Mutable
Thread Safe ?
Yes
Yes
Performance
Fast
Slow
Comparable
Comparator
elements.
5) Collections.sort(List) method.
Collections.sort(List,Comparato
Collections mutable
Collection (I)
List (I) : first in first out, maintain the order of values, allows duplicates
Vector(C)
ArrayList (C)
LinkedList (C)
Vector
Array list
Synchronized
Unsynchronized
Allows duplicates
Allows null
Hashtable
Hashmap
Synchronized
Unsynchronized
No duplicates
Allows null
Array list
Linked list
Slow access
Fast access
Random access
No random access
Ordered
Duplicates
LIST
Yes
Yes
SET
No
No
LIST ordered
LINKED faster access, and ordered access
SET and MAP unique values, no duplicates
MAP key-value pairs, and no duplicates
HASH not sorted
TREE sorted
init()
service()
destroy()
init()
service()
destroy()
doGet()
doPost()
ServletConfig
ServletContext
By implementing SingleThreadModel.
Synchornize the part of sensitive code.
Your servlet service() method should not access any member variables,
unless these member variables are thread safe themselves.
Directives
<%@
%>
Declarations
<%!
%>
Expressions
<%=
%>
Scriptlets
<%
%>
Directives :
<%@ page import = %>
<%@ include file = %>
<%@ taglib uri = %>
<%@ page errorPage = %>
Servlet RequestDispatcher (I) :
forward() same request is passed to other jsp and control does not go to
UI
Include()
response.sendRedirect(other.jsp) control goes to UI and then gets rerouted to other jsp with new request
forward() method
sendRedirect() method
url?name1=value1&name2=value2&??
String n=request.getParameter("userName");
HttpSession session=request.getSession();
session.setAttribute("uname",n);
String n=(String)session.getAttribute("uname");
ACID :
Transactio
n
Atomicity
Consisten
cy
Isolation
Durability
Dirty Read
Reading uncommitted data. First txn could roll back before com
second txn
Non-Repeatable
Read
Phantom Read
First txn still not done adding data, and may add more data af
a read
grant, revoke
Delete
Truncate
Auto COMMIT
Drop
Remove table
Stored Procedure
Function
Code fragment
a row or tab
Join
Left
All rows of left table with or without matching rows in the right table
Left Outer
Right
All rows of right table with or without matching rows in the left table
Right
Outer
Inner
Outer
All rows from both left and right tables except the common/matching
ones
Clustered Index
Non-clustered Inde
Telephone directory
Optimistic locking
Assuming data duplication will never occur, bother
about locks and eliminate duplicates as they
occur
Pessimistic loc
View
Materialized V
Only when there is a IS-A relation, use Inheritance. If you want just code
reuse, use Composition.
Use Interfaces if you want polymorphism.
Aggregation
Composition
Data Modeling :
-
Identify entities
Identify entity attributes
Apply naming conventions as per logical model standards
Identify relationships cardinality
Apply design patterns
Assign keys
Normalize : eliminate data redundancy
Denormalize : improve performance
Prototype
Singleton
Composite
Decorator
Faade
Proxy
Chain of
Responsibility
Observer
One object changes state and all dependent objects are upd
wait-notify
Service Locator
Business
Delegate
DAO
TO
View
HTML, JSP
Controller
ActionServlet
ActionForm
ActionMapping
Deployment
descriptor
Struts-config.xml , contains :
- form beans
Action class
action classes
action mappings
global forwards
controller configuration(action servlet)
SPRING:
Core
Context
AOP
DAO (JDBC)
ORM (Hibernate, JDO, IBatis)
Web(MVC: Struts,JSF, Servlets, JSP)
Web MVC
BeanFactory
ApplicationContext
Bean Scopes :
Singleton(d
)
Prototype
Request
Session
IOC
Dependency
Injection
Constructor
Setter
Interface
Container finds bean definition from config file and instantiate the bean
Using IOC dependency injection , populates all properties as specified
in config file
Call init()
Call service methods
Advantages of Spring :
-
POJO programming
Layered architecture
Open source (free)
IOC, DI and AOP
IOC with Hibernate template (there is a Spring JDBC template also, for
doing DB txns via JDBC)
Extend HibernateDAOSupport and AOP
o Configure HibernateSessionFactory
o Extend the DAO implementation of the HibernateDAOSupport
class
o Wire in the transaction support using AOP
AOP
Aspect
Joint Point
Advice
Interceptors
Hibernate:
-
.hbm files
.cfg file
Advantages of Hibernate :
-
Disadvantages of Hibernate :
-
Session
SessionFactory
Session.load()
Session.get()
update()
merge()
WEB SERVICES
Reusable component , that can be exposed as a service, and made
available over the network , for remote access.
Interoperability
XML
SOAP
Header(o)
Body
o Request
o Response
o Fault(o)
SOAP Faults
Version Mismatch
Must understand
Client
Server
Principles of SOA
Autonomous so that services alone have total control over the logic
Reusable
Statelessness
Granularity
Discoverability
Composability
10 Interoperability
Service transport layer Responsible for transporting messages between applications usin
XML messaging layer
Service discovery
layer
Service description
layer
Responsible for describing the public interface for the service usi
Better interoperability
WSDL elements :
Types
Data types, pojos, XSD elements. All XSD types can be declared in separ
then linked into WSDL
Message
Message types based on XSD types for REQUEST, RESPONSE and FAULT
Port Type
Binding
Service
Binds java service to port, this is where you define soap address(end poi
@WebMethod
@WebService
@Oneway
@WebParam
@WebFault
maps to <wsdl:fault
@WebResult
@postConstruc
class
@preDestroy
@Resource
JAX RPC
JAX WS
Advantages of webservices:
-
Disadvantages of webservices:
-
REST
SOAP
Point-to-point tunneling
Distributed messaging