1. Why is the main method static ?
Ans: So that it can be invoked without creating an instance of that class
2. What is the difference between class variable, member variable and
automatic(local) variable ?
Ans: - 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
3. When are static and non static variables of the class initialized ?
Ans: The static variables are initialized when the class is loaded Non static variables
are initialized just before the constructor is called
4. When are automatic variable initialized ?
Ans: Automatic variable have to be initialized explicitly
5. What is a modulo operator % ?
Ans: This operator gives the value which is related to the remainder of a divisione.g
x=7%4 gives remainder 3 as an answer
6. How is an argument passed in java, by copy or by reference What is a modulo
operator % ?
Ans: This operator gives the value which is related to the remainder of a divisione.g
x=7%4 gives remainder 3 as an answer
7. What is garbage collection ?
Ans: 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 finds memory that is no longer accessible from any live thread it takes steps to
release it back to the heap for reuse
8. Does System.gc and Runtime.gc() guarantee garbage collection ?
Ans: No
9. What are different types of operators in Java ?
Ans: - Uniary ++, –, +, -, |, ~, ()
- Arithmetic *, /, %,+, -
-Shift <<, >>, >>>
- Comparison =, instanceof, = =,!=Bitwise &, ^, |Short Circuit &&, ||
Ternary ?:Assignment =
10. How does bitwise (~) operator work ?
Ans: It converts all the 1 bits in a binary value to 0s and all the 0 bits to 1