Summary of Java knowledge points in operation and maintenance angle

Source: Internet
Author: User


Java is an object-oriented programming language, developed by Sun's programmers, not only absorbs the various advantages of C + +, but also forsake concepts that are difficult to understand in C + +, such as multiple inheritance, pointers, and so on, so the Java language has two features that are powerful and easy to use. Java is the representative of static object-oriented languages and is the most popular computer language in the world (no one)


Java contains four independent but interrelated technologies

    1. Jvm,java virtual machines, bytecode (bytecode) running Java on the JVM

    2. Programming languages for Java

    3. Java Class,java's class file format, which determines that bytecode compiled by Java programs should follow those specifications

    4. Java APIs (Java API), Java APIs are available to enable Java applications to develop faster and more efficiently




Java-presented files are usually file formats for Java classes, and Java source programs are converted to bytecode to run on the JVM


General Java program code from write to run to go through the following several steps:

    1. Java programming language +java API developed by programmers such as X.java

    2. X.java source program compiler compiled into Java class files such as X.class (Java class file is Java bytecode)

    3. In the JVM, class loader loads the X.class class file and the interpreter interprets the X.calss file as the corresponding OS platform binary by the bytecode format, so that the Java program can run on the JVM again.



Note: the. class file is a byte-code, but the bytecode cannot be run directly and still needs to be interpreted by the interpreter in the JVM as the corresponding OS binary to run (the machine can only understand the binary)


The process of writing from write to execution for Java code


650) this.width=650; "src=" http://img1.51cto.com/attachment/201309/18/2033581_1379484229ak7w.png "alt=" Effect 1 "/>


How the JVM performs the interpretation:

    1. A one-time interpreter that interprets bytecode and executes, but the second execution requires the bytecode to be re-interpreted

    2. The instant compiler, the interpreted class (bytecode), is cached in memory, used for the next execution, and not executed again, but it is very memory-intensive to cache all the binaries generated by the interpretation

    3. Adaptive interpreter, which only interprets the code with high frequency and then caches the interpreted binary, the next execution does not need to be explained, and generally only caches 20% of the code interpretation (think that 20% of the code completes 80% of the operation)


Here is the Java execution process

650) this.width=650; "src=" Http://img1.51cto.com/attachment/201309/18/2033581_1379484230GET7.png "alt=" 2033581_ 1379484230get7.png "/>





The JVM, the Java Virtual machine, is a specification for computing devices, the core and foundation of Java, and a virtual processor between the Java interpreter and the OS platform. It is a computer based on the lower-level operating system and hardware platform abstracted by software method. Java's bytecode program can be executed above, because the JVM exists in Java to achieve a single compilation run everywhere, to achieve a complete cross-platform operation


Java compilers only need to target the JVM, generate bytecode files that the JVM can understand, and then translate each instruction into a machine code (binary) of different platforms by the JVM, which can then be executed on the corresponding platform


650) this.width=650; "src=" Http://img1.51cto.com/attachment/201309/18/2033581_1379484229OcvU.png "alt=" 2033581_ 1379484229ocvu.png "/>


The Java platform consists of a Java virtual machine (Java VM, abbreviated JVM) and a Java application Programming interface (application programming Interface, short API). The Java application programming interface provides a standard interface that is independent of the operating system and can be divided into basic and extended sections. After installing a Java platform on a hardware or operating system platform, Java applications can run. The Java platform is already embedded in almost all operating systems. This allows the Java program to be compiled once and run on a variety of systems. The Java application programming interface has been developed from version 1.1x to version 1.2. The common Java platform is based on Java1.5, and the most recent version is Java7.0.



JRE (Java running environment) Java Runtime Environment: The JRE can let the compiled class (bytecode) run up, is the smallest environment which lets the Java run up. Simple to say Jre=jvm+api (excluding development-related APIs)


The JDK (Java Development Kit) is the Java Language Software Development Toolkit, the smallest environment in which Java language development and operation is implemented. Simply speaking, Jdk=java language +api+ compiler +JVM


Depending on the Java application domain, the JDK has the following categories:


Java SE (J2SE), Standard Edition, is a version we typically use, starting with JDK 5.0 and renaming Java SE.


Java EE, Enterprise Edition, Business Edition, uses this JDK to develop the Java EE application, starting with JDK 5.0, and renaming it to the same.


Java Me (J2ME), Micro Edition, is primarily used for Java applications on mobile devices and embedded devices, starting with JDK 5.0 and renaming Java me.


