webshell大码_对大码说不

webshell大码

To become a good Java developer, just knowing Java syntax is not enough. There is so much more to work out to become a better Java developer. One such is to have a sound knowledge of Java libraries and frameworks, and learning how and when to use them.

要成为一名优秀的Java开发人员,仅了解Java语法是不够的。 要想成为一名更好的Java开发人员,还有许多工作要做 。 其中之一是对Java库和框架有充分的了解,并学习如何以及何时使用它们。

Java libraries are packages that contain classes or interfaces that fall into a certain category. These classes and interfaces contain methods that you can use in your program to address your programming-related issues.

Java库是包含属于特定类别的类或接口的程序包。 这些类和接口包含可在程序中使用的方法,以解决与编程相关的问题。

While Frameworks can be anything we use in developing applications- a library, a collection of libraries, or a collection of scripts, etc.

虽然框架可以是我们在开发应用程序时使用的任何东西,例如库,库的集合或脚本的集合等。

There are tons of libraries and frameworks available, so being familiar with at least a few of the most used is very important. So I will share with you some library categories which I thought Java developers, no matter whether you are an expert or a newbie should be aware of.

有大量可用的框架 ,因此至少熟悉一些最常用的框架非常重要。 因此,无论您是专家还是新手,我都将与您分享一些我认为Java开发人员认为需要的库类别。

1.记录库 (1. Logging Libraries)

Using print statements to print messages to the console for testing and debugging a Java program is a common practice. But this method of debugging is not that effective, as scanning hundreds of lines could be exhausting. Also, by experience, you all know that these lines of debugging you add, make your code cluttered and a mess.

使用打印语句将消息打印到控制台以测试和调试Java程序是一种常见的做法。 但是这种调试方法不是很有效,因为扫描数百行可能会很累。 同样,根据经验,大家都知道添加的这些调试行会使代码混乱不堪。

Logging libraries come in handy at such instances. These libraries are vital, especially in server-side applications, as you cannot see what’s going on inside servers, log files must be used for this purpose.

在这种情况下,日志库会派上用场。 这些库至关重要,尤其是在服务器端应用程序中,因为您看不到服务器内部正在发生什么,因此必须将日志文件用于此目的。

The java.util.logging package comes along with the JDK, but there are much better logging frameworks available like Flogger, SLF4j, LogBack, and also Log4j2(Log4j).

JDK附带了java.util.logging但还有更好的日志记录框架,例如Flogger SLF4j LogBack以及Log4j2(Log4j)

You can learn more about these here.

您可以在此处了解更多信息。

2.单元测试库 (2. Unit Testing Libraries)

A Java developer should ensure the quality of the software he develops and should catch bugs as soon as possible. For those, Unit testing is a good approach.

Java开发人员应确保所开发软件的质量,并应尽快发现错误。 对于那些人, 单元测试是一个好方法。

Unit testing means breaking your code into the smallest pieces of testable codes and subjecting each piece to a series of tests to verify if the purpose of that code is satisfied or not.

单元测试意味着将您的代码分成最小的可测试代码段,并对每个代码段进行一系列测试,以验证该代码的目的是否得到满足。

Simply, it means — writing a piece of code(unit test) to verify the code (unit) written for implementing requirements. But most developers skip this step as they think this is extra work or due to a tight schedule.

简单来说,这意味着-编写一段代码(单元测试)以验证为实现需求而编写的代码(单元)。 但是,大多数开发人员会跳过此步骤,因为他们认为这是多余的工作或时间紧迫。

But writing good unit tests is important because it is better to detect and fix bugs during this test and save both money and time rather than finding bugs at the latter stages of software development.

但是编写良好的单元测试很重要,因为在此测试期间检测和修复错误并节省金钱和时间比在软件开发的后期发现错误要好得多。

Writing own codes for unit testing is a lot of work and it is not necessary. This Stack Overflow answer will show you an example of writing unit tests manually.

为单元测试编写自己的代码是很多工作,并且没有必要。 这个Stack Overflow答案将向您展示手动编写单元测试的示例。

A library like JUnit, AssertJ, TestNG, Mockito, Wiremock, and PowerMock can be used, for you to get the job done.

就像一个图书馆的JUnit AssertJ TestNG的 的Mockito Wiremock PowerMock可以使用,为您完成工作。

So be familiar with using unit testing libraries. It will help you to detect bugs early, improve code quality, save money and time, and many more benefits.

因此,熟悉使用单元测试库 。 它将帮助您及早发现错误,提高代码质量,节省金钱和时间,并获得更多好处。

For unit testing debug,info, or warn log messages the above mentioned frameworks wouldn’t work. The LogCaptor library would help you out at these instances.

对于单元测试debug,info或warn日志消息,上述框架不起作用。 LogCaptor库将在这些情况下为您提供帮助。

3.数据库连接池库 (3. Database Connection Pooling Library)

Connection pooling is a data access pattern used by software applications to connect to databases.

连接池是软件应用程序用来连接数据库的数据访问模式。

This is done by a set of existing, reusable connection objects. Once a new connection is required, a connection object in the pool is retrieved, and then it is placed back in the pool after the thread which used is completed.

这是通过一组现有的可重用连接对象完成的。 一旦需要新的连接,就检索池中的连接对象,然后在使用的线程完成后将其放回池中。

If not for this data pattern, database connections are quite expensive. We can use libraries like Commons Pool and DBCP, as creating database connections at runtime takes time and makes request processing slower.

如果不是这种数据模式,则数据库连接非常昂贵。 我们可以使用Commons Pool之类的 DBCP ,因为在运行时创建数据库连接会花费时间,并使请求处理变慢。

