• No results found

Programming in Java

In document Tadm10 1 en Col72 Fv Part Ltr (Page 171-175)

When creating Java programs, the developer first creates a source file in the format

“MyProgram.java” (see the figure Tools of the Java Development Kit).

The Java compiler generates a separate file for each class from the source file that contains the bytecode for this class. The file name is then the name of the class with the extension “.class”, and therefore has the format “MyProgram.class”. In accordance with the object-oriented approach, Java “functions” are grouped in classes. Each Java source file may only contain one public class. The file name of the source file must then be the name of this class (which is case-sensitive) with the extension “.java”.

This bytecode is platform-independent: irrespective of the type of system on which the Java compiler was called, the bytecode can also be executed on any other computer system, at least in the case of “100% pure Java”, which unfortunately cannot be guaranteed for all products.

Unit 3: The System Core TADM10_1

Figure 56: Tools of the Software Development Kit

You can also combine multiple class files into a compressed archive file, which then requires less transfer time over the Internet. Java archive files of this type then have, for example, names in the format “MyArchive.jar”. A Java archive contains files and possibly also entire directory structures in the same compressed format used by PKZIP and WinZip. They are administered with the program jar (Java Archiver); the call is similar to that of the UNIX program tar (tape archiver). It is not usually necessary to extract or unpack archive files: The Java compiler and the Java Virtual Machine can read and load the class files directly from the archive files. For this purpose, the file name of the archive file must be specified in a defined format.

The bytecode of a Java application is executed by calling the Java Virtual Machine JVM (in the Java Runtime Environment JRE) in the format java MyProgram.

In a similar way to sub program libraries in other programming languages, in Java there are also small Java programs (classes) with precisely defined conventions for the interfaces that allow reuse in multiple applications (applications and applets).

These programs are known as Java Beans.

J2EE Specification

Java became popular with the Internet as a language of the World Wide Web. Life can be added to static HTML pages using Applets and Java Script. By extending Web servers with the Common Gateway Interface (CGI), these can perform simple database accesses and display the results formatted in the browser. However, these technologies are limited in the case of simultaneous accesses from very large numbers of users who expect reliable information and quick response times.

Sun provides a solution to these problems in terms of server-side architecture for

TADM10_1 Lesson: Fundamental Concepts of Java

created in the Java programming language. Sun wishes to ensure that developments comply with the specification of the Java 2 Enterprise Edition using compatibility tests for J2EE.

The specification provides a generally-accepted framework for developing distributed, multi-level applications with modular components. Clearly-defined interfaces between the components and layers are intended to ensure that software components from different vendors are interoperable if they comply with the specification. With the J2EE specification, Sun wishes to ensure that Web applications that conform to the specification run on all J2EE-compatible servers. In accordance with the J2EE specification, the application logic is packed into components, the Enterprise Java Beans (EJB). They represent modular java program components. A container implicitly provides the components with the services of the runtime environment.

Three-level client/server architectures for enterprise applications can be realized in accordance with the J2EE specification. The J2EE application server forms the core of these architectures (see the figure Three-Level J2EE Architecture).

Figure 57: Three-Level J2EE Architecture

The J2EE application server (see the figure Architecture of the J2EE Application Server) processes client requests, executes the application logic, and returns the results to the clients. The application data is accessed using the database level. The

Unit 3: The System Core TADM10_1

application logic is implemented in the form of Enterprise Java Beans. These are executed in an EJB Container, which is part of the J2EE Application Server. The communication between the client and the J2EE is based on Web standards such as HTTP, HTML, and XML. The J2EE server uses Java Server Pages (JSP) and Java Servlets to generate HTML pages or XML data. Java Server Pages and Java servlets are executed in a Web Container, which is, in turn, part of the J2EE Application Server. Java applets can be included in the HTML pages that are sent to the Web browser. These applets are executed in the browser.

Java Server Pages (JSP) are a technology developed by Sun, which essentially allow the simple dynamic generation of HTML and XML output for a Web server.

This technology allows the embedding of Java code and special JSP actions in static content. This has the advantage that the logic can be implemented independently of the design with this technology. Java Server Pages are converted to Java source code using a special JSP compiler. This source code, which corresponds to a Java servlet, is then converted to bytecode by the Java compiler.

Figure 58: Architecture of the J2EE Application Server

Each application component is executed in a container. These containers provide the application components with services in accordance with the J2EE specification.

Examples of these services are transaction management, availability, security, scalability, client connection, and database access. This means that the developer can concentrate purely on the application logic and does not need to deal with these system functions.

The following figure shows an example of the processing of a client request by a J2EE Server.

TADM10_1 Lesson: Fundamental Concepts of Java

Figure 59: Processing of a Client Request by a J2EE Server

To achieve the aims of quick response times and reliable information, the J2EE application server must also provide scalability and reliability in addition to the functional side. The J2EE Server must handle clustering and load balancing for this.

In document Tadm10 1 en Col72 Fv Part Ltr (Page 171-175)