About APIs, commenting documents, and string

Source: Internet
Author: User
Tags processing text

API: (Appilcation programming Interface)

Is something that has been written, can be used directly to use the function, in Java in the form of a class encapsulation;

The role of the package: classify all class libraries as if a school is divided into different colleges,

Commonly used packages:

Java.lang: base class, such as String, Multi-threading, import not required

Java.util: Common tool classes, such as collection random generator, calendar, clock

java.io: File operation, input/output operation

java.net: Network operation

Java.math: Operations related to mathematical operations

Java.security: Security-related operations

java.sql: Database access

Java.text: Processing text, date numbers, information formats

Documentation notes:

/** Document Comments */

Added at the beginning of the class and method, to describe the author, time, version, to implement a detailed description of the function and other information

Convert annotations to HTML document descriptions through Javadoc;

String:

    1. Java.lang.String uses the final decoration and cannot be inherited;
    2. The string bottom encapsulates the character array and the operation algorithm for the character array;
    3. Once a string is created, the object is never changed, but the string reference can be re-assigned;

For example, string str = "Hello World": There is Hello World memory in the heap, and the STR variable holds the address in the stack.

If str = str+ "! "How did you add a" Hello world "to the heap? The new object, which is re-directed by Str, and the original "Hello World" will be recycled.

    1. Java strings are Unicode encoded in memory, with any one character corresponding to a two-byte fixed length encoding

string constant pool:

  1. For recurring string literals, the JVM will first look in the constant pool and return the object if it exists
  2. string is not conducive to frequent modification;
    1 /**2 * used to test string3  * @authorAdministrator4  */5  Public classdemo01 {6      Public Static voidMain (string[] args) {7String str = "HelloWorld";8String str1 = "HelloWorld";//The object of the STR is reused9System.out.println (STR==STR1);//trueTen         /* One * Compiler small features: A * If both sides of an operation are literal, then - * Calculations are calculated during compilation, and results are generated at the location of the expression - * Can save the overhead of Operation the          */ -String str2 = "Hello" + "World"; -         //String str2= Look in the "Hello World" bytecode file, the compilation process itself transforms the -System.out.println (STR==STR1);//true +          -String STR3 =NewString ("Hello World"); +System.out.println (STR==STR3);//flase Create a new object because it uses new A     } at}

About APIs, commenting documents, and string

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.