ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
What is Transient and volatile
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: What is Transient and volatile
Answer
# 1
we cant write the value of a transient variable into 
datastream.volatile means its just like temporary variable
 
Is This Answer Correct ?    5 Yes 3 No
Soumay M Cyriac
 
  Re: What is Transient and volatile
Answer
# 2
transient 
identifies a variable not to be written out when an 
instance is serialized  (It can'nt be copied to remove 
system)

volatile 
indicates that the field is used by synchronized threads 
and that the compiler should not attempt to perform 
optimizations with it.

When more than one thread share a (volatile) data it is 
checked every time. Every thread keeps the latest value of 
volatile variable
 
Is This Answer Correct ?    6 Yes 2 No
Subrahmanyam
 
 
 
  Re: What is Transient and volatile
Answer
# 3
Trying to put a non-serializable variable in a 
seriealisible class,we can use transient modifier ,so that 
the jvm skips the transient variable ,and make that class 
as serializable class
 
Is This Answer Correct ?    3 Yes 0 No
Lakshmidontukurthy
 
  Re: What is Transient and volatile
Answer
# 4
both are used for declaring a vaiables.we can say it is a
modifiers.
 
Is This Answer Correct ?    1 Yes 2 No
Loganathan S
 
  Re: What is Transient and volatile
Answer
# 5
Transient
~~~~~~~~~
          identifies a variable not to be written out when 
an instance is serialized  (It can'nt be copied to remove 
system)

Volatile
~~~~~~~~
        indicates that the field is used by synchronized 
threads and that the compiler should not attempt to perform 
optimizations with it.When more than one thread share a 
(volatile) data it is checked every time. Every thread 
keeps the latest value of volatile variable
 
Is This Answer Correct ?    1 Yes 0 No
Sudhadevi
 
  Re: What is Transient and volatile
Answer
# 6
Transient
.........
          Only variable can be declared as Transient, When 
used as a Modifier in a variable Declaration it suggests 
that a variable may not be return out when the class is 
serialized

Volatile
.........
          The keyword volatile can be used to declare 
variables. The use of the keyword volatile in a variable 
declaration suggests the compiler that multiple threads may 
access the variable. Therefore the value of the variable 
may change unexpectedly. A Compile time error will  occur 
declaring a variable both volatile and final.

      Example for Volatile:
      .....................
         
            volatile int v = 0;
            Thread 1:
            v++;
            Thread 2:
             v--;

       The questioners usually want the answer "v can only 
be 0 after this code is run", because

           volatile int v = 0;
           Thread 1:
             r1 = v;
             r2 = r1 + 1;
             v = r2;
           Thread 2:
             r3 = v;
             r4 = r3 - 1;
             v = r4;
       So, if Threads 1 and 2 both read v and see the value 
0, then Thread 1 will write 1 to it and Thread 2 will 
write -1 to it. You are not guaranteed to see the value 0!
 
Is This Answer Correct ?    6 Yes 0 No
Jagan Kumar(zylog Systems Ltd.
 
  Re: What is Transient and volatile
Answer
# 7
Transient variable is used to make the variable out of 
synchronization.
Volatile variable is used when the variable is changing 
it's state continuously
 
Is This Answer Correct ?    0 Yes 3 No
Ravikiran
 
  Re: What is Transient and volatile
Answer
# 8
1.transient variables can not be serialized.
2.volatile variables may change with the affect of other one
 
Is This Answer Correct ?    2 Yes 0 No
Deepak Divvela
 
  Re: What is Transient and volatile
Answer
# 9
Trsnsient:
If you mark an instance variable as transient you're telling
the JVM  to skip this variable when you attempt to serialize
the object containing it.

Volatile:
The volatile modifier tells the JVM that a thread accessing
the variable must always reconcile its own private copy of
the variable with the master copy in memory.
It can be apply only to instance variables.
 
Is This Answer Correct ?    0 Yes 0 No
Pasindu
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
Does Java support multiple Inheritance?  6
What is the difference between Trusted and Untrusted Applet ? IBM1
how many access specifiers are available in java  5
what is private constructor?what are the uses of writing private constructor in our program?  5
without using arthematic operation ,how can you write the logic for adding/substraction/multiplication? Wipro4
What are the common problems you have faced while implementing Java?  1
How many ways can an argument be passed to a subroutine?  2
Can a Byte object be cast to a double value?  2
How the elements are organized in GridBagLayout?  1
Howmany classes that package java.applet.* contains? TCS1
write java code to print second max number in the array Huawei9
what is the difference between equals method and == Professional-Access11
What is the default initialized value of a boolean type variable?  3
wHAT IS DEFAULT SPECIFIER IN JAVA wHAT IS DEFAULT CONSTRUCTOR IN JAVA wHAT IS DEFAULT METHOD IN JAVA IBM10
whats is inheritance? HCL14
how to call One constructor from another; Innodata-Isogen7
What is System class and its purpose?  2
methods in Applet?  1
If your team member writes code with lots of static variables and static methods, will it cause any side effects? KPIT1
There are 2 methods in a class. Both have the same method signature except for return types. Is this overloading or overriding or what is it? KPIT7
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com