标签:文档 com 注意 mamicode 语法 运算 void lazy param
Java语言支持一下运算符
新建一个base包

然后把这些类移动到base包中
创建一个operator包,在这个包中新建类
package operator;
public class Demo02 {
    public static void main(String[] args) {
        long a = 123123123123123L;
        int b = 123;
        short c = 10;
        byte d = 8;
        System.out.println(a+b+c+d);//long
        System.out.println(b+c+d);//int
        System.out.println(c+d);//int
    }
}
package operator;
public class Demo04 {
    public static void main(String[] args) {
        int a = 3;
        int b = a++;//执行完这行代码后,先给b赋值,再自增
        int c = ++a;//执行完这行代码后,先自增,再给c赋值
        System.out.println(a);//5
        System.out.println(b);//3
        System.out.println(c);//5
    }
}
注意短路特性
package operator;
public class Demo05 {
    public static void main(String[] args) {
        //短路运算
        int c = 5;
        boolean d = (c<4)&&(c++<4);
        System.out.println(d);//false
        System.out.println(c);//5
    }
}
位运算
package operator;
public class Demo06 {
    public static void main(String[] args) {
         /*
        A = 0011 1100
        B = 0000 1101
        ----------------------
        A&B = 0000 1100
        A|B = 0011 1101
        A^B = 0011 0001
        ~B = 1111 0010
        2*8 16 2*2*2*2
        位运算效率极高!!!
        <<相当于*2
        >>相当于/2
        */
        System.out.println(2<<3);
        /*
        0000 0010 是2
        0000 0100 是4
        0000 1000 是8
        0001 0000 是16
         */
    }
}
拓展:字符串连接符 +
package operator;
public class Demo07 {
    public static void main(String[] args) {
        //字符串连接符
        int a = 10;
        int b = 20;
        System.out.println(""+a+b);//"1020"
        System.out.println(a+b+"");//"30"
    }
}
一般使用公司域名倒置作为包名
package com.brucezhang.base;
/**
 * @author brucezhang
 * @version 1.0
 * @since 1.8
 */
public class Doc {
    String name;
    /**
     * @param name
     * @return 
     * @throws Exception
     */
    public String test(String name) throws Exception{
        return name;
    }
}
在文件管理器中打开这个Doc的类

在当前目录中打开cmd,运行命令

打开生成的index.html
标签:文档 com 注意 mamicode 语法 运算 void lazy param
原文地址:https://www.cnblogs.com/hack2xia/p/14774699.html