j2se/j2ee j2se – java 2, standard edition “core” java – the base classes on which everything...

26
J2SE/J2EE J2SE – Java 2, Standard Edition “core” java – the base classes on which everything else is built Base tools and utilities J2EE – Java 2, Enterprise Edition APIs and technologies for delivering multi-tier “enterprise” applications Web Applications Web Services

Post on 22-Dec-2015

234 views

Category:

Documents


0 download

TRANSCRIPT

J2SE/J2EE• J2SE – Java 2, Standard Edition

• “core” java – the base classes on which everything else is built

• Base tools and utilities• J2EE – Java 2, Enterprise Edition

• APIs and technologies for delivering multi-tier “enterprise” applications

• Web Applications• Web Services

J2SE• Tools and Utilities

• javac.exe – java compiler• java.exe – the java VM• Javadoc.exe – Javadoc tool

J2SE APIs• Java Foundation Classes (JFC/Swing)

• API/Framework for building GUIs• Used to be VERY SLOW• Used for “fat clients” and applets

• JDBC – Java Database Connectivity• Connect to databases• Query/Update capability• Connection pooling• Each DB vendor provides their own driver

• Must conform to the JBDC API

J2SE APIs• Java Platform Debugger Architecture (JDPA)

• Standardized API for debugging• This gives all IDEs easy debugging capabilities

• Vendors used to build their own debugging functionality

• Remote Method Invocation (RMI)• Allows a class in one VM to call a method on

another class in another VM• Allows distributed applications

• Break up an application into parts (across different machines)

J2SE - RMI

VM1

Obj1

VM2

Obj2

RMI directory

Obj2(stub)

J2SE - RMI• Marshalling

• “Flattening” an object• Turning it into a “stream” or “string”

• Can be passed over the wire• Unmarshalling

• Turning a marshalled stream back into an object

• RMI is java-to-java only

J2SE – Javadoc• Javadoc is a tool that takes your source code and

generates HTML documentation from it• Uses special tags that you put into the comments

of your source code• Configure your IDE or code editor tool to generate

template documentation

J2SE - Javadoc

MyClass.java javadoc.exe

html

html

html

•Javadoc example•http://java.sun.com/j2se/1.4.2/docs/api/

•Source code with javadoc in it:•http://java.sun.com/blueprints/code/jps131/src/index.html

J2SE - JNDI• Java Naming and Directory Interface (JNDI)

• Standard API for accessing naming and directory services• LDAP• CORBA• RMI

• For any directory/naming service, a provider can be built that follows the JNDI API.

• This allows any java application the ability to “look up” something independent of implementation

• A framework that allows vendors to add their own “provider” so their directory can be accessed via the JNDI API (for example)

• NDS• NIS

J2SE – Java Mail• Java Mail API

• API for accessing e-mail functionality• POP• IMAP• Send/receive with attachments

J2EE APIs - JMS• Java Messaging Service API (JMS)

• Standard API for accessing message-based systems

• Asynchronous messaging between components or other systems

• “Loosely Coupled”• Sender and Receiver do not “know” about each

other• Messages sent to a destination• Messages picked up from a destination

• Unlike RMI, which is tightly coupled• Similar to e-mail, but for software, not humans

J2EE APIs - Servlets• A special java object that runs on a server• An extension of a web server. It allows a web

server to perform specialized processing.• Similar to CGI programs

• Servlet API is a framework• You add your own servlet classes by subclassing

the HttpServlet superclass• Your servlet must have certain public methods to

work properly• Servlets run in a “Servlet Engine”• Usually used for short/quick on-line processing.

WebServer

BrowserS

S

S

Servlet Engine

DB

J2EE APIs - Servlets

Servlet Engine• This is a vendor-provided program that

manages the servlets you write• a.k.a. – “Servlet Container”• Loading/Unloading servlets• Managing multiple requests from web

server(s)• Administration utilities• “Plugs-into” various web servers

• Some web servers come with their own servlet engine

