base基础
1.0
public class Doc {
String name;
public String test(String name) throws Exception{
return name;
}
//我是通过命令行 javadoc 参数 Java 文件
//作业:学会查找使用TDEA生产JavaDoc文档! 面向百度查找学习
//基础部分的一切知识,后面几乎每天都会用
}
-
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello,World!"); String teacher = "佳卉老婆"; } } //输出一个Hello,World! //单行注释// // 多行注释 /* 注释 */ /*我是多行注释 * 我是多行注释 * 我是多行注释 * 我是多行注释*/ //JavaDoc:文档注释 /** */
-
public class JH01 { /*public static void main(String[] args) { String 英雄联盟 = "疾风剑豪"; System.out.println(英雄联盟); }*/ public static void main(String[] args) { String Ahello = "佳卉"; String hello = "佳卉"; String $hello = "佳卉"; String _hello = "佳卉"; //String Ahello = "佳卉"; //String Ahello = "佳卉"; System.out.println(Ahello); } }
-
public class JH02 { public static void main(String[] args) { //八大基本数据类型 //整数 int num1 = 10;//最常用 byte num2 = 20; short num3 = 30; long num4 = 40L;//Long类型要在数字后面加个L //小数:浮点数 float num5 = 50.1F;//float类型要在数字后面加个F double num6 = 3.14159263125434354; //字符类型 char name = 'A'; //字符串:String 不是关键字,类 String namea = "佳卉"; //布尔值 boolean flag = true; //boolean flag = false; } }
public class JH03 {
public static void main(String[] args) {
//整数拓展 进制 二进制0b 十进制 八进制0 十六进制0x
int i = 10;
int i2 = 010;//八进制
int i3 = 0x102;//十六进制
System.out.println(i);
System.out.println(i2);
System.out.println(i3);
System.out.println("===============================");
//===============================
//浮点型数拓展? 银行业务怎么表示?
//BigDecimal 数学工具类
//===============================
//float 有限 离散 舍入误差 大约 接近但不等于
//double
//最好完全使用浮点数进行比较
//最好完全使用浮点数进行比较
//最好完全使用浮点数进行比较
float f = 0.1f;//0.1
double d = 1.0/10;//0.1
System.out.println(f==d);//false
//System.out.println(f);
//System.out.println(d);
float d1 = 121123123131232f;
float d2 =d1 + 1;
System.out.println(d1==d2);
//===============================
//字符拓展?
//===============================
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 表:a = 97 A = 65 2字节 65536 Excel 2ˇ16 = 65536
//u0000 UFFFFFF
char c3 = '\u0061';
System.out.println(c3);//a
//转义字符
// \t 制表符
// \n 换行
//
System.out.println("Hello\tWorld!");
//
String sa = new String("Hello World!");
String sb = new String("Hello World!");
String sc = "Hello World!";
String sd = "Hello World!";
System.out.println("=====================================");
System.out.println(sa==sb);
System.out.println(sc==sd);
//对象 从内存分析
//布尔值扩展
boolean flag = true;
if (flag==true){}// 新手
if (flag){}//老手
//Less is More! 代码要精简易读
}
}
-
public class JH04 { public static void main(String[] args) { int i = 128; byte b = (byte) i; //内存溢出 //强制转换 (类型)变量名 高----低 //自动转换 变量名 低----高 System.out.println(i); System.out.println(b); System.out.println("================"); System.out.println((int)23.7);//23 System.out.println((int)-45.89f);//-45 System.out.println("================"); char c = 'a'; int d = c+1; System.out.println(d); System.out.println((char) d); } /* 注意点: 1.不能对布尔值进行转换 2.不能把对象类型转换为不相干的类型 3.在把高容量转换为低容量的时候,强制转换 4.转换的时候可能存在内存溢出或者精度问题! */ //结果: 128 -128 23 -45 98 b }
-
public class JH05 { public static void main(String[] args) { //操作比较大的数时,注意溢出问题 //JDK7新特性 int money = 10_0000_0000; int years = 20; int total = money*years; long total2 = money*years; long total123 = money*((long)years); System.out.println(money); System.out.println(total);//-1474836480,是否计算时溢出 System.out.println(total2);//默认是int,转换之前已经存在问题 System.out.println(total123);//200_0000_0000 // L l 一般使用大写的L } }
-
public class JH06 { public static void main(String[] args) { //int a,b,c; //int a=1,b=2,c=3; 注重程序可读性 int a = 1; int b = 2; int c = 3; String name = "佳卉"; char x = 'x'; double pi = 3.14; } }
public class JH07 {
//类变量 static
static double salary = 2500;
//属性:变量
//实例变量:从属于对象;如果不自行初始化,这个类型的默认值 0 0.0 u00000
//布尔值:默认是false
//除了基本类型,其余的默认值都是null
String name;
int age;
//main方法
public static void main(String[] args) {
//局部变量:必须声明和初始化值
int i = 10;
System.out.println(i);
//变量类型 变量名字 = new com.JH.base.JH07();
JH07 jh07 = new JH07();
System.out.println(jh07.age);
System.out.println(jh07.name);
//类变量 static
System.out.println(salary);
}
//其他方法
public void add(){
}
}
public class JH08 {
//修饰符,不存在先后顺序
static final double PI = 3.14;
public static void main(String[] args) {
System.out.println(PI);
}
}