栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java基础——数据类型

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java基础——数据类型

数据类型 数据类型 强类型语言

要求变量的使用要严格符合规定,所有的变量必须先定义,再使用

弱类型语言

java的数据类型分为两大类

基本数据类型:有8种,分别是,byte,short,int,long,float,double,char,boolean

整数类型:

  1. byte

  2. short

  3. int

  4. long

    byte num1 = 10;
    short num2 =20;
    int num3 = 30;
    long num4 = 40L;//Long类型的,数字后面加一个L

    浮点类型:

    1. float

    2. double

      float num5 = 3.1F;//float类型,后面加一个F
      double num6 = 3.1415926;

    字符类型:char

    char a = "A";
    char name = "中国";//这个就会报错,char是字符类型,它只支持一个字符
    String name = "中国"//String是一个类,它可以定义字符串

    boolean类型: 只有true和false

引用数据类型:类,接口,数组

其中:Integer,Short等,是基本数据类型的包装类

什么是字节

bite(位),是计算机中最小的单位

byte(字节),是计算机中最基本的数据单位

1B=8b

1个字节=8个位

数据类型拓展面试题 整数拓展

进制:十进制,二进制(0b),八进制(0),十六进制(0x)

int i = 10;
int i2 = 010;//八进制0
int i3 = 0x10;//十六进制0x 0~9 A~F
浮点数拓展

银行业务怎么表示?

不能用float或者double,需要用一个类:BigDecimal 数学工具类

float和double是有限的,离散的,舍入误差,接近但是不等于、

float f = 0.1f//0.1
double d = 1.0/10 //0.1
System.out.println(f==d)//false
    
float f1 = 2323232455f;
float f2 = f1+1;
System.out.println(f1==f2);//true

最好完全使用浮点数进行比较

字符拓展

所有的字符本质还是数字

char c1 = 'A';
char c2 = '中';
System.out.println(c1);
System.out.println((int)c1);//强制类型转换
转义字符

t 制表符

n 换行

..........

String sa = new String("hellotworld");
//hello world
String sb = new String("hellonworld");
//hello
//world
String sc = "hello world";
String sd = "hello world";
System.out.println(sa==sb);//false
System.out.println(sc==sd);//true

 

数据类型 强类型语言

要求变量的使用要严格符合规定,所有的变量必须先定义,再使用

弱类型语言

java的数据类型分为两大类

基本数据类型:有8种,分别是,byte,short,int,long,float,double,char,boolean

整数类型:

  1. byte

  2. short

  3. int

  4. long

    byte num1 = 10;
    short num2 =20;
    int num3 = 30;
    long num4 = 40L;//Long类型的,数字后面加一个L

    浮点类型:

    1. float

    2. double

      float num5 = 3.1F;//float类型,后面加一个F
      double num6 = 3.1415926;

    字符类型:char

    char a = "A";
    char name = "中国";//这个就会报错,char是字符类型,它只支持一个字符
    String name = "中国"//String是一个类,它可以定义字符串

    boolean类型: 只有true和false

引用数据类型:类,接口,数组

其中:Integer,Short等,是基本数据类型的包装类

什么是字节

bite(位),是计算机中最小的单位

byte(字节),是计算机中最基本的数据单位

1B=8b

1个字节=8个位

数据类型拓展面试题 整数拓展

进制:十进制,二进制(0b),八进制(0),十六进制(0x)

int i = 10;
int i2 = 010;//八进制0
int i3 = 0x10;//十六进制0x 0~9 A~F
浮点数拓展

银行业务怎么表示?

不能用float或者double,需要用一个类:BigDecimal 数学工具类

float和double是有限的,离散的,舍入误差,接近但是不等于、

float f = 0.1f//0.1
double d = 1.0/10 //0.1
System.out.println(f==d)//false
    
float f1 = 2323232455f;
float f2 = f1+1;
System.out.println(f1==f2);//true

最好完全使用浮点数进行比较

字符拓展

所有的字符本质还是数字

char c1 = 'A';
char c2 = '中';
System.out.println(c1);
System.out.println((int)c1);//强制类型转换
转义字符

t 制表符

n 换行

..........

String sa = new String("hellotworld");
//hello world
String sb = new String("hellonworld");
//hello
//world
String sc = "hello world";
String sd = "hello world";
System.out.println(sa==sb);//false
System.out.println(sc==sd);//true

布尔值扩展
boolean flag = true;
if(flag){}
强制类型转换

由于java是强类型语言,因此有些运算的时候,需要类型转换

低——————————————>高

byte,short,char,int,long,float,double (boolean不参与)

int i1 = 10;
double b1 = i1;
char c1 = (int)i1;
//强制转换:(类型)变量名 高——>低
//自动转换:低——>高
System.out.println((int)23.55);//23
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/318781.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号