Home > Java > Javagetting Started > What are the characteristics and functions of the finally keyword in java

What are the characteristics and functions of the finally keyword in java

王林
Release: 2020-09-01 16:00:14
forward
3089 people have browsed it

What are the characteristics and functions of the finally keyword in java

What are the characteristics of the finally keyword?

The statement body controlled by finally will definitely be executed.

(Video tutorial recommendation: java course)

Special case: jvm exited before execution to finally (such as System.exit(0)).

What is the function of finally keyword?

The function of finally is to release resources, which can be seen in IO stream operations and database operations.

(Related tutorial recommendations: Getting started with java)

Example:

package com.heima.exception;

public class Demo07_Finally {

	public static void main(String[] args) {
		try {
			System.out.println(10/0);
		} catch (Exception e) {
			System.out.println("除数为零了");
			System.exit(0);								//退出jvm虚拟机
			// return语句相当于是方法的最后一口气,那么在他将死之前会看一看有没有
			// finally帮其完成遗愿,如果有就将finally执行后在彻底返回。
			return;
		} finally {
			System.out.println("看看我执行了吗");
		}
	}
}
Copy after login

The above is the detailed content of What are the characteristics and functions of the finally keyword in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template