File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes finally block and non-memory resources Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "finally block and non-memory resources" Watch "finally block and non-memory resources" New topic

finally block and non-memory resources

Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
I read that the finally block is used to release non-memory resources.

On the other hand, nonmemory resources like file handles and socket handles must be explicitly released by the program, using methods with names like close(), destroy(), shutdown(), or release().

Why are these resources called non-memory?
Even if I open an RMI socket, I agree that the objects are constructed on a different heap area (diff. JVM), but still it comsumes some area in my JVM?
Also, why IO streams called as non-memory resources?

pls help..
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Do you really mean try, catch, finally? Or the overridden Object.finalize() method?

For the SCJP you only need consider resources in the same JVM. An IO stream would be allocated an operating system resource (a filehandle) which you should return if not being used.
[ November 30, 2006: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
Yup! i meant the finally, not the finalize method in the Object class..
I agree. Here's the link:
subject: finally block and non-memory resources
It's not a secret anymore!