Java学习十六

学习内容:

1.做毕设

2.Java异常类

3.Java包装类


1.System.exit(1):终止程序运行,终止final执行方法

2.throws抛出异常类型,throw抛出异常对象

用法:throw new Exception("提示信息")

3.异常链:捕获一个异常后在抛出另一个异常

保留异常信息机制:

package com.imooc.test;

public class TryDemoFive {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try {
            testThree();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static void testOne() throws HotelAgeException {
        throw new HotelAgeException();
    }

    public static void testTwo() throws Exception {
        try {
            testOne();
        } catch (HotelAgeException e) {
            throw new Exception("我是新产生的异常1",e);
        }
    }

    public static void testThree() throws Exception {
        try {
            testTwo();
        } catch (Exception e) {
            Exception e1=new Exception("我是新产生的异常2");
            e1.initCause(e);
            throw e1;
//            throw new Exception("我是新产生的异常2",e);
        }
    }
}

4.用final修饰的类是不能被继承

static方法既可以通过类名调用,又可以通过对象名调用

5.装箱与拆箱:

装修:将基本数据类型转换为包装类

拆箱:装箱逆操作

6.基本数据类型和包装类之间的转换

package wrap;

public class WrapTestOne {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //装箱:把基本数据类型转换成包装类
        //1、自动装箱
        int t1=2;
        Integer t2=t1;
        //2、手动装箱
        Integer t3=new Integer(t1);
        
        //测试
        System.out.println("int类型变量t1="+t1);
        System.out.println("Integer类型对象t2="+t2);
        System.out.println("Integer类型对象t3="+t3);
        System.out.println("*************************");
        //拆箱:把包装类转换成基本数据类型
        //1、自动拆箱
        int t4=t2;
        //2、手动拆箱
        int t5=t2.intValue();
        //测试
        System.out.println("Integer类型对象t2="+t2);
        System.out.println("自动拆箱后,int类型变量t4="+t4);
        System.out.println("手动拆箱后,int类型变量t5="+t5);
        double t6=t2.doubleValue();
        System.out.println("手动拆箱后,double类型变量t6="+t6);
        
    }

}

7.基本数据类型转换为字符串

基本数据类型转换为字符串:

int t1 = 2;
String t2 = Integer.toString(t1)

字符串转换为基本数据类型

法一:包装类的parse

int t3 = Integer.parseInt(t2)

法二:包装类的valueOf

int t4 = Integer.valueOf(t2)

毕设进度:今天一直没有解决的问题是servlet中接收到的json数据不能在前端显示。

查询的可能原因是json数据不符合导致解析错误不能成功显示数据。也有可能是接收域与请求域的不一致

原文地址:https://www.cnblogs.com/-2016/p/12257798.html