1. 1. How are Observer and Observable used?
Observer is a interface, Observable is a class. Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.
2. 2. What will be the default values of all the elements of an array defined as an instance variable?
If the variable 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 initialized to false. Whereas if the variable is an array of references (of any type), all the elements will be initialized to null.
3. What happens if you don’t initialize an instance variable of any of the primitive types in Java?
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.
4. 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. In program you must set a valid object, other wise you will get NullPointerExceptions.
5. What are the scopes for Java variables?
There are three types of scopes are:
1. Instance variable : - These are typical object level variables, they are initialized to default values at the time of creation of object, and remain accessible as long as the object accessible.
2. Local variable : - These are the variables that are defined within a method. They remain accessbile only during the course of method excecution. When the method finishes execution, these variables fall out of scope.
3. Static variable: - These are the class level variables. They are initialized when the class is loaded in JVM for the first time and remain there as long as the class remains loaded. They are not tied to any particular object instance.
6. What is the default value of the local variables?
The local variables are not initialized to any default value If you try to use these variables without initializing them explicitly, the java compiler gives an error in compile time.
7. some not a keyword in Java?
Main, next, delete, exit, No, main() is a Static Method.
8. What is the Locale class?
The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.
9. What is the purpose of finalization?
The purpose of finalization is to cleanup the unused java object.
10. What is the difference between preemptive scheduling and time slicing?
Under preemptive scheduling, the highest priority task executes. Under time slicing, a task executes for a predefined slice of time and then execute next task.
11. What is garbage collection ?
The runtime system keeps track of the memory that is allocated and is able to determine whether that memory is still useable. This work is usually done in background by a low-priority thread that is referred to as garbage collector. When the gc(System.gc()) finds memory that is no longer accessible from any live thread it takes steps to release it back to the heap for reuse.
No comments:
Post a Comment