If you do not have a JDK, you cannot compile the Java program, and if you want to run only Java programs, make sure that the appropriate JRE is installed.



Here's a Java two special class applet and servlet


Applets are written in the Java programming language, and after the compilation applet applets can be embedded in the HTML (the HTML file containing the applet page with the <applet> and </applet> a pair of tags), Then the client side of the browser as long as the installation of the JRE plug-in can be run on the client side of the Apple Application applet, and the results displayed on the clients, which is the Dynamic Web site


But the client dynamic site has a very dangerous place, that is, if someone gives you an HTML page embedded in a harmful applet, you do in the client will damage your computer, and the implementation of the applet must be installed on the client side of the JRE, So applets are rarely seen now.



The information about the applet in the HTML file should contain at least the following three points:

1) bytecode file name (compiled Java file with. class suffix)

2) The address of the byte-code file

3) How to display applets on a Web page.


The servlet (server Applplet) is a server-side program written in Java, whose main function is to interactively browse and modify data to generate dynamic Web resources; The servlet allows the Java language to be based on a similar CGI (Common Gateway Interface) technology develops dynamic Web resources running on the server side, but on servers with large traffic, the advantage of Java Servlet is that they execute faster than CGI programs. Individual user requests are activated as one thread in a single program without creating a separate process, which means that the overhead of server-side processing requests is significantly reduced.


The main function of a Servlet is to interactively browse and modify data to generate dynamic Web content. This process is:

1. The client sends the request to the server side;

2. The server sends the request information to the Servlet;

3.Servlet generates the response content and passes it to the server. Response content is generated dynamically, usually depending on the client's request;

4. The server returns the response to the client.



JSP (Java server Page) Java Server page, which is a special class of the servlet, is fundamentally a simplified servlet design, JSP is in the traditional Web page HTML file (*.html or *.htm) inserted in the Java program segment, A JSP file (usually *.jsp) is formed, and a Web application developed with JSP is supported across platforms that can run on Linux and run on other operating systems, and a well-known framework for developing JSP programs is SSH (Structs, Spring, Hebernate)


The JSP implements the Java extension in HTML syntax (in <%,%> form). JSP, like a servlet, is executed on the server side. Usually returned to the client is an HTML text, so the client can browse as long as there is a browser (applet to install the JRE on the client).


Note:

The applet simply embeds a compiled applet applet into the HTML and sends it to the client, which runs on the client side according to the JRE;


The servlet mainly implements the development of Web dynamic resources running on the server side in the Java language, and most of these web dynamic resources developed by the Java language are. JSP Resources


JSP is a scripting language, the main implementation of the Java code embedded in the HTML (which is the main difference between JSP and servlet), resulting in the. JSP class Web dynamic resources, so that the development of dynamic web based on Java technology


JSP performance is better than PHP, so some large sites are used JSP development,. JSP program execution process is as follows


    1. The. JSP is handled by Jasper. Java source Program

    2. . Java is compiled by the compiler into a. class

    3. The. Class class is loaded on the JVM to interpret and run


The process of JSP operation

A JSP page has multiple customer access, the following is the first customer Access JSP page when the JSP page execution process:

The client sends the request to the server-side JSP page through the browser

    • The JSP engine checks to see if the servlet source code for the JSP file exists, and if there is no move to 4th, perform the next step

    • The JSP engine checks to see if the JSP page needs to be modified, and if not, move to the 5th step, otherwise proceed to the next

    • The JSP engine translates the JSP paging file into the servlet source code (corresponding. Java code)

    • The JSP engine compiles the servlet source code into its corresponding bytecode (. Class code)

    • JSP engine loads bytecode into memory

    • Bytecode processes customer requests and returns the results to the customer


650) this.width=650; "src=" Http://img1.51cto.com/attachment/201309/18/2033581_1379484230Pbtf.png "alt=" 2033581_ 1379484230pbtf.png "/>



In the case of not modifying the JSP page, in addition to the first customer Access JSP page needs to go through the above steps, the subsequent access to the JSP page of the customer request, directly to the JSP corresponding bytecode processing, and the processing results are returned to the customer, in this case, the JSP page does not need to start the server, To reload the modified JSP page.


CGI (Common Gateway Interface) Universal Gateway Interface, CGI is the interface standard between external applications (CGI programs) and Web servers (also understood as a protocol or mechanism), which is the process of passing information between CGI programs and Web servers CGI allows a client to transfer data from a Web browser to a program executing on a network server CGI describes a standard for transmission between a client and a server

