#业余学习 java基础

编写Hello,world!

public class Hello{
           public static void main(String[]args){
                   System.out.println("Hello,world!");
     }    
}

注释

public class Kang{
    public static void main(String[]args){
    System.out.println("hello,world!");
   }
}
     //单行注释
     
/*
* 多行注释
* 多行注释
*/

/**
 * @apiNote文档注释
 * @deprecated 文档注释
 */
    

常用标识符关键字!

在这里插入图片描述

常用标识符及关键字
abstractbreakbytebooleancatch
casecharclasscontinuedefault
dodoubleelseextendsfalse
finalfloatforfinallyif
importimplementsintinterfaceInstancof
longlengthnativenewnull
packageprivateproteedpublicreturn
switchsynchronizedshortstaticsuper
trytruethisthrowthorws
threadsafetransientvoidvolatilewhile
⬆表格内容手打,可能会有错误

标识符不能用作变量名,变量名可用大小写,_ $开头,其余符号均不可(A123 a123 $123 _123)

例如:

public class Kang{
     public static void main(String[]args){
        String A123 = "普泰";
        String a123 = "普泰";
        String _123 = "普泰";
        String $123 = "普泰";
         System.out.println(a123 );     //该行未测试 
         System.out.println(A123);
         System.out.println(_123);
         System.out.println($123);   
         }
 }

数据类型

八大基本数据类型

整数类型

public class Kang{
  public static void main(String[]args){
    int num1 = 10;
    byte num2 = 20;
    long num3 = 30L;//long类型在后面加L
    short num4 = 40;
    System.out.println(num3);
     }
}

浮点数类型(小数)

public class Kang{
   public static void main(String[]args){
     float num5 = 4.5F; //float类型要在后面加F
     double num6 = 19.96;
     System.out.println(num6);
   }
}

字符 & 字符串

public class Kang{
  public static void main(String[]args){
     char name = '康';     //字符用单引号
     String firm = "普泰";//字符串用的双引号i
      System.out.Println(firm);
     }
}

布尔值

public class Kang{
   public static void main(String[]args){
      boolean flag = true;  // 是
      boolean flag1 = false;  // 非
     }
}
明日学习P24(初学,有不足之处望指正)
public class Demo02 {
    public static void main(String[] args) {
    //整数拓展
        int a = 10;
        int a2 = 010; //八进制0
        int a3 = 0x10; //十六进制0x
        int a4 = 0b10; //二进制0b
        System.out.println(a);
        System.out.println(a2);
        System.out.println(a3);
        System.out.println(a4);
              System.out.println("==============================================================================");
    //浮点数拓展
        float b = 0.1f;
        double b2 = 1.0/10;
        System.out.println(b);  //0.1
        System.out.println(b2);//0.1
        System.out.println(b==b2);//false
        float b3 = 1234567890f;
        float b4 = b3 + 1;
        System.out.println(b3==b4);//true
        //浮点数有有限性,离散性,舍入误差,接近但不等于
              System.out.println("==============================================================================");
    //字符拓展
        char c = 'a';
        char c1 = '康';
        System.out.println(c);
        System.out.println((int)c);//97
        System.out.println(c1);
        System.out.println((int)c1);//24247
            //所有的字符本质还是数字,依据unicode编码表,\u0000~\uffff
        char c2 ='\u0061';
        System.out.println(c2);//a
        //转义字符
        System.out.println("Hello\tworld");// \t 制表
        System.out.println("Hello\nworld");// \n 换行
        System.out.println("Hello\bworld");// \当前位置前移一列
        System.out.println("Hello\0world");// \0空字符
              System.out.println("==============================================================================");
         String d = new String("hello,world");
         String d2 = new String("hello,world");
            System.out.println(d==d2);//false
         String d3 = "hello,world";
         String d4 = "hello,world";
            System.out.println(d3==d4);//true
              System.out.println("==============================================================================");
     //布尔值拓展
        boolean flag = true;
        if (flag==true){}
        if(flag){}
        //以上两种写法一样的结果,但是代码要精简易读   Less is more
    }
}

明日学习P25(初学,有不足之处望指正)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值