In Jave Socket resources should always be closed when they a

In Jave, Socket resources should always be closed when they are no longer needed. How does the “finally” clause of a try/catch/finally block facilitate this requirement?

Solution

finally block is a concept of exception handling in java.
finally block should come after try or catch block.
in java finally block always executed whether the exception has occurred or not.
so if we place our code which handles to close the resources in finally block, that gets executed in all the scenarios. if there was any error, finally will be executed after catch block else after try block. thus finally block makes sure to execute that code to clpse the resources.

In Jave, Socket resources should always be closed when they are no longer needed. How does the “finally” clause of a try/catch/finally block facilitate this req

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site