🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

EAD-2 SHORT NOTE INTRODUCTION TO ENTERPRISE APPLICATION DEVELOPMENT Java Virtual Machine (JVM) Interprets bytecode into machine code specific to the underlying OS and hardware Reads bytecode and executes it, without knowledge of the original Java program Platform-dependent, wi...

EAD-2 SHORT NOTE INTRODUCTION TO ENTERPRISE APPLICATION DEVELOPMENT Java Virtual Machine (JVM) Interprets bytecode into machine code specific to the underlying OS and hardware Reads bytecode and executes it, without knowledge of the original Java program Platform-dependent, with different implementations for different OSes Enables platform-independent Java bytecode to run consistently across systems Just-In-Time (JIT) Compilation Part of the JVM architecture that compiles bytecode to machine code at runtime Compiles only the code that is needed, on demand, to boost performance Avoids compiling the entire bytecode upfront, which would significantly delay execution Java Runtime Environment (JRE) 1. Software package that includes the JVM and Java API libraries 2. Provides the environment to execute Java programs on a computer 3. Consists of the JVM, Java APIs (e.g., util, math, lang, awt, swing), and runtime libraries Java Development Kit (JDK) Set of development tools for writing and compiling Java programs Includes the JRE plus additional libraries and tools for development Enables developers to create, compile, and run Java applications Advantages of Java Simple: Easy to learn and use due to its clear syntax and structure. Object-Oriented: Promotes code reusability and modularity through encapsulation, inheritance, and polymorphism. Distributed: Facilitates the development of applications that can run on multiple systems across a network. Interpreted: Allows for platform independence by executing bytecode on any system with a JVM. Robust: Strong memory management and exception handling provide reliability and stability in applications. Secure: Built-in security features protect against threats, making it suitable for networked environments. Architecture-Neutral: Bytecode can run on any platform without modification, ensuring compatibility. Portable: Java applications can be easily moved between different environments without changes. Performance: Just-In-Time (JIT) compilation and optimizations improve execution speed and efficiency. Multithreaded: Supports concurrent execution of multiple threads, enhancing application performance and responsiveness. Dynamic: Capable of adapting to changing environments and loading classes at runtime. Java Platforms A platform is any hardware or software that works as an environment to host an application or a service. In Java, there are 3 main such platforms. Java Platform, Standard Edition (Java SE): The Java Standard Edition is the core platform for developing standalone applications and contains essential libraries and APIs for Java programming. Java Platform, Enterprise Edition (Java EE): The Java Enterprise Edition builds on Java SE and provides additional libraries and APIs for developing large-scale, distributed, and enterprise- level applications. Java Platform, Micro Edition (Java ME): The Java Micro Edition is a subset of Java SE designed for developing applications on mobile devices and embedded systems, focusing on resource- constrained environments. Enterprise Applications An enterprise Application is a computer software that is used to satisfy the needs of organizations such as businesses, schools, interest-based user groups, clubs, charities and governments. The Java EE platform is designed to reduce the complexity of enterprise application development by providing a development model, API, and runtime environment that allows developers to concentrate on functionality. Common Characteristics of Enterprise Applications Distributed: Enterprise applications are often spread across multiple servers and locations, allowing for better resource utilization and load balancing. Multi-tiered: These applications are structured in layers, typically separating the presentation, business logic, and data access layers to enhance maintainability and scalability. Scalable: Enterprise applications can efficiently handle increased loads by adding resources without significant changes to the architecture. Complex: They often involve intricate business logic, multiple integrations, and interactions with various systems, making them sophisticated in nature. Mission-critical: Enterprise applications are essential for business operations, and their failure can significantly impact organizational performance and continuity. Transactional: They support complex transactions that require data integrity and consistency, often utilizing ACID properties to ensure reliable processing. Secure: Enterprise applications incorporate robust security measures to protect sensitive data and ensure compliance with regulations and standards. Enterprise Application Architecture Here is how the enterprise application architecture works when a simple request is created. 1. A request originates from the client side, either via a web browser or an application client. 2. The request travels over the network to the J2EE Server. 3. If it's a web request, it arrives at the Web Container first. 4. The Web Container determines which Servlet or JSP should handle the request. 5. The Servlet or JSP processes the initial request, potentially preparing data or performing preliminary logic. 6. If complex business logic is required, the Web Container component reaches out to the EJB Container. 7. An appropriate Enterprise Bean in the EJB Container is activated to handle the business logic. 8. The Enterprise Bean may need to interact with the database to retrieve or update information. 9. Database operations are performed, and results are returned to the Enterprise Bean. 10. The Enterprise Bean completes its processing and returns results to the calling component in the Web Container. 11. The Web Container component (Servlet or JSP) receives the results and prepares the final response. 12. For web requests, the response is typically formatted as HTML or another web-friendly format. 13. The prepared response is sent back through the network to the originating client. 14. If it was a browser request, the page is rendered in the user's browser. 15. For application client requests, the response is processed by the client application. 16. Throughout this process, the J2EE Server manages resources, handles security, and ensures proper execution of all components. 17. The system remains ready to handle the next incoming request, maintaining stateful information if necessary. Here are the explanations of the terms used in the diagram. Client Machine: o Browser: A web browser used to access web-based applications. o Application Client: A standalone Java application that runs on the client machine. o Application Client Container: Manages the execution of application clients. J2EE Server: The core of the enterprise application, hosting various components. o Web Container: Manages web components like Servlets and JSP pages. ▪ Servlet: Java classes that handle requests and generate dynamic content. ▪ JSP Page: Java Server Pages, allowing Java code to be embedded in HTML. o EJB Container: Manages Enterprise JavaBeans (EJBs). ▪ Enterprise Bean: Server-side components for modular construction of enterprise applications. Database: Stores persistent data for the application. Servers A server is a computer program or machine that responds to requests from clients over a network. There are many types of servers, with the most popular being: Web Server Application Server FTP Server Online Game Server Web Server vs. Application Server Feature Web Server Application Server Purpose Delivers web pages to clients Provides a platform for running applications and business logic Content Serves static content Handles dynamic content and business logic Protocols Uses HTTP Uses protocols like RMI or IIOP Examples Apache HTTP Server, Nginx Apache Tomcat, JBoss, WebLogic Java EE Servers And Containers Java EE server: The runtime portion of a Java EE product. A Java EE server provides EJB and web containers. EJB container: Manages the execution of enterprise beans for Java EE applications. Enterprise beans and their container run on the Java EE server. Web container: Manages the execution of web pages, servlets, and some EJB components for Java EE applications. Web components and their container run on the Java EE server. Application client container: Manages the execution of application client components. Application clients and their container run on the client. Applet container: Manages the execution of applets. Consists of a web browser and a Java Plug- in running on the client together. Java EE Services Messaging: The Java Message Service (JMS) provides asynchronous messaging between disparate parts of your applications. Transaction: Provided by the Java Transaction API (JTA) implementation. Persistence: Offered by the Java Persistence API (JPA) which drives Object Relational Mapping (ORM) and an abstraction for the Database operations. Web service: JAXRS and JAXWS provide support for REST and SOAP style services respectively. Contexts & Dependency Injection: CDI provides loosely coupled and type safe injection of resources. Java EE Benefits High availability Scalability Integration with existing systems Freedom to choose vendors of application servers, tools, components Multi-platform Flexibility of scenarios and support to several types of clients Programming productivity INTRODUCTION TO SERVLETS A servlet is a Java component that can be plugged into a Java enabled web server to provide custom services. Servlet Container A servlet container (also known as a web container) is the component of a web server that interacts with Java servlets. A web container is responsible for managing the lifecycle of servlets. Example: Apache Tomcat is an open-source web container. Servlet Life Cycle The servlet life cycle refers to the process by which a servlet is loaded, initialized, executed to handle client requests, and finally destroyed by the web server, managed through its key methods. Main Methods: o init(): This method is called by the servlet container to initialize the servlet instance, allowing it to perform any required setup before handling requests. It is invoked only once during the servlet's lifecycle. o service(): The core method that handles client requests. It receives ServletRequest and ServletResponse objects, processes the request, and generates the appropriate response. This method can delegate to specific methods like doGet() or doPost() based on the type of HTTP request. o destroy(): This method is called when the servlet is being taken out of service, allowing it to release resources and perform cleanup operations. It is invoked only once at the end of the servlet's lifecycle. Ancillary Methods: o getServletConfig(): Returns a ServletConfig object that contains initialization parameters and servlet-specific configuration information. o getServletInfo(): Provides a string containing information about the servlet, such as its author, version, and description, which can be useful for documentation and management purposes. Container Handling a Dynamic Request The following steps are followed when the container handles a dynamic request. 1. User clicks or type a link that has a URL to a servlet instead of a static page. 2. Container (Apache Tomcat is one of the examples) sees that the request is for servlet , so create two objects named HttpServletRequest & HttpServletResponse. 3. The container finds the correct servlet based on the URL in the request with the help deployment descriptor (web.xml) file, creates or allocates a thread for that request, and passes the request and response objects to the servlet thread. 4. Container calls the servlets service() method, on the type of request, service calls doGet() or doPost() 5. Let us assume that service calls the doGet() method. doGet() () method generates dynamic page and add the page in response object. 6. Thread completes, container converts the response object into HttpResponseobject and destroys the response and request object. HTTP Requests The request sends by the computer to a web server that contains all sorts of potentially interesting information is known as HTTP requests. The HTTP client sends the request to the server in the form of request message which includes following information: The Request-line The source IP address and port The destination IP address, protocol, port, and host The Requested URI (Uniform Resource Identifier) The Http request method and Content There are four main types of HTTP Request methods. Method Description CRUD GET Used to retrieve information from the server using a given URI; should not Read alter any data. POST Asks the server to accept the body information attached; like GET but with Create additional data. PUT Replaces all current representations of the target resource with the Update uploaded content. DELETE Requests the deletion of the resource at the specified URL. Delete HTTP Response After receiving and interpreting a request message, a server responds with an HTTP response message. A Status code Http version Optionally a message-body Content type Actual content There are different types of HTTP status codes that are found, and they can be categorized as follows. Range Response Meaning Common Status Codes and Descriptions 100- Informational 199 200- Client request successful 200: Request was processed normally. 299 300- Client request redirected; 399 further action necessary 400- Client request incomplete 401: Unauthorized (authentication is required and has 499 failed). 403: Forbidden (server understands the request but refuses to authorize it). 404: Not Found (requested resource not found on the server). 405: Method Not Allowed (the method specified in the request is not allowed for the resource). 500- Server error 500: Internal Server Error (the server encountered an 599 unexpected condition). INTRODUCTION TO JAVA SERVER PAGES (JSP) Java Server Pages are HTML pages embedded with pieces of Java code in it. It is an inverse of a Java Servlet. Four different elements are used in constructing JSPs. 1. Scripting Elements 2. Implicit Objects 3. Directives 4. Actions Advantages of JSP Has implicit objects. It is more convenient to write regular HTML than to have plenty of println statements that generate the HTML. Provides implicit/global exception handling mechanism. Provides and additional concept called custom tags development. Suitable for both java and non-java programmer. Increases readability of code because of tags. JSP Architecture JSPs run in two phases 1. Translation Phase: JSP page is compiled into a servlet called JSP Page Implementation class. 2. Execution Phase: In execution phase the compiled JSP is processed. JSP Life Cycle The JSP life cycle consists of three main phases: 1. JSP Initialization (jspInit): This phase occurs when the JSP page is first requested. The servlet container initializes the JSP by creating an instance of the JSP servlet and calling the jspInit() method, where any required initialization tasks can be performed, such as loading resources or setting up configuration parameters. 2. JSP Execution (_jspService): In this phase, the servlet container processes client requests by invoking the _jspService() method. This method handles all incoming requests and generates dynamic content by executing the JSP code. It can respond to multiple requests concurrently, making it efficient for handling user interactions. 3. JSP Cleanup (jspDestroy): When the JSP page is no longer needed, typically when the web application is being shut down or the JSP is being recompiled, the servlet container calls the jspDestroy() method. This phase allows the JSP to release any resources it has acquired during its execution, ensuring proper cleanup and resource management. JSP Scripting Elements (Tags) Tag Example Usage Comment Used to add comments to the JSP page. These comments are not visible in the generated HTML output. Directive Used to provide instructions to the JSP container. Directives include page, include, and taglib. For example: Declaration Used to declare variables, methods, or classes that can be used throughout the JSP page. Declarations are placed outside the _jspService() method. Scriptlet Used to insert Java code snippets that are executed at runtime. Scriptlets can contain any valid Java statements, including loops, conditional statements, and method calls. Expression Used to insert the value of a Java expression that is evaluated at runtime. The result of the expression is converted to a string and inserted into the output stream. Types of JSP Directives JSP directives provide global information about an entire JSP page and can be categorized into three types. Type Purpose Syntax Example Page Defines page-dependent Include Includes the content of another for code reusability. Taglib Declares a tag library to be used Types of Page Directives Language: Defines the server-side scripting language (default is Java). Extends: Declares the class that the servlet compiled from the JSP needs to extend. Import: Declares the packages and classes to be imported for use in the Java code (comma- separated). Session: Indicates whether the session implicit variable is allowed (default is true). Buffer: Defines the buffer size of the JSP in kilobytes; if set to none, no buffering is done. autoFlush: When true, the buffer is flushed when the maximum buffer size is reached; if false, an exception is thrown. isThreadSafe: Indicates whether the compiled servlet implements the SingleThreadModel interface (default is true). Info: Provides a string returned by the getServletInfo() method of the compiled servlet. errorPage: Defines the relative URI of the web resource to which the response should be forwarded in case of an exception. contentType: Defines the MIME type for the output response (default is text/html). isErrorPage: Indicates if the JSP page is defined as an error page (true if it is). pageEncoding: Defines the character encoding for the JSP page. JSP Implicit Objects JSP Implicit Objects are pre-defined Java objects that the JSP container makes available to developers on each page, allowing them to be accessed directly without explicit declaration. JSP supports nine implicit objects, each serving a specific purpose request: The HttpServletRequest object associated with the client's request. response: The HttpServletResponse object associated with the response sent to the client. out: The PrintWriter object used to send output to the client. session: The HttpSession object associated with the request, allowing session management. application: The ServletContext object associated with the application context. config: The ServletConfig object associated with the JSP page, providing initialization parameters. pageContext: Encapsulates server-specific features for higher performance, including access to other implicit objects. page: A synonym for this, used to call methods defined by the translated servlet class. exception: The Exception object that allows access to exception data in error handling scenarios. JSP Actions JSP actions are processed during the request processing phase, unlike JSP directives, which are processed during translation. Standard actions are supported by Java EE-compliant web servers, while custom actions can be created using tag libraries. The different JSP actions include: 1. jsp:include: Includes a file at the time the page is requested, allowing for modular content. 2. jsp:useBean: Finds or instantiates a JavaBean, enabling the use of reusable components. 3. jsp:setProperty: Sets the property of a JavaBean, allowing for dynamic data manipulation. 4. jsp:getProperty: Inserts the property of a JavaBean into the output, facilitating data display. 5. jsp:forward: Forwards the requester to a new page, redirecting the flow of control. 6. jsp:plugin: Generates browser-specific code that creates an OBJECT or EMBED tag for the Java plugin. 7. jsp:element: Defines XML elements dynamically, enhancing the flexibility of JSP pages. 8. jsp:attribute: Defines attributes for dynamically defined XML elements, allowing for customization. 9. jsp:body: Defines the body for dynamically defined XML elements, enabling structured content. 10. jsp:text: Used to write template text in JSP pages and documents, simplifying static content inclusion. MVC (Model-View-Controller) MVC is a design pattern used in software development to separate an application into three interconnected components, enhancing modularity and maintainability: 1. Model: The Model represents the data and business logic of the application. It manages the data used to generate output through Views and is responsible for retrieving, storing, and processing data. 2. View: The View is the presentation layer of the MVC framework, serving as the user interface. It consists of templates that define how data is displayed to the user, typically using HTML, CSS, and JavaScript. 3. Controller: The Controller acts as an intermediary between the Model and the View. It handles user requests, processes input data, and determines the appropriate response by selecting the relevant View and Model. Controllers manage the flow of the application, ensuring that user interactions are appropriately handled. Framework A framework, or software framework, is a platform for developing software applications. It provides a foundation on which software developers can build programs for a specific platform. Advantages of Using a Framework Open Source: Most popular frameworks are open source, providing developers with free access to the source code and community contributions. Documentation and Support: Frameworks typically come with comprehensive documentation and community support, making it easier for developers to learn and troubleshoot issues. Reduced Repetitive Code: Frameworks eliminate the need to write repetitive code, allowing developers to focus on unique application features rather than common functionalities. Efficiency: The use of frameworks enhances development efficiency by providing pre-built components and tools, speeding up the development process. Security: Frameworks are often developed and tested by multiple developers, which can lead to a higher level of security through community scrutiny and regular updates. Integration: Frameworks facilitate integration with databases and other tools commonly used in web development, simplifying the process of connecting and communicating with these resources. Enterprise JavaBeans (EJB) Enterprise JavaBeans (EJB) is a specification and framework designed for developing large-scale, distributed business applications on the Java platform. EJB applications require an application server, also known as an EJB Container, such as WildFly, GlassFish, or WebLogic, which provides essential services including: Lifecycle Management: Manages the lifecycle of EJB components. Security: Ensures secure access and operations within the application. Transaction Management: Handles transactions to maintain data integrity. Object Pooling: Optimizes resource management by reusing EJB instances. When to Use Enterprise JavaBeans Remote Access: When the application requires distributed access across different locations. Scalability: EJB supports load balancing, clustering, and failover, making it suitable for scalable applications. Encapsulated Business Logic: EJB separates business logic from the presentation and persistence layers, promoting a clean architecture. Advantages of EJB Reusability: EJBs are reusable components that can be easily integrated into various applications (e.g., Visual Age, Visual Café). Visual Development: EJBs can be combined visually using development IDEs, enhancing productivity. Multithreading: Supports multi-threaded, multiple access code for efficient resource utilization. Database and Network Access: Simplifies database access (e.g., JDBC) and network communication (RMI) for client/server and EJB-to-EJB interactions. Transaction Management: Provides built-in transaction management, reducing the need for manual coding. Convenient Abstractions: EJBs offer well-defined interfaces, allowing for seamless interaction between EJBs from different businesses. EJB Types 1. Session Beans: These are used to perform tasks for a client and can be further categorized into: o Stateless: Do not maintain any client-specific state between method calls. o Stateful: Maintain state across multiple method calls for a specific client. o Singleton: A single shared instance for all clients, maintaining a global state. 2. Entity Beans: Represent persistent data stored in a database, allowing for data manipulation and retrieval. 3. Message-Driven Beans: Asynchronous beans that process messages from a messaging system, enabling decoupled communication between components. Java Message Service (JMS) Java Message Service (JMS) is a Java API that enables applications to create, send, receive, and read messages in a reliable and asynchronous manner. It facilitates communication between distributed components, allowing for loosely coupled interactions. Messaging Domains JMS supports two primary messaging models. Feature Point-to-Point (P2P) Publish/Subscribe (Pub/Sub) Message One producer to one consumer One producer to multiple consumers Delivery Message Messages are stored in a queue Messages are sent to a topic Storage Use Case Task distribution, request/response Event notifications, broadcasting scenarios updates INTRODUCTION TO SPRING Spring is a lightweight, open-source application development framework for Java Enterprise Edition (Java EE). It aims to simplify Java EE development and promote good programming practices. Key points about Spring: Spring is a popular framework used by millions of developers worldwide to create high- performing, easily testable, and reusable code for enterprise applications. It enables developers to build enterprise-class applications using plain old Java objects (POJOs). This allows using a robust servlet container like Tomcat instead of a full EJB container. Spring achieves loose coupling through dependency injection and interface-based programming. It provides an abstraction layer on existing technologies like servlets, JSPs, JDBC, JNDI, RMI, JMS and JavaMail to simplify development. Spring comes bundled with technologies like ORM frameworks and logging frameworks. Benefits of Using Spring 1. Enables POJO-based development: Spring allows building enterprise applications using plain old Java objects (POJOs) without requiring an EJB container. 2. Achieves loose coupling: Spring uses dependency injection and interface-based programming to decouple components. 3. Provides abstraction layers: Spring simplifies development by providing abstraction layers over existing technologies like JDBC, JMS, etc. 4. Comes with bundled technologies: Spring includes popular technologies like ORM frameworks and logging frameworks. 5. Easy to test: The dependency injection feature of Spring makes it easier to test applications without requiring a server, unlike EJB or Struts. 6. Facilitates fast development: Spring's dependency injection and support for various frameworks enable faster development of Java EE applications. Spring Framework Architecture The Spring Framework architecture is modular and designed to provide a comprehensive programming and configuration model for building enterprise applications. It consists of several key modules organized into four main areas: Core Container: o Core Module: Provides the fundamental features of the Spring framework, including Inversion of Control (IoC) and Dependency Injection (DI). o Beans Module: Implements the factory pattern through the BeanFactory, which manages the creation and configuration of beans. o Context Module: Builds on the Core and Beans modules, providing a medium to access and manage application objects through the ApplicationContext interface. o SpEL Module: Offers the Spring Expression Language for querying and manipulating object graphs at runtime. Data Access / Integration: o JDBC Module: Provides an abstraction layer for JDBC, simplifying database access and reducing boilerplate code. o ORM Module: Integrates with popular Object-Relational Mapping (ORM) frameworks like JPA, Hibernate, and iBatis, facilitating data persistence. o OXM Module: Supports Object/XML mapping implementations such as JAXB and XStream, allowing for easy data transformation. o JMS Module: Contains features for producing and consuming messages in a messaging system. o Transaction Module: Supports both programmatic and declarative transaction management for POJOs and classes implementing specific interfaces. Web: o Web Module: Provides integration features for web applications, including multipart file upload and IoC container initialization using servlet listeners. o Web-MVC Module: Implements the Model-View-Controller (MVC) design pattern, allowing for the separation of concerns in web applications. o Web-Socket Module: Supports WebSocket-based communication, enabling two-way interactions between clients and servers. o Web-Portlet Module: Mirrors the functionality of the Web-MVC module for use in portlet environments. Miscellaneous o AOP Module: Implements Aspect-Oriented Programming (AOP), allowing for the separation of cross-cutting concerns like logging and security. o Aspects Module: Provides integration with AspectJ, a powerful AOP framework. o Instrumentation Module: Offers class instrumentation support for certain application servers. o Messaging Module: Supports STOMP as a WebSocket sub-protocol and provides an annotation programming model for message routing and processing. o Test Module: Facilitates testing of Spring components using JUnit or TestNG frameworks. Spring Boot Spring Boot is an open-source Java-based framework developed by Pivotal Team, designed to simplify the creation of microservices and standalone, production-ready Spring applications. It allows developers to get started with minimal configuration, eliminating the need for extensive Spring setup. Advantages of Spring Boot Ease of Development: Spring Boot simplifies the development process, allowing developers to create applications quickly and efficiently. Increased Productivity: The framework reduces development time through auto-configuration and built-in features. Flexible Configuration: It supports various configurations, including Java Beans, XML, and database transactions. Autoconfiguration: Automatically configures components based on the dependencies present in the project, minimizing manual setup. Embedded Servers: Spring Boot includes embedded servlet containers like Tomcat, Jetty, and Undertow, allowing applications to be run as standalone JAR files. Annotation-Based: Facilitates the use of annotations for configuration, reducing the need for XML files. Dependency Management: Simplifies dependency management, making it easier to handle various libraries and frameworks. Batch Processing and REST Management: Provides powerful batch processing capabilities and manages REST endpoints effectively. Why Use Spring Boot? No XML Configuration: Developers can avoid complex XML configurations, streamlining the setup process. Microservices Friendly: Ideal for building microservices-based architectures, enhancing scalability and maintainability. Community Support: A large community and extensive documentation provide resources for learning and troubleshooting. INTRODUCTION TO RESTFUL WEB SERVICES Refer Amila’s Short note INTRODUCTION TO MICROSERVICES Pending

Use Quizgecko on...
Browser
Browser