JAVA Advanced Notes ii – Application classes

1. The enumeration:

a.why:

Do you need to manually specify certain values when passing in values? – the enumeration

b.what:

Enumerations are types that consist of a fixed set of constants

C. the grammar:

[Modifier] enum enumName{enumContantName1 [enumConstantName2... [and]]/ / [field, method]

}
Copy the code

d.how:

Enumeration class. Enumeration value;Copy the code

2. Packaging:

A. Hy: What does the packaging class do

Provides a series of practical methods

Collections are not allowed to store data of primitive datatypes. wrapper types are used when storing numbers

B. Hat: Wrapper classes convert primitive type data to objects

Each base type has a corresponding wrapper class in the java.lang package

C. Matters needing attention:

1). All wrapper classes can construct their instances by taking their corresponding primitive data types as parameters

Public Type (Type value)

For example, Integer I =new Integer(1);

(*) With the exception of the Character class, wrapper classes can construct their instances by taking a string as an argument

Public Type (String value)

For example, Integer I =new Integer(“123”);

2).Boolean class constructor arguments are String. The Boolean object represents true if the String content is true(case insensitive), otherwise it represents false

When the wrapper class constructor argument is String, the String cannot be null.

The string must be parsed to the corresponding basic data type, otherwise the compilation passes, and a NumberFormatException exception is run

D. Boxing: the process of converting a basic data type to an object type;

Unboxing: The process of converting an object type to a primitive data type;

The rest of the wrapping is like Integer:

		byte----Byte

		short---Short

		int ---Integer

		long---Long

		float---Float

		double---Double

		char---Character

		boolean--Boolean
Copy the code

E. features:

All wrapper classes are final and cannot subclass them

After JDK1.5, the basic data type and packaging type can be mixed math, JDK1.5 and later automatic boxing and unboxing;

Wrapper classes are not intended to replace primitive data types, but are used when primitive data types need to be represented by objects

3.String: Corner markers start from 0

A. Construction method:

See the API

B. Common methods:

Length (): Gets the length of the string; Equals (): compares whether the contents of the string are consistent; ==: Determine the address of two strings in memory, that is, determine whether it is the same string object; EqualsIgnoreCase (): Compares content in a case-insensitive manner; ToUpperCase (): converts a string toUpperCase; ToLowerCase (): converts a string toLowerCase; +: string concatenation; Concat (): string concatenation; IndexOf (): Gets the corner value of the first occurrence of a character or string; CharAt (index): returns the character of the specified corner substring(startIndex): intercepts the character from the specified corner substring(startIndex,endIndex): intercepts the character from the specified range - n/A n/A N/A N/A The value is greater than or equal to startIndex and less than or equal to endIndex Trim (): Removes whitespace before and after strings; Split: Splits according to the specified formatCopy the code

C. Process stored procedure

4.StringBuffer:–StringBuider

A. Hy: Using the StringBuffer class for frequent string modifications (such as string concatenation) can greatly improve program execution efficiency

B.hat: a String buffer similar to String

c.how:

Append (): append method

D. Compare String:

String is immutable; if the content value changes, the object changes; A stringBuffer is always an object

It is best not to use strings that change content frequently

A StringBuffer is a mutable string

In cases where strings change frequently, StringBuffer is more efficient

JDK1.5 provides A StringBuilder, equivalent to a StringBuffer

5.Math:

The java.lang.Math class provides common mathematical operations and two static constants E (base of the natural logarithm) and PI (PI)

Provides common mathematical methods

Pow (): exponential method Random (): method to obtain a random number --0.0 <= value <1.0Copy the code

6.Random:

The java.util.Random object can retrieve Random values

​ API

7.date:

The date object

8.calendar:

Calendar objects:

Notice how objects are created and how properties are acquired