Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


What are Transient and Volatile Modifiers?

Answers were Sorted based on User's Feedback



What are Transient and Volatile Modifiers?..

Answer / janet

Transient: The transient modifier applies to variable only
and it is not stored as part of it's objects persistent
state.Transient variables are not serialized.
Volatile: Volatile modifier applies to variables only and
it tells the compiler that the variable modified by
volatile can be changed unexpectedly by other parts of the
program.

Is This Answer Correct ?    22 Yes 4 No

What are Transient and Volatile Modifiers?..

Answer / shashank jain

Java defines two interesting type modifiers: transient and
volatile. These modifiers are
used to handle somewhat specialized situations.
When an instance variable is declared as transient, then its
value need not persist
when an object is stored. For example:
class T {
transient int a; // will not persist

int b; // will persist
}
Here, if an object of type T is written to a persistent
storage area, the contents of a
would not be saved, but the contents of b would.
The volatile modifier tells the compiler that the variable
modified by volatile can
be changed unexpectedly by other parts of your program. One
of these situations
involves multithreaded programs. (You saw an example of this
in Chapter 11.) In a
multithreaded program, sometimes, two or more threads share
the same instance
variable. For efficiency considerations, each thread can
keep its own, private copy of
such a shared variable. The real (or master) copy of the
variable is updated at various
times, such as when a synchronized method is entered. While
this approach works
fine, it may be inefficient at times. In some cases, all
that really matters is that the
master copy of a variable always reflects its current state.
To ensure this, simply specify
the variable as volatile, which tells the compiler that it
must always use the master
copy of a volatile variable (or, at least, always keep any
private copies up to date with
the master copy, and vice versa). Also, accesses to the
master variable must be executed
in the precise order in which they are executed on any
private copy.

Is This Answer Correct ?    14 Yes 4 No

What are Transient and Volatile Modifiers?..

Answer / harika.thota001@gmail.com

we can use volatile in the application where a lot of threads are working simultaneously. Each thread having its local copy for instance variable. If we use volatile then it will become master copy. All will access the master copy. so whatever is latest we can use.

While Transient is used in the case of serialization.
Serialization is a process of writing an object in the files.
if we use prefix transient with variable than that variable value will not store when we write the object in the file.

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is java and its types?

0 Answers  


What is thin driver and thick driver. why it is called so?

2 Answers   Logisoft,


What is the difference between private & public & friendly classes?

0 Answers  


what is the main class of all the classes

5 Answers   Photon,


What is final variable?

0 Answers  


What are the object and class classes used for?

0 Answers  


Why is stringbuffer faster than string?

0 Answers  


Can you override a private or static method in java?

1 Answers  


What is run time allocation?

0 Answers   Fidelity,


what is difference between Exception and Error?

36 Answers  


What is a layout manager?

1 Answers  


What are the 4 versions of java?

0 Answers  


Categories