DAY2
编译软件:IDEA
1.基本操作
缩写
psvm public static void main(String[] args) {
sout System.out.println();
2.语法
a.注释 单//、多/* / 、文档/* */
3.标识符
a.关键字
类 class 方法 main 字符串string void
b.标识符
string vicxiao ="肖"
以字母A-Z、美元符$、下划线_ ,不能用关键字,定义大小写有区别
eg:
public class hhh {
public static void main(String[] args) {
String a ="hahahha";
System.out.println(a);
}
}
4.数据类型
a.
强类型语言 string需要先定义才能使用
弱类型语言
b.java数据类型:
1.a.基本类型 ![image]()


2.b.引用类型 ![image]()
c.字节:

d.程序中学习
public class 数据类型 {
public static void main(String[] args) {
//数据类型
int a= 12;//常用
byte b= 1;
short c= 11;
long d= 12231L;//long类型要在数字后面加L
//小数;浮点数
float e= 1.2F;/* float类型要加F */
double f=1.111111 ;/* 八个字符*/
//字符
char g='肖';
// string 是类,不是关键字
//布尔值:真或假
boolean flag = true;
//boolean flag = false;
System.out.println(g);
//整数拓展:进制 二进制0b 十进制 八进制0 十六进制0x
int a1=10;
int a2=010;//八进制0
int a3=0x10;//十六进制0x
System.out.println(a1);
System.out.println(a2);
System.out.println(a3);
System.out.println("==================================");
/* 浮点数据 银行表示钱
BigDecimal 数学类工具
float 有限 离散 摄入误差 大约 接近但不等于
double 银行业务最好完全避免使用浮点数进行比较
*/
float b1=0.1f;
double b2=1.0/10;
System.out.println(b1==b2);
float b3=2131312312312313f;
float b4= b3 + 1;
System.out.println(b3==b4);//ture
//字符本质是数字
System.out.println("==================================");
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字节 0-65536 excel 2 16 =65536
char c3='\u0061';
System.out.println(c3);
/*
转义字符 \t制表符 \n换行
*/
System.out.println("hello\n world");
System.out.println("===========");
String sa = new String("hello world");
String sb = new String("hello world");
System.out.println(sa==sb);
String sc ="hello world";
String sd ="hello world";
System.out.println(sc==sd);
//布尔值扩展
boolean d1= true ;
if (d1==true){
System.out.println('1');
}
if(d1){
System.out.println('2');
}//老手
//lees is more!
}
}
5.类型转换

a.强制类型转换
b.自行类型转换
eg: public class 数据转换 {
public static void main(String[] args) {
//操作比较大的数字需要注意溢出
//数字之间可用下划线分割
int a=10_0000_0000;
int b=20;
int and=ab;//计算溢出
long and2=ab;//默认是int数据=int
System.out.println(and);
System.out.println(and2);
long ad=a((long)b);//
System.out.println(ad);
long ac=1231213111111L;//long定义的时候后面是要加大写L改变数据类型的
System.out.println(ac);
//L 最好用大写
}
}
6.变量、常量、作用域


public class a3variety {
static double aa=2500;
// 类变量 static
// 属性:变量
// 实例变量:从属对象,不初始化就是0
// 布尔值,默认null
// 除了基本型,其他都是默认null
String cc;
int a;
//main 方法
public static void main(String[] args) {
//局部变量必须先声明和初始化
int i = 11;
System.out.println(i);
a3variety a3variety=new a3variety();
System.out.println(a3variety.a);
System.out.println(a3variety.cc);
System.out.println(aa);
}
}
public class a3variety1 {//常量,固定值的值
//修饰符不存在先后顺序
static final long GG=121231231L;
public static void main(String[] args) {
System.out.println(GG);
}
}
7.运算符

package basic;
public class a4arithmetic {
public static void main(String[] args) {
long a = 156156156;
int b = 123;
short c = 11;
byte d = 1;
System.out.println(a + b);// Long
System.out.println(b + c);// int
System.out.println(c + d);// int
//关系运算符返回结果:正确,错误 布尔值
int a1 = 10;
int a2 = 20;
int a3 = 21;
System.out.println(a > b);
System.out.println(a < b);
System.out.println(a == b);
System.out.println(a3 % a2);
// ++ -- 自增,自减 一元运算符
int b1=2;
int b2 = b1++;//运行代码 后,先赋值,再自增
int b3 = ++b1;//运行代码 前,先自增,再赋值
System.out.println(b1);System.out.println(b1);
System.out.println(b2);System.out.println(b2);
System.out.println(b3);System.out.println(b3);
//幂运算,2^3,有些运算使用工具类运算
double ccd=Math.pow(2,3);
System.out.println(ccd);
//
boolean c1=true;
boolean c2=false;
System.out.println("(c1&&c2)="+(c1&&c2));
System.out.println("(c1||c2)="+(c1||c2));
System.out.println("!(c1&&c2)="+!(c1&&c2));
//短路运算
int ddd=5;
boolean c3=(ddd<4)&&(++ddd<4);
System.out.println(ddd);
System.out.println(c3);
/*位运算
A=0011 1100
B=0000 1101
A&B=0000 1100 位与
A|B=0011 1101 位或
A^B=0011 0001 位异或运算
~B=1111 0010 按位取反
0000 0000 0
0000 0001 1
0000 0010 2
0000 0011 3
0000 0100 4
0000 1000 8
0001 0000 16
*/
System.out.println(2<<3);
}
}
public class a6 {
public static void main(String[] args) {
// X?Y:Z
//如果x==true,则结果为y,否则结果为z
int score = 60;
String type = score < 60 ? "不及格" : "及格";
System.out.println(type);
}
}
8.包
注意开发的时候包民命,反着 com.baidu.www

9.javaDoc 生成文档

javadoc -encoding UTF-8 -charset UTF-8 Doc.java
package abb;
/**
- @author xiao
- @version 1.0
- @since 1.8
/
public class Doc{
String name;
/*- @author xiao
- @param name
- @return
- @throws Exception
*/
public String test(String name)throws Exception{
return name;
}
}



浙公网安备 33010602011771号