J2EE APIs - Servlets• A servlet is usually executed from a request

coming from a user’s browser. (e.g., you hit the Submit button on a form)

• A servlet handles multiple requests concurrently. It is up to the servlet engine to ensure this.

J2EE APIs – Java Server Pages (JSPs)

• Run and behave just like servlets with the following differences:• Servlets are written as normal java classes• JSPs are written as HTML/Web pages

• Servlet engine converts them into servlets behind the scenes

Servlets vs. JSPs

Servlets JSPsJava objects that subclass from HttpServlet

HTML page with embedded java code

Used for processing browser requests Used for building web pages

Can be dynamically changed while the servlet container is running

Can be dynamically changed while the servlet container is running

Written by java programmers Can be written by “web page folks”, not necessarily java programmers

Some configuration/setup is necessary to use (deploy) a servlet

Deployment is quick and easy

Can use “object things” like methods and subclassing

Defining methods or subclassing not easy or not possible

More thoughts on JSPs• You can build an entire system using JSPs only!

• Good candidate for very small systems• Read-only• No transactions• 2 – 3 pages at most

• In your JSP, embed all your database calls (JDBC) to display the information

• If the system gets bigger, consider moving functionality into other objects• Make them components so they can be used again

• Database calls• Screen navigation• Authorization logic

Tag Libraries• Normally, a JSP file has lots of HTML with java

code interspersed throughout• Tag Libraries (taglibs), allow us to encapsulate

java logic into an HTML-like tag• If you have a sufficiently robust tag library, web

page developers can build all of your screens for you. You don’t need java programmers!

• Java programmers still build and maintain the tag libraries

Tag Libraries – JSTL• Java Standard Tag Libraries

• Standard taglibs:• Core processing

• Including/excluding page parts• Looping• Manipulating URLs• Session tracking

• XML Processing• SQL Processing• Accessing java objects

• Standard way to build your own taglibs

J2EE - EJB• Enterprise Java Beans – EJB

• A “Component Based Architecture”• You can build business objects as components and the EJB

framework gives you:• Built-in transactional support

• Automatic commit/rollback• Security

• Access on a per-method basis• DB Access

• No need to write SQL• Distributed Objects

• Allows you to distribute parts of your application across VMs or different machines

• Distributed transactions all within one unit of work

J2EE - EJB• Probably use EJBs when:

• Business Reasons• Your system is truly transactional

• All changes need to happen or not at all

• High-volume updates• Multi-user access to the same objects

• Multi-user access to the same data rows in a DB

• Technical Reasons• Many many tables that must be updated• You want to provide a transaction as a service

• Available to other applications

J2EE - EJB• Probably don’t use EJBs (may be overkill) when:

• Application is “read-only”• Viewing account info on-line, no updates

• Application is not transactional in nature• Application is “single user”

• User alone has access to his data

J2EE - EJB• 2 Types of EJBs

• Entity Beans• Concrete business objects whose data is transaction

dependent• Used across transactions• Can be shared by multiple users• Rows in a database table• Examples

• Account• Payment• Charge

• Session Beans• Associated with a User Login• Controls a transaction where multiple Entity Beans participate• The main entry point for a business transaction

EJB example (database view) AccountNum Address123 55 Main St.987 33 Grand Ave.

AcctActivitynum type amount123 pur 12.00

PurchaseOrdernum qty item amount123 4 BB 8.00123 1 WI 4.00

Inventoryitem qtyBB 10WI 17

ShippingItemitem qty acctNum when statusBB 4 123 today pendingWI 1 123 today pending

EJB example – EJB view

PurchasingManager(session bean)

AccountManager(session bean)

ShippingManager(session bean)

InventoryManager(session bean)

Purchase(purchase info)

Is available?

yes

Remove from

inventory

Charge account

Ship to

InventoryItem(entity bean)

Account(entity bean)

AccountActivity(entity bean)

ShippingItem(entity bean)

Find inventory listing

Update inventory listing

find

Create activity item

Create shipping item