cs441 current topics in programming languages

34
1 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES LECTURE 2 George Koutsogiannakis / Summer 2011

Upload: elijah-donovan

Post on 01-Jan-2016

42 views

Category:

Documents


1 download

DESCRIPTION

CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES. LECTURE 2. George Koutsogiannakis / Summer 2011. Overview of Java EE. Past discreet APIs allowed building of complex enterprise solutions. EE combines most of the above and new APIs into one enterprise bundle of tools and APIs. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

1

CS441 CURRENT TOPICS IN

PROGRAMMING LANGUAGES

LECTURE 2

George Koutsogiannakis / Summer 2011

Page 2: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Overview of Java EE

• Past – discreet APIs allowed building of complex

enterprise solutions.

• EE – combines most of the above and new APIs into

one enterprise bundle of tools and APIs.

2

Page 3: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Distributed Multi-tiered Applications

• Enterprise applications can be distributed in various servers located in different locations.

• They are comprised of various tiers i.e.:

– Client Tier (Presentation Tier): Consists of components that run on the client machine. Can be applets working in a Browser or application programs.

• These components can communicate with a Web Server using HTTP protocol to send requests and receive responses.

Or

• They can communicate via another protocol with the Business Tier applications.

3

Page 4: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Distributed Multi-tiered Applications

– Web Tier: Consists of the Web Server and applications that run in the web server using special containers that the web server must have, i.e. Servlet container.

The Web Server can be Jakarta Tomcat or any other Web Server that has the proper containers.

The term container refers to special executable programs (sometimes called engines) that a server can have . These containers are capable of recognizing the particular type of java program that the server is interfacing with.

4

Page 5: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Distributed Multi-tiered Applications

– Business Tier: Components that run on distributed servers. Those servers can be RMI (Remote Method Invocation) servers or Application Servers with Enterprise Java Beans.

• Notice that either the web server applications act as client to the remote servers (to RMI or Application Servers)

• Or, that the Client Tier can directly contacts these distributed services via some protocol (without going through the web server).

• The application servers are available through various vendors including Sun Microsystems (on April 20, 2009 Oracle announced that it is acquiring Sun MS- the deal is still pending closure).

5

Page 6: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Distributed Multi-tiered Applications

– Enterprise Information System Tier (Data Tier): Data bases that run on legacy machines and have various data that the customer at the Client Tier needs.

• The Enterprise hires developers (and other software engineers) and obtains tools to establish the tiers.– A number of developers are working on the various tiers.

Developers have specialized experiences based on the tier they are working with.

• Their experience also is tool depended. Some are familiar with NetBeans, others with Websphere , others with .NET tools (Microsoft) and so on.

6

Page 7: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Distributed Multi-tiered Applications

– Other software engineers are responsible for the• Temporary deployment in the servers and the testing of the various

parts of the enterprise application.

• The final deployment in the servers.

7

Page 8: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Example of Past Implementations

• Web Server: Jakarta Tomcat

• JDK SE:

– SWING AND AWT Graphical Components

– JDBC (Java Data Base Connectivity)

– RMI (Remote Method Invocation)

– RMI over IIOP (RMI over Internet Inter-Operability Protocol)

– Servlet and Java Server Pages API could be added to SE

– Java Email API couled be added to SE

– Java Messaging Services API could be added to SE

– Java Beans API

8

Page 9: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

9

3-TIER ARCHITECTURE- Example from CS441 Project 2 Spring 08

• THE BASIC BANK SERVICES ARCHITECTURE IS:

INTERNETCLIENT GUI

BROWSER

WEBSERVER

Customer Accounts Servlet, Users Servlet, Updated Selections Servlet e.t.c,Applet, html files, images

RMI SERVER/JDBC

RMI SERVER / JDBC

DATABASE

PRESENTATION TIER WEB TIER AND BUSINESSRULES TIER

DATA TIER

Page 10: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

3 Tier Example discrete API usage

• The Web Server was Jakarta Tomcat

• The Client GUI was an Applet

• The business rules were applied via servlets, jsp

• The RMI server demonstrated distributed applications (not necessarily collocated with the web server).

• The distributed services used JDBC to connect to respective databases

• Client Request -> Web Server-> proper servlet (servlet was a client to a RMI server) -> RMI server JDBC query->Database

• Database query result (data)-> RMI server-> corresponding servlet (its client)-> response to web server servlet container-> HTTP response packets to client Applet

10

Page 11: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Revised 3 tier architecture using Enterprise Java Beans and Application Servers

11

INTERNET

CLIENT GUI

BROWSER

WEBSERVER Servlets/

Java Server Pages

Application Server EJBs

Application Server EJBs

DATABASE

PRESENTATION TIER BUSINESS

RULES TIER

DATA TIER

Distributed Applications

WEB TIER

Page 12: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Revised 3 tier architecture using Enterprise Java Beans and Application Servers

• Notice that the Communication between the client and the service needed can also be direct by passing the web tier and going through a private network:

12

CLIENT NETWORK

APPLICATIONSERVER

Page 13: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Revised 3 tier architecture using Enterprise Java Beans and Application Servers

• Quite often the Application Server (such as GlassFish) contain the web server and the database.– Note that GlassFish used to be called Sun

Application Server

13

Page 14: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Multi Tier

• Multi Tier architectures can be built where additional servers become part of the architecture such as:– Firewall server: handles all incoming traffic

from the Internet, helps protect the rest of the system from attacks.

– Local Balancer: Distributes transactions to various servers.

14

Page 15: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Multi Tier

– Transaction Processing Monitor: Handles incoming requests and forwards the request to the proper application server.

• The above 3 types of servers define what is called PortalServices.

15

Page 16: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Java EE

• Integrates all API s and tools needed for establishing multi-tiered applications.– Combines Web Server and Application Server

into Java EE Server.– GUI components for the client tier are created

using Java Server Faces technology• Graphical Components are created on the server

side and rendered as an object in a mark up language (HTML, XML etc.)

16

Page 17: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Java EE Tiers

17

CLIENT TIER- Java Application/Dynamic HTML pages/Java Script / Java Bean components

Web Tier (Web Server)

Enterprise Java Beans (Application Server)

Databases

Java EEServer

Page 18: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Naming Services

• Distributed Services Need to be discovered.

• For Example: RMI provides a simple server called rmiregistry where remote servers can register their remote objects. – A client first contacts the registry to get a

reference to the remote object (i.e. the name of the server, the port number that the server listens, the remote object id).

18

Page 19: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Naming Services

• Java EE includes the Java Naming and Directory Interface API ( JNDI).– This API allows clients to discover remote

objects (provided those remote objects have registered with the JNDI)

19

Page 20: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Java EE Security

• Java EE allows security to be defined at the time of deployment of the application.– In discrete APIs security needs to be defined with special policy

files and certificates. In addition separate programs are needed by using the various Security APIs.

– Cumbersome and application specific.

• Java EE utilizes the various Security APIs in an integrated approach to provide security settings at the time of deployment.– Uses the Java Authentication and Authorization Service.

20

Page 21: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

JEE APIs

• Other APIs included in JEE:

– JDBC (Java Data Base Connectivity)

– Java Servlets and Java Server Pages (JSP)

– Java Server Faces

– Java Enterprise Beans

– Java Message Service

– Java Transactions

– Java Email

– JavaBeans Activation Framework

– Various APIs for Web Services implementation

21

Page 22: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Types of Tasks in an Enterprise

– Purchasing of software from Java EE vendors who have implemented the Java EE server.

– Tool providers for development tools and also packaging tools (i.e. NetBeans Development tool).

– Development of Java Enterprise Beans, web components (applets,servlet, jsp other programs, java applications for client and other programs)

– Assembly of the application into an EAR file.

– Temporary Deployment of the application by an administrator into the server(s).

– Testing

– Final Deployment into the server(s).

22

Page 23: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

JAVA GRAPHICS

• Let us revert to some basic Java Graphics before we return to the topics of server side Java.

• Graphics should be understood before the concept of Java Server Faces as a substitute for graphical components is discussed or

• Before the usage of NetBeans to create graphical components is discussed.

23

Page 24: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

24

JAVA GRAPHICS BASICS

• JAVA CONCEPTS INVOLVED– AWT & SWING APIs PROVIDE

• TOP CONTAINERS OBJECTS

• COMPONENTS OBJECTS

• SUB CONTAINERS OBJECTS

• LAYOUT MANAGERS OBJECTS

• PAINT / UPDATE/ REPAINT METHODS FOR EACH CONTAINER

Page 25: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Java Graphics

• Involves knowledge of various containers

– i.e. Top Containers: JFrame, JApplet, JDialog

– Other containers can be dropped into top containers:

• JPanel

• JInternal Frame

• Other components can be dropped in a Container i.e.– JTextArea

– JTextField

– JButton

– JEditorPane ( a component that allows html files to be displayed plus other text formats).

25

Page 26: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Java Graphics

• Involves knowledge of Layout Managers:– FlowLayout manager (default)– BorderLayout Manager– GridLayout Manager– GridBagLayout Manager

• GridBagLayout is the one Layout manager used for professional presentations.

26

Page 27: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

BorderLayout Manager

• Divides Screen up to 5 Areas:

27

NORTH

WEST CENTER EAST

SOUTH

Page 28: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

BorderLayout Manager

• Set up the top Container first by extending your class to inherit the container:

public class MyClass extends JFrame

{

//call super class’ constructor to pass a name for the Frame

public MyClass()

{

super(“My Frame Name”);

28

Page 29: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

BorderLayout Manager

• Usage: Container c= getContentPane();

c.setLayout(new BorderLayout(5,5));

JButton b1=new Jbutton(“First Action”);

c.add(b1, BorderLayout.NORTH);

……………………………………………………

29

Page 30: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

30

EVENT HANDLING

• EVENT LISTENER INTERFACES.

• EVENT OBJECTS.

• EVENT ADAPTER CLASSES

• TECHNIQUES FOR GENERATING EVENTS.

Page 31: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

31

EVENT HANDLING

EVENT SOURCE

EVENT OBJECT

EVENT LISTENER

Page 32: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

Event Handling

• Create component object

• Register component object with the event handler object.

• Create an event handler class that implements the Event Listener interface that goes with the particular component– Implement the proper method of the Even

Listener Interface.32

Page 33: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

33

MORTGAGE CALCULATOR –APPLICATION VERSION

• JFRAME AND BORDER LAYOUT MANAGER• USAGE OF JPANEL AND BOX MANAGER.• JTABLE COMPONENT.• MODEL/ VIEW / CONTROLLER DESIGN PATTERN• DEMONSTRATION OF EVENT HANDLING

– USING ANONYMOUS INNER CLASS– USING AN INNER CLASS– USING A SEPARATE FILE

• ANOTHER VERSION USES GRID BAG LAYOUT MANAGER

Page 34: CS441  CURRENT TOPICS IN PROGRAMMING LANGUAGES

STUDY GUIDE

• Read Web Based Applications Development: chapters 2 and 3

• Read Java EE Tutorial: Part II Chapter 3.

• Study Mortgage Calculator examples for Graphics.

34