Rapid Java development for PHP programmers

小云云
Release: 2023-03-17 19:00:02
Original
2254 people have browsed it

PHP programmers quickly develop Java, just like we are learning java with a magnifying glass. After so many years of development, java can be said to be very huge. The same goes for learning a new language. There are many online tutorials, which are very large and comprehensive. Generally, you have to study systematically for 30 to 60 hours before you can formally contact project development. The basics are very important, but learning too many basics will make everyone lose the fun of learning and self-confidence. Many knowledge points can actually be made up after the project. Learning on demand is the best way to learn driven by yourself.

Rapid Java development for PHP programmers

For example, the hash distribution, hash collision, and dynamic expansion of hashmap, these are what we need to understand in the later stage to improve in depth. In the early stage, we only need to know how to get the hashmap Just do whatever you want.

Oriented to implement things that we are familiar with

For example, when we develop Web back-end APIs, we first start with commonly used loops/iterations, conditional judgments, additions, deletions and modifications. So can we quickly use java to implement these things that we can do very easily with php?

This will help us quickly improve our self-confidence.

Learning method using analogy

How to implement it in PHP, just implement it again in java.

Finally, in-depth systematic study

After you have implemented some small demos, you can refer to other people's projects. If you just look at other people's projects from the beginning, you may have no idea what others are doing. For example, if someone else uses ConcurrentHashMap, then think about why I use HashMap but he uses ConcurrentHashMap. Look at the open source code with questions and thoughts.

After completing some simple projects, you can go back to systematic study. At this time, there will be different gains.

Finally, when the project needs to be tuned and performance improved, break it down individually and learn in depth to be more targeted and targeted.

The actual battle begins

We use netty to provide high-performance web services. It is simple and convenient to use (netty is not simple) and does not depend on other software. Then think about what are the essential components needed to complete a simple web api server. (In fact, when thinking about this, you must keep in mind that making a simple architecture must be done by heart).

I briefly summarized it:

  1. java basic data type (php also has it, don’t be afraid)

  2. java collection framework ( PHP has arrays, very powerful)

  3. First introduction to maven (php has composer)

  4. Reflection (used in framework routing and other places, PHP Also available)

  5. Serialization (used for data transmission, PHP does not have complex data structures and is N times simpler)

  6. jdbc (database operation To use it, php has pdo)

  7. Get a general understanding of generics, annotations and other syntax (optional)

  8. Use netty to actually develop a web api service (php has swoole)

Java basic data structure, various basic data type packaging classes

Rapid Java development for PHP programmers

Java - Collections Framework high-frequency class example

Rapid Java development for PHP programmers

#HashSet is a set without duplicate elements. It is implemented by HashMap and does not guarantee the order of elements, which means that the order of insertion of the elements is inconsistent with the order of output.

This is actually an old friend of mine. It is often used in redis. For example, we can use it to implement a blacklist, so that the search speed is very fast, and there is no need to query redis remotely. It is directly in the current memory. Inquiry.

ArrayList implements the function of a collection based on an array. It maintains a variable-length object array internally. All objects in the collection are stored in this array and realize dynamic expansion and contraction of the length of the array.

Isn’t this the commonly used index array in our PHP?

HashMap is implemented as a hash table data structure. When searching for an object, its position is calculated through a hash function. It is designed for fast query. The characteristics are fast and non-thread-safe.

First introduction to maven

The basic principle of Maven is very simple. It uses remote warehouse and local warehouse and a core configuration file pom.xml. The jar file defined in pom.xml is downloaded from the remote warehouse. To the local warehouse, each project uses the jar of the same local warehouse. The same version of the jar only needs to be downloaded once, and avoids copying the jar for each application.

This is very similar to PHP's package management tool composer, or composer is designed with reference to maven. Maven is more powerful. Composer needs to be imported for each project. Maven, like git, has a local warehouse. Third-party packages will not be directly referenced into the project, but will be introduced during compilation (yes not convenient). On the other hand, maven is not only a package management tool, but also a project management tool that integrates compilation, packaging, unit testing and other functions.

Implement controller access

Specific requirements: provide an api that allows users to specify user information

Definition interface:

http://localhost:10000/users/{id}
http://localhost:10000/?method=user.get&id={id}
Copy after login

Perhaps everyone is already accustomed to the former restful api interface.

Because this requires routing mapping and http method matching, considering the cost of learning, I did not choose this method.

Our goal today is to implement our functionality in the simplest and most effective way.

We first implement it in the simplest way (in fact, the API without routing is the fastest, after all, less judgment needs to be made).

The above content is how PHP programmers can quickly develop Java. I hope it can help everyone.

Related recommendations:

A PHP file upload class sharing_php example

php image watermark adding, compressing, and cutting encapsulation Class

The most complete PHP regular expression in history_regular expression

The above is the detailed content of Rapid Java development for PHP programmers. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!