Coding specification for Java programs (6)

xiaoxiao2021-03-06  58

This article is selected from: IBM DW China ● Utility class UTILITY class (class only) should be stated to prevent inheritance or initialization. ● Initialization The following code is a good way to initialize array: Objectarguments = new object [] {arguments}; ● Enumeration Type Java's support for enumeration, but the following code is a very useful template : Class Colour {Public Static Final Colour Black = New Colour (0, 0, 0); Public Static Final Color Red = New Colour (0xFF, 0, 0); Public Static Final Color Green = New Colour (0, 0xFF, 0 ); Public static final color blue = new color final color white = new color final color white = new color (0xFF, 0xFF, 0xFF);} This technology implements RED, Green, Blue, etc. can like other languages. The constant used in the enumeration type. They can compare with '==' operators. But this is used to use a defect: if a user uses such a method to create a color Black New Colour, this is another object, the '==' operator generates an error. Her equal () method is still valid. For this reason, the defect of this technology is best to indicate in the document, or only in your own package. Swing avoids using AWT components ● Mixing Use AWT and SWING components If you want to use the AWT components and Swing components, use it. In fact, try not to mix them up. ● Scrolling AWT Components AWT components must not use JScrollPane classes to implement scrolling. When scrolling the AWT component, you must use the AWT SCROLLPANE component to be implemented. ● Avoid using AWT components to use AWT components in the InternalFrame component to do so, or else will have unpredictable consequences. ● Z-Order issues AWT components are always displayed on the Swing component. Be careful when using the POP-UP menu containing the AWT component, try not to use it like this. Debugging debugging is a very important part of software development, there is a part of the software lifecycle. Debug can be opened with configuration, the key is the most basic. A very commonly used debugging method is to use a PrintStream class member, when not defined the trial flow, the class wants to define a DEBUG method to set the stream of debugging. Performance ● When writing code, you should consider performance issues from head until tails. This is not to say that time should be wasted on the optimization code, but we always remind yourself to pay attention to the efficiency of the code. For example, if there is no time to implement an efficient algorithm, then we should record in the document so that you will come again in the future. Not all people agree to optimize the performance of this view when writing code, and they think that performance optimization should be considered in the later stage of the project, that is, after the outline of the program has been implemented. ● Unnecessary object constructs do not construct and release objects in the loop. Use StringBuffer objects: Try to use StringBuffer classes when processed String, and the StringBuffer class is the basis for constituting the String class.

转载请注明原文地址:https://www.9cbs.com/read-82750.html

New Post(0)