C # vs. Java learning: type judgment, class and interface inheritance, code specification and coding habits, constant definitionsType judgment symbol:C#:object A; if (A is int) {} Judged by the IS symbolJava:object A; if (a instanceof Integer) {} is judged by the instanceof symbolClass-To-Interface inheritance:C #: public class Mdatarow:listJava:Publicclass Mdatarow extends arraylistThe common denominato
Java coding in JS
In the current web applications, more and more page elements are operated by js, especially when an asynchronous request is initiated by js, encoding problems often occur. The following describes the Encoding Problems in js.1. Introduce js files externally
Contains string input in a separate js file, for example:
If a script. js script is introduced, the script contains the following code
Java coding specification (2)-General Linux technology-Linux programming and kernel information. For details, see the following section. 6.3 Placement)
Declare variables only at the beginning of the code block. (A block refers to any code contained in braces "{" and .) Do not declare the variable when it is used for the first time. This will confuse unfocused programmers and impede code portability in this
Understanding the basic thread mechanism of java-18.2 from the ground up (6)-using constructors or internal classes to implement multi-thread coding variations
In this section, we will discuss how to use constructors or internal classes to implement multi-threaded coding variations.
1. Basic implementation
package com.ray.ch17;public class Test {public static voi
. */@OverridepublicgetFilethrows IOException { thrownew" cannot be resolved to absolute file path");}Comments on attributes and variables and in-method codeUse // to annotate variables and attributes, and code within methods to use // annotationsIf the non-essential variables and attributes can be commented out, if the code has the responsible logic should be explained by using // annotationspublicServletContextResource(ServletContext servletContext, String path) { // check ServletContext
encoding to store it. This will take into account the importance of storage space or the efficiency of coding (three common).
1. ASCII code
We all know that ASCII code, a total of 128, with a byte of low 7-bit, 0-31 is the control character Furu space, enter, delete 32-126 is the print characters, can be entered through the keyboard and can be displayed.
Figure 1-ascii Code
2, UTF-16
Speaking of UTF must mention Unicode,iso trying to create a new hy
/** Coding Specification:* 1, all the names follow the "see the name of the understanding" principle* 2, all the names do not allow the use of Chinese characters or pinyin* 3, Java Engineering naming recommendations using lowercase, such as: OA, CRM, CMS ...* 4, package names use lowercase, for example: Cn.yeah, Com.ali, Com.baidu 、...* 5, the name of the class name, interface name:* 1) The name has only on
(); byte[] bytes4 = S.getbytes ("Utf-16be"); //utf-8 Code Chinese occupies 3 bytes, English occupies 1 bytes for(byteb:bytes4) { //converts bytes to int to be displayed in 16 binary modeSystem.out.print (integer.tohexstring (BAMP;0XFF) + ""); } System.out.println (); /** When your byte sequence is some kind of encoding, this time you want to turn the byte sequence into a * string, also need to use this encoding method, no one will appear garbled*/String str1=NewString
Coding and decoding of two-dimensional code qrcode in Java
Related to some of the main class library, convenient for everyone to download:
Code Lib:Qrcode_swetake.jar (Website introduction-- http://www.swetake.com/qr/index-e.html)
Decoding Lib:qrcode.jar (Website introduction-- http://sourceforge.jp/projects/qrcode/)
"One", Code:
Java Code Qrcodeencoderhandl
, int[] R3, int[] R4) throws illegalargumentexception{Ensure the arrays is of equal size......}9) ToString methodIn general, each class should define a ToString method:Public String toString () {...}) Main methodGeneral class, consider placing a main () method that contains the code used to test the class, and if it contains the main () method, it should be written at the bottom of the class.4. Java Coding
Java Coding Style:1. Factory method should be stateless.State normally refers to the member variables of class. Stateless, more precisely, it means immutable.Factory was just to create objects, and one call should not affect anothers, if it was mutable, then the method call Mnight The chance to the States.And then it would affect other calls which is not supposed to happen.2.Restrict the access level of any
we call the second position, the encoding in the page encoding declaration should be the same as the encoding used when the Web page file was saved.
and the browser's coding settings are actually not strict, as we said in the third section, in the browser choose to use GB2312 to view, it will actually still use GBK. And the browser also has the good habit, that it will try to guess what to use the code to see the most appropriate.
I would like to r
. Since I have set the operation as a high-level concept, more work can be done freely at the underlying runtime.
For imperative objects, developers often consider using reusable classes because their language encourages classes as building blocks. Function programming languages tend to reuse functions. Functional Languages construct complex general functions (suchfilter(),map()Andreduce()) And can be customized by functions provided as parameters. In functional languages, it is common to conver
member variable: Need to use GET, set method read, setting9.2. Important or repetitive expressions or methods should be extracted.9.2. Exception handling: Do not ignore any exception information. If you want to track more advanced exceptions, do not ignore the lower level exception information.9.3. Release resources: If you need to release resources, you need to put them in a finally block.Other references:Http://www.oracle.com/technetwork/java/codec
The norm needs to be noticed in the regular coding process, which is a good habit to develop slowly.1. Basic PrinciplesMandatory principle:1. The StringBuilder of the string must be used;The use of 2.try...catchTry {}catch{Exception e e.printstacktrace ();} finally {}// can be used in the outermost action, all other places are forbidden to use;Try { // program code }catch(Exception e) { // is empty, nothing is written } // prohibit use in any
public key, the public key and the private key belong to the message passing parties, carries on the encrypted message passing.Consider a scenario.A machine module needs to export the data to a file, send the file to the B machine, and import the data by B.In this scenario, a is equivalent to the server, which needs to give the certificate to B, encrypt the data with the private key, generate the signature, and export to the file.b corresponds to the client, using the received digital certifica
before the question, let's take a look at what is Url,uri and QueryString, as shown in 1:Figure 1:url-uri-querystringURL: is the acronym for the Global Resource Locator, as above localhost: refers to domain (IP or hostname), 8080: is the port Web service is generally 80,8080 is the use of its own test, to avoid and browser port conflicts.ROOT: Is the Contentpath, which is the virtual path, if the Tomcat server object is the Servlet: Is the Servletpath message, which corresponds to the Getspecial
Java inside the built-in strings are all UTF-16 encoding, detailed coding way to see hereimport Java.nio.charset.charset;import java.util.arrays;import java.util.Map; Public classString2bytes { Public Static voidMain (string[] args) {String str="\u005bab Me"; Mapcharset.availablecharsets (); for(String charsetName:charsetMap.keySet ()) {System. out. println (CharsetName +":"+ Charsetmap.Get(CharsetName));
Learn Java for a few months, has been to public,private,protected,static,final keyword and with each other not too concerned about, today read the "Java Security coding standards" only to find the severity of the problem.Code that does not conform to the rule:A data member of the underlying data type of public (common). Should be changed into private form.Public
directly allocated NIO buffer to read sensitive data from a file. After the data has been used. It can be cleared immediately, and sensitive data is not slow to exist in multiple locations, only in system memory.void ReadData () {Bytebuffer BB = bytebuffer.allocatedirect (16*1024); try (filechannel rdr = (new FileInputStream ("file")) . Getchannel ()) {while (Rdr.read (BB) > 0) {//does something with the Bufferbb.clear ();}} catch (Throwable e) {//Handle err or}}It is important to note that the
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.