Give a few Reasons for using Java?

Slides:



Advertisements
Similar presentations
11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
Advertisements

3 Copyright © 2005, Oracle. All rights reserved. Designing J2EE Applications.
Spring, Hibernate and Web Services 13 th September 2014.
JNDI Java Naming Directory Interface JNDI is an API specified in Java that provides naming and directory functionality to applications written in Java.
Inheritance Inheritance Reserved word protected Reserved word super
Introduction to Spring Matt Wheeler. Notes This is a training NOT a presentation Please ask questions Prerequisites – Introduction to Java Stack – Basic.
Notes to the presenter. I would like to thank Jim Waldo, Jon Bostrom, and Dennis Govoni. They helped me put this presentation together for the field.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
© 2005, Cornell University. Rapid Application Development using the Kuali Architecture (Struts, Spring and OJB) A Case Study Bryan Hutchinson
Faculty of Information Technology © Copyright UTS Faculty of Information Technology 2004Design-1 Advanced Java Programming Design issues Chris Wong
Basics of JNDI Alessio Bechini June Naming and Directory Services: Rationale A fundamental element in every application is the capability to find.
JMS Java Message Service Instructor Professor: Charles Tappert By Student: Amr Fouda.
July 23 th, 2005 Software Architecture in Practice RiSE’s Seminars Bass’s et al. Book :: Chapter 16 Fred Durão.
The Spring Framework: A brief introduction to Inversion of Control James Brundege
Intro to Spring CJUG - January What is Spring? “The Spring framework provides central transaction control of various objects.” This means that any.
Struts 2.0 an Overview ( )
Lecture 2 - Struts ENTERPRISE JAVA. 2 Contents  Servlet Deployment  Servlet Filters  Model View Controllers  Struts  Dependency Injection.
Java Frameworks Indy Java Users Group January 29, 2003.
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
Java Beans.
Introduction to the Spring Framework By: Nigusse A. Duguma Kansas State university Department of Computer Science Nov 20, 2007.
Spring Overview, Application demo -Midhila Paineni 09/23/2011 Spring Overview, Application demo9/8/20151.
1 The JNDI ENC and Injection Every EJB container that is deployed in an application server has its own personal internal registry called the Enterprise.
Introduction to the Spring Framework Rajesh. Spring Mission Statement J2EE should be easier to use OO design is more important than any implementation.
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 11 : Frameworks SWE 316: Software Design and Architecture  To understand.
95-843: Service Oriented Architecture 1 Master of Information System Management Service Oriented Architecture Lecture 10: Service Component Architecture.
Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
Introduction to J2EE Architecture Portions by Kunal Mehta.
EJB Framework.  As we know, EJB is the center of the J2EE architecture that provides a sturdy framework for building enterprise applications. The major.
Spring core v3.x Prepared by: Nhan Le. History v3.0 Spring Expression Language Java based bean metadata v3.1 Cache Abstraction Bean Definition Profile.
® IBM Software Group © 2007 IBM Corporation J2EE Web Component Introduction
Spring Framework. Spring Overview Spring is an open source layered Java/J2EE application framework Created by Rod Johnson Based on book “Expert one-on-one.
Introduction to Spring Matt Wheeler. Notes This is a training NOT a presentation Please ask questions Prerequisites – Introduction to Java Stack – Basic.
Webcommerce Computer Networks Webcommerce by Linnea Reppa Douglas Martindale Lev Shalevich.
Source: Peter Eeles, Kelli Houston, and Wojtek Kozaczynsky, Building J2EE Applicationa with the Rational Unified Process, Addison Wesley, 2003 Prepared.
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Sakai Montreal CRIM Workshop Introduction to Spring Framework,
A Presentation By V AIBHAV S AHARAN Web-enHanced Information Management COMS E6125.
Core Indigo Patterns Ted Neward
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Spring Remoting Simplifying.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
Distribution and components. 2 What is the problem? Enterprise computing is Large scale & complex: It supports large scale and complex organisations Spanning.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 8 1COMP9321, 15s2, Week.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Spring and DWR Frameworks for Rich Web Enterprise Application Thomas Wiradikusuma Presentation to the 20 th.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
1 Spring Framework April, 2012 Lam Ho Lam To. © 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 2 1.Spring Overview 2.Framework.
1 Copyright © 2004, Oracle. All rights reserved. Oracle Application Development Framework.
Session Beans Based on: Patel, Brose, Silverman, Mastering Enterprise JavaBeans 3.0.
SCA and Java n SCA provides support for multiple Java-based component implementation types l Java POJOs (implementation.java) l Spring Beans (implementation.spring)
Chapter 3 JSP Overview. The Problem with Servlets processing the request and generating the response are both handled by a single servlet class Java programming.
Enterprise JavaBeans 3.0. What is EJB 3.0 -Reusable server-side component framework-technology -Designed to support building demanding enterprise – level.
Component Patterns – Architecture and Applications with EJB copyright © 2001, MATHEMA AG Component Patterns Architecture and Applications with EJB Markus.
1 Distributed System using J2EE. 2 What is J2EE?  J2EE (Java2 Enterprise Edition) offers a suite of software specification to design, develop, assemble.
Java Servlets and Java Server Pages
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Classes, Interfaces and Packages
EJB Enterprise Java Beans JAVA Enterprise Edition
17 Copyright © 2004, Oracle. All rights reserved. Integrating J2EE Components.
Introduction to Inversion Of Control (IOC). IOC Definition (based on Wikipedia)  Consider the way in which an object obtains references to its dependencies.
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Sakai Montreal CRIM Workshop Introduction to Spring Framework.
Leveraging ColdSpring to build a robust Flex applications Chris Scott, Cynergy Systems.
Enterprise Java Beans. Contents  Understanding EJBs  Practice Section.
J2EE Platform Overview (Application Architecture)
J2EE Lecture 6: Spring – IoC and Dependency Injection
Distribution and components
Introduction to J2EE Architecture
Intro to Spring CJUG - January 2013.
Tuesday Brown Bag Inversion of Control with Howard Abrams
Knowledge Byte In this section, you will learn about:
Presentation transcript:

Give a few Reasons for using Java? Java is a fun language. Let’s look at some of the reasons: Built-in support for multi-threading, socket communication, and memory management (automatic garbage collection). Object Oriented (OO). Better portability than other languages across operating systems. Supports Web based applications (Applet, Servlet, and JSP), distributed applications (sockets, RMI, EJB etc) and network protocols (HTTP, JRMP etc) with the help of extensive standardized APIs (Application Programming Interfaces).

What is spring Spring is an open source,lightweight,loosely Coupled java framework That allows you to build Enterprise applications. By using Spring you can develop various types Like standalone applications,distributed, Webapplications etc…. Spring handles the infrastructure so you can focus on your application. Spring enables you to build applications from "plain old Java objects" (POJOs) and to apply enterprise services non-invasively to POJOs. This capability applies to the Java SE programming model and to full and partial Java EE.

What is a Service Locator? Problem: J2EE makes use of the JNDI interface to access different resources like JDBC, JMS, EJB etc. The client looks up for these resources through the JNDI look-up. The JNDI look-up is expensive because the client needs to get a network connection to the server first. So this look-up process is expensive and redundant. J2EE makes use of the JNDI interface to access different resources like JDBC, JMS, EJB etc. The client looks up for these resources through the JNDI look-up. The JNDI look-up is expensive because the client needs to get a network connection to the server first. So this look-up process is expensive and redundant.

With Service Locator Solution: To avoid this expensive and redundant process, service objects can be cached when a client performs the JNDI look-up for the first time and reuse that service object from the cache for the subsequent look-ups. The service locator pattern implements this technique. Refer to diagram below:

Advantages of ServiceLocator J2EE Design Pattern? expensive and redundant JNDI lookups can be avoided by caching and reusing the already looked up service objects.

Why Dependency Injection What’s wrong here? public class Mechanic { public void fixCar() { PhillipsScrewdriver tool = new PhillipsScrewdriver(); tool.use(); }

Why Dependency Injection public class Mechanic { public void fixCar() { Tool tool = new PhillipsScrewdriver(); tool.use(); }

Why Dependency Injection This one is better compared to above two public class Mechanic { public void fixCar() { ToolFactory tf = ToolFactory.getInstance(); Tool tool = tf.getTool(); tool.use(); }

public class Mechanic { public void fixCar() { InitialContext ctx = null; try { ctx = new InitialContext(); Tool quest = (Tool) ctx.lookup( "java:comp/env/Tool"); tool.use(); } catch (NamingException e) { } finally { if(ctx != null) { try {ctx.close(); } catch (Exception e) {} }

Why Dependency Injection ? In Deveoping huge systems using the Object Oriented programming methodology ,we Generally divide the system into Object’s where each of the Object’s represents Some functionality. In this case ,the Objects in the system use some other objects(dependencies) to complete given Request. The Traditional ways of obtaining the dependcies are by creating the dependencies With new operator and constructors (OR) by pulling the dependencies using some Factory methods (OR) from Naming Registry. But these approaches result in some problems which are described below The complexity of the application increases The development increases the difficulty for unit testing increases To Solve the above problems we have to use a push model.that is ,inject the dependent objects into our object instead of creating (OR) pulling the dependent Objects.

What is DI? The Process of Injecting (pushing) the dependencies into an object (dependent) Object is known as Dependency Injection(DI). This gives some benefits the Application development will become faster Dependency will be reduced(that is it will provide the loose coupling ) DI provides a proper test enviroment.

With DI Constructor DI public class Mechanic { private Tool tool; Setter DI public class Mechanic { private Tool tool; public void setTool(Tool tool) { this.tool = tool; } public void fixCar() { tool.use(); Constructor DI public class Mechanic { private Tool tool; public Mechanic(Tool tool) { this.tool = tool; } public void fixCar() { tool.use();

What is IOC? IoC is also known as dependency injection (DI) IOC is a design principle . IOC is describing an external entity (that is container) used to wire the Object’s Creation time by injecting there dependencies. This is fundamentally the inverse,hence the name Inversion of control(IOC),of the bean It-self being in control of instantiating (OR) locating it’s dependencies on it’s own using direct construction of classes,(OR ) something like the ServiceLocator Pattern.

Types of IOC? IOC is broad concept . IOC is two types 1) dependency lookup 2) dependency injection Dependency lookup is a very old technique. In Dependency lookup container provides Callbacks to components and a lookup context. The managed Object’s are responsible for their Other lookups.This is the EJB Approach. Here we need to use JNDI to look up other EJB’s And resources .There are some problems in this implementation. The class needs an Application Server Environment as it is Depedent on JNDI and it is hard to test as we need to provide a dummy JNDI contest for testing purpose.

In the dependency Injection application Object’s are not responsible for looking up resources they depend on. Instead IOC container configures the object Externalizing resources lookup from application code into the container,t hat is Dependencies are injected into object’s Thus lookups are completely removed from Application object’s and it can be used outside the container also. In this approach,the objects can be populated via Setter injection (OR) constructor injection.

Here a few reasons why a JNDI look up is not Elegant : Why dependency injection is more elegant than a JNDI lookup to decouple client and Service? Here a few reasons why a JNDI look up is not Elegant : The client and service being lookedup must Agree on a string based name. The JNDI lookup code is verbose with it’s own Try-catch block,which is repeated acrosss the application. But DI is more elegant because it promotes loose coupling with minimal effort. Dependency is injected into requesting piece of code by the IOC containers Elegant :- graceful and stylish in appearance (OR)solution to a problem

What is Spring Bean Any java class that are controlled by Spring Container are known as Spring Bean

Which injection is better? Setter injection is always preferable ,because we can change the dependency value any no.of times as we required . But with constructor injection we can’t change dependency object value when we require.

What is BeanFactory? The root interface for accessing a Spring bean container And IT is an implementation of the factory Design pattern. BeanFactory is the actual representation of the Spring IOC ontainer The BeanFactory container instantiate and managed the lifecycle of the beans. That is container manages bean objects – from instantiation to destruction When BeanFactory container is acitivated it does not creates any spring bean class Objects. It creates the spring bean class Objects completes the Dependecy Injection only when the getBean(-) is called. There are a number of implementations of the BeanFactory interface .The most commonly used BeanFactory implementation is the XmlBeanFactory class XmlBeanFactory loads beans based on the definations Contained in an XML File. To create an XMLBeanFactory ,we can pass resource object reference to constructor. The resource will creare an InputStream object.

What is Bean Inheritance? Inheritance is the concept of reusing the existing functionality . In case of java you can inherit a class fom an interface (OR) another class.when you inherit a class from another class,your child (OR) Derived class get’s all the functionalities of Your base class. When it comes to spring Bean Inheritance,it talks about how to reuse the existing bean configuration instead of re-defining again.Let’s consider a scenari where your class contains 5 attributes , if we want to configure it as a spring bean you need to inject values for 5 attributes via constructor (OR) setter injection. If we want to create 20 beans of that class ,we need to configure for all the 20 beans for setter (OR)constructor injection. In case If most of the attributes has same value,even then also we need to re-write the configuration.This leads to dulicate configiration declaration in high amount of maintenance. Example code for bean inheritance :- public class Student{ private int studentId; private String studentName,email,gender; private int age; //setters and getters }

BeanInheritance continue… In order to avoid this you can declare the configuration in one bean which acts as parent bean.And All the remaining 19 bean Declarations can inherit their declaration values from the parent bean,so that we don’t need to repeatedly wirte the same configuration in all the child beans.. In this way if we modify the attribute value in parent bean,it will automatically reflects in all It’s 19 child beans. The child bean can override the inherited value of parent by re-declaring at the child level. myBeans.xml ========= <bean id=“baseStudent” class=“com.nareshit.bean.Student” abstract=“true”> <property name=“studentId” value=“1001”/> <property name=“studentName” value=“rama”/> <property name=“age” value=“25”/> <property name=“email” value=“rama@gmail.com”/> <property name=“gender” value=“Male”/> </bean> <bean id=“childStudent” class=“com.nareshit.bean.Student” parent=“baseStudent”> <property name=“age” value=“27”/> <property name=“gender” value=“M”/> In the above cfg we declared baseStudent as abstract which means spring IOC container will not Instantiate the object for the bean declaration.But it acts as a base bean from it’s property values Will be inherited to child beans

What is collection merging? In spring 2.0 the container supports the collection merging. In this your parent bean can declare a list as parent list.In your child beans you can declare a list with values ,you can inherit the values of your parent list values into your child bean list values .As the list merged with parent list values,this is called Collection merging. public class Course{ private List<String> subjects; //setter and getter } <bean id=“parentCourse” class=“Course” abstract=“true”> <property name=“subjects”> <list><value>c</value> <value>c++</value> <value>java</value></list> </property> <bean id=“childCourse” class=“Course” parent=“parentCourse”> <list merge=“true”> <value>java</value></list> </property>

Bean Aliasing In Spring when you configure a class as bean you will declare an id with which you want to retrieve it back from the container. Along with id you ca attach multiple names to beans, and these names act as alias names with which you can look up the bean from the container. To declare multiple names multiple names You need to declare an “name” attribute at the bean tag level . We can separate multiple names with comma

what is parent and child containers in Spring ? Spring supports setting parent-child relationship between two IoC contains If we have two beanFactory containers in the Application, we can set one BeanFactory into Another beanFactory to allow the beans in one bean factory to refer to the beans of other factory.in this we can declare one beanfactory as a parent and other as a child. This is similar to concept of base class and Derived classes.Derived Class can access the properties of base class,but base classs can not access the properties of derived class. In order to refer to parent beans, we can use tag <ref parent=“ “/> Apart from parent attribute it has local which indicates refer to the local bean.Along with it we have Bean attribute as well,which indicates look in local first if not found then search in parent factory and peform Injection.

Using P& C-Name Space If we want to perform setter injection on a spring bean we need to use <property> tag.Instead of writing length<property> tag declaration under the <bean> tag we can replace with short form of representing the same with p-namespace. In order to use the p-namespace,you first need to import the “htttp:www.springframework.org/schema/p” Name space in the spring bean cfg file. Xmlns:p=“htttp:www.springframework.org/schema/p” Xmlns:c=“htttp:www.springframework.org/schema/c”

Perform the injection as p:propertyname=“value” (OR) Once you have imported it,you have to write the attribute at the <bean> tag level to Perform the injection as p:propertyname=“value” (OR) P:propertyname-ref=“refbean” C-Namespace has been introduced in spring 3.1.1, in order to perform constructor injection we need to use<constructor-arg> tag.instead of writing the length <constructor-arg> tag,we can replace it with c:namespace. The syntax for Writing the C-NameSpace is c:argument=“value” (OR) c:argument-ref=“refbean” public class Student{ private int sid; Private String name; //required setters and getters } myBeans.xml <beans> <bean id=“student1” class=“Student” p:sid=“1001” p:name=“sathish”/> <bean id=“student2” class=“Student” p:sid=“1002” p:name=“ramu”/>