Difference between final. finally , and finalize() final, finally 和finalize区别

Final --- constant declaration.  常量声明

   A final method or variable is one that can't be overridden, you can define a method as final within a class to ensure that any extesions to the class don't replace it.

 

    Finally-- executed by try catch block undoubtedly     异常必定执行

    The finally block always executes when the try block exits, except System.exit(0) call. This ensures that the finally block is executed enven if an unexpeted exception occurs. But finally is useful for more than just exception handing , it allows the programmer to avoid having clearnup code accidentally bypassed by a return, continue, or break. Putting cleanup code in a finally block is always a good practice, even when no exceptions are anticipated.

 

    Finalize()--- garbage collection 垃圾回收

    finalize()  method helps in garbage collection. A method that is invoked before an object is discarded by the garbage collector, allowing it to clean up its state. Should not be used to release non-memory resources like file handles, sockets, database connections etc because Java has only a finite number of these resources and you do not know when the garbage collection is going to kick in to release these non-memory resources through the finalize() method.

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值