SlideShare una empresa de Scribd logo
1 de 50
Descargar para leer sin conexión
JAVA
Agenda:
● Introduction to Java
○ About Java
○ Java vs C#
● Java EE platform
○ Java EE Components (web, business)
○ Java EE server
○ Enterprise JavaBeans
○ Servlet
○ JavaServer Faces
○ Session Bean
Goal: Overview of Java EE Technology
Java: History
● June 1991: James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project, in Sun
Microsystem
● 1995: Sun Microsystem released first public implementation. It promised “Write Once, Run Anywhere”
○ Major web browsers soon incorporated the ability to run Java applets
● December 1998: Java 2 released:
○ J2EE includes api for enterprise applications running in server environments
○ J2ME includes api for mobile applications
○ JSE for desktop environments
● November 13, 2006: Sun released much of Java as free and open-source
project, under GPL
● January 27, 2010: Oracle acquired Sun. The Oracle implementation is packaged
into two different distributions:
○ Java Runtime Environment (JRE), intended for end users
○ Java Development Kit (JDK), intended for software developers
http://en.wikipedia.org/wiki/Java_(programming_language)
About the Java Technology
● javac compiler: compile source files into .class files
● a .class file contains bytecode
● bytecode is the machine language for Java Virtual Machine
● java launcher tool runs the application
About the Java Technology
● Java VM is available on many
different operating system
The Java Platform
● The Java Virtual Machine
● The Java Application Programming Interface (API)
The API is a large collection of ready-made software components that provide many useful capabilities
(packages)
Package
● a package is a group of related types providing access protection and namespace management
● package name are written in all lower case to avoid conflict with names of classes or interfaces
● companies use their reverse Internet domain name
In Java the directory structure should match the package structure.
No such restriction in C#
Java vs C#: Declaring Constants
Java:
● In Java, compile-time constant value are declared inside a
class as
static final int K = 100;
C#:
● in C# the keyword const is used for compile time constants, while the readonly
keyword is used for runtime constants.
const final int K = 100;
readonly int aField;
Java
class Test
{
final int afield = 5;
final int workday = 256;
...
int getAfield() {
return afield;
}
}
//set method is not allowed for both finals
//cannot be written to by a constructor
Java vs C#: Declaring Constants
C#
class Test
{
readonly int afield;
const byte workday = 256;
Test(int n) {
afield = n;
}
...
int getAfield() {
return afield;
}
}
//set method is not allowed for both.
//readonly can only be written to by a
constructor
Java vs C#: Inheritance
Java:
class B extends A implements Comparable
{
…
...
}
C#:
class B : A, IComparable
{
…
...
}
Polymorphism and Overriding
● In Java all methods are virtual
● In C# you must explicitily state which methods are virtual
using System;
public class Parent
{
public virtual void DoStuff(string str)
{ … }
}
public class Child : Parent
{
public override void DoStuff(string str)
{ … }
} public new void DoStuff(string str)
Multiple classes in a Single File
● In Java, only one class per source file with public
access (it must have the same name of the source file)
● C# doesn’t have restriction on the number
of public classes that can exist in a
source file
Importing libraries
● C#: using keyword
using System;
using System.IO;
using System.Reflection;
● Java: import keyword
import java.util.*;
import java.io.*;
Enumerations
C#
public enum Direction {
North = 1,
East = 2,
West = 3,
South = 4
};
Usage:
Direction wall = Direction.
North;
Java
public enum Planet {
MERCURY (3.303e+23, 2.4397e6),
VENUS (4.869e+24, 6.0518e6),
EARTH (5.976e+24, 6.37814e6),
MARS (6.421e+23, 3.3972e6),
JUPITER (1.9e+27, 7.1492e7),
SATURN (5.688e+26, 6.0268e7),
URANUS (8.686e+25, 2.5559e7),
NEPTUNE (1.024e+26, 2.4746e7);
private final double mass; // in kilograms
private final double radius; // in meters
Planet(double mass, double radius) {
this.mass = mass;
this.radius = radius;
}
private double mass() { return mass; }
private double radius() { return radius; }
}
Properties
Java
public int getSize()
{
return size;
}
public void setSize(int val)
{
size = val;
}
C#
public int Size
{
get
{
return size;
}
set
{
size = value;
}
}
Pass by Reference
● In Java the arguments to a method are passed by value
● In C# it is possibile to specify the arguments by
reference: ref and out keywords
ChangeMe(out param);
Swap(ref a, ref b);
Delegate
● In C# delegate are reference types which allow to
indirect calls to method
● There is no delegate concept in Java (it may be
mimiced with reflection)
Delegate
C#
using System;
using System.IO;
public class DelegateTest
{
public delegate void Print (String s);
public static void Main()
{
Print s = new Print (toConsole);
Print v = new Print (toFile);
Display (s);
Display (v);
}
public static void toConsole (String str)
{
Console.WriteLine(str);
}
public static void toFile (String s)
{
File f = new File("delegate.txt");
StreamWriter fileOut = f.CreateText();
fileOut.WriteLine(s);
fileOut.Flush();
fileOut.Close();
}
public static void Display(Print pMethod)
{
pMethod("This should be displayed in the
console");
}
}
Event Handling: C#
using System;
using System.Drawing;
using System.Windows.Forms;
// custom delegate
public delegate void StartDelegate();
class EventDemo : Form
{
// custom event
public event StartDelegate StartEvent;
public EventDemo()
{
Button clickMe = new Button();
// an EventHandler delegate is assigned
// to the button's Click event
clickMe.Click += new EventHandler(OnClickMeClicked);
// our custom "StartDelegate" delegate is assigned
// to our custom "StartEvent" event.
StartEvent += new StartDelegate(OnStartEvent);
// fire our custom event
StartEvent();
}
// this method is called when the "clickMe" button is pressed
public void OnClickMeClicked(object sender, EventArgs ea)
{
MessageBox.Show("You Clicked My Button!");
}
// this method is called when the "StartEvent" Event is fired
public void OnStartEvent()
{
MessageBox.Show("I Just Started!");
}
Event Handling: Java
● Source: is an object on which event occurs
● Listener: is responsible to generate response to an event
Steps involved in event handling
● The User clicks the button and the event is generated.
● Now the object of concerned event class is created automatically and information about the
source and the event get populated with in same object.
● Event object is forwarded to the method of registered listener class.
● The method is now get executed and returns.
http://en.wikipedia.org/wiki/Observer_pattern
Inner and anonymous classes
Since the Java language does not permit multiple inheritance, your class cannot extend both the Applet and MouseAdapterclasses. A
solution is to define an inner class a class inside of your Applet subclass
public class MyClass extends Applet {
...
someObject.addMouseListener(new MyAdapter());
...
class MyAdapter extends MouseAdapter {
public void mouseClicked(MouseEvent e) {
...//Event listener implementation goes here...
}
}
}
When considering whether to use an inner class, keep in mind that application startup time and memory footprint are typically directly
proportional to the number of classes you load. The more classes you create, the longer your program takes to start up and the more memory it
will take. As an application developer you have to balance this with other design constraints you may have. We are not suggesting you turn
your application into a single monolithic class in hopes of cutting down startup time and memory footprint this would lead to unnecessary
headaches and maintenance burdens.
● Inner classes can also be useful for event
listeners that implement one or more interfaces
directly.
● Inner classes work even if your event listener
needs access to private instance variables
Java - Multithreading
● New: A new thread begins its life cycle in the new state. It remains in this state
until the program starts the thread. It is also referred to as a born thread.
● Runnable: After a newly born thread is started, the thread becomes runnable.
A thread in this state is considered to be executing its task.
● Waiting: Sometimes, a thread transitions to the waiting state while the thread
waits for another thread to perform a task.A thread transitions back to the
runnable state only when another thread signals the waiting thread to continue executing.
● Timed waiting: A runnable thread can enter the timed waiting state for a specified interval of time. A thread in this state transitions back to the
runnable state when that time interval expires or when the event it is waiting for occurs.
● Terminated: A runnable thread enters the terminated state when it completes its task or otherwise terminates.
Java Serializable
● mechanism to represent an object as a sequence of bytes (including object’s data)
○ serialized object can be written in file, …
○ bytes can be used to recreate object in memory
● serialization is JVM indipendent
1. Class must be implement java.io.Serializable interface
2. all the fields in the class must be serializable. If a field is
not serializable, it must be marked transient
Java EE platform
● large-scale, multi-tiered, scalable, reliable, secure network application
○ Client-tier components run on client (web
browser)
○ Web-tier components run on the
Java EE server
○ Business-tier components run on the
Java EE server
○ Enterprise information system (EIS)-tier
runs on the EIS server
Java EE Components
● A Java EE component is a self-contained functional software unit
The Java EE specification defines the following components:
● Application clients and applet are components that run on client
● Java Servlet, Java Server Faces, JSP are web components that run on
server
● Enterprise Java Bean (EJB) components are business components that
run on the server
Java EE components are assembled into a Java EE application and managed by the Java EE server
Java EE clients
● Web Clients
○ Dynamic web pages (Html, Xml, ...) which are generated by web components running in
the web tier
○ Web browser, which renders the pages received from the server
● Application Clients
○ runs on client machine
○ graphical user interface (GUI) created from the Swing or AWT API
● Applets
○ small client application running in the Java virtual machine installed in the web browser
Java EE web components
● servlet or web pages created using JSF
and/or JSP.
● Servlets are Java classes that dynamically
process requests and construct response
Business components
● Business code is handled by enterprise
bean running in either the web tier
or the business tier
● The EIS tier include enterprise
infrastructure system: database
systems, mainframes
Business tier
● Enterprise Java Bean (EJB): encapsulate the core functionality of application.
● JAX-RS RESTful web services: REST API for creating web services that respond to
HTTP methods
● JAX-WS web sercice endpoints: api for creating and consuming SOAP web services
● Java Persistence API entities: api for processing data in data stores and mapping
that to JAVA programming
● Java EE managed beans: managed components that may provide business logic, but
do not require the transactional or security features of EJB
Java EE server
● A Java EE server, also called applicaton server, hosts several application component and
provides the standard Java EE services in the form of container
○ Java EE container: interface between a component and the low-level platform-specific
that support the component.
■ provides services like security, transaction management, JNDI API lookups, remote connectivity…
● A Java EE server provides EJB and web containers
Container
● Enterprise JavaBeans (EJB) container:
manages the execution of enterprise beans,
run on the Java EE server
● Web container: manages the executes of web
pages, run on the Java EE server
● Application client container: manages the
execution of application client components, run
on the client
● Applet container: manages the execution of the
applet. Consists of a web browser and Java Plug-in
Packaging Applications
● A Java EE app is delivered in a Java Archive (JAR) file, a
Web Archive (WAR) file or an Enterprise Archive (EAR) file.
● Using JAR, WAR and EAR files and modules makes it possibile to
assemble different JEE applications.
● An EAR file contains J2EE modules (optionally) and deployment descriptors.
○ A deployment descriptor is an XML document that describes the deployment settings of
an application, or module, or a component.
Java EE module
● A Java EE module consists of one or more Java EE
component for the same container type
○ EJB modules, wich contains class files for Enterprise
Java Beans (.jar)
○ Web modules, which contains servlet class files,
web files, HTML files, ecc. (.war)
○ Resource adapter modules, which contains classes,
libraries, ecc. (.jar)
Java EE Server
Java EE Web Module
● the smallest deployable and usable unit of resources
● contains:
○ web components
○ web resources (image, ...)
○ classes utility
Servlet
● client send an HTTP request to the server
● a web server, implementing a Java Servlet and JSP,*
converts the request into a HTTPServletRequest object
● this object is delivered to a web component, which can
interact with Java Bean component or database
● the web component generates an HTTPServletResponse
object
● the web server converts it into an HTTP Response
Servlet are Java classes that dinamically process the request and construct response.
Configuration info can be specified using JAVA EE annotation or via XML file (web application deployment descriptor)
http://docs.oracle.com/javaee/6/tutorial/doc/geysj.html
JavaServer Faces
● JSF is a server-side component framework
○ api for representing component and managing state, handling event, validation, data-conversion, page
navigation…
○ tag libraries for adding components to web pages and connecting to server-side objects
A typial JSF applications includes:
● a set of web pages
● a set of tags to add components to the web page
● a set of managed bean
● a web deployment descriptor (web.xml)
● optionally, one or more configuration files (faces.config.xml), used to define page navigation rules and
configure beans
● optionally, a set of custom objects: validators, converters, listeners, ecc…
- JSF offers clean separation from behavior and presentation for web applications.
- A JSF application can map an HTTP request to a component-specific event handling and manage component as stateful objects on the
server
http://javaserverfaces.java.net/
Enterprise JavaBeans
● EJB is a server side component that encapsulates the business logic
Types of Enterprise Beans:
● A session bean rapresents a transient conversation with the client.
○ stateful bean: business object having state. Access is limited to one client at a time.
○ stateless bean: business object that don’t have a state. Access to a single bean instance
is limited to only one client at a time (the container routes a request to a different instance)
○ singleton bean: business object having a global shared state whithin a JVM
Enterprise JavaBeans
● Message Driven Bean: business objects whose execution is triggered by
messages instead of method calls. The message driven bean is used to
provide an abstraction for the lower level JMS
EJBs are deployed in an EJB container.
● Clients not instantiate them directly, but have to obtain a reference via the EJB
container.
○ through dependency injection
○ using annotation
○ using JNDI lookup
Session Bean
● encapsulate business logic than can be invoked by a client over local,
remote or web services.
● stateful session bean: the client interacts (talks) whith its bean (conversional state). It
is not shared, it can have only one client
● stateless session bean: does not mantain a conversional state with the client. When
the client invokes a method, the bean’s instance variable may contain a state specific to that
client but only for the duration of invocation. All instance of a stateless bean are equivalent,
allowing the EJB container to assign an instance to any client. Because they support many
clients, stateless bean can offer better scalability
● singleton session bean: is instantied once per application and exists for
all the lifecycle.
Message-driven Bean
● is an enterprise bean that allows the Java EE applications to process messages
asynchronously.
● receives JMS messages (or other kind of messages)
● it resemble a stateless sesson bean:
○ no data or conversational state for a specific client
○ all instances of MdB are equivalent
○ a single MdB can process messages from multiple clients
When a message arrives, the container calls the message-driven bean’s onMessage method to process the message.
Enterprise Beans
● Enterprise Beans are Java EE components that implements the Enterprise
JavaBeans (EJB) technology
● run on the EJB container
● encapsulate the business logic
● simplify the development of large and distributed applications
● EJB container is responsible for system-level services,
such as transactions and security authorization
Two types of enterprise beans:
- session
- message driven
Accessing Enterprise Beans
Clients can obtain a reference to an instance of a bean through:
● dependency injection, using Java annotations (javax.ejb.EJB)
● JNDI lookup, using the Java Naming and Directory Interface syntax
JNDI: is a Java api that allows clients to discover and lookup data or objects via
a name. It provides:
● a mechanism to bind an object to a name
● a directory-lookup interface that allows general queries
● an event interface that allows clients to determine which directory entries has been modified
● LDAP extensions…
JNDI is composed of five packages:
● javax.naming
● javax.naming.directory
● javax.naming.event
● javax.naming.ldap
● javax.naming.spi
Lookup enterprise beans
Three namespaces are used for JNDI lookups:
● java:global: to find remote enterprise bean using lookups
java:global[/application name]/module name/enterprise bean name[/interface name]
● java:module: to lookup local enterprise beans whithin the same module
java:module/enterprise bean name/[interface name]
● java:app: to lookup local enterprise bean packaged withind the same application
java:app[/module name]/enterprise bean name[/interface name]
For example, if an enterprise bean, MyBean, is packaged within the web application archive myApp.war, the module name is myApp. The portable JNDI name
is java:module/MyBean An equivalent JNDI name using the java:global namespace is java:global/myApp/MyBean.
Remote or Local Access
● Tight or loose coupling of related beans: when a bean depends on one another. They are good candidates
for local access
● Type of client: if an enterprise bean is accessed by application clients, it should allow remote access. If an
enterprise bean is accessed only by other beans, think on how you want to distribute your components
● Component distribution: Java EE applications are scalable because their server-side components can be
distributed across multiple machines
● Performance: remote calls may be slower than local calls
Remote or Local access
● Define remote or local access:
//@Local or @Remote (@Local is default)
@Local(InterfaceName.class)
public class BeanName implements InterfaceName { ... }
● Accessing local beans
○ use the javax.ejb.EJB annotation
@EJB
ExampleBean exampleBean;
○ use the javax.naming.InitialContext interface’s lookup method
ExampleBean exampleBean = (ExampleBean)
InitialContext.lookup("java:module/ExampleBean");
Accessing remote beans
@EJB
Example example;
ExampleRemote example = (ExampleRemote)
InitialContext.lookup("java:global/myApp/ExampleRemote");
Contents of an Enterprise Bean
● Enterprise bean class: implements the business methods of the enterprise bean
● Business interfaces: not required if the enterprise bean expose a local, no-interface view
● Helper classes: other classes needed by bean (utility classes, exception, ...)
Packaging Enteprise Beans in EJB JAR modules:
● to assemble a Java EE application, package one or more modules, such as EJB jars, into an EAR file. You can
also deploy EJB Jar not contained in an EAR file
Packaging Enterprise Beans in WAR modules:
● to include enterprise bean class files in WAR module,
the class should be in the WEB-INF/classes directory
● to include a JAR containing enterprise beans in a WAR module,
add the JAR to the WEB-INF/lib directory of the WAR module
Lifecycle of Enterprise Beans
● Stateful Session Bean’s Lifecycle
○ client obtaines a reference to a stateful session bean
○ the container perform dependency injection
○ the c. invokes the method annotated with @PostConstruct
○ the EJB container may decided to deactivate, or
passivate, the bean by moving it from memory to a
secondary storage
○ client invokes a method annotated @Remove
○ EJB container calls @PreDestroy
○ Bean’s instance is ready for garbage collection
● Stateless Session Bean’s Lifecycle
● stateless session bean is never
passivated
● EJB container creates and mantains a pool of
stateless beans
Lifecycle of Enterprise Beans
● Singleton Session Bean’s Lifecycle
○ EJB container creates the singleton instance
○ at the end, EJB container calls the method annotated
@PreDestroy, if it exists
● Message-Driven Bean’s Lifecycle
● EJB container creates and mantains a pool of message-driven
beans
● like a stateless bean, it is never passivated, and only has two
states: non existent and ready to receive message
JAX-RS: Java api for RESTful WS
● RESTful web service are built to work best on the web
● JAX-RS: api that provides support in creating web services rest
● developers decorate Java class files with JAX-RS annotations
○ @Path: indicating where the Java class will be host
○ @GET: Java method annotated with this
will process HTTP GET requests
○ @POST
○ @PUT
○ @DELETE
○ .
○ .
….
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.Path;
// The Java class will be hosted at the
URI path "/helloworld"
@Path("/helloworld")
public class HelloWorldResource {
// The Java method will process HTTP
GET requests
@GET
// The Java method will produce
content identified by the MIME Media
// type "text/plain"
@Produces("text/plain")
public String getClichedMessage() {
// Return some cliched textual
content
return "Hello World";
}
}

Más contenido relacionado

La actualidad más candente

Learn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarLearn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarAbir Mohammad
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.pptVMahesh5
 
Java Development Kit (jdk)
Java Development Kit (jdk)Java Development Kit (jdk)
Java Development Kit (jdk)Jadavsejal
 
Fundamentals of JAVA
Fundamentals of JAVAFundamentals of JAVA
Fundamentals of JAVAKUNAL GADHIA
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java ProgrammingMath-Circle
 
Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3sandeep54552
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsMahika Tutorials
 
Enterprise java unit-1_chapter-1
Enterprise java unit-1_chapter-1Enterprise java unit-1_chapter-1
Enterprise java unit-1_chapter-1sandeep54552
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepGuo Albert
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javaAjay Sharma
 
Keyword Driven Testing
Keyword Driven TestingKeyword Driven Testing
Keyword Driven TestingMaveryx
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)arvind pandey
 
Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2sandeep54552
 

La actualidad más candente (20)

Learn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarLearn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat Shahriyar
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
Java Development Kit (jdk)
Java Development Kit (jdk)Java Development Kit (jdk)
Java Development Kit (jdk)
 
Fundamentals of JAVA
Fundamentals of JAVAFundamentals of JAVA
Fundamentals of JAVA
 
Java basic
Java basicJava basic
Java basic
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
 
Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
Java programming course for beginners
Java programming course for beginnersJava programming course for beginners
Java programming course for beginners
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
 
Enterprise java unit-1_chapter-1
Enterprise java unit-1_chapter-1Enterprise java unit-1_chapter-1
Enterprise java unit-1_chapter-1
 
Spring boot
Spring bootSpring boot
Spring boot
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Keyword Driven Testing
Keyword Driven TestingKeyword Driven Testing
Keyword Driven Testing
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Servlets
ServletsServlets
Servlets
 
Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2
 
Java Logging
Java LoggingJava Logging
Java Logging
 

Destacado

Introduction to Java Enterprise Edition
Introduction to Java Enterprise EditionIntroduction to Java Enterprise Edition
Introduction to Java Enterprise EditionAbdalla Mahmoud
 
Enterprise Java Beans - EJB
Enterprise Java Beans - EJBEnterprise Java Beans - EJB
Enterprise Java Beans - EJBPeter R. Egli
 
Lecture 04 - Loose Coupling
Lecture 04 - Loose CouplingLecture 04 - Loose Coupling
Lecture 04 - Loose Couplingphanleson
 
Languages formanandmachine
Languages formanandmachineLanguages formanandmachine
Languages formanandmachineGireesh Punathil
 
IBM IMPACT 2009 Conference Session 2024 - WebSphere sMash Integration, PHP wi...
IBM IMPACT 2009 Conference Session 2024 - WebSphere sMash Integration, PHP wi...IBM IMPACT 2009 Conference Session 2024 - WebSphere sMash Integration, PHP wi...
IBM IMPACT 2009 Conference Session 2024 - WebSphere sMash Integration, PHP wi...Robert Nicholson
 
Accelerating Innovation with Java: The Future is Today
Accelerating Innovation with Java: The Future is TodayAccelerating Innovation with Java: The Future is Today
Accelerating Innovation with Java: The Future is TodayJohn Duimovich
 
2011-03-15 Lockheed Martin Open Source Day
2011-03-15 Lockheed Martin Open Source Day2011-03-15 Lockheed Martin Open Source Day
2011-03-15 Lockheed Martin Open Source DayShawn Wells
 
Wicket Introduction
Wicket IntroductionWicket Introduction
Wicket IntroductionEyal Golan
 
Eclipse + Maven + OSGi has never been so easy - Atllia Kiss
Eclipse + Maven + OSGi has never been so easy - Atllia KissEclipse + Maven + OSGi has never been so easy - Atllia Kiss
Eclipse + Maven + OSGi has never been so easy - Atllia Kissmfrancis
 
Ekon20 mORMot SOA Delphi Conference
Ekon20 mORMot SOA Delphi Conference Ekon20 mORMot SOA Delphi Conference
Ekon20 mORMot SOA Delphi Conference Arnaud Bouchez
 
Why a DevOps approach is critical to achieve digital transformation
Why a DevOps approach is critical to achieve digital transformationWhy a DevOps approach is critical to achieve digital transformation
Why a DevOps approach is critical to achieve digital transformationAgileSparks
 
OSGi & Java in Industrial IoT - More than a Solid Trend - Essential to Scale ...
OSGi & Java in Industrial IoT - More than a Solid Trend - Essential to Scale ...OSGi & Java in Industrial IoT - More than a Solid Trend - Essential to Scale ...
OSGi & Java in Industrial IoT - More than a Solid Trend - Essential to Scale ...mfrancis
 
PHP, Java EE & .NET Comparison
PHP, Java EE & .NET ComparisonPHP, Java EE & .NET Comparison
PHP, Java EE & .NET ComparisonHaim Michael
 
OOW16 - Migrating and Managing Customizations for Oracle E-Business Suite 12....
OOW16 - Migrating and Managing Customizations for Oracle E-Business Suite 12....OOW16 - Migrating and Managing Customizations for Oracle E-Business Suite 12....
OOW16 - Migrating and Managing Customizations for Oracle E-Business Suite 12....vasuballa
 

Destacado (20)

Introduction to Java Enterprise Edition
Introduction to Java Enterprise EditionIntroduction to Java Enterprise Edition
Introduction to Java Enterprise Edition
 
J2ee architecture
J2ee architectureJ2ee architecture
J2ee architecture
 
J2EE Introduction
J2EE IntroductionJ2EE Introduction
J2EE Introduction
 
Enterprise Java Beans - EJB
Enterprise Java Beans - EJBEnterprise Java Beans - EJB
Enterprise Java Beans - EJB
 
EJB .
EJB .EJB .
EJB .
 
Lecture 04 - Loose Coupling
Lecture 04 - Loose CouplingLecture 04 - Loose Coupling
Lecture 04 - Loose Coupling
 
Languages formanandmachine
Languages formanandmachineLanguages formanandmachine
Languages formanandmachine
 
Final Presentation
Final PresentationFinal Presentation
Final Presentation
 
3.1 oracle salonika
3.1 oracle salonika3.1 oracle salonika
3.1 oracle salonika
 
IBM IMPACT 2009 Conference Session 2024 - WebSphere sMash Integration, PHP wi...
IBM IMPACT 2009 Conference Session 2024 - WebSphere sMash Integration, PHP wi...IBM IMPACT 2009 Conference Session 2024 - WebSphere sMash Integration, PHP wi...
IBM IMPACT 2009 Conference Session 2024 - WebSphere sMash Integration, PHP wi...
 
Accelerating Innovation with Java: The Future is Today
Accelerating Innovation with Java: The Future is TodayAccelerating Innovation with Java: The Future is Today
Accelerating Innovation with Java: The Future is Today
 
2011-03-15 Lockheed Martin Open Source Day
2011-03-15 Lockheed Martin Open Source Day2011-03-15 Lockheed Martin Open Source Day
2011-03-15 Lockheed Martin Open Source Day
 
Wicket Introduction
Wicket IntroductionWicket Introduction
Wicket Introduction
 
Eclipse + Maven + OSGi has never been so easy - Atllia Kiss
Eclipse + Maven + OSGi has never been so easy - Atllia KissEclipse + Maven + OSGi has never been so easy - Atllia Kiss
Eclipse + Maven + OSGi has never been so easy - Atllia Kiss
 
Ekon20 mORMot SOA Delphi Conference
Ekon20 mORMot SOA Delphi Conference Ekon20 mORMot SOA Delphi Conference
Ekon20 mORMot SOA Delphi Conference
 
EJB 2
EJB 2EJB 2
EJB 2
 
Why a DevOps approach is critical to achieve digital transformation
Why a DevOps approach is critical to achieve digital transformationWhy a DevOps approach is critical to achieve digital transformation
Why a DevOps approach is critical to achieve digital transformation
 
OSGi & Java in Industrial IoT - More than a Solid Trend - Essential to Scale ...
OSGi & Java in Industrial IoT - More than a Solid Trend - Essential to Scale ...OSGi & Java in Industrial IoT - More than a Solid Trend - Essential to Scale ...
OSGi & Java in Industrial IoT - More than a Solid Trend - Essential to Scale ...
 
PHP, Java EE & .NET Comparison
PHP, Java EE & .NET ComparisonPHP, Java EE & .NET Comparison
PHP, Java EE & .NET Comparison
 
OOW16 - Migrating and Managing Customizations for Oracle E-Business Suite 12....
OOW16 - Migrating and Managing Customizations for Oracle E-Business Suite 12....OOW16 - Migrating and Managing Customizations for Oracle E-Business Suite 12....
OOW16 - Migrating and Managing Customizations for Oracle E-Business Suite 12....
 

Similar a Java Enterprise Edition

Similar a Java Enterprise Edition (20)

java basic for begginers
java basic for begginersjava basic for begginers
java basic for begginers
 
Core Java
Core JavaCore Java
Core Java
 
Java Programming concept
Java Programming concept Java Programming concept
Java Programming concept
 
Letest
LetestLetest
Letest
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
 
The State of the Veil Framework
The State of the Veil FrameworkThe State of the Veil Framework
The State of the Veil Framework
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
 
All experiment of java
All experiment of javaAll experiment of java
All experiment of java
 
Adv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdfAdv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdf
 
React native
React nativeReact native
React native
 
OOP-Chap2.docx
OOP-Chap2.docxOOP-Chap2.docx
OOP-Chap2.docx
 
Java lab-manual
Java lab-manualJava lab-manual
Java lab-manual
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to Java
 
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
 
Javascript
JavascriptJavascript
Javascript
 
Core java &collections
Core java &collectionsCore java &collections
Core java &collections
 
Core java1
Core java1Core java1
Core java1
 
Core java
Core java Core java
Core java
 

Último

Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics
 

Último (20)

Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024
 

Java Enterprise Edition

