adbrite adds

Your Ad Here

Java J2EE Best Answer

Read all the question and answer in the post and success the Interview.


search for Interview questions and job

Monday, August 25, 2008

Java Variable questions

Vaiables in java



1. What is the difference between class variable, member variable and automatic(local) variable?

Class variable is a static variable and does not belong to instance of class but rather shared across all the instances
member variable belongs to a particular instance of class and can be called from any method of the class
automatic or local variable is created on entry to a method and has only method scope

2. What are transient variables?
A transient variable is not stored as part of objects persistent state and they cannot be final or static. Transient variable can't be serialize. For example if a variable is declared as transient in a Serializable class and the class is written to an ObjectStream, the value of the variable can't be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null.

3. What are volatile variables?

It indicates that these variables can be modified asynchronously.

4. When are automatic variable initialized?

Automatic variable have to be initialized explicitly.

5. What types of values does boolean variables take?

It only takes values true and false.

6. Which primitive datatypes are signed?

All except char and Boolean
7. How is an argument passed in java, by copy or by reference?

If the variable is primitive data type then it is passed by copy.
If the variable is an object then it is passed by reference

8. Can abstract modifier be applied to a variable?

No, It is applied only to class and methods.

9. What is the difference between parameters and arguments?

While defining method, variables passed in the method are called parameters. While using those methods, values passed to those variables are called arguments.

10. Why we should not have instance variable in an interface?

Since all data fields and methods in an Interface are public by default, then we implement that interface in our class then we have public members in our class and this class will expose these data members and this is violation of encapsulation as now the data is not secure.

11. What happens if you don’t initialize an instance variable of any of the primitive types in Java?

A: Java by default initializes it to the default value for that primitive type. Thus an int will be initialized to 0, a boolean will be initialized to false.

12. What will be the initial value of an object reference which is defined as an instance variable?

The object references are all initialized to null in Java. However in order to do anything useful with these references, you must set them to a valid object, else you will get NullPointerExceptions everywhere you try to use such default initialized references.

13. What will be the default values of all the elements of an array defined as an instance variable?

If the array is an array of primitive types, then all the elements of the array will be initialized to the default value corresponding to that primitive type. e.g. All the elements of an array of int will be initialized to 0, while that of boolean type will be initializedto false. Whereas if the array is an array of references (of any type), all the elements will be initialized to null.

No comments:

Study JAVA J2EE

Read EJB Session Bean Guide post and do EJB with a hour BEST OF LUCK CONTACT 9942291292

click to get job