10 Garbage Collection Interview Questions Too Answers Inward Coffee Programming
GC Interview Questions Answer inwards Java
Garbage collection interview questions are rattling pop inwards both gist Java together with advanced Java Interviews. Apart from Java Collection together with Thread many tricky Java questions stems Garbage collections which are tough to answer. In this Java Interview article I volition portion unopen to questions from GC which is asked inwards diverse gist Java interviews.These questions are based upon concept of How Garbage collection works, Different kinds of Garbage collector and JVM parameters used for garbage collection monitoring together with tuning. As I said GC is an of import business office of whatever Java interview then brand certain yous receive got skillful command inwards GC. One to a greater extent than affair which is getting rattling of import is might to encompass together with understand Garbage collection Output, to a greater extent than together with to a greater extent than interviewer are checking whether candidate tin empathise GC output or not. During Java interview they may render a snippet of GC output together with enquire diverse questions based on that e.g. Which Garbage collector is used, whether output is from major collection or kid collection, How much retentiveness is complimentary from GC, What is size of novel generation together with quondam generation afterward GC etc. I receive got included few Garbage collection interview questions together with answers from GC output to aid amongst that. It’s recommended to gear upwards questions from Java collection, multithreading together with programming along amongst Garbage collection to produce good inwards Java interviews at whatever stage.
Interview questions on Java Garbage collection
Here is unopen to Garbage collection Interview questions from my personal collection, which I receive got created from my sense together with amongst the aid of diverse friends together with colleagues which has shared GC interview questions amongst me. Actually at that topographic point are lot many questions than What I am sharing hither but to proceed this post little I idea to solely portion unopen to questions, I tin scream back of minute business office of GC interview enquiry if yous guys discovery this useful. Question 1 - What is construction of Java Heap ? What is Perm Gen infinite inwards Heap ?
Answer : In companionship to ameliorate perform inwards Garbage collection questions inwards whatever Java interview, It’s of import to receive got basic agreement of Java Heap space. To acquire to a greater extent than nearly heap, come across my post 10 points on Java heap space. By the way Heap is divided into dissimilar generation e.g. novel generation, quondam generation together with PermGen space.PermGen infinite is used to shop class’s metadata together with filling of PermGen infinite tin cause java.lang.OutOfMemory:PermGen space. Its also worth noting to remember JVM pick to configure PermGen space inwards Java.
Question 2 - How produce yous position kid together with major garbage collection inwards Java?
Answer: Minor collection prints “GC” if garbage collection logging is enable using –verbose:gc or -XX:PrintGCDetails, piece Major collection prints “Full GC”. This Garbage collection interview enquiry is based on agreement of Garbage collection output. As to a greater extent than together with to a greater extent than Interviewer are asking enquiry to banking corporation stand upwards for candidate’s might to empathise GC output, this theme croak fifty-fifty to a greater extent than important.
Question iii - What is departure betwixt ParNew together with DefNew Young Generation Garbage collector?
Answer : This Garbage Collection interview questions is late asked to 1 of my friend. It require to a greater extent than than average noesis on GC to reply this question. By the way ParNew together with DefNew is 2 immature generation garbage collector. ParNew is a multi-threaded GC used along amongst concurrent Mark Sweep piece DefNew is unmarried threaded GC used along amongst Serial Garbage Collector.
Question four - How produce yous discovery GC resulted due to calling System.gc()?
Answer : Another GC interview enquiry which is based on GC output. Similar to major together with kid collection, at that topographic point volition live a give-and-take “System” included inwards Garbage collection output.
Question v - What is departure betwixt Serial together with Throughput Garbage collector?
Answer : Serial Garbage collector is a halt the Blue Planet GC which stops application thread from running during both minor together with major collection. Serial Garbage collector tin live enabled using JVM pick -XX:UseSerialGC together with it's designed for Java application which doesn't receive got recess fourth dimension requirement together with receive got customer configuration. Serial Garbage collector was also default GC inwards JDK 1.4 earlier ergonomics was introduced inwards JDK 1.5. Serial GC is most suited for little application amongst less number of thread while throughput GG is to a greater extent than suited for large applications. On the other mitt Throughput garbage collector is parallel collector where kid together with major collection happens inwards parallel taking sum payoff of all the organisation resources available similar multiple processor. Though both major together with kid collection runs on stop-the-world fashion together with introduced recess inwards application. Throughput Garbage collector tin live enable using -XX:UseParallelGC or -XX:UseOldParallelGC. It increases overall throughput of application my minimizing fourth dimension spent inwards Garbage collection but withal has long pauses during sum GC.This is a variety of Garbage collection interview questions which gives yous an chance to exhibit your noesis inwards item piece answering. I e'er propose to reply these variety of questions inwards detail. See Java Performance The Definitive Guide for to a greater extent than details on this topic.
Question half-dozen – When does an Object becomes eligible for Garbage collection inwards Java ?
Answer : An object becomes eligible for garbage collection when at that topographic point is no alive reference for that object or it tin non live reached past times whatever alive thread. Cyclic reference doesn’t count every bit alive reference together with if 2 objects are pointing to each other together with at that topographic point is no alive reference for whatever of them, than both are eligible for GC. Also Garbage collection thread is a daemon thread which volition run past times JVM based upon GC algorithm together with when runs it collects all objects which are eligible for GC.
Question vii - What is finalize method inwards Java ? When does Garbage collector calls finalize method inwards Java ?
Answer : Finalize method inwards Java also called finalizer is a method defined inwards java.lang.Object together with called past times Garbage collector earlier collecting whatever object which is eligible for GC. Finalize() method provides lastly run a endangerment to object to produce cleanup together with complimentary whatever remaining resource, to acquire to a greater extent than nearly finalizers, read What is finalize method inwards Java.
Question 8 - If Object Influenza A virus subtype H5N1 has reference to Object B together with Object B refer to Object A, apart from that at that topographic point is no alive reference to either object Influenza A virus subtype H5N1 or B, Does they are eligible to Garbage collection ?
This Garbage collection interview questions is related enquiry v “When object croak eligible for Garbage collection”. An object becomes eligible for Garbage collection if at that topographic point is no alive reference for it. It tin non live accessible from whatever Thread together with cyclic dependency doesn’t forestall Object from beingness Garbage collected. Which agency inwards this illustration both Object Influenza A virus subtype H5N1 together with Object B are eligible of Garbage collection. See How Garbage collection industrial plant inwards Java for more details.
Question ix -Can nosotros strength Garbage collector to run at whatever fourth dimension ?
Answer : No, yous tin non strength Garbage collection inwards Java. Though yous tin asking it past times calling Sytem.gc() or its cousin Runtime.getRuntime().gc(). It’s non guaranteed that GC volition run forthwith every bit upshot of calling these method.
Question 10 - Does Garbage collection occur inwards permanent generation infinite inwards JVM?
Answer : This is a tricky Garbage collection interview enquiry every bit many programmers are non certain whether PermGen infinite is business office of Java heap space or non together with since it maintains bird Meta information together with String pool, whether its eligible for garbage collection or not. By the way Garbage Collection does occur inwards PermGen infinite together with if PermGen infinite is sum or cross a threshold, it tin trigger Full GC. If yous await at output of GC yous volition discovery that PermGen infinite is also garbage collected. This is why right sizing of PermGen infinite is of import to avoid frequent sum GC. You tin command size of PermGen infinite past times JVM options -XX:PermGenSize together with -XX:MaxPermGenSize.
Question eleven : How to yous monitor garbage collection activities?
Answer : One of my favorite interview questions on Garbage collection, simply to check whether candidate has ever monitored GC activities or not. You tin monitor garbage collection activities either offline or real-time. You tin run tools similar JConsole together with VisualVM VM amongst its Visual GC plug-in to monitor existent fourth dimension garbage collection activities together with retentiveness condition of JVM or yous tin redirect Garbage collection output to a log file for offline analysis past times using -XlogGC=<PATH> JVM parameter. Anyway yous should e'er enable GC options similar -XX:PrintGCDetails -X:verboseGC together with -XX:PrintGCTimeStamps every bit it doesn't impact application performance much but render useful states for surgery monitoring.
Question 12: Look at below Garbage collection output together with reply next enquiry :
[GC
[ParNew: 1512K->64K(1512K), 0.0635032 secs]
15604K->13569K(600345K), 0.0636056 secs]
[Times: user=0.03 sys=0.00, real=0.06 secs]
1. Is this output of Major Collection or Minor Collection ?
2. Which immature Generation Garbage collector is used ?
3. What is size of Young Generation, Old Generation together with sum Heap Size?
4. How much retentiveness is freed from Garbage collection ?
5. How much fourth dimension is taken for Garbage collection ?
6. What is electrical current Occupancy of Young Generation ?
This Garbage collection Interview questions is completely based on GC output. Following are answers of higher upwards GC questions which volition non solely aid yous to reply these enquiry but also aid yous to empathise together with translate GC output.
Answer 1: It's Minor collection because of "GC" word, In illustration of Major collection, yous would come across "Full GC".
Answer 2: This output is of multi-threaded Young Generation Garbage collector "ParNew", which is used along amongst CMS concurrent Garbage collector.
Answer 3: [1512K] which is written inwards bracket is sum size of Young Generation, which include Eden together with 2 survivor space. 1512K on left of arrow is occupancy of Yong Generation earlier GC together with 64K is occupancy afterward GC. On the side past times side delineate of piece of employment value if bracket is sum heap size which is (600345K). If nosotros subtract size of immature generation to sum heap size nosotros tin calculate size of Old Generation. This delineate of piece of employment also shows occupancy of heap earlier together with afterward Garbage collection.
Answer 4: As answered inwards previous garbage collection interview question, minute delineate of piece of employment shows heap occupancy earlier together with afterward Garbage collection. If nosotros subtract value of right side 13569K, to value on left side 15604K, nosotros tin acquire sum retentiveness freed past times GC.
Answer 5: 0.0636056 secs on minute delineate of piece of employment denotes sum fourth dimension it took to collect dead objects during Garbage collection. It also include fourth dimension taken to GC immature generation which is shown inwards outset delineate of piece of employment (0635032 secs).
Answer 6: 64K
Here are few to a greater extent than interesting Garbage collection Interview question for your practice, I haven’t provided answers of all garbage collection interview questions. If yous know the reply than yous tin post via comments.
Question - What is departure betwixt -XX:ParallelGC together with -XX:ParallelOldGC?
Question - When produce yous ConcurrentMarkSweep Garbage collector together with Throughput GC?
Question - What is departure betwixt ConcurrentMarkSweep and G1 garbage collector?
Question - Have yous done whatever garbage collection tuning? What was your approach?
Further Learning
Java Memory Management
20 pattern pattern together with software pattern interview enquiry – Answered


Komentar
Posting Komentar