By Sandeep Desai (http://www.thedesai.net)
Java is a language and a platform. There are
large number of Java, Vendor specific and open source frameworks and APIs for
developing thick applications, web applications and mobile applications
Java based APIs
are JDBC, Servlets, JSP, JSF, EJB and Web
Services. Some of the popular open sources API and frameworks available are
Struts, Spring and Hibernate. Some vendor based frameworks
are Oracle
ADF
Web
Applications can be rich client AJAX
based or HTML based
Ant for building Java Applications
JUnit Java Testing Framework (See my sample)
Eclipse (Open Source IDE for Java UML etc)
Apache Tomcat ervlet and JSP Container (pache
Open Source)
Apache Axis (Java Web Services)
Apache Geronimo Application J2EE Server
(Apache Open Source)
Even if you do client side validation, you
should do server side validation to make sure that invalid data is not entered
by customers
Struts is a configurable MVC framework
that simplifies the job of developing web applications
Struts is a Model2 Framework
Struts Components
Struts
Struts Powerpoint
Presentation
Free
Jakarts Struts Live Book PDF
Java Server Faces is an alternative to
Struts. MyFaces is Apache
implementation of Java Server Faces
Spring is a J2EE framework and aims to
simplify J2EE development
You can use all of Spring's functionality
in any J2EE server, and most of it also in non-managed environments. A central
focus of Spring is to allow for reusable business and data access objects that
are not tied to specific J2EE services. Such objects can be reused across J2EE
environments (web or EJB), standalone applications, test environments, etc
without any hassle.
Spring has a layered architecture; all its
functionality builds on lower levels. So you can e.g. use the JavaBeans
configuration management without using the MVC framework or AOP support. But if
you use the web MVC framework or AOP support, you'll find they build on the
configuration framework, so you can apply your knowledge about it immediately.
Spring uses a setter based dependancy injection
pattern (Inversion of Control)
An
Introduction to AOP Programming with the Spring Framework by Russell Miles
Pro
Spring by Rob Harrop Jan Machacek
The goal is to make the core logic simpler to write and test
AOP use cases
AspectJ and Spring are the most popular AOP frameworks
Aspects and pointcuts are expressed in AspectJ language. Pre-compiler generates Java code. An .lst file specifies which Aspects apply to the subsystem. There is no runtime support for turning Aspects on or off. AJDT Eclipse plug-in is available
Provides dynamic proxy-based approach to implementing AOP (using Java Reflection APIs). Target application classes must implemented interfaces. Uses springconfig.xml for Spring Framework and Spring AOP configuration. Uses AOP alliance. Pointcuts and advice are implemented using Spring's IOC (Inversion of control) framework. IOC is a POJO with a Java Bean setter method. Spring AOP comes with built in transaction and security support
http://ramnivas.com/
author of AspectJ In Action
See SCJP notes for Java Fundamentals
Fundamentals.java
demonstrates primitive data types, arrays, controls etc
Objects.java
inheritance, exceptions, inner classes
JavaCollections.java
demonstrates how to create Lists, Sets and Hash Tables (Associative Arrays)
JavaThreads.java demonstrated how to create and use Threads
Java and JDBC, Oracle
JDBC FAQ
Java Basics and Sun
Certified Java Programmer Notes
J2EE is a set of API and
services. The services are typically implemented in an Application server. The
API/services for J2EE 1.3 are
SOA is a standards-based platform that lets you model,
develop, find, and combine services into flexible business processes
Products needs for SOA
Web services is a set of XML-based technologies (SOAP, UDDI, WSDL) that are the means by which interoperable application-to-application communication is carried out on the World Wide Web through a set of standard programmatic interfaces. Web services are a set of implementation technologies, whereas SOA is an architectural style or strategy. SOA uses web services
SOAP Version 1.2 is a lightweight protocol intended for exchanging structured information in a decentralized, distributed environment. It uses XML technologies to define an extensible messaging framework providing a message construct that can be exchanged over a variety of underlying protocols. The framework has been designed to be independent of any particular programming model and other implementation specific semantics.
Books
Designing Web Services with the J2EE(TM) 1.4 Platform: JAX-RPC, SOAP, and XML Technologies
naming service stores names
and associate objects with it.
directory is similar to
naming service and it allows you to store attributes with directory objects
javax.naming used for
accessing naming services
javax.naming.directory for accessing
naming and directory services
javax.naming.event support
event notification in naming and directory services
javax.naming.ldap access LDAP
v3 protocol (Lightweight directory access protocol)
javax.naming.spi implement a
naming or directory service
Context context = new
InitialContext();
// lookup data source
javax.sql.DataSource myDS =
(javax.sql.DataSource) context.lookup(“jdbc/myDS”);
java.sql.Connection mc =
myDS.getConnection();
// lookup EJB Local or Remote
Home Interface
LineItemLocalHome home =
(LineItemLocalHome) context.lookup(“java:comp/env/LocalItemLocal”);
PurchaseOrderHome po =
(PurchaseOrderHome) context.lookup(“java:comp/even/PurchaseOrderHome”);
// above code can also be
written using InitialContext(Hashtable env) constructor
Nested transactions are not
supported. Transactions are demarcated using the
javax.transaction.UserTransaction interface. EJB specification defines the
following transactions attribute values NOTSUPPORTED, REQUIRED, SUPPORTS,
REQUIREDNEW, MANDATORY, NEVER. Message driven beans support only REQUIRED and
NOTSUPPORTED
OC4J supports following
transaction type
·
Declarative transactions: used in container managed
persistent beans and called container managed transactions
·
Programmatic transactions: used in bean-managed
persistent beans and called bean managed transactions
·
EJB Transactional attributes: such as REQUIRED ...
·
Transaction isolation:
such as READ_COMMITED, SERIALIZABLE are directly supported by Oracle database
·
Concurrency control
Install
Cd $ORACLE_HOME
Unzip oc4j.zip
Cd $ORACLE_HOME/j2ee/home
Java –jar orion.jar –install
Start: java
–jar orion.jar
Stop: java
–jar admin.jar ormi://localhost admin
password –shutdown force
Books: Oracle 9iAS Building J2EE Applications
cd <OC4J_HOME>\j2ee\home
Java –jar oc4j.jar (Start OC4J)
Java –jar admin.jar –shutdown
Java –jar
admin.jar ormi://localhost admin password –deploy –file oowa.ear
–deploymentName oowa
(admin password could be admin)
java -jar admin.jar ormi://sbdesai-pc2/ admin ****
-bindWebApp oowa oowa http-web-site /oowa-iinstall
Stop: java
–jar admin.jar ormi://localhost admin
password –shutdown force
Restart:
java –jar admin.jar ormi://localhost
admin password –shutdown restart
deploy: java –jar admin.jar ormi://localhost admin password
–deploy –file foo.ear –deploymentName foo –targetPath \xyz\foo
bind: java –jar admin.jar ormi://localhost admin
password –bindWebApp foo foo http-web-site /foo
set the admin password
java –jar oc4j.jar –install
java –jar oc4j.jar –validateXML
java –jar oc4j.jar –out [file] {sends stdout to
file}
Default web port is 8888 (edit
j2ee/home/config/http-web-site.xml to change port)
Default RMI Port is 23791
j2ee/home/config/data-sources.xml (list of
datasources)
Oracle iAS 9.2
Distributed Configuratin Management tool
$ORACLE_HOME/dcm/bin/dcmctl stop
$ORACLE_HOME/dcm/bin/dcmctl start
Default web site port is 7778
JNDI 1.2 service is implemented using XML files
JMS 1.0.2 compliant
Data Sources: emulated data source is a wrapper
around data source and is used to access a single database, the data source is
described in the data-sources.xml file. The connection information will be in
the xml file so that it can be easily changed without changing the application.
Non emulated data source is used to coordinate
access to multiple sessions for the same or multiple databases (distributed
transaction)
java -jar
D:\orahome\jdev9irc2\j2ee\home\admin.jar ormi://sbdesai-pc2/ admin **** -deploy
-file D:\ \oowa.ear -deploymentName oowa
A Web
application consists of java code, html file, configuration file all bundled
into an .war file (like a .jar file) The configuratin file is WEB-INF/web.xml
WEB-INF/web.xml
WEB-INF/classes
WEB-INF/lib
<web-app>
<description>Empty web.xml file for Web
Application</description>
<servlet>
<servlet-name>oowa</servlet-name>
<servlet-class>oracle.olap.webAgent.servlet.oowa</servlet-class>
<init-param>
<param-name>log.main.file</param-name>
<!--param-value>\apache\jakarta-tomcat-3.3\webapps\oew-install\oowa_log.html</param-value-->
<param-value>console</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>oowa</servlet-name>
<url-pattern>/oowa</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<mime-mapping>
<extension>html</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<mime-mapping>
<extension>txt</extension>
<mime-type>text/plain</mime-type>
</mime-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
UI can be rendered declaratively using XML or using
Java (oracle.cabo.ui) UIX also provides utilities for generating images, makes
localization easy. (oracle.cabo.image)
UIX Controller is based on Java Servlet and is used
for managing navigation among all UI aplication components. It standardizes
support for error page loops, login support and file uploading (
oracle.cabo.servlet)
UIX styles provides support for defining style
sheets for different user environments (locales, browsers etc) UIX includes XML
Style Sheets (XSS) for defining environment specific style sheets. XSS is based
on Cascading Style Sheets (CSS) (oracle.cabo.style)
UIX Share (oracle.cabo.share)
Avoid oracle.cabo.ui.laf.LookAndFeel,
oracle.cabo.ui.laf.*, oracle.cabo.ui.UINode/RenderingContext/Renderer,
oracle.cabo.ui.io.OutputMethod
Page is one unit of UI. Page consists of nodes.
Nodes can have parents and children
UIX Component UINodes (User Interface Nodes), they
are building blocks used to create a UIX Component page e.g Buttons, Images,
Tables etc. All UINodes have a name and their namespace. The namespace and name
combination form a unique paring. UINodes can have attributes or properties e.g
text of a button is an attribute, destination when button is clicked
UIX pages are created with .uix extension, They
must have a valid XML syntax and should have valid UIX syntax as dictated by
the UIX XML schema (.xsd files)
e.g
<text
xmlns=”http://xmlns.oracle.com/uix/ui” text=”hello, world”>
e.g
<div
xmlns=”http://www.w3.org/TR/REC-html40”
xmlns:ui=”http://xmlns.oracle.com/uix/ui”>
Hello World.
<ul>
<li> first </li>
<li> second </li>
</ul>
<ui:button text=”Push me”
destination=”http://www.example.org”>
</div>
UIX pages can be created using Java
oracle.cabo.ui.html.HTMLWebBean
div = new HTMLWebBean(“div”);
oracle.cobo.ui.TextNode
helloText = new TextNode(“Hello
World”);
div.addIndexedChild(helloText);
...
oracle.cabo.ui.beans.nav.ButtonBean
button = new ButtonBean();
button.setText(“Push
Me”);
div.addIndexedChild(button);
UINodes support Indexed children
(where order is important but all children are equal)and Named children (e.g.
where children maybe in a border layout and need to be set in the left, top,
righ bottom position)
<stackLayout xmlns="http://xmlns.oracle.com/uix/ui"> <contents> <button text="Indexed child 1" destination="http://www.example.org"/> <button text="Indexed child 2" destination="http://www.example.org"/> <button text="Indexed child 3" destination="http://www.example.org"/> </contents></stackLayout>
In UIX,
named children are added to a node by first creating under the parent an
element representing the name which the child node should take and then placing
the child inside that name element. A border layout node with named text
children in four regions would appear as follows:
<borderLayout xmlns="http://xmlns.oracle.com/uix/ui"> <top> <text text="Top text"/> </top> <bottom> <text text="Bottom text"/> </bottom> <right> Right text </right> <left> Left text </left></borderLayout> UINode.render(RenderingContext context) renders the UINodes, this method will be run on the root
Data Binding
The BoundValue interface is used for creating dynamic UIX pages
public class CurentDate implements oracle.cabo.ui.data.BoundValue {
public Object getValue(RenderingContext context) {
return new Date();
}
}
DateFieldBean dateField = new DateFieldBean();
dateField.setValueBinding(new CurrentDate());
The DataObject interface is the generic data source for UIX, they are used to conect the back end to the UI
</dataScope><dataScope> <provider> <data name="demo:inlineData"> <inline> <tableKey textKey="Row 0" text2Key="Column 2, Row 0"/> <tableKey textKey="Row 1" text2Key="Column 2, Row 1"/> ... etc ... <tableKey textKey="Row 4" text2Key="Column 2, Row 4"/> </inline> </data> </provider><contents>
<table data:tableData="tableKey@demo:inlineData"> <contents><styledText data:text="textKey"/>
<styledText styleClass="OraErrorText" data:text="text2Key"/></contents>
</table> </contents></dataScope><dataScope> <provider> <data name="demo:inlineData"> <inline> <tableKey textKey="Row 0" text2Key="Column 2, Row 0"/> <tableKey textKey="Row 1" text2Key="Column 2, Row 1"/> ... etc ... <tableKey textKey="Row 4" text2Key="Column 2, Row 4"/> </inline> </data> </provider> <contents>
<table data:tableData="tableKey@demo:inlineData"> <contents><styledText data:text="textKey"/>
<styledText styleClass="OraErrorText" data:text="text2Key"/></contents>
</table> </contents> </dataScope> UIX Controller
ctrl:event will fire the event of name“StoreName”The handler specifies which java class method should handle the event
<page xmlns="http://xmlns.oracle.com/uix/controller" xmlns:ctrl="http://xmlns.oracle.com/uix/controller"><content> <header xmlns="http://xmlns.oracle.com/uix/ui" text="Enter Your Name"> <contents> <form name="form1"> <contents> <messageTextInput name="txt1" prompt="Enter Name" text="YourName" /> <submitButton ctrl:event="StoreName" text="Submit" /> </contents> </form> </contents> </header></content><handlers> <event name="StoreName"> <method class="MyClass" method="handleStoreNameEvent" /> </event></handlers></page>
Example below will handle all events as a null action
<page xmlns="http://xmlns.oracle.com/uix/controller" ><handlers> <event name="*"> <null/> </event></handlers></page>
Java Event Handler
import javax.servlet.http.HttpSession;import oracle.cabo.servlet.Page;import oracle.cabo.servlet.BajaContext;import oracle.cabo.servlet.event.PageEvent;import oracle.cabo.servlet.event.EventResult; public class MyClass{
public static EventResult handleStoreNameEvent(BajaContext context, Page page,
PageEvent event){
String userName = event.getParameter("txt1"); HttpSession session = context.getServletRequest().getSession(true); session.putValue("User Name", userName); Page nextPage = new Page("NextPage"); return new EventResult(nextPage); }}
EventResult is use by the PageFlowEngine to determine which page to display next. Method can throw a Throwable exception