This is the sixth day of my participation in Gwen Challenge

The data type

Java is a strongly typed language, that is, Java variables must be used in strict accordance with the rules, defined before use

Strongly typed languages: All variables must be defined strictly and must be defined before they are used. High security, slow speed

Weakly typed languages:

JS VB

Java data types are divided into basic data types and reference types

Primitive data types There are 8 primitive data types

Integer types

type placeholder The most value note
byte 8bit 0x7f~0x80 127
short 16bit 0x7fff~0x8000 (32767).
int 32bit 0x7fffffff~0x80000000 (2.1 billion).
long 64bit Literals need the L suffix

Example code is as follows:

Public class Demo01{public static void main(String[] args){public static void main(String[] args){num1 = 10; Byte num2 = 20; short num3 = 30; long num4 = 40L; Float num5 = 10.1f; float num5 = 10.1f; //float with F double num6 = 3.14; // char name = 'a'; //String, String is not a keyword, is a class //String name = "abba "; // Boolean flag = true; }}Copy the code

Floating point types

Float :32 bits

Double :64bit

type placeholder The most value note
float 32 (2 ^ 31) ~ (2 ^ 31-1) Float is too low-precision, rarely used (double is used), and the literal suffix F
double 64 Floating-point literals default to double and end with D

Character types

Char :16 bits

type placeholder The values note
char 16 0 ~ 2 ^ 16-1 Char is a base 2 number (16-bit unsigned integer), which is a Unicode encoding

Code development

A number can also be represented as a character in addition to a number

Unicode encoding is a global encoding method

package datatype; Public class Demo02 {public static void main(String[] args) {char c = 88; System.out.println(c); }}Copy the code

Special characters are represented by escape characters

Escape character Stand for
\n enter
\t TAB

Boolean type

Boolean type: used to express true or false. Often used to judge statements.

type placeholder The values note
boolean 1 false/ true The default value is false

Reference Type Reference Type

Class:

Interface:

Array: