search
HomeJavaJavagetting StartedWhat are the characteristics and functions of the finally keyword in java

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("看看我执行了吗");
		}
	}
}

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!

Statement
This article is reproduced at:csdn. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool