I learned Java has more than a year, and now can only be used on Jsp write something, anything else is too many places are places I could not finish the day, I am confused, I do not know how to learn in a targeted manner to find a Java work, it is now in a dire strait in Java.
To write this article, is designed to help readers see the kaleidoscope of the essence of Java, from the appearance of complex general rule to find, only to master the universal laws to make no changes at all, easy to grasp the new Java technology development trends, and will quickly appreciate the skilled use of a new technology, rather than as a passive follower, but I do not know their所以然know.
In the search for universal law, let us first take a look at the development process of Java:
(1) SUN mainstream of technological development
GUI Interface: Java AWT API -> Java Swing API
JavaWeb: Servlet -> JSP -> JSF
Persistence Layer: JDBC -> CMP EJB or BMP EJB or JDO
Distributed Application: Socket -> RMI -> J2EE or Java Web Service
(2) the main types of Java open-source software
JavaWeb containers: Tomcat, Resin
EJB Container: JBoss
Framework: Java Web framework (Struts), Business Logic Tier Framework (Spring)
Persistence layer: DAO, ORM mapping tools (such as Hibernate, OJB)
Project management tools: ANT, Elipse
Log output tools: Log4J
JavaWeb service tools: Apache Axis
Contributed to Java world the basic driving force for such a wonderful core idea is the following:
Interface and Implementation
Between different software systems to interact through the interface. Software systems use only the public interface, package implementation details. Interface describes the functions of a software system, which is designated software systems can do, but do not specify how. Interface has three main functions:
(1) for the interface makers: SUN through the definition of interfaces, to develop a new software system specifications, such as the Servlet specification, EJB and JDO specification norms, these norms mainly in the form of interface describes the software system must have features. Through the development of norms, SUN company guided the direction of development of Java technology, at the same time to the interface to provide a broad space for free play.
(2) for the interface are: interface-specific manner in order to achieve the standard norms. For example, some open-source software, such as Tomcat and Resin, respectively, in different ways to achieve the standard Servlet specification. With an interface allowing the realization of a number, making the area of Java maintained opinions good momentum
(3) interface for the caller: the caller of the program interface have good portability. Application to JavaWeb for example, Tomcat and Resin subject to the same specifications, so users can smoothly JavaWeb application from Tomcat to Resin container container transplantation.
Packaging and abstract
Packaging refers to a large system that contains a small system, large-scale systems are built on small systems have been based on more complex, more powerful systems. For example, Hibernate carried out on the JDBC API package to rely on the Hibernate internal JDBC API to manipulate the database, but the Hibernate API than JDBC API has more powerful functions, such as JDBC API to connect and manipulate only the function of the database, and Hibernate not only with this a function, also has the object - relational mapping functionality.
Refers to an abstract from the already existing functions with similar, but different interfaces to extract common system, to extract a unified interface. For example, Hibernate Transaction API is JDBC Transaction API and Java Transaction API (JTA) abstract.
Inheritance and expansion of
Inheritance and expansion is a pair of twin brothers, when the succession between the two types of relations, then there must also exist to expand the relationship. The advantages of inheritance is to improve the reusability of code, sub-class will inherit all the parent types of public and protected properties and methods, the procedures in the sub-class code, no need to repeat the definition of these attributes and methods. The merits of the expansion is to make software applications with scalability, has been able to expand the basis of functional new features.
Make full use of the Struts framework for the expansion of thinking. Struts framework, the supply of many types of procedures are scalable, which one is the most important categories of Action, Class Action has been in the definition of a number of commonly used methods, the use of Struts application framework JavaWeb Class Action will be extended to create a specific process is responsible for customers or business category of the Action.
Object life cycle
When an object is created through the new statement, it will have a fixed memory space, if there is no variable references it, it will end of life cycle, the memory space occupied by it at any time may be the JVM garbage collector recovery.
How to manage the application life cycle of this object? At present, the practice of the popular object stored in a "zone". For example, in JavaWeb applications, JavaBean can be stored in request, session or application scope. Each range corresponds to an object, such as the HttpServletRequest object corresponding request scope, session scope of the corresponding HttpSession object, application object ServletContext scope of the corresponding. Stored in a JavaBean with request scope, in essence, is a collection of the HttpServletRequest object properties to join the JavaBean references, this collection of attributes, also known as the cache object HttpServletRequest.
Stored in a JavaBean with request scope, is equivalent to the following two statements:
A JavaBean into the HttpServletRequest object cache and a JavaBean object HttpServletRequest
When the request is located in the framework of JavaBean, the JavaBean dependent on the life cycle of the life cycle of the HttpServletRequest object, HttpServletRequest object when the end of the life cycle, and this JavaBean application nor the other variables quoted, it will be the end of the life cycle.
HttpServletRequest object itself, then the life cycle of who is going to manage the money? This is determined by JavaWeb containers (also called Servlet containers) to management. For each HTTP request, JavaWeb container will automatically create a HttpServletRequest object, when completed in response to HTTP requests, JavaWeb containers will be the end of the life cycle of this object. Similarly, when the beginning of each HTTP session, JavaWeb container will automatically create a HttpSession object, when the session ends, JavaWeb containers will be the end of the life cycle of this object; JavaWeb application when each startup, JavaWeb container will automatically create a ServletContext object, when this application was closed, JavaWeb containers will be the end of the life cycle of this object.
In Hibernate, in the framework of net.sf.hibernate.Session to add a persistent object is, in essence, a collection of objects in the Session attribute added to the persistent object. The following is equivalent:
Session to include in the scope of a persistent object in the Session's cache by adding a persistent object of a persistent object associated with the Session
It is worth noting that, Hibernate can not only manage the Session cache of persistent object life cycle, will be responsible for persistent object in accordance with changes in the state to update the database simultaneously.
Integration of the basic steps of open source software
In the development of Java applications, in order to enhance development efficiency and shorten the development cycle, often provided by the need to integrate third-party Java software, ORM mapping tools such as Hibernate, MVC frameworks Struts, log tools Log4J and Web service software such as Apache AXIS. Applications in their own integration of these third-party software, the whole steps are very similar.
(1) to copy their files to the JAR in the classpath.
(2) to create their configuration file (XML file or Java properties file), the configuration file usually located in the classpath.
(3) in the proceedings of the interface to access them.
Interface with the configuration file is the software system's two main window open. Whether it is Tomcat, Struts or Hibernate, is inseparable from the configuration file, as compared with the preparation of program code, configuration files can improve the maintainability of software, more flexible to adapt to the changing needs of users, but not good at expression profiles are very complex logic, in which case, we must resort to the procedure code. As software users, if only want to quickly master a new Java software to use and does not intend to deeper understanding of software principles and the inherent structure, nothing more than to understand its interface, as well as the use of configuration files. Of course, if you want to use the software easier to reach the point, but also should be aware of the software itself, the realization of the principle and structure, and nothing but the software is through the abstract, such as packaging and the realization of means, from simple small system, the more complex structure , but the external interface has a simple and unified large-scale system.
Author:孙卫琴Writing Time: 2005 / 5







