1 Integer类是int的包装类,能存储的最大整型值为231-1,,long类也是有限的,最大值为263-1.如果要表示再大的整数,不论是基本数据类型还是他们的包装类 都无能为力,
2 java.math包的Biginteger可以表示不可变的任意精度的整数.
Biginteger的一些使用
package Bigintrger;
import java.math.BigDecimal;
import java.math.BigInteger;
public class Biginteger_01 {
public static void main(String[] args){
//必须传入字符串
BigInteger v1 = new BigInteger("123123");
BigDecimal v2 = new BigDecimal(20);
BigDecimal v3 = new BigDecimal(20);
//+
BigDecimal result = v2.add(v3);
System.out.println(result);
//-
result = v2.subtract(v3);
System.out.println(result);
/
public class Exception_01 {
public static void main(String[] args){
System.out.println("---------");
//除数不能为0
int a = 10;
int b = 0;
if (b!=0){
int c = a/b;
}else{
System.out.println("除数不能为零");
}
System.out.println("=======");
}
}
package java_exception;
import java.io.FileInputStream;
public class Exception_02 {
public static void main(String[] args){
try{
//加载对应文件
FileInputStream fis = new FileInputStream("123.text");
System.out.println("======");
}catch(Exception e){
//打印错误栈帧和信息,一般用于程序员排错
e.printStackTrace();
//获取错误信息位置,一般用于反馈给客户端
String msg = e.getMessage();
System.out.println(msg);
System.out.println("xxxxxx");
}
//不在终止生命周期执行
System.out.println(1111);
}
}
public class Exception_03 {
public static void main(String[] args){
try{
m1();
}catch(Exception e){
//e.printStackTrace();
//TODO解决错误的措施
}
System.out.println("====");
}// throws 可以同时抛出多个异常,多个用逗号隔开
public static void m1() throws FileNotFoundException,Exception {
m2();
}
public static void m2() throws FileNotFoundException {
m3();
}
public static void m3() throws FileNotFoundException {
new FileInputStream("123");
}
}
public class Exception_04 {
public static void main(String[] args) {
// 当try下面 可能会出现多个异常的时候,并且每个异常对应的解决方案不同的时候
// 需要写多个catch进行不同的处理
// 如果解决方案一致,则只写一个 exception 即可
try {
new FileInputStream("123");
String stre = null;
System.out.println(stre.trim());
} catch (FileNotFoundException e) {
System.out.println("找不到指定文件");
} catch (IOException e) {
} catch (NullPointerException e) {
System.out.println("不能为空");
} catch (Exception e) {
System.out.println("其他异常");
}
}
}
public class Exception_05 {
public static void main(String[] args) {
try {
new FileInputStream("123");
} catch ( FileNotFoundException | NullPointerException e) {
// TODO: handle exception
}
}
}
public class Exception_06 {
public static void main(String[] args) {
try {
FileInputStream fis = new FileInputStream("123");
System.out.println(fis);
} catch (IOException e) {
e.printStackTrace();
}finally{
System.out.println("必须执行");
}
}
}
public class Exception_07 {
public static void main(String[] args) {
int result = m1();
// 11
System.out.println(result);
}
public static int m1() {
int i = 10;
try {
// 因为finally中有return,所以这里的return 不执行,但是 i++执行,编译之后 会把return去掉
return i++;
} catch (Exception e) {
} finally {
System.out.println(i + "-------");
return i;
}
}
}
public class Exception_08 {
public static void main(String[] args) {
// 提升作用域,否则访问不到
// 添加默认值,否则因为局部变量没有默认值而报错
FileInputStream fis = null;
try {
fis = new FileInputStream("D://123.txt");
System.out.println("执行成功");
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
try {
// 判断是否打开该资源
if (fis != null) {
System.out.println("关闭成功");
fis.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public class Exception_09 {
public static void main(String[] args) {
try(
FileInputStream fis = new FileInputStream("123");
) {
// 操作
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class Exception_10 {
public static void main(String[] args) {
}
}
class A {
public void m1() throws IOException {
}
}
class B extends A {
public void m1() throws IOException {
}
}



