GeekInterview.com
Series: Subject: Topic:

Java Interview Questions

Showing Questions 1 - 2 of 2 Questions
Sort by: 
 | 

What is a transient variable

Asked By: Interview Candidate | Asked On: Sep 4th, 2005

A transient variable is a variable that may not be serialized.

Star Read Best Answer

Editorial / Best Answer

Answered by: sivagopal

View all answers by sivagopal

Member Since Jun-2009 | Answered On : Jun 8th, 2009

A variable that won't be allowed for object serialisation. so that the state of the value will always be defaulted after the deserialisation.
For example a variable x's value is set to 9, it's default value is '0' say, when the object has been serialized having x's value 9, after deserialisation will be defaulted to '0'

Use: In Java, serialization of an object allowed only when all the underlying objects of the object that is currently under serialization contains has a relationship, will not be allowed, some times the developer has no choice of implementing serializable marker interface on some classes as the classes might have been arrived from a third party and the developer has no control over them, but the developer needs to serialize the object's state, then the developer has the choice of marking the objects that not serializable as transient.

Answered by: raisha on: May 6th, 2013

transient is a keyword....If a variable is declared as a Transient ,we cant serialize that variable.. The important points about Transient are: 1) Transient keyword can only be applied to fields or ...

Answered by: vijay on: Sep 12th, 2011

A transient variable is a variable that may not be serialised.

What is the difference between throw and throws clause, explain in programatically

Asked By: sundaramoorthy.k | Asked On: Dec 23rd, 2005

Star Read Best Answer

Editorial / Best Answer

Answered by: sri

Answered On : Dec 24th, 2005

throw is used to throw an exception manually, where as throws is used in the case of checked exceptions, to reintimate the compiler that we have handled the exception. so throws is to be used at the time of defining a method and also at the time of calling that function, which rises an checked exception.

Prog. to explain diff. b/w  throw and throw:

class MyException extends Exception //to create our own exception
{
public String toString()   //overriding the method toString() to print the desired msg.
{
return "Can not divide a no. with one: "+"MyException";
}
public static void main(String args[]) throws MyException //use of throws
{
int a=Integer.parseInt(args[0]);
int b=Integer.parseInt(args[1]);
if(b==1)
throw new MyException();  // rises an MyException, if we try to divide a no. with 1
else
System.out.println((float)a/b);
}
}

if we want to rise our own exception, we have to use either throws or to handle the exception by try-catch. if not, it gives the compile time error.

and throw is to rise the exception manually, In the above prog. I rised an exception when you try to divide a no with 1.(own Exception)

     ----sri

Answered by: muthud on: Nov 22nd, 2011

Exception handling is done by two ways . One is handled by JVM and another is handled by User. JVM does Exception handling by using principle of Exception can be Caught or Declared . Caught is nothin...

Answered by: micklesharma on: Jul 6th, 2010

Throws is a userdefined exception handling whereas throw is system defined....

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.