Home  >  Article  >  Backend Development  >  What are java and php

What are java and php

青灯夜游
青灯夜游Original
2021-11-18 10:18:253011browse

Java is a general-purpose object-oriented programming language designed to generate code that can be used the same everywhere; it supports both server-side and client-side. PHP, "Hypertext Preprocessor", is a general open source, object-oriented, interpreted, architecture-independent, portable and dynamic scripting language, mainly suitable for the field of Web development.

What are java and php

The operating environment of this tutorial: windows7 system, PHP7.1&&java8 version, DELL G3 computer

What is java?

Java is a general-purpose object-oriented programming language designed to generate code that can be used the same everywhere. This programming language is class-based, object-oriented and human-readable. It supports both server side and client side.

Java can be both compiled and interpreted. The Java compiler converts the source code into bytecode, and then the Java interpreter generates machine code, which is directly executed by the machine running the Java program. It's reliable, distributed, and portable. It can be used to develop standalone applications or web-based applications.

Java has the characteristics of simplicity, object-oriented, distributed, robustness, security, platform independence and portability, multi-threading, and dynamics. Java can write desktop applications, Web applications, distributed systems and embedded system applications, etc.

What is php?

PHP (foreign name: PHP: Hypertext Preprocessor, Chinese name: "Hypertext Preprocessor") is a general open source, simple, object-oriented, interpreted , a robust, secure, very high-performance, architecture-independent, portable, dynamic scripting language.

PHP is a scripting language executed on the server side. It is similar to C language and is a commonly used website programming language. PHP's unique syntax mixes C, Java, Perl, and PHP's own syntax. It is conducive to learning and widely used. It is mainly suitable for the field of web development.

PHP has been influenced by different programming languages ​​such as Perl, C, C, Tcl and Java. It is primarily developed and implemented using the C programming language and some features of the C programming language. PHP supports different cross-platform operating systems such as Windows and UNIX-like systems.

Most popular content management systems use PHP, which is currently considered the most entrenched runtime environment on servers; providing hosting providers with better search engine ratings and accessibility.

Comparison of java and php

1. Running mechanism:

Java code is compiled After being converted into bytecode, it will be re-compiled by JIT in the virtual machine into local code. According to rumors, its execution speed can be comparable to C. After my own testing, I implemented a simple Memcache protocol cache server in Java. Running under Java 1.6, compared with memcache itself, the access time ratio for the same amount of data is about 3:2. Although there is a gap, it is much better than imagined. Java 1.7 has made a lot of improvements in JIT, and its performance is even better than Java 1.6.

PHP directly interprets and executes text codes. Even with opcode caching technology, there is still an insurmountable performance gap. PHP's opcode is similar to Java's class bytecode, which is still interpreted and executed.

2. Processing concurrency:

Java adopts a single-process multi-thread approach for concurrent processing. The web application will start with the startup of the web server, and from The web browser's request will be assigned to the idle thread in the thread pool for processing. That is to say, when a request arrives, the process is ready, the thread is ready, and all Java has to do is process the business logic.

PHP adopts a multi-process approach for concurrent processing. There is no physical concept of web application in the web server. Each request is equivalent to an independent application, and the process is started as the request arrives. , and dies as the request ends. In the Fast CGI environment, there is a process pool technology similar to the thread pool, which is very helpful in improving performance. However, on the one hand, the communication between the web server and Fast cgi still needs to go through sockets, which causes a certain amount of IO loss. On the other hand, it is also difficult to communicate between processes in the process pool, so it is still unable to compare with Java in terms of concurrent processing.

3. Database application:

Java can use database connection pool technology to save time loss caused by the database connection process.

PHP does not have this benefit, the reason comes from the second point above.

As for the database interface, Java has JDBC and PHP has PDO. The two are very similar. However, Java has a lot of ORM technology frameworks (such as Hibernate) that make database operations extremely simple, and the way PHP runs determines that it is a restricted area for ORM (of course you can also do ORM, but to what extent you can do it depends on your ORM Determined by the tolerance of the performance loss caused).

The specific reason is that PHP cannot save global variables. Although there are static variables in the PHP class, this variable will be deleted from the memory after an http request is completed, but Java's static variables can always be exist in memory. In this way, PHP cannot use the "pool" technology, because the data in the pool cannot be saved

4. Caching technology

Java is a single process and has many caches It can be done directly in the Java heap without resorting to external tools. Of course, there are also good caching frameworks, such as Ehcache, which have very high performance because there is no network IO.

PHP’s multi-process and single-thread determines that it can only use external cache servers, such as Memcache.

5, hot deployment

Java’s hot The deployment capability is very weak. If you want to fix a bug without stopping the server, it is difficult to do so.

PHP is naturally hot deployed.

6. Development cost

A good Java programmer requires more knowledge reserves, and the cycle required for development and debugging is longer. A better web server There is also a fee.

PHP is free, and the web server is also free.

7. Security

This depends on how you define security. If it is code security, it is easy to decompile java class. In this regard, both almost.

Java has a security configuration mechanism to ensure that some "illegal operations" cannot be executed. In this regard, PHP is weaker.

However, while Java can easily cause the entire application to crash due to a BUG, ​​PHP is much safer.

In fact, there are many benefits to Java, but only the last three can make decision-makers choose PHP and abandon Java.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What are java and php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Can't I write js in php?Next article:Can't I write js in php?