The Java language Java language was first known as Oak, which was generated to achieve embedded consumer electronics applications, and its author was James Gosling. Ed Frank, Patrick Naughton, Jonathan Payne, Chris Warth joined a lot of features for Java languages in the subsequent years, and made a re-positioning of the Java language, locked in the language suitable for the Internet. Java language is a multi-purpose language, concurrent language, class-based, object-oriented language. Its design is as close as possible to the operating system, which is the sentence propagated by Java: "Written, run everywhere." Java's design refer to C and C language, so familiar with C and C procedures The Java language is very fast, and the principle of Java design is to use the Java language shortcut to write applications, so we can find that in the Java language, there is no complex mechanism in C and C . The most obvious is that the pointer used in C is replaced by Java by Java due to its randomness. The operator overload, template, and generic characteristics in C are also not adopted because it is more complicated. But the current Java is still constantly launching new features to meet the development of applications. For example, in the newly launched JDK1.4, the Java language can support the ASSERTMENT mechanism and the most useful regular expression mechanism in the Perl language. The Java language is mainly composed of the following five elements: identifiers, keywords, text, operators, and separators. These five elements have different syntax meanings and composition rules, which cooperate with each other to complete the language of Java language. 1: Identifier. Variables, classes, and methods require a certain name, we call this name as identifier. 2: Keywords. The keyword is the identifier used by the Java language itself, which has its specific syntax meaning. All Java keywords will not be used as identifiers. 3: Data type. Java has different data types. More worth mentioning is the string data type, the string data type is the character sequence enclosed in a pair of double quotes, and the string data is actually implemented by the String class, not the characters used in the C language. Each string data will generate a new instance of a String class. Users don't have to have a string with the concept of the class. Due to the characteristics of the class, you don't have to worry about how to implement them, they will take care of themselves. It should be noted that the string is only for security considerations in Java. 4: Operator. Any language has its own operator, Java language is no exception, such as , -, *, /, etc., the operator's role is to form a corresponding operation with a certain arithmetic data. Different data types have different operators. 5: Separator. The separator is used to make the compiler to confirm where the code is separated. '' '' ';' ':' Is a separator of the Java language. Learning a Java language is simple. After all, Java language only contains more than 50 keywords (Keyword) and dozens of operators (Operator), plus Java syntax (Syntax) is also very simple, so average person can soon learn Java language. It is dangerous that many people think that they have fully controlled Java language, but in fact, for internal operational mechanisms still can't master it, these blind spots will sometimes make you unable to control Java languages.
Overcoming these blind spots is to see "The Java Language Specification, 2nd Ed." (Without Chinese) to completely understand the Java program language, and see "Inside the Java Virtual Machine, 2nd Ed." To thoroughly master the Java virtual machine Mode of operation. Learn the language does not mean that you can design a good object-oriented system architecture. Experts want to be object-oriented, often need: (1) more related books, especially the book of Design Pattern and Refactoring. (2) Dachematic procedures (such as the DESIGN and IMPLEMENTATION) (3) of Java API (3). After learning Java language, you need to learn some APIs to write a useful program. Java's API is very much, you must plan a learning path, which will not be lost in the vast API sea. The essential API includes: IO, New IO, Collection Framework, Network, RMI, JAXP ..., etc. As for other APIs, you can see your needs, approximately, approximately: * GUI class: javabean -> swing -> javahelp -> java2d -> Image Io -> jai -> Java 3D ... * Enterprise class: JDBC -> jdo -> servlet -> jsp -> ejb -> jms -> JTA / JTS ... * J2ME class (this is not my expertise, unable to provide learning order suggestion) Java language is usually based on Java virtual machines Definition in The Java Virtual Machine Specification, compiles to bytecode instructions and binary formats. Therefore, we will discuss the Java Virtual Machine (JVM) JVM. We have already talked about the syntax of the Java language similar to C and C , but abandon complex, doubts and unsafe features in C and C . The Java language was first used to build software for consumer network devices, so it would support multi-host architecture and requiring secure software components. In order to meet these needs, compiled code must be able to spread through the network, which can be run on any client, while also ensuring that the client is secure. The Java virtual machine is the cornerstone of Java and Java 2 platforms. It guarantees Java language and hardware, the operating system has nothing to do, ensuring the smallest compiled code and protects the user from malicious programs. What is the Java virtual machine? In fact, it is a computer that does not actually exists. Similar to true computers, it also has its own instruction set and can allocate memory area in the operating environment. Using virtual machine mechanisms to implement programming languages is not Java's innovation, this is already very common practice, the most famous Xu You will not be the P-Code machine of UCSD Pascal. As long as the browser detects the contents of the web files currently contains a Java Applet, the browser will open another JVM for this Java applet, perform this Java application applet. The Java apparatus executing in the JVM can get sufficient security protection. As we mentioned above, JVM is a self-sufficient work environment, just like a separate computer. For example, an APPLET operated in JVM cannot access a host operating system. The advantage is: 1. System neutrality. Java applications can operate in any JVM, regardless of the hardware, software for the system. 2. Safety.
For JVMs without any contact, Java programs are difficult to damage to other files or applications. The disadvantage is that due to the operation of the JVM operation in the operating system, the operating system is unable to enjoy the specific functions of the operating system. Java technology has been such a broad application today, where its security is not mentioned. Different from other technologies (such as Microsoft ActiveX) safety as additional design and patches, Java takes the safety from the beginning of design. Therefore, Java's security is implemented in language level. Java's security is guaranteed by the following three aspects: 1. Language characteristics (including boundary checks, type conversion, cancellation of the needle type variable). 2, resource access control (including local file system access, socket connection). 3, code digital signature (by digital signature to confirm the code source and the code is complete). Java's source code is the intermediate code that is first compiled into a zoning code, and the file that stores this code is .CLASS file. When you really execute, loading the class file into the JVM (virtual machine) and then explained by the JVM. So the up and down inspection and legal type conversion of the array are guaranteed by JVM. Java loads a virtual machine code file (ie, Class file) into the JVM through a class loader class, and after the load is completed, a class called the security manager (SecurityManager) begins to run, for example when an applet After the Class file is loaded into the JVM, the Class file is loaded into the JVM, and the JVM will immediately load a sub-class AppleTSecurity of the SecurityManager, which is verified by this manager. All actions of the code (such as file reading and writing) must first be verified, only the action accepted by the security manager can be completed, otherwise the securityException exception will be thrown. For JDK1.0, permissions are divided into two blocks. First, have all permissions, one is only "sandbox //" (SANDBOX) permission, which is also the permissions owned by the ordinary applet. At this time, the local file read or written or host connections other than the source host (Orignal Server) is disabled. The biggest problem with this division is the lack of flexibility. For example, we want an applet to read and write a directory of the local file system in the case of user trust, but do not connect to other hosts via Socket. This is the authority division of JDK1.0 can't achieve requirements. JDK1.1 has changed the division of permissions and introduces the concept of permission set (Permissions). Since our article is not discussing JVM, we are just a simple introduction to JVM. If you need to know more, you can refer to "The Javatm Tmvirtual Machine Specification". Objective viewing Java relative to other programming speech, Java has a non-doubtful advantage: users and compilers do not have to know a specific CPU detail that generates executable code for the first time. Java introduced a compiled code intermediate layer called byte code and uses a virtual abstract machine, not a real machine. When the Java compiler ends after the compilation of a source file, what you get can be immediately running on a given platform, but the one-in-one code can be run on any real platform, the only condition is this The platform should be understood and support Java. These developments include a cultural change.
As a developer, you only need to determine the abstraction layer provided by the Java Virtual Machine (JVM). Different OS vendors are responsible for executing the code layer, thereby mapping the byte code in the platform to the host platform. In this case, Java seems to be a leader candidate in a unified distributed computer world. "Write once, run forever" (and wherever it) becomes Java attracted but true slogan. But we flatten, Java's cross-platform is not a very attractive feature? The development of cross-platform theory has proven this. We see that the Java code is transplanted from a platform to another platform - the most important and most touched characteristics of the language - is not like propaganda. Any Java platform has its own virtual machine, which can understand the universal byte code and compile it to a local code in time. Contradictions thus produced, the implementation of different virtual machines is also very different, this is enough to make the transcation of the code much more time than expected, and is basically not automatic. In the corporate user's perspective, there are also rarely have frequent replacement platforms, so this feature can bring high value to evaluate. So, where is the benefits of the Java model? First, Java is an advanced, object-oriented language that includes a built-in function that prevents common errors and carries a lot of functions that often need to be used in only one or two objects. Compared with C , Java is easier to read and write, not easy to make mistakes, and more beautiful, but it is not very flexible. Want to achieve virtual transplant on any software and hardware platform, Java uses a censor model as little as possible, that is, abandoning the ability to develop each platform to the limit. Second, the concept of virtual machines itself is portable and can be shared, so it is ideal for distributed environments. Java is the best language for developing code for non-Windows platform. So what about Java for the Windows platform? Make Java adapt to Windows, which is due to Sun's license constraints. But Java is really attractive, Microsoft is more clear than anyone else. Microsoft proved this in the previous Visual J , but unfortunately, Microsoft made a hegemonic old shortage, Visual J is not easy. Therefore, Microsoft has taken the technique of "brought-to-mind", which has greatly taken a number of characteristics of Java, which has launched the new power of the Windows platform, which is quite simple but very powerful object-oriented C # programming language. C # exceeds C , which is naturally included in the .NET Framework class library, and simplifies grammar. It is already some existing ahead here, but Java is not able to use, JDK and most of the IDE support Windows platforms on the Windows platform. The architecture of Java technology - J2ME, J2SE, and J2EE usually define the version of Java with a version of JDK (a set of Java development tools developed by Sun). JDK version 1.0 is open in early 1996, and JDK 1.1 is open, and the JDK version 1.2 is open to the end of 1998. Based on marketing, Sun was renamed "Java 2" in JDK 1.2 version, and the Java 2 Software Development Kit (hereinafter referred to as J2SDK) will be renamed "Java 2 Software Development Kit". J2DK (originally called JDK) 1.3 is open in April 2000, and this version is still called "Java 2".
At present, J2SDK 1.4 has also been disclosed. You can access a large number of JDK1.4 information on Sun's official Java site. Java technology is divided into several branches based on the difference between the hardware platform and the applicable environment. JDK 1.1, suitable for general consumer electronic products, etc., the Java platform of embedded systems is Personaljava and Embeddedjava, which has no clear boundaries, which is roughly, computing resources, memory, and display devices are relatively rich. Use Personaljava, such as SET-TOP BOX, Video Phone ... etc .; contrary, resources are limited by EmbeddedJava, such as a call, a mobile phone ..., etc. In addition to the Java platform used by the PC, the Personaljava used by IA is outside the Embeddedjava platform, Javacard is also a Java platform that is used on Smart Card (IC Card). After Java 2 appeared, overthrew the previous Personaljava and EmeddedJava's assay, and changed into Java 2 Platform Enterprise Edition (Java 2 Platform Standard Edition), Java 2 Platform Micro Edition (Java 2 Platform Micro Edition). J2EE is suitable for servers, and is currently a quite popular technology in the fields of corporate operations, e-commerce; J2SE is suitable for general computers; J2ME is suitable for consumer electronics. In addition to these three, Javacard is still a stand-alone standard. Currently, the architecture of Java technology includes three aspects: J2EE (Java 2 Platform Enterprise Edition) - Enterprise (J2EE) is a solution for developing applications for enterprises. J2se (Java 2 Platform Stand Edition) - Standard Edition (J2SE) provides a feasible solution for desktop development and low-end business applications. J2ME (Java 2 Platform Micro Edition) - Small Edition (J2ME) is the best solution for consumer products and embedded devices J2EE J2EE has become a factual standard for developers to create e-commerce applications. It is to recognize the J2EE platform as an extensible, full-featured platform that extends key enterprise applications to any web browser and can be suitable for a variety of different Internet data streams, which can be connected to almost any kind of tradition. Databases and solutions enable business manager to reduce the cost and complexity of the development of networking applications based on the products and technological development and deployment of many companies, many manufacturers represent the J2EE Support and J2EE technology as a safe and stable end-to-end platform for large BTOB markets and massive transactions. The basis of J2EE technology is the J2SE standard version, which consolidates many of the advantages in the standard version. The ultimate goal is to be an architecture that enables enterprise developers to significantly shorten the market time. It provides powerful service functions for flexible configuration of various multi-storey enterprise applications, especially e-commerce applications such as B2B, B2C. Recently, the CONNECTOR API service has recently added to the development and deployment of enterprise applications with a series of mature technologies. J2SE J2SE is a standard version of the Java 2 platform, which is suitable for desktop systems, providing CORBA standard ORB technology, combined with Java's RMI support distributed interoperability environments. It runs on the Java virtual machine. After introducing Java IDL, J2SE supports IIOP communication. It is highly portable, isomeric realization environment and robust platform, but also standard platform for scalability, portability, distributed heterogeneous interoperability applications.
J2ME J2ME provides an HTTP advanced Internet protocol that enables mobile phones to access all information about Internet in a Client / Server mode, different client access to different files, and access the local storage area, providing the highest efficiency wireless communication. J2ME is a miniature version of the Java 2 platform, which is divided into two parts: CDC (Connected Device Configuration) and CLDC (Connected Limited Device Configuration). CDC runs on the Connected Virtual Machine, provides an application platform for a smuggle computer for a whose computer; CLDC is running on the core virtual machine (KVM), which implements the MIDP (Mobile Information Device Profile mobile information device application platform, namely Establish a mobile computing platform for your mobile phone. In terms of small J2ME (Java 2 Micro Edition), it is mainly applied to electronic devices that are small in memory capacity and small volume. Small to smart cards, mobile phones, personal digital assistants are the best platform for J2ME. Java In Palm's application, Palmos 4.0 contains KJAVA, and Sun also introduces J2ME versions for Palmos. Therefore, in the Palm PDA, various application systems can be developed on the Palm PDA. The combination of two standard platforms of Java and Palm will be the trend of the next wave of PDA applications. Java applied to mobile phones, NOKIA, MOTOROLA, Ericsson will launch new mobile phones with J2ME technology, so Java programming is more platform for exhibiting. This kind of wireless open application platform combined with J2ME and wireless communication technology will provide an excellent solution. In the medium-sized J2SE (Java 2 Standard Edition), Sun launches a new solution called Java Web Start. The original Java Applet is to perform a square area in WebBrowser to perform Java programs, but this is limited to the original Web Browser in performing performance and compatibility. Now the new Java Web Start is the Java Application directly executed on the operating system, but can be activated on the web page. This can be combined with web pages, faster, more efficient. And, Sun and IBM will launch a Java version that supports 64-bit operations, which will be a major tool for the development of client Java application systems executed on the normal computer. In addition, in a large J2EE (Java 2 Enterprise Edition), it can be said that "J2EE" has become a standard for server operations. Java servlets, JAVA Serverpages, EJB (Enterprise Javabeans), JavaMail, JDBC, JMS, etc. are the key directions of various manufacturers' products development. J2EE is compatible with general Intel personal computers (Linux, Windows .....), McKin Tower, and high-efficiency high-stable UNIX servo hosts must be one of the main choices on server operations market. In addition to the above three large Java combinations, Java and XML integration is also the future of the future. Sun has introduced Java processing XML standard extension API - Java API for XML Parsing (JAXP) that allows each XML parser to have interfaces on interfaces. So in the Java program, just understand the XML file completely, so that XML applications are more convenient.
Java This cross-platform development environment, coupled with XML this cross-platform data format, which will become the main application technology for future message transmission and data exchange, such as tiger, combined into a best cross-platform solution . By J2SE (Java 2 Standard Edition) can develop applications on the PC, with J2ME (Java 2 Micro Edition) can cross a more large home appliance, smart card, electronic device, etc., with J2EE (Java 2 Enterprise) Edition can integrate the servo host operation environment. The application range of Java technology is almost all, Java technology can provide a full range of solutions in all areas of Internet and e-commerce. As the application is different, Java has many API (Application Programming Interface), which are divided into three categories: · Java Core API: The basic API set by Sun, any Java platform must be available. · Java Standard Extension API: The expansion API set by Sun, the Java platform can be selectively provided or installed. · The API provided by vendors or organizations: provided by various companies or organizations. The Core API and Standard Extension API have gradually covered most of the information applications, such as multimedia, database, web, corporate operation, voice, real-time system, network, telephone, image processing, addess, GUI, distributed operation. ...... If you have a requirement that there is no standard Java API to follow, you can make requests for new APIs to Sun. After review, your requirements may pass, dismiss ... Wait. If pass, you will start entering the program that develops APIs. The development process of the Java API is publicly involved in public participation, and through many industry technology leadership, it is quite perfect. EJB Ecological Environment In the EJB specification provided by Sun, our complete EJB-based distributed computing structure consists of six roles. These six roles can be provided by different developers, and the work made by each role must follow Sun provides the EJB specification to ensure compatibility between each other. EJB Component Developer: Develop and sell EJB. Application Combinator: Build different EJBs into applications. Deployers: Use the corresponding tool to configure EJB in the operating environment. EJB Server Provider: Develop and sell EJB Server EJB Container Suppliers: Develop and sell EJB container system administrators: Monitor runtime / R 1, EJB Components Developers (Enterprise Bean Provider) EJB Components Developers responsible for developing executive business logic The rules of EJB components, the developed EJB component packaged into an EJB-JAR file. The EJB component developer is responsible for defining the EJB's REMOTE and HOME interface, writing EJB Class, executing business logic, providing deployment descriptor. The deployment file contains the name of EJB, and the resource configuration used by EJB, such as JDBC, etc. EJB Components Developers are typical business application development field experts. EJB component developers do not need to be proficient in system-level programming, so you don't need to know some system-level processing details, such as transactions, synchronization, security, distributed calculations. 2. Application ASSEMBLER Application Components is responsible for using a complete application system using various EJBs. Application portfoliors sometimes need to provide some related programs, such as in an e-commerce system, application portfoliors need to provide JSP (Java Server Page).
Application portfoliors must master the EJB HOME and REMOTE interface used, but do not need to know the implementation of these interfaces. 3. Deployer deployers are responsible for deploying the EJB-JAR file to the user's system environment. The system environment contains some EJB Server and EJB Container. Deployers must guarantee that all resources declared by the EJB component developer in the deployment file, for example, deployers must configure the database resources required for EJB. Deployment procedures Two steps: Deployers first use the tools provided by EJB Container to generate some classes and interfaces, so that EJB Container can use these classes and interfaces to manage EJBs in operation. Deployers Install the EJB component and other classes generated in the previous step to EJB Container. Deployers are an expert in an EJB operating environment. In some cases, deployers need to understand the business methods included in EJB in deployment to write some simple program tests after deployment. 4, EJB Server Provider (EJB Server Provider) EJB server provider is an expert in the system, proficient in distributed transaction management, distributed object management, and other system-level services. EJB server providers are generally provided by operating system developers, middleware developers, or database developers. In the current EJB specification, assume that the EJB server provider and the EJB container provider come from the same developer, so no interface criteria between the EJB server provider and the EJB container provider are defined. 5. EJB Container Provider (EJB Container Provider) EJB container provider provides the following features: Provide EJB deployment tools to provide an operational environment for deploying EJB components. The EJB container is responsible for providing transaction management, safety management such as EJB. The EJB container provider must be a system-level programming expert, but also have some experience in the application. The work of the EJB container provider is mainly focused on the development of a retractable and transaction management functionality in the EJB server. EJB container providers provide a set of standards for EJB component developers, easy-to-use API access to EJB containers, so that EJB component developers do not need to understand various technical details in the EJB server. The EJB container provider is responsible for providing system monitoring tools to monitor EJB containers in real time and the state of EJB components running in the container. 6. System administrator system administrators are responsible for providing an enterprise-level computing and network environment for EJB servers and containers. System administrators are responsible for monitoring the operation of EJB components using the Monitoring Management Tools provided by EJB servers and containers. Another benefit of separating the responsibility is on the code level, and the assignment of EJBS-based system logic can be used to a more suitable expert. Sun's EJB specification is recommended to use several independent roles, which is very important to determine the responsibility chain of the operating environment. For example, the EJB provider is a role played by a business expert and an analyst that determines the best information flow within an organization. But still have Second Domain Expert, such as application assembly, they integrate different EJB components and make sure it makes it possible to meet the needs of the application. There are also two roles to enter the system level, the first is the configuration personnel, they are responsible for installing and configuring EJB-based systems. This requires an experience of setting directory services and integrating existing applications. The second is a system administrator who offers full-day monitoring and support to ensure proper operation. Although the role of the system administrator does not need Java programming experts, he needs to cope with the following questions: Set Java Virtual Machine (JVM) and associate system environment parameters (such as: ClassPath) Save class files Using Java Archive (JAR) command Save Class file knows Web The working principle of the server and servlet. It is necessary to determine the optimization method by monitoring the status of the program in the run.
Obviously, some roles are cross-crossed, such as system administrators and configuration personnel. Although the configuration personnel may be copying the class file to the server and the system administrator needs to determine if the configuration person is copied to the correct location.
The basis of EJB technology is the other two technologies: RMI-IIOP and JNDI. To learn about EJB, you must first understand RMI-IIOP and JNDI. Therefore, we know these two technologies before introducing EJB details. Our introduction is basically, so most organizations are enough to know these. Java RMI-IIOP Java RMI-IIOP (Java Remote Method Invocation Over The Internet Inter-ORB Protocol) is a network mechanism for J2EE. Java RMI-IIOP allows you to write a distributed object such that the communication range of objects can be in memory, crossing Java virtual machines, across physical devices. Remote Method Invocation RPC (Remote Procedure Call) is a process for the process of calling another machine. Remote Method Invocation is further further, allowing communication between distributed objects than RPC. RMI-IIOP allows the way to call remote objects, not just a process. This facilitates object-oriented programming. Java RMI (Remote Method Invocation Remote Method Call) is implemented in JAVA in JDK1.1, which greatly enhances the ability of Java development distributed applications. As a popular network development language, Java has a huge power to reflect the ability of its powerful development of distributed network applications, and RMI is one of the core solutions of developing 100% pure Java network distributed application. In fact, it can be seen as a Java version of the RPC. However, traditional RPCs do not be well applied to distributed object systems. Java RMI supports communication between program-level objects stored in different address spaces to implement seamless remote calls between remote objects. Remote Method Invocation is not simple, you need to consider a few questions: Marshalling and Unmarshalling. Transfer variables between different machines (including Java basic types and objects), if the target machine represents data, what should I do? For example, the binary library is different. Therefore, Marshalling and Unmarshalling are the process of transmitting variables. Variable transmission method. There are two ways to transfer: Pass-by-value and pass-by-reference. For the former, your target method only needs a copy, but for the latter, any modification of the variable will affect the source data. The instability of the network and machines. It is necessary to have a mechanism to ensure that a JVM crashes will not affect the normal operation of the system. In the Java Distributed Object model, Remote Object is an object: its method can be called from other Java virtual machines (possibly on different hosts). This type of object is described by one or more Remote Interfaces (which is a Java interface of the declaration remote object method). Remote Method Call (RMI) is the action of calling the remote interface on the remote object. More importantly, the method of the remote object calls the same as the method of calling the local object. Remote Interface RMI-IIOP follows the principles of interfaces and implementations. All the network code you write is applied to the interface, not an implementation. In fact, you must use the example in RMI-IIOP, there is no other choice. It is impossible to perform remote calls directly on your object, you can only do this separately on the interface of the object class. So when we use RMI-IIOP, you have to build a customer interface called Remote Interface. This remote interface should expand the java.rmi.Remote interface.
The Remote Object Implementation Remote object and the physical location of the client are not very important. You can run in the same address space or run across the Internet. In order to make the object become a remote object, you need to perform steps: inherit javax.rmi.portableremoteObject. PortableRemoteObject is a base class for remote calls. When your remote object calls the constructor, the constructor of the PortableRemoteObject object is automatically called. Do not inherit Javax.rmi.PortableRemoteObject. If your remote object needs to inherit other classes, while Java does not allow multiple inheritance, so you can't inherit PortableRemoteObject. At this time, you need to manually call Javax.rmi.PortableRemoteObject.ExportObject (). STUB and SKELETONS Let's take a look at the network architecture hidden behind RMI-IIOP. One advantage of RMI-IIOP is that you can't take care of the object you want to call or remote. This is called Local / Remote Transparency. RMI applications typically include two independent programs: server programs and client programs. A typical server application will create multiple remote objects that allow these remote objects to be referenced, then wait for the client to call the method of these remote objects. Typical client programs get a reference to one or more remote objects from the server, and then call the way to remote objects. RMI provides a mechanism for servers and clients. During communication with remote objects, RMI uses standard mechanisms: Stub and Skeleton. The Stub of the remote object acts as a client representative or agent role of a remote object. The calling program will call the local STUB method, and local STUB will be responsible for performing method calls for remote objects. In RMI, the STUB of the remote object is the same as the remote interface set implemented by the remote object. The following operations will be performed when calling the Stub: (1) Initialize the connection to the remote virtual machine containing the remote object; (2) Group parameters of the remote virtual machine (write and transfer); (3) Waiting method call results ; (4) Decoding (read) return value or returns an exception; (5) returns the value to the call. In order to display a relatively simple call mechanism to the calling program, STUB hides the sequence of the parameters and network-level communications. In a remote virtual machine, each remote object can have the corresponding SKELETON (no SKELETON in the JDK1.2 environment). Skeleton is responsible for assigning calls to actual remote objects. It performs the following operations when the method is called: (1) Decode (read) the parameter of the remote method; (2) Call the method of actual remote object implementation; (3) Group the result (return value or exception) group (write Encomposite transmission) to the calling program. Stub and Skeleton are generated by the RMIC compiler. It is not that simple to implement local / recote transparency. In order to shield you call the object on the remote host, the RMI-IIOP needs to simulate a local object for you to call. This local object is called STUB. It is responsible for accepting local method call requests to delegate these requests to the object that truly implement them (can be positioned through network). This makes the remote call look like local calls. Use RMI to write distributed object applications to complete the following: (1) Positioning remote objects. Applications can use one of two mechanisms to get references to remote objects. It can register its remote object either use RMI's simple naming tool RMireGistry, or you can deliver remote objects as part of a regular operation. (2) Communication with remote objects.
Details of inter-remote object communication are handled by RMI. For programmers, remote communication looks like a standard Java method call. (3) Load the class byte code to the object transmitted as a parameter or return value. Since the RMI allows the call to pass the pure Java object to the remote object, the RMI will provide the necessary mechanism, which can load the code of the object and the data of the object. When the RMI distributed application is run, the server calls the registration service program to associate the name with the remote object. Use the remote object's name in the registration service program on the server to find the remote object and then call it. Positioning a remote object. Applications can use one of two mechanisms to get references to remote objects. It can register its remote objects with a simple naming tool RMireGistry of RMI; you can also deliver a remote object reference as part of a regular operation. Communicates with a remote object. Details of inter-remote objects are handled by RMI; for programmers, remote communication looks like a standard Java method call. The object loaded by the parameter or returned value is loaded by the RMI allows the caller to pass the pure Java object to the remote object, so the RMI will provide the necessary mechanism, which can load the object's code and data of the object. The server calls the registration service program to associate the name with the remote object. The client uses the remote object in the server registration service program to find the remote object, and then call it. RMI can load the class bytecode with any URL protocol supported by the Java system (such as HTTP, FTP, File, etc.). STUB only solves half of the problem. We also hope that the remote object does not have to consider the network problem. Therefore, the remote object also requires a local SKELETON to accept calls. Skeleton accepts network calls and commissioned to remote objects. Your J2EE server should provide a way to generate must-have STUBs and SKELETON to mitigate your burden on your network problem. Typically, through the command line tool, such as Sun's J2EE reference implementation package uses a tool named RMIC (RMI Compiler) to generate STUB and SKELETON classes. You should deploy Stub on the client and deploy the SKELETON on the server. Object Series and Variable Passing In the RMI Distributed Application System, the Java objects transmitted between servers and clients must be sequentially sequentially. An immortal-rated object cannot be passed in the object stream. Object serialization extends the core Java input / output class while also supports objects. Object serialization supports the object coding and the object coding will be coded through the objects accessed into byte flow; at the same time, it also supports complementary reconstruction of the abstract graphics in the stream. Serialization is used for light persistence and communication with the help of socket or remote method (RMI). The serialization now includes an API (Application Programming Interface, Application Interface), allows sequence data for specifying objects independently of class, and allows serialized data domains to be written into streams or read in streams using existing protocols Take it to ensure compatibility with the default read and write mechanism. To write applications, in addition to most transient applications, you must have the ability to store and retrieve Java objects. The key to storing and retrieving objects in serialization is to provide a sufficient object state required to re-construct the object. Objects that store the stream may support the Serializable or ExternalIZable interface. For Java objects, serialization must identify and verify the Java class belonging to the object to which its content is stored, and restore the content as a new instance. For sequential objects, the stream will provide sufficient information to restore streams to compatible versions. For an externalized object, the class will fully be responsible for the external format of its content.
The purpose of serialization Java object is to provide a simple but expandable mechanism to serialize the type and security attribute of Java objects in a serialized manner; it has the need to support group and solve the need to meet the needs of remote objects; To support the simple persistence of the Java object; only the serialized self-realization of each class is required for each class; allowing the object to define its external format. Java.rmi.Remote Interface In RMI, the remote interface is declared the method set from the remote Java virtual machine. Remote interfaces must meet the following requirements: The remote interface must be directly or indirectly expanded directly or indirectly. The method declaration in the remote interface must meet the requirements of the following remote method declaration: Remote method declarations In addition to the exception related to the application in its throws clause (note that the application related to the application does not need to expand java.rmi.RemoteException) In addition, Java.Rmi.RemoteException is exception (or its superclass, such as java.ioException or java.lang.exception). In a remote method declaration, the remote object must be declared as a remote interface, not the implementation class of the interface (in a non-remote object that directly declares or embedded to the parameter in the parameter table). Java.rmi.Remote interface is a tag interface that does not define methods: Public interface Remote remote interface must extend at least the java.rmi.Remote interface (or other remote interface for extended java.rmi.Remote). However, remote interfaces can extend non-remote interfaces in the following cases: Remote interfaces can also extend other non-remote interfaces, as long as all methods of extended interfaces (if any) meet the requirements of remote methods. For example, the following interface BankAccount defines a remote interface for the access bank account. It comprises a deposit account to the account balance and withdrawal from the account of the remote method: public interface BankAccount extends java.rmi.Remote {public void deposit (float amount) throws java.rmi.RemoteException; public void withdraw (float amount) Throws overdrawnexception, Java.rmi.RemoteException; Public Float getBalance () throws java.rmi.RemoteException;} The following example illustrates a valid remote interface Beta.
It is a non-extended remote interface Alpha (with a remote method) and interfaces java.rmi.Remote: public interface Alpha {public final String okay = "constants are okay too"; public Object foo (Object obj) throws java.rmi.RemoteException; public void bar () throws java.io.IOException; public int baz () throws java.lang.Exception;} public interface Beta extends Alpha, java.rmi.Remote {public void ping () throws java.rmi.RemoteException;} RemoteException The class java.rmi.RemoteException class is an exception that is thrown by the RMI runtime during the remote method call. To ensure the robustness of the application of the RMI system, the remote approach declared in the remote interface must specify java.rmi.RemoteException (or its superclars, such as java.io ioException or java.lang. " Exception. When the remote method calls failure for some reason, the java.rmi.RemoteException exception will be thrown. Remart Method Cancer Failure Included: Communication Failure (Remote Server is unreachable or denied; connection is closed, etc.) Parameter or return value Transmission or reading failure protocol error RemoteException class is an exception that has been tested (must be remote) The method of calling the program is handled and the compiler is instead of the runtimeexception. The RemoteObject class and its subclass RMI server functions are provided by java.rmi.server.RemoteObject and its subclass java.rmi.server.RemoteServer, java.rmi.server.unicastRemoteObject and java.rmi.activation.active. Java.rmi.Server.RemoteObject provides implementation of the Java.lang.Object method that is sensitive to remote objects, Hashcode, Equals, and Tostring. Create a remote object and export it (allowing them to utilize remote clients) by classes UnicastRemoteObject and Activatable. Subclasses can identify the semantics of remote references, such as a simple remote object or activaneous remote object (remote object that will be performed). The java.rmi.server.UnicastRemoteObject class defines a single (single transmission) remote object whose reference only is valid when the server process is alive. Class java.rmi.activation.activatable is an abstract class, which defines the Activatable Remote object to start executing while its remote method is called and is shut down if necessary. The general rules for implementing the class for remote interfaces to implement remote interfaces are as follows: This class usually expands java.rmi.server.UnicastRemoteObject, thus providing remote behavior provided by Java.rmi.Server.RemoteObject and java.rmi.server.Remoteserver. This class can achieve any more remote interface. This class can expand other remote implementations.
This class can define methods that do not appear in remote interfaces, but these methods can only be used locally without being used remotely. For example, the following classes BankAcctImpl implement and extend java.rmi.server.UnicastRemoteObject BankAccount remote interface class: package mypackage; import java.rmi.RemoteException; import java.rmi.server.UnicastRemoteObject; public class BankAccountImpl extends UnicastRemoteObject implements BankAccount {private float balance = 0.0; public BankAccountImpl (float initialBalance) throws RemoteException {balance = initialBalance;} public void deposit (float amount) throws RemoteException {...} public void withdraw (float amount) throws OverdrawnException, RemoteException {...} public float GetBalance () throws remoteException {...}} Note: When necessary, implement a remote interface class can extends other classes other than the Java.rmi.Server.UnicastREMoteObject class. However, the implementation of the class must assume some responsibility, that is, the export object (responsible by the UnicastRemoteObject constructor) and implementing the correct remote semantic (if needed) from the Java.LANG.Object class. Parameters in the remote method call pass the parameters passing to the remote object or the return value stem from it can be any sequentially sequenceful Java object. This includes Java basic type, remote? Java object, and non-remote Java objects that implement java.io.serializable interface. For more information on how to make the class, see Java "Object Series Specification". The class that is not available as a parameter or return value can be dynamically downloaded via the RMI system. Transfer Non-Remote Object Non-Remote Objects Transfer as a remote method call or as a result of the remote method call to return, is passed by copying; that is, serializing the object using the Java object serialization mechanism. Therefore, during the remote object call, when the non-remote object is passed as a parameter or return value, the content of the non-remote object will be copied before calling the remote object. When you return to a non-remote object from a remote method, you will create a new object in the called virtual machine. Transfer Remote Object When the remote object is passed as a parameter or return value called by a remote method, the STUB program of the remote object is passed out. Remote objects that are passed as parameters can only implement remote interfaces. Quote Integrity If two references for an object are passed from a virtual machine to another in a single remote method call (or return value), and they point to the same object in the sending virtual machine. Two references will point to the same copy of the object in the receiving virtual machine. It is to say: In a single remote method call, the RMI system will remain referenced in the object that is called parameters or returned values. Class annotation When an object is sent from a virtual machine to another in a virtual machine in a virtual machine, the RMI system adds information (URL) to the class descriptor in the call stream so that the class can be on the receiver. load. During the remote method call, calls can be downloaded at any time.
The parameter transfer is in the destination file of the parameter called the RMI to the remote call, and the parameter needs to be written to the stream of subclasses as the Java.io.ObjectOutstream class. The ObjectOutputStream subclass will override the ReplaceObject method, with its corresponding STUB class to replace each remote object. The object parameters will be written in the stream via the ObjectOputStream WriteObject method. ObjectOutputStream calls the replaceObject method for the object (including the object referenced by the object) through the WriteObject method. RMIOBJECTOUTSTREAM subclass's replaceObject method returns the following value: If the object passed to ReplaceObject is an instance of java.rmi.Remote, the Stub program of the remote object is returned. The Stub program of the remote object is obtained by calling the java.rmi.server.RemoteObject.Tostub method. If the object that is transmitted to ReplaceObject is not a Java.rmi.Remote instance, only the object is returned. The ObjectOutputStream subclass of RMI also implements an AnnotateClass method, which uses a stream with a class of the class to download the class in the receiver. See "Dynamic Class Load" section for more information on how to use AnnotateClass. Because the parameters are only written to an ObjectOutputStream, the reference to the same object to the calling program will point to the same copy of the object there. On the receiver, the parameters will be read by a single ObjectInputStream. All other default behaviors used to write objectOutputStream (similar to ObjectInputStream for reading objects) will remain in parameter delivery. For example, the call to WriteReplace is called when the object is called and read objects, is completed by the RMI parameter group and the decoction. Similar to the above RMI parameter transmission mode, return value (or abnormal) will be the same as the subclass of ObjectOutputStream and the alternative behavior of parameter transmission. Location Remote Objects We specially provide a simple boot name server for storing naming references to remote objects. The URL-based method using class java.rmi.naming can store remote object references. The client must call the remote object, you must first get the reference to the object. The reference to the remote object is usually obtained in the form of a return value in the method call. The RMI system provides a simple boot name server that obtains a remote object on a given host. The java.rmi.naming class provides a method based on the Unified Resource Locator (URL) to bind, rebound, unlock and list the name-object pair located on a host and port.
J2EE's thirteen technology / RJAVA Database Connection (JDBC) JDBC API accesses various databases in a unified manner. Similar to ODBC, JDBC exits the problem between developers and private databases. Since it is built on Java, JDBC can provide a platform-independent database access. JDBC defines four different drivers. Specifically, the JDBC-ODBC bridge is very useful when JDBC is just generated when JDBC is just generated. Through it, developers can use JDBC to access an ODBC data source. Disadvantages are that it needs to be installed on the client machine with an ODBC driver, which is usually in the Microsoft Windows system. With this type of drive, you will lose the benefits of the JDBC platform. In addition, the ODBV driver requires the management of the client. Type 2: JDBC-Native Drive Bridge JDBC-Native Drive Bridge provides a JDBC interface on the local database drive - no ODBC. The JDBC driver converts the standard JDBC call to local calls to the database API. The use of type 2 drivers will also lose the benefits of unrelated JDBC platforms, and the client's local code is required. Type 3: JDBC-NetWork Bridge JDBC-Network Bridge does not require a client's database driver. They use the network-server middle layers to access a database. This will lead to technical buffers, such as load balancing, connecting pools, and data buffering. Since the drive of type 3 is usually relatively small download time, it is a platform-independent and does not require the client's installation and management, so it is well suited for use as an Internet application. Type 4: Pure Java Drive Type 4 Use pure Java database drivers to provide direct database access. Since the type 4 drives runs on the client, and directly accesses the database, running in this mode suggests that a two-layer system is used. To use the type 4 driver in an N layer system, you can pass an EJB containing data access code, and let the EJB provide a database that has a database for its customers. Java Naming and Directory Interface (JAVA Naming and Directory Interface, JNDI) JNDI is an image of Java Naming and Directory Interface, interested in: Java Names and Directory Interface, which is access to the directory infrastructure in the development of advanced network applications . In fact, this directory is a special database that provides quick access to stored data, unique to traditional directory services - you must provide different API interfaces to access different directory services (such as: LDAP, NIS, ADS, etc. It provides a standard API to access different types of directories. It is said that the use of the full SDK can develop the directory service providers that JNDI still supported. JNDI is an API of J2EE, providing a standard interface to locate users, machines, networks, objects, and services. For example, you can use JNDI to locate a printer in the intranet, you can also use it to locate the Java object or connect to a database. JNDI can be used in EJB, RMI-IIOP, JDBC. It is a standard method for network finding positioning. JNDI API is used to access naming and directory services. It provides a compatible mode to access and operate large resources, such as DNS, LDAP, local file system, or objects in an application server. In JNDI, each node in a directory structure is called Context. Every JNDI's name is opposite to a context, there is no absolute name concept.
An application can use the InitialContext class to get its first context: context (); through this initial context, the application can be positioned to the required resources or objects via the directory tree. For example, assuming that you have configured an EJB in WebLogic Server and bind HOME interfaces in MyApp.myejb. EJB client, after getting this initial context, then you can use the following code to locate: myejbhome home = ctx.lookup ("myapp.myejb"); once you get the object you need Quote - In this example, it is the Home interface of EJB - then you can call the method above. In order to find an object in a context, JNDI also provides a method to do: insert or bind an object to a context. This is a very effective way when you configure an EJB; move from a Context to list all objects / r in a context creation and delete SubconTexts Enterprise Java Beans (Enterprise Java Beans, EJB) J2EE A leading technique is EJB. It provides an architecture to develop and configure distributed business logic for the client, so it can significantly reduce development scalability, difficult to high complex enterprise applications. The EJB specification defines how the EJB component should interact with their containers. The container is responsible for providing ordinary services, such as directory services, transaction management, security, resource pools, and fault tolerance. The EJB specification defines three basic beans: session beans: Session Beans modeling for business processes, because they usually represent an action, so they can treat them as a verb. This action can be anything, such as adding quantities, accessing the database, calling other systems, calling other enterprise beans. We can make a lot of examples, including a pricing engine, a workflow engine, a directory engine, a credit card authentication center, or an online securities trading engine. Entity Beans (Entity Beans): This is a representative of persistent storage data - typically stored in the database - therefore still exists after the server crashes. Multiple clients can use EJB to represent the same data. Entity Beans models for corporate data, because they represent data objects (just java objects for cache database information), so they can be used as named. Examples of entity Beans include a product, an order, an employee, a credit card, or a stock. The session beans typically uses entity Beans to achieve business objectives, such as a securities trading engine (session beans) handling stock (entity beans). Message-Driven Beans: Message-Driven Beans also said actions, which is similar to session beans. The difference between them is that you can only call them by sending messages to Message-Driven Beans. The example of Message-Driven Beans includes Beans, credit authentication messages, or workflow messages that receive stock trading messages. These Message-Driven Beans can also call other enterprise Beans.
Next, we discussed stateless and stateless Beans (Stateless Beans): This is a single service, no maintenance, no longer exists when the server crashes, and the survival is relatively short. For example, a stateless Session bean may be used as performing temperature conversion. State Bean: It provides a traditional way to interact with the client, store the client's state. Online shopping cart is a typical example of such a stateful Session Ean. There is no longer existent when the server crashes on the server, and the survival period is relatively short, and each instance can only be used in a single thread. JavaServer Pages (JSPS) may be very familiar with Microsoft's Active Server Pages (ASPS); JSP is also similar technique, but it is platform-independent. They are all designed to help web content developers can create dynamic web pages using relatively few code. Web designers can use JSP to create dynamic web pages even if they don't know how to program. JavaServer Page is a mix of HTML code and Java code. When the customer requests the page, the server will process the Java code and then return to the HTML page to the browser. You can also have to hear JHTML, it is an old standard, which has been replaced by JSP. WebLogic Server not only supports JSP, but also supports JHTML. However, under default settings, WebLogic Server does not support JSP (for version 5.1). You must edit WebLogic.Properties to activate the web server, which is the case for JSPSERVLET. Most of the functions provided by Java Servlets Servlets is the same, which uses a bit different way. Most of the JSP is HTML code, with only a small number of Java code, while servlets, which is completely written in Java and generate HTML code. Servlet is a Java applet running on the server, which can extend the functionality of the web server. These server-side applications can be dynamically executed during being requested, similar to the CGI Perl script on the traditional web server. One of the CGI scripts and servlets is that the CGI script launches a new process for each request - requires additional system overhead - and the servlet is executed as long as you start a separate thread in the Servlet engine. Therefore, the SERVET has better scalability. When developing a servlet, you usually have to expand the javax.servlet.http.httpservlet class and override some of its methods. Interested methods include: service (): as a scheduler / r doget () as a Command-Specific method / r doget (): handles HTTP GET requests from one customer's HTTP GET (): handle HTTP POST request / r from a customer Some other methods to handle different types of HTTP requests - more relevant information for text that can refer to the HTTPSERVLET API. Java IDL / CORBA supports Java's IDL support, developers can integrate Java with CORBA. They can create Java objects that can be configured in a CORBA ORB, or create a Java class as a CORBA object client configured in other ORBs. For a new application and previous system integration through Java, the latter provides an additional method.