Select chapter



basics (7.papers)
constructors (1.papers)
packages (1.papers)
inheritance (7.papers)
misc (3.papers)
exceptions (5.papers)
threads (4.papers)
overloading (1.papers)
jsp (3.papers)
servlets (9.papers)
jdbc (2.papers)
util (1.papers)
xml (2.papers)
IO stream (3.papers)
Hide

Sponsored Links


  

java misc interview questions and answers

1
Should every JVM implement Garbage Collector?
  1. Yes its mandatory
  2. Sun documentation doesn't mandate GC implementation in JVM.
  3. none
Show Answer
Share Facebook gmail Twitter
2
Will Garbage Collector be called immediately, once an object is ready to be freed (once object doesn't have any references)?
  1. No, it takes some time to GC to trigger and reclaim the memory of un referenced objects in the heap.
  2. Yes, GC will be triggered immediately to reclaim the memory of un referenced objects in the heap.
  3. There is no guarantee as such. That depends on GC logic of that JVM.
  4. none
Show Answer
Share Facebook gmail Twitter
3
What is the purpose of Garbage collector?
  1. It will clean or release the memory occupied by java resources in the heap. Note: provided there is no references to those objects.
  2. It will clean or release the memory occupied by java and non-java resources in the heap. Note: provided there is no references to those objects.
  3. It will clean or release the memory occupied by java resources in the stack & heap. Note: provided there is no references to those objects.
  4. It will clean or release the memory occupied by java and non-java resources in the stack & heap. Note: provided there is no references to those objects.
Show Answer
Share Facebook gmail Twitter
4
Does java have memory leaks?
  1. Since Garbage collector will clean all the memory, there is no chance of having memory leaks in java
  2. There is a chance of memory leaks in java also, if you tie up the object reference to a static variables and doing it indefinitely can cause memory leak.
Show Answer
Share Facebook gmail Twitter
5
What is the use of finalize() method?
  1. Finalize() method doesn't have any specific purpose, practically.
  2. you can use finalize() method to clean or reclaim non java resources, as they are not cleaned by GC.
  3. you can use finalize() to clean both java and non-java resources.
  4. all are true.
Show Answer
Share Facebook gmail Twitter
6
What type of resources should be cleaned in finalize() method? Which of the below statements are true about finalize method?
  1. you can clean all non-java resources only in finalize() method.
  2. Though you clean all non-java resources in finalize() method, it is a good practice to clean all non java resources in all the functions where ever you are using it.
  3. It is better to clean both java and non-java resources in finalize() method.
  4. It is mandatory for all classes to override and implement finalize() method of Object class.
Show Answer
Share Facebook gmail Twitter
7
"Though you clean all non-java resources in finalize() method, it is a good practice to clean all non java resources in all the functions where ever you are using it."  why?
  1. Because there is no guarantee that JVM's GC will call finalize method before cleaning an object.
  2. Because there is no guarantee that when GC will run, so we don't know when finalize will be called, so we can't hold important system resources for too much of time, as there are very limited system resources will be available for processes.
  3. Though we know that when GC will clean the object, but still we can't guarantee whether GC will call finalize() method of that object before cleaning or after cleaning that object.
  4. this statement is not true.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
11
How to create a singleton class? should it have private or public constructor?
  1. Singleton class will have public constructors.
  2. Singleton class can have public constructors.
  3. Singleton class should have only private constructors.
  4. Singleton class can have both public and private constructors.
Show Answer
Share Facebook gmail Twitter
12
Is this an example of a Singleton class?
class Single{
        private Single(){
                System.out.println("Constructor called");
        }
        public static Single getInstance(){
                Single s = new Single();
                return s;
        }
        public void fun(){
                System.out.println("Single fun..");
        }
}
public class SingletonDemo {
        public static void main(String[] args) {
                Single s = Single.getInstance();
                Single t = Single.getInstance();
                s.fun();
                t.fun();
        }
}
  1. Yes, because we are having private constructor, and we are creating only object "s" in getInstance() all the time. So this is singleton class.
  2. No, because every time client calls Single.getInstance() we are creating a new object Single s = new Single(); This will create n number of objects if you call n number of times. So this is not singleton class.
  3. This program gives compile time error
  4. This program gives run time exception.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
18
Which of the below options are false about nested classes?
  1. A class with in a class is called as Nested class.
  2. A non static nested class can access the private members of outer class directly
  3. A static nested class can access the private members of outer class directly.
  4. A static or non static nested class can be declared as private, public, or protected as it is the member of the outer class.
Show Answer
Share Facebook gmail Twitter
19
What is a singleton Class?
  1. A class which can't be inherited.
  2. A class for which we can create only one object.
  3. A class for which we can't create any object.
  4. none of the above
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Read more papers :