JDK环境变量的配置
我的电脑—>属性—>高级系统设置
选择JDK安装文件中的bin文件的地址
但是一般这样改
%JAVA_HOME%
bin目录上一层的地址新建一个变量
hello world
建造字节码文件
注释
//单行注释
/* 多行注释 */
java所特有的文档注释
/**
文档注释
注释内容可以被JDK提供的工具 javadoc 所解析 , 生成一套以网页文件形式体现的该程序的说明文档
*/
JAVA API的文档
API(Application Programming Interface)是Java提供的基本程序接口
命名规范
包名:都是小写 xxxuuyyy
类名、接口名:首字母大写 XjflsjYflajf
变量名、方法名:第一个字母小写、第二个单词大写 xxxxYyyyy
常量名:所有字母都大写 XXX_YYY
变量
基本数据类型(primitive type):数值型(整数类型:byte,short,int,long ,浮点型float),字符型:char 布尔型 : boolean
引用数据类型(reference type):类(class),接口(interface),数组([])
变量的使用
①整数类型
byte == 1字节 == 8 bit位
范围 -128 — 127
short == 2字节
范围 -2^15 到 2^15-1
int == 4字节
范围 -2^31 到 2^31 -1
long == 8 字节
范围 -2^63 到 2^63-1
②浮点型
float == 4字节
范围 -3.403E38 到 3.403E38
float a = 1.232F;
double == 8字节
范围 -1.798E308 到 1.798E308
③字符型
char == 2字节
char c1 = ‘a’;
char c5 = ‘\n’;
char c6 = ‘\u0043’; 0043== c ;
④布尔型
boolean
基本数据类型之间的运算
1、自动类型提升
(byte 、char 、short < int < long < float < double)
特别的
当 byte 、 char 、 short 做运算时 结果为 int 型
byte b1 = 2;
int i1 = 12;
由于int > byte
int b2 = b1 + i2;
2、强制类型转换
double d1 = 12.3;
int i1 = (int)d1;
3、两种特殊情况
①编码情况
long l = 123213;
//此时long型被认为时int型
long 1 = 315423524242342314;//报错
long 1= 37917497294194719L;//这样才行
②编码情况2
byte b = 12;
4、String
/*
String属于应用数据类型,翻译为:字符串
声明String变量用" "
String可以和8种基本数据类型做运算 但是只能是连接运算,运算的结果仍然是String类型
*/
String s1 = "hello world";
int number == 1001;
String numberStr = " 学号:";
String info = numberStr + number;
boolean b1 = true;
String info1 = info + b1;
//String的两个练习
//练习1
char c = 'a';
int num = 10;
String str = "hello";
Systemp.out.println(c + num + str);
Systemp.out .println( c+ str + num);
Systemp.out.println(c+ (num + str ));
Systemp.out.println((c+ num) + str));
Systemp.out.println(str + num + c);
//练习2
//表示* *
Systemp.out.println("* *");
Systemp.out.println('*' + '\t' + '*');//不行
Systemp.out.println('*' + "\t" + '*');
Systemp.out.println('*' + '\t' + "*");//不行
Systemp.out.println('*' + ('\t' + "*"));
//练习3
String str1 = 4;//no
String str2 = 3.5f + "";//yes
System.out.println(str2);//"3.5"
//练习4
short s = 5;
s = s -2;//no
byte b = 3 ;
b = b + 4;//no
b = (byte)(b+4);//yes
char c = 'a';
int i = 5;
float d= .314F;
double re = c + i + d;//yes
byte b = 5;
short s = 3;
shortt = s+ b;//no
进制与进制之间的转换
- 二进制:ob或OB开头
- 八进制:0开头
- 十六进制:0X 或 0X开头