The following can be used to understand the role of CGI


The client requests the server, the Web server responds to an HTML static form, and the user fills out the form and then gives the form to the Web server (equivalent to another HTTP request). When a Web server receives a form that is filled out by the client, it is submitted to the backend application as a CGI protocol for processing


Many applications can pass parameters, and CGI allows the user to provide some data through the form, and then pass the data as parameters to the appropriate back-end application (such as PHP) for the program to process it (not the backend application is PHP, C, C + + Even a script CGI can interact with the backend program or script to process the data, after processing, the backend program again through the CGI mechanism back to the previous segment of the Web server (Httpd/nginx) and then by the Web server to encapsulate the results of the response to the client


In the lamp and LNMP architecture between PHP and the previous apache/nginx is a combination of CGI mechanism, for the client's dynamic request (mainly for PHP dynamic resource request) from the front-end web_server to the back of the PHP, let PHP processing.




Servlet Container (servlet Container): Contains features that the JDK and JDK do not have, allows a servlet to run, has a corresponding servlet process, and the servlet process is responsible for receiving requests from the front-end CGI. and runs the processing on the local JVM, and is responsible for monitoring the Local. Java program has been modified, and once the modification has been made, the compiler (provided by the JDK) is compiled into a. class


Web Container (Web container) is a framework that contains Jasper and servlet-related technologies. One of the Jasper is responsible for monitoring the local. JSP program is modified, as soon as it is modified to replace it with the. Java source code, and. Java is given to the servlet for processing


Note: Web container is one more than servlet container Jasper


Now a lot of web containers can directly interact with the user's request directly (that is, the front end does not have Web server decoding HTTP requests and encapsulating HTTP responses) the Web container can rely entirely on its own components (for Tomcat as a web Container connector) enables direct interaction with the client. But let the connector directly face the user's request, may cause too much pressure to handle the situation (if the performance of the connector is not very good), it is generally in the front end plus a Web proxy (such as Nginx), let Nginx establish, maintain, release the user's request and connection, When a user's request resource does not have a cache on the front-end Web server (nginx), the request is then forwarded to the backend Web Container (such as Tomcat) for processing by Nginx. and the corresponding architecture is called:


Nginx + Java Web Container (sometimes also an application server)


But whether the Web Container or servlet Container or the JDK is running in the JVM, the Web container| Servlet container| The JDK actually starts and then the OS behaves as a JVM process (JVM instance), that is, in the JVM if you are a web containter it has the function of Web container, JDK has JDK function, responsible for the function of only the JVM itself


The JVM instance can start multiple threads in the same JVM instance to complete the concurrency response, and the JVM also includes:


Thread Private Memory Area

    1. Program counter

    2. Java Virtual machine stack (primarily used to hold local variables)


Thread Shared memory Area

    1. Method area

    2. The heap (the largest amount of memory used by the heap) is primarily intended for storing objects, and when the counter is 0 o'clock, the object is considered dead and then purged by GC (garbage Collector) to avoid heap overflow



And the GC to the object cleanup according to a certain algorithm, there are the following several

    1. Tag cleanup algorithm (which object is dead first marked and then unified clear), but this mechanism has a drawback is that the GC garbage removal will cause the CPU to soar, resulting in a sudden decline in server performance, and generate a lot of memory fragmentation

    2. Copy algorithm, two copies per object, no memory fragmentation but only 1/2 memory utilization




Types of GC

    1. Serial only one object can be recycled at a time, serial

    2. Parnew can be recycled one at a time, parallel recycling

    3. CMS (Concurrent Mark Sweet) parallel tag cleanup, multi-threading, minimizing cleanup of programs in the JVM, but with the drawback that floating garbage cannot be collected (as long as the thread is running, it cannot be collected)

    4. G 1 features no memory fragmentation, time to define pauses




Wish you a happy New Year!!! 2017 effort! Struggle!!!


650) this.width=650; "Src=" https://ss0.bdstatic.com/94ojfd_baact8t7mm9gukt-xh_/timg?image&quality=100& size=b4000_4000&sec=1483198356&di=28a68ae39aecbecb90db34bb151cf8d8&src=http://img22.mtime.cn/up/ 2011/07/09/222256.34952163_500.jpg "alt=" 222256.34952163_500.jpg "/>







This article is from the "11097124" blog, please be sure to keep this source http://11107124.blog.51cto.com/11097124/1888133

Summary of Java knowledge points in operation and maintenance angle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.