Basic data types of Java
Java is divided into basic data types and reference data types. Basic data types are divided into four categories and eight types. Reference data types are divided into interface, class, array and string.
There are four categories and eight basic data types:
Integer type: byte, short, int, long
[in Java, the default integer type is int]
Floating point type: float, double
The memory space of float (single fine point floating point type) is 4 bytes and that of double (double fine point floating point type) is 8 bytes
[the default decimal type in Java is double]
Character type: char
The type used to store a letter or Chinese character. The memory space is 2 bytes
[in Java, Unicode international unified coding is adopted for characters. One character occupies two bytes, and a Chinese character can also be stored in char type, because a Chinese character also occupies two bytes]
Boolean type: Boolean
There are only two values: true and false, which are used for logical operation and process control
Basic data type conversion
Boolean type cannot be converted to any other type
Automatic conversion type: convert data types with small storage range to data types with large storage range
Forced data type conversion: conversion from data types with large storage range to data types with small storage range requires the addition of a cast character
Capacity valid to large: int ----- > long ------ > float ------ > double
[byte, short and int are all calculated according to the int data type]
Char type and int type conversion
1. You can copy char type variables directly to int type. When outputting int type variables, the result is the ASCII code value corresponding to the character
2. Converting int to char requires a cast character.