java基础知识01

时间:2020-05-23 09:52:17   收藏:0   阅读:52

java基础语法

注释

单行注释 //

多行注释 /* content */

文档注释 /** this is javadoc comment */

标识符

关键字

Abstract assert boolean break byte case.....

不可作为变量名或方法名

数据类型

强类型语言:要求变量的使用严格符合规定,所有变量都必须先定义再使用。安全性较高,速度较慢。(java)

弱类型语言:javascript

java数据类型

字节

位 bit:是计算机内部数据存储的最小单位

字节 byte:是计算机中数据处理的基本单位

1B = 8 bit

拓展

  int i = 10; // 二进制 -- 10
int i2 = 010; // 八进制 -- 8
int i3 = 0x10; // 十六进制 -- 16

memory overflow

char c = ‘a‘; // a

int v = c+1; // 98

System.out.println((char)v);

//manipulate a large number, attention to overflow problem
int money = 1_000_000_000; // _ can be used in numbers, it won‘t print
int years = 20;
int total = money * years; //-1474836480 memory overflow
long total2 = money * years; // -1474836480
// the type of money and years is int
// so the default type of total2 is also int
// before casts it to long, the result already got problem

// First, cast one number to long
long total3 = money * ((long)years); //20000000000

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!