4. HTTP库 (4. HTTP Libraries)

There is a built-in Java class HttpUrlConnection which allows us to perform basic HTTP requests without the support of any third-party libraries. All the classes needed for this are contained in the java.net package.

有一个内置的Java类HttpUrlConnection 这使得 我们可以执行基本的HTTP请求,而无需任何第三方库的支持。 为此所需的所有类都包含在java.net中 包。

But the code written with the help of HttpUrlConnection can be bulky and it does not provide advanced functionalities, full flexibility, and the user-friendliness needed.

但是借助HttpUrlConnection编写的代码可能很庞大,并且不能提供高级功能,完全的灵活性以及所需的用户友好性。

Therefore, we must use third-party libraries to fill this void. Some of those libraries which we can use are Apache HttpComponents Client, Jetty, and Spring 5 WebClient.

因此,我们必须使用第三方库来填补这一空白。 我们可以使用的一些库包括Apache HttpComponents ClientJettySpring 5 WebClient

But note that starting from JDK 11, Java provides a new API, the HttpClient API, as a replacement for the HttpUrlConnection. This supports modern web features without the need to add third-party libraries.

但是请注意,从JDK 11开始,Java提供了一个新的API HttpClient API 以替代HttpUrlConnection 。 这支持现代Web功能,而无需添加第三方库。

5.消息传递库 (5. Messaging Libraries)

A Message, as you know is a piece of information — a text, XML document, or JSON data, etc. Then messaging means the exchange of information between software applications or software components.

如您所知,消息是一条信息-文本,XML文档或JSON数据等。然后消息传递意味着在软件应用程序或软件组件之间交换信息。

JMS(Java Message Service), which is provided by Java, is used to create, send, receive, and read messages between different systems. You can also use Tibco RV messaging protocols to get the job done.

JMS(Java消息服务) 这是由提供的Java,用于创建,发送,接收和读取不同系统之间的消息。 您还可以使用Tibco RV消息传递协议来完成工作。

6. JSON解析库 (6. JSON Parsing Libraries)

The use of web-based applications is rapidly growing. This has resulted in increasing the use of JSON.

基于Web的应用程序的使用正在Swift增长。 这导致增加了JSON的使用。

JSON is used as a communication protocol between server and client. Earlier this task was done using XML and now it is almost completely replaced by JSON. This is because JSON requires less coding and has a smaller size, making it faster to process and transmit data.

JSON用作服务器和客户端之间的通信协议。 之前,此任务是使用XML完成的,现在几乎完全由JSON代替。 这是因为JSON需要较少的编码,并且具有较小的大小,因此可以更快地处理和传输数据。

In JSON parsing, the JSON data received is read, then interpreted as a list object, and presented it to the end-users in a user-friendly way.

J SON解析中 读取接收到的JSON数据,然后将其解释为列表对象,并以一种用户友好的方式将其呈现给最终用户。

Although, there is no in-built JSON library in JDK you can use third-party libraries like Jackson, Gson, JSON.simple, JsonParser, Genson. The best one for your project must be decided by you accordingly.

尽管JDK中没有内置的JSON库,但是您可以使用第三方库,例如Jackson Gson JSON.simple JsonParser Genson 。 您的项目的最佳选择必须由您相应地决定。

Here is some help for you in selecting the library which suits best to your project.

这里有一些帮助您选择最适合您的项目的库。

7.通用Java库 (7. General Purpose Java Libraries)

There are some really exciting third party libraries available which you can use to make coding a lot more simplified and cleaner. Here are some of them;

有一些非常令人兴奋的第三方库可供您使用,您可以使用它们来简化和简化代码。 这里是其中的一些;

This is a project which is concerned with creating Java libraries- Commons Math, Commons CLI, Commons CSV, and Commons IO are some commonly used Apache Commons libraries.

这是一个与创建Java库有关的项目-Commons Math,Commons CLI,Common CSVCommons IO是一些常用的Apache Commons库。

Provide solutions for many problems encountered in projects like collections, Maths, strings, inputs, and outputs.

提供解决方案中遇到的许多问题的解决方案,例如集合,数学,字符串,输入和输出。

Lombok is a very useful library, especially this helps to avoid repetitive code. For example, you know that getters and setters of a program take a considerable number of lines of code, making it cluttered. But with Lombok, you can have a cleaner code as it generates the repetitive code but does not make it visible in the code.

Lombok是一个非常有用的库,尤其是有助于避免重复的代码。 例如,你知道一个程序的gettersetter需要相当数量的代码行,使其混乱。 但是,使用Lombok,您可以使用更简洁的代码,因为它会生成重复代码,但不会使其在代码中可见。

As I mentioned at the beginning there are tons of libraries and frameworks available. Explaining them in detail to the depth is impossible and it will make this article too lengthy.

正如我在开始时提到的,有大量的库和框架可用。 不可能对它们进行深入的详细解释,这会使本文太冗长。

This article was only meant to enlighten you on how Java libraries and Frameworks can help you out from boilerplate code. So there are many more things that you should investigate by yourself about the above-mentioned library categories as well as about the ones I haven’t touched. Explore more about their pros and cons that will give you an idea about what best suits your program.

本文仅旨在向您启发Java 框架如何帮助您摆脱样板代码。 因此,关于上述库类别以及我没有涉及的类别,您还需要自己研究更多的事情。 进一步了解他们的优缺点,这将使您对最适合您的程序的想法有所了解。

I hope this was helpful. Hope to see you with more articles soon. Thank you for reading.

我希望这可以帮到你。 希望很快能再见到您。 感谢您的阅读。

翻译自: https://medium.com/javarevisited/say-no-to-bulky-codes-83a792474597

webshell大码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值