java 学习day03

注释


注释:项目结构复杂起来,我们就需要用注释。注释并不会被执行,是给我们写代码的人看的

书写注释是一个非常好的习惯

java中的注释种类

  • 单行注释://

  • 多行注释:/* */

  • 文档注释:/**

标识符


标识符注意点

所有标识符都应该以字母(A-Z或者a-z),美元符($),或者下划线(_)开始

首字符之后可以是字母(A-Z或者a-z),美元符($)、下划线(_)或者数字的任何字符组合

不能使用关键字作为变量名后方法名

标识符是大小写敏感

e、$salary、_value

非法标识符举例:123abc、-salary、#abc

可以使用中文命名,但是一般不建议这样去使用,也不建议使用拼音,很low

数据类型


强类型语言

  • 要求变量的使用要严格符合规定,所有变量都必须先定义后才能使用

弱类型语言

Java的数据类型分为两大类

  • 基本类型(Primitive type)

整数类型:

byte占1个字节范围:-128-127

short占2个字节范围:-32768-32767

int占4个字节范围:-2147483648-2147483648

long占8个字节范围:

浮点类型:

float占4个字节

double占8个字节

字符类型char占2个字节

Boolean类型:占1位其值只有true和false两个

  • 引用类型(Reference type)

类 接口 数组

public class Demo02
{
    public static void main(String[] args) {
        //整数拓展 进制 二进制0b 十进制 八进制0 十六进制0x
​
        int i = 10;
        int i2 = 010;  //八进制
        int i3 = 0x10;  //十六进制 0~9 A~F 16
​
        System.out.println(i);
        System.out.println(i2);
        System.out.println(i3);
        //float 有限 离散 舍入误差 大约 接近但不等于
        //最好完全避免使用浮点数进行比较
        //bigdecimal使用在银行
        char c1='a';
        char c2='中';
        System.out.println(c1);
        System.out.println((int)c1);//强制转换
        System.out.println(c2);
        System.out.println((int)c2);//强制转换
​
        //所有的字符本质还是数字
        //编码unicode 表:(97=a 65=A) 2字节  65536  Excel  2 16=65536
        //U0000 UFFFF
​
        char c3='\u0061';
        System.out.println(c3);//a
        //转义字符
        //\t 空格
        //\n 换行
        System.out.println("Hello\tWorld");
        System.out.println("Hello\nWorld");
​
        System.out.println("===================");
        String sa=new String("hello world");//string里面打双引号出现original。new开辟了新的内存空间,没有new是指向同一个内存空间
        String sb=new String("hello world");
        System.out.println(sa==sb);//false
        String sc="hello world";
        String sd="hello world";
        System.out.println(sc==sd);//true
        //对象 从内存分析
​
        //布尔值拓展
        boolean flag = true;
        if (flag=true);{}
        if (flag){}
        //这里两个程序是同理
    }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值