Java Data types
Basic data type (lowercase is generally used)
- Characteristics
- In addition to the value without any identification, 1=1
- Immutable data types
- Within scope, local stacks are stored
- Low build costs
Object data type (except for data types other than base data types)
- Characteristics
- In addition to the value, there is an identity
- Partially variable
- In-heap storage, auto-recycle
- Generics for a unified representation
- High cost of building
- Ancestor: A subclass of object (the default is the parent class is object)
Wrapper classes for basic data types
- Encapsulates the base data type as an object for operation
- Use as little as possible and have less utility
- Java automatically transforms the basic data types into basic data types
Operator
- "+" to complete the concatenation of strings
-
- Operator form
- The method form of the object
- function Form Math.sin ()
Static language and Dynamic language
- Java is a static language
- Compile-time check
- Python is a dynamic language, run-time check
- Static check
- Bug check before running, compile-time check
- Purpose: Avoid bugs that result from using the wrong type of operation
- Content:
- Syntax error
- Wrong number of arguments
- Wrong parameter type
- return value Error
- Dynamic check
- Checking when the program is running
- Content
- Array out of bounds
- Null Object Call method
- The results are not clearly expressed.
- Static check for check type, dynamic check for value check
- The base data type may not show its original result
- Overflow
- The special value of the floating-point number represents nan,positive_infinity, negative_infinity
- Variability and immutability
- Invariance:
- The value cannot be modified after the immutable data type creation is complete
- Invariant references, once the reference location is specified, cannot be specified again
- Final retouching to avoid errors and easy to understand
- notation
- Final class cannot inherit
- The final method cannot be overridden
- Final variable cannot be modified
- Variability:
- Modify without changing the direction of the variable, directly modify the data
- Variability vs non-volatile
- Variable Type advantages:
- Minimizing copy copies of variables
- can be shared
- Variable type disadvantage: unsafe!
- aliases, alias
- Different names but access to the same area can cause problems!
- So you need to use defensive programming.
- So in a variable data type you can use the following notation: return new DATE (End.modify ()), or clone
Snapshot chart
- 显式地表示模型 - 单线是可变的,双线是不可变的 - 不可变的引用指向可变的值
Complex data types
- 数组: 1. 数组一旦创建,长度不可以进行修改—>a.length().- 数组列表 1. 变长数组,只能放对象数据类型 2. List本身是一个接口,new时必须时要初始化具体实现,arraylist或linkedlist- 迭代器(Iterator)- 集合set 同样也只是一个接口 - 不允许重复 - 无序性- 表 MAP 接口++,键值对- Iteration 遍历器。 1. for each循环时隐式地使用Iterator
Immutable data types
- Packing class
- You can control the user's use rights
- So that the collection cannot be modified after it is established
null reference
- Null is the object data type that corresponds to the
- Careless use of NULL can cause problems
- The meaning of NULL is ambiguous
Summary of simple Java data types