Discover java coding best practices, include the articles, news, trends, analysis and practical advice about java coding best practices on alibabacloud.com
%, the former is 100 times the latter, but it does use the same number of digits in the binary. Can do better, the method is variable length coding, the guiding principle is high frequency with a shorter number of digits encoded, low frequency with a longer digit code. Huffman coding algorithm is to deal with such problems. Huffman coded Java implementation
The d
subscript of each node of the Huffcode array is filled by the back forward and the prefix of the encoding is guaranteed to be the same as XX ... huffcode[0][6]=1 huffcode[0][5]=0Then Huffcode is 0000 0001 that is small Mark 1 of a Huffman node Huffman slowedFor (Huffmannode c=hn[j],p=c.getparent ();p!=null;c=p,p=p.getparent ()) {if (P.getlchild (). Equals (c)) huffcode[j][start--]=0;else huffcode[j][start--]=1;}//a path to the same node.huffcode[j][start--]=-1;//to the remaining path is padding
meaning of the Description field */Special NOTES:TodoA place that has not been completed but must be completedFixmeWhere the bug must be modifiedIf a method is an implementation of an interface, then the detailed method document comment should be written in the method of the interface class, and the implementing class method should guide the past through the @see.Code optimization:1. Avoiding the "God class"2. Try to separate some logic implementations, especially reusable ones, into different
1, the class name uses the Hump name method, the first letter capitalization.2, the class variable uses the Hump name method, the first letter lowercase.3, the method name is a verb phrase, the first letter lowercase, as far as possible to describe the intent of this method.4, note in the fine not many, a good note to try to describe the code to express the meaning.5, a function of the different operations of the Code section separated by a blank line, convenient for later maintenance.6, the var
Package (packages)Naming conventions for package names: 1, lowercase 2, at least one level of directory 3, domain inversion writingPackage Baidu;Package com.baidu.www;Class (classes)----- Large Hump MethodNaming conventions for class names: capitalize all words in the first letterClass MobileClass TestmobileInterface (interface)Naming conventions for interfaces: Capitalize all words in the first letterInterface Animal;Method (Methods)Naming conventions for methods: first letter lowercase, initia
Java multi-thread programming practices
Multithreading in Java programs is much easier to use than C or C ++, because the Java programming language provides language-level support. This article uses simple programming examples to illustrate how intuitive multithreading is in Java
java.sql.PreparedStatement instead of java.sql.Statement.(6) The method prefix used to set the state of the object must be set; the method prefix used to retrieve the state of a Boolean type object must be is, and the other method prefix must be get.(7) The program should use as few numbers (or characters) as possible, define static variables to illustrate the meaning of the number (or character). When you need to assign or compare in a program, use the static variables defined earlier. Excepti
In this paper, we describe the method of Base64 encoding for utf-8 of Chinese strings by JS. Share to everyone for your reference, specific as follows:
String to encode: "Select username from user"
Using Java for encoding, Java programs:
String sql = "Select User name from user";
String encodestr = new String (Base64.encode (Sql.getbytes ("UTF-8")); Coding
Writing concurrent code is more difficult, although the Java language provides a lot of synchronization and concurrency support, but ultimately it takes a person's diligence and expertise to write Java concurrency code without bugs. Java multithreaded concurrency best practices are a good set of practical ideas that he
Eclipselink and Hibernate, as follows: Eclipselink
q.sethint ("Eclipselink. Jdbc_fetch_size "," 100000 ");
Hibernate
@BatchSize
//Query here ...
Also, you can set paging-related settings for query: Query q = em.createnamedquery ("SelectAll");
Query.setfirstresult (101);
Query.setmaxresults (+);
list This will allow the data to be obtained from the 101th to No. 200 section only. At the same time, the above uses a named query (Named query,createnamedquery ()) instead of a temporary query (Ad-ho
Preface
To learn any technology that is a little difficult, you must make a rational analysis of it, and then make a decisive decision-> that is, what people often say is "Seeking for profit "; although this series involves socket-related knowledge, it is a kind of state of mind that I want to share with the programmers before learning: learning is a step-by-step process, and the mentality should be adjusted at any time, keep your defense against arrogance and rashness. For example, I recen
Java Database performance Best Practices
Spend time evaluating the bestJDBC driverfor the application.
The best driver would often vary depending on the specific deploy ment. The same application is better with one JDBC driver in one deployment and a different JDBC driver in a differ ENT deployment.
If There is a choice,avoid ODBC and type 1 JDBC Dr Ivers.
J
Java coding SpecificationThe first letter of each word in the naming conventions class must be capitalized, as shown in figureUserServiceIncorrect naming methoduserService、userserviceTest caseTestEnd, suchUserServiceTestIf it starts with the abbreviation, the abbreviation should all be in uppercase, as shown in figureHTMLEditorIncorrect syntax · the class name should contain English letters or numbers, and
the parent delegation model, where a classloader receives a request for class loading, is first delegated to the parent ClassLoader to complete, all load requests are routed to the top-level startup ClassLoader, and if the parent ClassLoader feedback fails to complete the load request, it continues to be loaded by the subclass.The benefit of this load is that the Java class has a hierarchical relationship with precedence over its classloader, avoidin
Introduction: Traditional Java EE applications typically use some kind of MVC framework (for example, Struts) as a front-end user interface, with the advent of Flex, RIA-based clients can bring users cooler interfaces, shorter response times, and closer to the experience of desktop applications. This article will describe how to integrate Flex into an existing Java EE application, and how to apply best
same problems as I do then look down, if not that may not help you in the following content.
First, check the text encoding of the current database.SHOW VARIABLES like ' character_set_% '
I am using the MySQL database, the code is as follows:
The workaround is simple to add a sentence after the database connection statement? USEUNICODE=TRUECHARACTERENCODING=GBK on the line.String url = "Jdbc:mysql://localhost:3306/db_databaseuseunicode=truecharacterencoding=gbk";String user = "root"
Do you think you are a Java expert? Are you sure you have fully mastered the Java exception handling mechanism? In the following code, can you quickly find the six problems for exception handling?
1 outputstreamwriter out =...2 Java. SQL. Connection conn =...3 try {// retry4 Statement stat = conn. createstatement ();5 resultset rs = stat.exe cutequery
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.