1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc)

Java interview questions

  • How to retrieve a key and Value from a map ? view answer
  • Why can an interface supertype call methods that belong to Object class? view answer
  • Q. What is difference between shallow copy and deep copy ? view answer
  • Q.Why to override equals() and hashCode()? and How i can implement both equals() and hashCode() for Set ? view answer
  • Q.How to sort list of objects ( User Defined) using comparator? in Descending Order. view answer
  • Q. How to sort list of objects ( User Defined) using comparator? view answer
  • What is the difference between int and Interger? view answer
  • Singleton Double-checked locking in Java? view answer
  • What are the parameters to follow Creating and Destroying Objects in Java? view answer
  • Q.What are the different scopes for Java variables? view answer
  • Q.What method must be implemented by all threads? view answer
  • Q.Can an unreachable object become reachable again? view answer
  • Q.What are the steps in the JDBC connection? view answer
  • Q.How are this() and super() used with constructors? view answer
  • Q.What is the difference between static and non-static variables? view answer
  • Q.What is the purpose of finalization? view answer
  • Q.Does garbage collection guarantee that a program will not run out of memory? view answer
  • Q.What is synchronization and why is it important? view answer
  • Q.What is daemon thread and which method is used to create the daemon thread? view answer
  • Q.What are synchronized methods and synchronized statements? view answer
  • Q.If I write System.exit (0); at the end of the try block, will the finally block still execute? view answer
  • Q.If I write return at the end of the try block, will the finally block still execute? view answer
  • Q.Is it necessary that each try block must be followed by a catch block? view answer
  • Q.What is the basic difference between the 2 approaches to exception handling. 1> try catch block and 2> specifying the candidate exceptions in the throws clause? When should you use which approach? view answer
  • Q.What are the different ways to handle exceptions? view answer
  • Q.What is the difference between error and an exception? view answer
  • Q: What is wrapper class? Explain with example? view answer
  • Q.What is serialization? Explain with example? view answer
  • Q.What one should take care of while serializing the object? view answer
  • Q. When you serialize an object, what happens to the object references included in the object? view answer
  • Q.What happens to the static fields of a class during serialization? view answer
  • Q. Objects are passed by value or by reference? view answer
  • Q. Primitive data types are passed by reference or pass by value? view answer
  • Q. What type of parameter passing does Java support? view answer
  • Q.Can a top level class be private or protected? view answer
  • Q.What is the default value of an object reference declared as an instance variable? view answer
  • Q.What is the difference between declaring a variable and defining a variable? view answer
  • Q. What are different types of inner classes? view answer
  • Q. What is Overriding? view answer
  • Q.What are Checked and UnChecked Exception? view answer
  • Q. What is final? view answer
  • Q.What is static in java? view answer
  • What is an abstract class? view answer
  • Q. What are the modifiers in Java ? view answer
  • Q.Difference between HashMap and HashTable? view answer
  • Q.Difference between Vector and ArrayList? view answer
  • Q.Difference between ArrayList and LinkedList? view answer
  • Q.What are pass by reference and passby value in Java? view answer
  • Q. When we go for Abstract and Interface in Java? view answer
  • Q.What is the difference between interface and abstract class? view answer
  • Q.What are the Garbage collection algorithms in Java? view answer
  • Q.What is garbage collection and the purpose of garbage collection in Java? view answer
  • Q. What is the difference between an Interface and an Abstract class? view answer

!!! Java interview questions !!!

Q.What are the Garbage collection algorithms in Java?



Any garbage collection algorithm must do two basic things.
First, it must detect garbage objects.
Second, it must reclaim the heap space used by the garbage objects and make it available to the program.
Garbage detection is ordinarily accomplished by defining a set of roots and determining reachability from the roots.
An object is reachable if there is some path of references from the roots by which the executing program can access the object.
The roots are always accessible to the program. Any objects that are reachable from the roots are considered live.
Objects that are not reachable are considered garbage, because they can no longer affect the future course of program execution.

    a. Reference counting collectors
Reference counting was an early garbage collection strategy.
here a reference count is maintained for each object.
When an object is first created its reference count is set to one.
When any other object or root is assigned a reference to that object, the object's count is incremented.
When a reference to an object goes out of scope or is assigned a new value, the object's count is decremented.
Any object with a reference count of zero can be garbage collected.
When an object is garbage collected, any objects that it refers to has their reference counts decremented.
In this way the garbage collection of one object may lead to the subsequent garbage collection of other objects.

b. Tracing collectors
Tracing garbage collectors trace out the graph of object references starting with the root nodes.
Objects that are encountered during the trace are marked in some way.
Marking is generally done by either setting flags in the objects themselves or by setting flags in a separate bitmap.
After the trace is complete, unmarked objects are known to be unreachable and can be garbage collected.
The basic tracing algorithm is called mark and sweep.
This name refers to the two phases of the garbage collection process.
In the mark phase, the garbage collector traverses the tree of references and marks each object it encounters.
In the sweep phase unmarked objects are freed, and the resulting memory is made available to the executing program.
In the JVM the sweep phase must include finalization of objects.

    c. Compacting collectors
Garbage collectors of JVMs will likely have a strategy to combat heap fragmentation.
Two strategies commonly used by mark and sweep collectors are compacting and copying.
Both of these approaches move objects on the fly to reduce heap fragmentation.
Compacting collectors slide live objects over free memory space toward one end of the heap.
In the process the other end of the heap becomes one large contiguous free area.
All references to the moved objects are updated to refer to the new location.

    d. Copying collectors
Copying garbage collectors move all live objects to a new area.
As the objects are moved to the new area, they are placed side by side,
thus eliminating any free spaces that may have separated them in the old area.
The old area is then known to be all free space.
The advantage of this approach is that objects can be copied as they are discovered by the traversal from the root nodes.
There are no separate mark and sweep phases.
Objects are copied to the new area on the fly, and forwarding pointers are left in their old locations.
The forwarding pointers allow objects encountered later in the traversal that refer to already copied objects to know the new location of the copied objects.

Reviews and Comments


PMP, CAPM, PMI is a registered certification mark of the Project Management Institute, Inc

Copyright © www.techfaq360.com 2016


About US | Contact US | Privacy Policy | Terms and Conditions  | Website disclaimer  | Cancellation and Refund Policy  | Shipping & Delivery Policy