?
Solved

Finalize and Transient

Posted on 2006-05-07
6
Medium Priority
?
388 Views
Last Modified: 2010-03-31
What is the use of finalize and transient keyword
0
Comment
  • 3
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
hoomanv earned 80 total points
ID: 16624329
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16624398
another finalize: http://cs.anu.edu.au/~Steve.Blackburn/pubs/papers/finalize-pjw3.pdf

a transient variable will not be written out when an instance is serialized
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16624443
When you write or read an object to a file or network or other stream using serialization process, It writes/reads the complete object state that means it writes the object, it's instance variables, and  super class instance variables except transient variables and class (static) variables

Variables that have access modifier  'transient'  will not be read from or written into streams. It gives facility to avoid writing unnecessary data into streams. In other words, it boosts the performance by avoiding writing unnecessary data into streams.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:Mayank S
ID: 16629253
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 16630169
could you explain with simple , what is the use of finalize
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 120 total points
ID: 16630620
I personally never use it. When you call System.runFinalization (), it calls finalize () on all objects eligible for garbage-collection. By default, the finalize () method in Object is protected. You can override it in your class using:

public void finalize ()
{
  // do some clean-up like closing resources, DB connection pools, etc

}

You can also set the JVM to call finalize () on all objects when the application exits using System.runFinalizersOnExit ( true ) ;
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question