Dark Horse programmer-easy to confuse knowledge

Source: Internet
Author: User
Tags throw exception

String and StringBuffer class differences
1.String is fixed-length
For example: String s1= "abc"; s1= "EGF";
StringBuffer class: Is a string, because it has a buffer: The StringBuffer class represents a string whose contents and length are dynamically variable at any time .
The string itself can be inserted, deleted, modified, replaced and other operations, and the result of the operation affects the string object itself.
Ii. methods for creating StringBuffer type strings
1. Using the method of construction, it is not possible to use similar stringbuffer s1= "ABC";
A.stringbuffer (): Constructs a string buffer with no characters, with an initial capacity of 16 characters.
B.stringbuffer (String str) constructs a string buffer and initializes its contents to the specified string content. Initial capacity size is string length +16
c.stringbuffer (int capacity) constructs a string buffer with no characters but with the specified initial capacity
2. Common Methods
(1) Append () Series: Appends the string representation of a parameter to the sequence.
(2) setLength (): Sets the length of the character sequence and appends a valid null character if the Newlength parameter is greater than or equal to the current length
(3) Insert () Series: Inserts the string representation of a parameter into a sequence where: offset refers to the starting position of the character you want to insert
(4) Delete (int start, int end) Removes the characters from the substring of this sequence.
(5) reverse () replaces this sequence of characters with its inverted form.
3. Capacity and character length of the class
(1) Capacity () returns the current capacity.
(2) Length () returns (number of characters).
(3) Ensurecapacity: Ensures that the capacity is at least equal to the specified minimum value, and later dynamically adjusts the capacity

Abstraction and Interfaces

= = and equals

How to judge the equality of two objects
(1) For the object, if you use two object variables to make a judgment, can only explain two
Object variable is not pointing to the same block of memory.
(2) Note null: Represents a null reference
2.equals: Indicates whether another object is "equal" to this object.
(1) The method of inheriting from object is still not pointing to the same memory area.
public boolean equals (Object obj) {
return (this = = obj);
(2) rewrite in subclasses as needed in general
3.instanceof: operator, left is an object variable, the right is a type
Determines whether the left is an instance of the right type or its subclass, returns True, otherwise false
Application premise: The left side represents the type of object and the right type has an inheritance relationship

Characters and strings

(1) Character value: Defines the character type keyword: The char type constant is: "Enclose" as: ' A ', ' B ', ' \ \ '
(2) String: value enclosed in double quotation marks: "abc", "Cdef", "ab\n" (said: AB carriage return), "ab\\":(represents ab\), "China"

Overloading and overwriting

Up-and-down transformation

Throw and throws

Throws keywords: only describe what exceptions the method might have, not inside the method
Throws: After adding throws to the back of the method, the shape is as follows:
Method () throws Exception Class 1, Exception Class 2
Refers to: The method may throw exception Class 1, Exception Class 2 These class exceptions
Throw: Auto Throw exception
Such as: throw new ArithmeticException (), program and manual throw ArithmeticException type exception

Throws: Description of exceptions that may be thrown by the method
Throw: Throw exception

The difference between throws and throw:
Throws is an exception (system or custom) that is used to describe the future method that may be thrown by a method.
Throw: To throw an exception in a method, a new exception object is required and the exception information is encapsulated

Continue and break
Break: End Loop or switch statement
Continue: Usually indicates the end of this cycle.

Dark Horse programmer-Easy to confuse knowledge

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.