当前位置:网站首页>2022/07/30 学习笔记 (day20) 面试题积累
2022/07/30 学习笔记 (day20) 面试题积累
2022-07-30 21:42:00 【激进的黄瓜】
目录
4.三个字符串String StringBuffer StringBuilder的区别 :
随时学,随时加
1.throws和throw的区别:
throws:在方法后边声明异常,其实就是自己不想对异常做出任何的处理,告诉别人自己可能出现的异常,交给别人处理,然别人处理
package com.xinkaipu.Exception;
class Math{
public int div(int i,int j) throws Exception{
int t=i/j;
return t;
}
}
public class ThrowsDemo {
public static void main(String args[]) throws Exception{
Math m=new Math();
}
}
throw: 就是自己处理一个异常,有两种方式要么是自己捕获异常try...catch代码块,要么是抛出一个异常(throws 异常)
package com.xinkaipu.Exception;
public class TestThrow
{
public static void main(String[] args)
{
try
{
//调用带throws声明的方法,必须显式捕获该异常
//否则,必须在main方法中再次声明抛出
throwChecked(-3);
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
//调用抛出Runtime异常的方法既可以显式捕获该异常,
//也可不理会该异常
throwRuntime(3);
}
public static void throwChecked(int a)throws Exception
{
if (a > 0)
{
//自行抛出Exception异常
//该代码必须处于try块里,或处于带throws声明的方法中
throw new Exception("a的值大于0,不符合要求");
}
}
public static void throwRuntime(int a)
{
if (a > 0)
{
//自行抛出RuntimeException异常,既可以显式捕获该异常
//也可完全不理会该异常,把该异常交给该方法调用者处理
throw new RuntimeException("a的值大于0,不符合要求");
}
}
}
2.代码块执行顺序:
代码块执行顺序:静态代码块——> 构造代码块 ——> 构造函数——> 普通代码块
继承中代码块执行顺序:父类静态块——>子类静态块——>父类代码块——>父类构造器——>子类代码块——>子类构造器
3.try ... catch、finally执行顺序:
finally永远是在最后执行的
如果在try ... catch语句中有return,
catch可以写多个异常(可以捕获多个异常)
顺序问题:先写小的,再写大的
4.三个字符串String StringBuffer StringBuilder的区别 :
边栏推荐
- [Deep Learning] Target Detection | SSD Principle and Implementation
- 【Summary】机器人方法汇总
- The reason for not using bs4 is that the name is too long?Crawl lottery lottery information
- Difference between cookie and session
- Solve npm warn config global `--global`, `--local` are deprecated. use `--location=global` instead
- 系统结构考点之并行主存
- Advanced c language: pointers (5)
- DistSQL 深度解析:打造动态化的分布式数据库
- MYSQL JDBC图书管理系统
- 我是如何让公司后台管理系统焕然一新的(上) -性能优化
猜你喜欢
MySQL 5.7详细下载安装配置教程
mysql deadlock
LeetCode·Daily Question·952. Calculate Maximum Component Size by Common Factor·Union Check
cmd (command line) to operate or connect to the mysql database, and to create databases and tables
cnpm安装步骤
Advanced c language: pointers (5)
Solve the problem of centos8 MySQL password ERROR 1820 (HY000) You must reset your password using the ALTER USER
navicat新建数据库
Teach you how to build a permanently running personal server
Difference between cookie and session
随机推荐
MySQL user authorization
系统结构考点之多级混洗交换网络
JUC原子类详解
[Limited Time Bonus] 21-Day Learning Challenge - MySQL from entry to mastery
socket:内核初始化及创建流(文件)详细过程
cmd(命令行)操作或连接mysql数据库,以及创建数据库与表
JDBC(详解)
WinDbg实践--入门篇
Solve the problem of centos8 MySQL password ERROR 1820 (HY000) You must reset your password using the ALTER USER
mysql创建表
关于MySQL主从复制的数据同步延迟问题
Union, the difference between union and structure, the knowledge of enumeration of C language corners
Apache DolphinScheduler新一代分布式工作流任务调度平台实战-
触摸屏状态机
ELF:加载过程
openim支持十万超级大群
The mysql time field is set to the current time by default
It is enough for MySQL to have this article (disgusting typing 37k words, just for Bojun!!!)
MySql 5.7.38 download and installation tutorial, and realize the operation of MySql in Navicat
Day 16 of HCIP