Define your own tool library in Java

Source: Internet
Author: User

An experienced Java program person often defines a common statement as a tool and then puts it in its own ToolPak. Do not know if we have such a habit of operation, anyway, the author's tool library, there are hundreds of tools. With these tools, it is very convenient for the author to develop Java applications. That is, you can not worry about the conflict caused by the duplicate name, but also can simplify the input, kill both birds. To this end I strongly recommend that Java programmers from now on to build their own tool library, and in the future work constantly improve it.

A simple example of a tool library.

Remember when I first set up the tool library, is from an output statement started. Sometimes Java program developers need to include output statements in program code. such as the need for debugging to temporarily increase output statements to determine the accuracy of the results of operations, such as sometimes in order to enhance interaction with the user, before the user input parameters to the screen to output some of the prompt statements and so on. For this to happen, it is done in a Java program by either the Print method or the Println method. The difference between the two is mainly whether you want to wrap the line. But if you call both methods in a Java program, you'll need a whole bunch of prefixes. If you call this two method, write the following code full, that is System.out.print (), and System.out.println (). Obviously in order to output a string of information, to revenue such a long code, in the input of the workload is relatively large. It is also important to note that s must be capitalized in the system word here. For some beginners who just touch Java programs, the first is often written in the lowercase s, resulting in a syntax error. Especially in a Java code, this method needs to be used frequently. The use of this is more inconvenient. So is there a simpler way? In fact, Java program developers can simply add these methods to their own ToolPak to simplify the input method. And there is no need to worry about conflicts that can result from duplicate names. If you can install this method into your own tool library as follows.

After this definition, the next time you need to output to the screen, simply call it as follows, such as PR.PLN () or PR.P (). The difference between the two is whether you need to wrap lines. This is much simpler than calling the original output command directly. This is just one of the simplest examples. In fact, Java programmers can also enrich this screen output command. If you can add "Hu Jintao" to a similar transitional content before outputting the message, to indicate the content that emphasizes or formats the output. All of these can be defined in this tool. So, the next time you need to implement this requirement, you can use it directly. Without having to write more code to implement it.

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.