  • 2. Agenda: ● Introduction to Java ○ About Java ○ Java vs C# ● Java EE platform ○ Java EE Components (web, business) ○ Java EE server ○ Enterprise JavaBeans ○ Servlet ○ JavaServer Faces ○ Session Bean Goal: Overview of Java EE Technology
  • 3. Java: History ● June 1991: James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project, in Sun Microsystem ● 1995: Sun Microsystem released first public implementation. It promised “Write Once, Run Anywhere” ○ Major web browsers soon incorporated the ability to run Java applets ● December 1998: Java 2 released: ○ J2EE includes api for enterprise applications running in server environments ○ J2ME includes api for mobile applications ○ JSE for desktop environments ● November 13, 2006: Sun released much of Java as free and open-source project, under GPL ● January 27, 2010: Oracle acquired Sun. The Oracle implementation is packaged into two different distributions: ○ Java Runtime Environment (JRE), intended for end users ○ Java Development Kit (JDK), intended for software developers http://en.wikipedia.org/wiki/Java_(programming_language)
  • 4. About the Java Technology ● javac compiler: compile source files into .class files ● a .class file contains bytecode ● bytecode is the machine language for Java Virtual Machine ● java launcher tool runs the application
  • 5. About the Java Technology ● Java VM is available on many different operating system
  • 6. The Java Platform ● The Java Virtual Machine ● The Java Application Programming Interface (API) The API is a large collection of ready-made software components that provide many useful capabilities (packages)
  • 7. Package ● a package is a group of related types providing access protection and namespace management ● package name are written in all lower case to avoid conflict with names of classes or interfaces ● companies use their reverse Internet domain name In Java the directory structure should match the package structure. No such restriction in C#
  • 8. Java vs C#: Declaring Constants Java: ● In Java, compile-time constant value are declared inside a class as static final int K = 100; C#: ● in C# the keyword const is used for compile time constants, while the readonly keyword is used for runtime constants. const final int K = 100; readonly int aField;
  • 9. Java class Test { final int afield = 5; final int workday = 256; ... int getAfield() { return afield; } } //set method is not allowed for both finals //cannot be written to by a constructor Java vs C#: Declaring Constants C# class Test { readonly int afield; const byte workday = 256; Test(int n) { afield = n; } ... int getAfield() { return afield; } } //set method is not allowed for both. //readonly can only be written to by a constructor
  • 10. Java vs C#: Inheritance Java: class B extends A implements Comparable { … ... } C#: class B : A, IComparable { … ... }
  • 11. Polymorphism and Overriding ● In Java all methods are virtual ● In C# you must explicitily state which methods are virtual using System; public class Parent { public virtual void DoStuff(string str) { … } } public class Child : Parent { public override void DoStuff(string str) { … } } public new void DoStuff(string str)
  • 12. Multiple classes in a Single File ● In Java, only one class per source file with public access (it must have the same name of the source file) ● C# doesn’t have restriction on the number of public classes that can exist in a source file
  • 13. Importing libraries ● C#: using keyword using System; using System.IO; using System.Reflection; ● Java: import keyword import java.util.*; import java.io.*;
  • 14. Enumerations C# public enum Direction { North = 1, East = 2, West = 3, South = 4 }; Usage: Direction wall = Direction. North; Java public enum Planet { MERCURY (3.303e+23, 2.4397e6), VENUS (4.869e+24, 6.0518e6), EARTH (5.976e+24, 6.37814e6), MARS (6.421e+23, 3.3972e6), JUPITER (1.9e+27, 7.1492e7), SATURN (5.688e+26, 6.0268e7), URANUS (8.686e+25, 2.5559e7), NEPTUNE (1.024e+26, 2.4746e7); private final double mass; // in kilograms private final double radius; // in meters Planet(double mass, double radius) { this.mass = mass; this.radius = radius; } private double mass() { return mass; } private double radius() { return radius; } }
  • 15. Properties Java public int getSize() { return size; } public void setSize(int val) { size = val; } C# public int Size { get { return size; } set { size = value; } }
  • 16. Pass by Reference ● In Java the arguments to a method are passed by value ● In C# it is possibile to specify the arguments by reference: ref and out keywords ChangeMe(out param); Swap(ref a, ref b);
  • 17. Delegate ● In C# delegate are reference types which allow to indirect calls to method ● There is no delegate concept in Java (it may be mimiced with reflection)
  • 18. Delegate C# using System; using System.IO; public class DelegateTest { public delegate void Print (String s); public static void Main() { Print s = new Print (toConsole); Print v = new Print (toFile); Display (s); Display (v); } public static void toConsole (String str) { Console.WriteLine(str); } public static void toFile (String s) { File f = new File("delegate.txt"); StreamWriter fileOut = f.CreateText(); fileOut.WriteLine(s); fileOut.Flush(); fileOut.Close(); } public static void Display(Print pMethod) { pMethod("This should be displayed in the console"); } }
  • 19. Event Handling: C# using System; using System.Drawing; using System.Windows.Forms; // custom delegate public delegate void StartDelegate(); class EventDemo : Form { // custom event public event StartDelegate StartEvent; public EventDemo() { Button clickMe = new Button(); // an EventHandler delegate is assigned // to the button's Click event clickMe.Click += new EventHandler(OnClickMeClicked); // our custom "StartDelegate" delegate is assigned // to our custom "StartEvent" event. StartEvent += new StartDelegate(OnStartEvent); // fire our custom event StartEvent(); } // this method is called when the "clickMe" button is pressed public void OnClickMeClicked(object sender, EventArgs ea) { MessageBox.Show("You Clicked My Button!"); } // this method is called when the "StartEvent" Event is fired public void OnStartEvent() { MessageBox.Show("I Just Started!"); }
  • 20. Event Handling: Java ● Source: is an object on which event occurs ● Listener: is responsible to generate response to an event Steps involved in event handling ● The User clicks the button and the event is generated. ● Now the object of concerned event class is created automatically and information about the source and the event get populated with in same object. ● Event object is forwarded to the method of registered listener class. ● The method is now get executed and returns. http://en.wikipedia.org/wiki/Observer_pattern
  • 21. Inner and anonymous classes Since the Java language does not permit multiple inheritance, your class cannot extend both the Applet and MouseAdapterclasses. A solution is to define an inner class a class inside of your Applet subclass public class MyClass extends Applet { ... someObject.addMouseListener(new MyAdapter()); ... class MyAdapter extends MouseAdapter { public void mouseClicked(MouseEvent e) { ...//Event listener implementation goes here... } } } When considering whether to use an inner class, keep in mind that application startup time and memory footprint are typically directly proportional to the number of classes you load. The more classes you create, the longer your program takes to start up and the more memory it will take. As an application developer you have to balance this with other design constraints you may have. We are not suggesting you turn your application into a single monolithic class in hopes of cutting down startup time and memory footprint this would lead to unnecessary headaches and maintenance burdens. ● Inner classes can also be useful for event listeners that implement one or more interfaces directly. ● Inner classes work even if your event listener needs access to private instance variables
  • 22. Java - Multithreading ● New: A new thread begins its life cycle in the new state. It remains in this state until the program starts the thread. It is also referred to as a born thread. ● Runnable: After a newly born thread is started, the thread becomes runnable. A thread in this state is considered to be executing its task. ● Waiting: Sometimes, a thread transitions to the waiting state while the thread waits for another thread to perform a task.A thread transitions back to the runnable state only when another thread signals the waiting thread to continue executing. ● Timed waiting: A runnable thread can enter the timed waiting state for a specified interval of time. A thread in this state transitions back to the runnable state when that time interval expires or when the event it is waiting for occurs. ● Terminated: A runnable thread enters the terminated state when it completes its task or otherwise terminates.
  • 23. Java Serializable ● mechanism to represent an object as a sequence of bytes (including object’s data) ○ serialized object can be written in file, … ○ bytes can be used to recreate object in memory ● serialization is JVM indipendent 1. Class must be implement java.io.Serializable interface 2. all the fields in the class must be serializable. If a field is not serializable, it must be marked transient
  • 24. Java EE platform ● large-scale, multi-tiered, scalable, reliable, secure network application ○ Client-tier components run on client (web browser) ○ Web-tier components run on the Java EE server ○ Business-tier components run on the Java EE server ○ Enterprise information system (EIS)-tier runs on the EIS server
  • 25. Java EE Components ● A Java EE component is a self-contained functional software unit The Java EE specification defines the following components: ● Application clients and applet are components that run on client ● Java Servlet, Java Server Faces, JSP are web components that run on server ● Enterprise Java Bean (EJB) components are business components that run on the server Java EE components are assembled into a Java EE application and managed by the Java EE server
  • 26. Java EE clients ● Web Clients ○ Dynamic web pages (Html, Xml, ...) which are generated by web components running in the web tier ○ Web browser, which renders the pages received from the server ● Application Clients ○ runs on client machine ○ graphical user interface (GUI) created from the Swing or AWT API ● Applets ○ small client application running in the Java virtual machine installed in the web browser
  • 27. Java EE web components ● servlet or web pages created using JSF and/or JSP. ● Servlets are Java classes that dynamically process requests and construct response
  • 28. Business components ● Business code is handled by enterprise bean running in either the web tier or the business tier ● The EIS tier include enterprise infrastructure system: database systems, mainframes
  • 29. Business tier ● Enterprise Java Bean (EJB): encapsulate the core functionality of application. ● JAX-RS RESTful web services: REST API for creating web services that respond to HTTP methods ● JAX-WS web sercice endpoints: api for creating and consuming SOAP web services ● Java Persistence API entities: api for processing data in data stores and mapping that to JAVA programming ● Java EE managed beans: managed components that may provide business logic, but do not require the transactional or security features of EJB
  • 30. Java EE server ● A Java EE server, also called applicaton server, hosts several application component and provides the standard Java EE services in the form of container ○ Java EE container: interface between a component and the low-level platform-specific that support the component. ■ provides services like security, transaction management, JNDI API lookups, remote connectivity… ● A Java EE server provides EJB and web containers
  • 31. Container ● Enterprise JavaBeans (EJB) container: manages the execution of enterprise beans, run on the Java EE server ● Web container: manages the executes of web pages, run on the Java EE server ● Application client container: manages the execution of application client components, run on the client ● Applet container: manages the execution of the applet. Consists of a web browser and Java Plug-in
  • 32. Packaging Applications ● A Java EE app is delivered in a Java Archive (JAR) file, a Web Archive (WAR) file or an Enterprise Archive (EAR) file. ● Using JAR, WAR and EAR files and modules makes it possibile to assemble different JEE applications. ● An EAR file contains J2EE modules (optionally) and deployment descriptors. ○ A deployment descriptor is an XML document that describes the deployment settings of an application, or module, or a component.
  • 33. Java EE module ● A Java EE module consists of one or more Java EE component for the same container type ○ EJB modules, wich contains class files for Enterprise Java Beans (.jar) ○ Web modules, which contains servlet class files, web files, HTML files, ecc. (.war) ○ Resource adapter modules, which contains classes, libraries, ecc. (.jar)
  • 35. Java EE Web Module ● the smallest deployable and usable unit of resources ● contains: ○ web components ○ web resources (image, ...) ○ classes utility
  • 36. Servlet ● client send an HTTP request to the server ● a web server, implementing a Java Servlet and JSP,* converts the request into a HTTPServletRequest object ● this object is delivered to a web component, which can interact with Java Bean component or database ● the web component generates an HTTPServletResponse object ● the web server converts it into an HTTP Response Servlet are Java classes that dinamically process the request and construct response. Configuration info can be specified using JAVA EE annotation or via XML file (web application deployment descriptor) http://docs.oracle.com/javaee/6/tutorial/doc/geysj.html
  • 37. JavaServer Faces ● JSF is a server-side component framework ○ api for representing component and managing state, handling event, validation, data-conversion, page navigation… ○ tag libraries for adding components to web pages and connecting to server-side objects A typial JSF applications includes: ● a set of web pages ● a set of tags to add components to the web page ● a set of managed bean ● a web deployment descriptor (web.xml) ● optionally, one or more configuration files (faces.config.xml), used to define page navigation rules and configure beans ● optionally, a set of custom objects: validators, converters, listeners, ecc… - JSF offers clean separation from behavior and presentation for web applications. - A JSF application can map an HTTP request to a component-specific event handling and manage component as stateful objects on the server http://javaserverfaces.java.net/
  • 38. Enterprise JavaBeans ● EJB is a server side component that encapsulates the business logic Types of Enterprise Beans: ● A session bean rapresents a transient conversation with the client. ○ stateful bean: business object having state. Access is limited to one client at a time. ○ stateless bean: business object that don’t have a state. Access to a single bean instance is limited to only one client at a time (the container routes a request to a different instance) ○ singleton bean: business object having a global shared state whithin a JVM
  • 39. Enterprise JavaBeans ● Message Driven Bean: business objects whose execution is triggered by messages instead of method calls. The message driven bean is used to provide an abstraction for the lower level JMS EJBs are deployed in an EJB container. ● Clients not instantiate them directly, but have to obtain a reference via the EJB container. ○ through dependency injection ○ using annotation ○ using JNDI lookup
  • 40. Session Bean ● encapsulate business logic than can be invoked by a client over local, remote or web services. ● stateful session bean: the client interacts (talks) whith its bean (conversional state). It is not shared, it can have only one client ● stateless session bean: does not mantain a conversional state with the client. When the client invokes a method, the bean’s instance variable may contain a state specific to that client but only for the duration of invocation. All instance of a stateless bean are equivalent, allowing the EJB container to assign an instance to any client. Because they support many clients, stateless bean can offer better scalability ● singleton session bean: is instantied once per application and exists for all the lifecycle.
  • 41. Message-driven Bean ● is an enterprise bean that allows the Java EE applications to process messages asynchronously. ● receives JMS messages (or other kind of messages) ● it resemble a stateless sesson bean: ○ no data or conversational state for a specific client ○ all instances of MdB are equivalent ○ a single MdB can process messages from multiple clients When a message arrives, the container calls the message-driven bean’s onMessage method to process the message.
  • 42. Enterprise Beans ● Enterprise Beans are Java EE components that implements the Enterprise JavaBeans (EJB) technology ● run on the EJB container ● encapsulate the business logic ● simplify the development of large and distributed applications ● EJB container is responsible for system-level services, such as transactions and security authorization Two types of enterprise beans: - session - message driven
  • 43. Accessing Enterprise Beans Clients can obtain a reference to an instance of a bean through: ● dependency injection, using Java annotations (javax.ejb.EJB) ● JNDI lookup, using the Java Naming and Directory Interface syntax JNDI: is a Java api that allows clients to discover and lookup data or objects via a name. It provides: ● a mechanism to bind an object to a name ● a directory-lookup interface that allows general queries ● an event interface that allows clients to determine which directory entries has been modified ● LDAP extensions… JNDI is composed of five packages: ● javax.naming ● javax.naming.directory ● javax.naming.event ● javax.naming.ldap ● javax.naming.spi
  • 44. Lookup enterprise beans Three namespaces are used for JNDI lookups: ● java:global: to find remote enterprise bean using lookups java:global[/application name]/module name/enterprise bean name[/interface name] ● java:module: to lookup local enterprise beans whithin the same module java:module/enterprise bean name/[interface name] ● java:app: to lookup local enterprise bean packaged withind the same application java:app[/module name]/enterprise bean name[/interface name] For example, if an enterprise bean, MyBean, is packaged within the web application archive myApp.war, the module name is myApp. The portable JNDI name is java:module/MyBean An equivalent JNDI name using the java:global namespace is java:global/myApp/MyBean.
  • 45. Remote or Local Access ● Tight or loose coupling of related beans: when a bean depends on one another. They are good candidates for local access ● Type of client: if an enterprise bean is accessed by application clients, it should allow remote access. If an enterprise bean is accessed only by other beans, think on how you want to distribute your components ● Component distribution: Java EE applications are scalable because their server-side components can be distributed across multiple machines ● Performance: remote calls may be slower than local calls
  • 46. Remote or Local access ● Define remote or local access: //@Local or @Remote (@Local is default) @Local(InterfaceName.class) public class BeanName implements InterfaceName { ... } ● Accessing local beans ○ use the javax.ejb.EJB annotation @EJB ExampleBean exampleBean; ○ use the javax.naming.InitialContext interface’s lookup method ExampleBean exampleBean = (ExampleBean) InitialContext.lookup("java:module/ExampleBean"); Accessing remote beans @EJB Example example; ExampleRemote example = (ExampleRemote) InitialContext.lookup("java:global/myApp/ExampleRemote");
  • 47. Contents of an Enterprise Bean ● Enterprise bean class: implements the business methods of the enterprise bean ● Business interfaces: not required if the enterprise bean expose a local, no-interface view ● Helper classes: other classes needed by bean (utility classes, exception, ...) Packaging Enteprise Beans in EJB JAR modules: ● to assemble a Java EE application, package one or more modules, such as EJB jars, into an EAR file. You can also deploy EJB Jar not contained in an EAR file Packaging Enterprise Beans in WAR modules: ● to include enterprise bean class files in WAR module, the class should be in the WEB-INF/classes directory ● to include a JAR containing enterprise beans in a WAR module, add the JAR to the WEB-INF/lib directory of the WAR module
  • 48. Lifecycle of Enterprise Beans ● Stateful Session Bean’s Lifecycle ○ client obtaines a reference to a stateful session bean ○ the container perform dependency injection ○ the c. invokes the method annotated with @PostConstruct ○ the EJB container may decided to deactivate, or passivate, the bean by moving it from memory to a secondary storage ○ client invokes a method annotated @Remove ○ EJB container calls @PreDestroy ○ Bean’s instance is ready for garbage collection ● Stateless Session Bean’s Lifecycle ● stateless session bean is never passivated ● EJB container creates and mantains a pool of stateless beans
  • 49. Lifecycle of Enterprise Beans ● Singleton Session Bean’s Lifecycle ○ EJB container creates the singleton instance ○ at the end, EJB container calls the method annotated @PreDestroy, if it exists ● Message-Driven Bean’s Lifecycle ● EJB container creates and mantains a pool of message-driven beans ● like a stateless bean, it is never passivated, and only has two states: non existent and ready to receive message
  • 50. JAX-RS: Java api for RESTful WS ● RESTful web service are built to work best on the web ● JAX-RS: api that provides support in creating web services rest ● developers decorate Java class files with JAX-RS annotations ○ @Path: indicating where the Java class will be host ○ @GET: Java method annotated with this will process HTTP GET requests ○ @POST ○ @PUT ○ @DELETE ○ . ○ . …. import javax.ws.rs.GET; import javax.ws.rs.Produces; import javax.ws.rs.Path; // The Java class will be hosted at the URI path "/helloworld" @Path("/helloworld") public class HelloWorldResource { // The Java method will process HTTP GET requests @GET // The Java method will produce content identified by the MIME Media // type "text/plain" @Produces("text/plain") public String getClichedMessage() { // Return some cliched textual content return "Hello World"; } }