Core Java - Interview Questions and Answers for 'Memory' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Core Java - Interview Questions and Answers for 'Memory' - 52 question(s) found - Order By Rating

next 30
 Q1. Can we do a thread specific heap allocation ?Memory Management
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     memory management  heap memory   heap allocation      expert


 Q2. Do threads have a distinct heap ?Memory Management
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     memory management  heap memory      expert


 Q3. Should we do anything to avoid memory leaks in Java ?Core Java
Ans. Java has a intrinsic way of checking leaks and reclaiming memory called garbage collection. Moreover Java doesn't support pointer arithmetics , so there is very low comparative chance of memory leaks, compared to C,C++

Though there may be tools that may audit code to make sure that we are not leaving much for the garbage collection to work but I have never heard anyone doing anything for memory leaks in Java.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     memory leak in java


 Q4. Explain memory leaks and how to prevent them.
 This question was recently asked at 'Polaris'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     memory leak     Asked in 1 Companies


 Q5. How many heaps will be there with 3 threads ?Core Java
Ans. All threads share a common heap.

Each thread has a private stack, which it can quickly add and remove items from. This makes stack based memory fast, but if you use too much stack memory, as occurs in infinite recursion, you will get a stack overflow.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     memory management  heap memory     Asked in 1 Companies


 Q6. Which memory segment holds the byte code ?Core Java
Ans. Code Segment

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Memory Management  Code Memory Segment  Code Segment Memory  Code Segment


 Q7. Which memory segment is cleaned by Garbage Collection - stack or heap ?Core Java
Ans. Heap as objects are stored ink heap.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     memory management   stack  heap  garbage collection


 Q8. What are different methods to get the permanent gen space of running application?Core Java
 This question was recently asked at 'Apcolite'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     jvm  memory management     Asked in 1 Companies      advanced


 Q9. How do you check memory leak in Java?Core Java
Ans. You need to capture heap dump when it's in the healthy state. Start your application. Let it take real traffic for 10 minutes. At this point, capture heap dump. Heap Dump is basically the snapshot of your memory. It contains all objects that are residing in the memory, values stored in those objects, inbound

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     memory leaks  heap dump     Asked in 1 Companies      intermediate


 Q10. In which memory segment - heap or stack, the following stored by JVM

1. static members
2. objects
3. object references
4. local or method variables

Core Java
Ans. static members are stored in method area of heap

objects are stored on heap

object references are stored on stack

local or method variables are stored on stack

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     jvm  memory management  stack  heap


 Q11. Java doesn't provide exclusive access to memory like C/C++ and other lower level languages ? What are the advantanges and disadvantages ?Core Java
Ans. Yes, doesn't provide exclusive access as we cannot allocate and deallocate memory exclusively as Java internally manages it. The advantage of this is that it relieves the coder for such tasks and helps protect from many bugs that may get introduced with imperfect coding. Moreover as java garbage collector collects all unclaimed memory or objects, it helps the application from memory leaks.

On the flip side , as coder doesn't have extensive excess to memory , it is upto java to decide on the state for programming construct and data storage and hence may introduce some security risks. For example - Java keeps string literals in string pool and there is no exclusive way to remove it and hence may stay and sensitive data in string pool may introduce security issues. Moreover when we overwrite a value or object for a variable / reference, it is upto java to purge those values and hence it may stay in memory for a while till java decide that it is no longer referenced and hence should be removed and hence makes it vulnerable for inappropriate access.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     disadvantages of garbage collection  advantages and disadvantages of java memory management  java for security applications  java with sensitive data  memory management


 Q12. What is the purpose of String Pool ? Don't you think it's a performance overhead to have unnecessary check for string in string pool ?Core Java
Ans. String Pool makes Java more memory efficient by providing a reusable place for string literals. It might be a little performance inconvenience but results in good amount memory saving.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     string pool  memory management      Intermediate


 Q13. How is garbage collection in Java 8 different from Java 7 ? Core Java
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     memory management  garbage collection


 Q14. What is JVM ?Core Java
Ans. JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed.JVMs are available for many hardware and software platforms (i.e. JVM is platform dependent).Runtime Instance Whenever you write java command on the command prompt to run the java class, an instance of JVM is createdThe JVM performs following operation:Loads codeVerifies codeExecutes codeProvides runtime environment

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     memory management  jvm     Asked in 3 Companies      basic        frequent


 Q15. Why do we need Garbage collection ?Core Java
Ans. Garbage collection mechanism frees up the memory that is no longer needed. In languages like C / C++ the deallocation needs to be done explicitly by the programmer and hence any leniency may result in memory leak. Garbage collection in java ensures that all unused memory is reclaimed and hence there are no memory leaks.Moreover it relieves the programmer from the hassle of carefully releasing all memory.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Garbage Collection  memory management     Asked in 2 Companies


 Q16. Difference between Virtual Memory and Demand Paging?Operating System
 This question was recently asked at 'Veritas'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Virtual Memory vs Demand Paging     Asked in 1 Companies


 Q17. What is memory leak ? How Java helps countering memory leaks compared to C++ ?Core Java
Ans. Memory Leak is a situation wherein we have a reserved memory location but the program has lost its reference and hence has no way to access it.

Java doesn't have concept of Pointers, Moreover Java has concept of Garbage collection that frees up space in heap that has lost its references.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     memory leak  garbage collection      intermediate        frequent


 Q18. Which memory segment holds String Pool in Java ?Core Java
Ans. String Pool resides in runtime constant Pool which is a part of Heap memory segment.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     string pool  memory management      Expert        rare


 Q19. Which type of memory is cleaned / recovered by garbage collection - stack or heap ?Core Java
Ans. Heap memory.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     memory management  stack  heap  garbage collection     Asked in 2 Companies


 Q20. Why two types of memory - stack and heap are required by Java ?Core Java
Ans. Because of the life cycle requirement for different type of values in java.

variables initialized and used in functions needs to be destructed with the execution of function and hence kept in stack. Same is applicable for the object references initialized within the method. If objects would have been created in stack, they wouldnt have been passed around across methods and hence they are created on heap.

So anything that is required beyond the scope of a method or function is kept on heap which is usually garbage collected by Java.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     memory management  heap  stack

Try 1 Question(s) Test


Frequently asked in Alibaba (Based on 2 feedback)
 Q21. What is the best Memory setting for JVM ?Core Java
Ans. In Java JVM memory settings is done by use the arguments -Xms -Xmx. Use M or G after the numbers for indicating Megs and Gigs of bytes respectively. -Xms indicates the minimum and -Xmx the maximum.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     jvm  memory management  jvm best memory setting     Asked in 1 Companies      intermediate


 Q22. How can we find the memory usage of JVM from Java code?Core Java
Ans. Using Runtime object.

Runtime runtime = Runtime.getRuntime();

runtime.totalMemory();
runtime.freeMemory();

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     jvm  memory management        rare


 Q23. When are static variables loaded in memory ?Core Java
Ans. They are loaded at runtime when the respective Class is loaded.

  Sample Code for static variable

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   static   static variable   memory      intermediate


Frequently asked in Infosys India
  Q24. What is a String Pool ?Core Java
Ans. String pool (String intern pool) is a special storage area in Java heap. When a string is created and if the string already exists in the pool, the reference of the existing string will be returned, instead of creating a new object and returning its reference.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   string   string class   string pool   heap memory     Asked in 31 Companies      intermediate        frequent

Try 2 Question(s) Test


  Q25. Which are the different segments of memory ?Core Java
Ans. 1. Stack Segment - Contains primitives, Class / Interface names and references.

2. Heap Segment - Contains all created objects in runtime, objects only plus their object attributes (instance variables), Static variables are also stored in heap.

3. Code Segment - The segment where the actual compiled Java bytecodes resides when loaded

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   memory   memory management   stack memory   heap memory   code segment memory   advanced     Asked in 9 Companies      expert        frequent

Try 6 Question(s) Test


 Q26. Which memory segment loads the java code ?Core Java
Ans. Code segment.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     memory   java   memory management   code segment  code segment memory      expert        rare


 Q27. Does garbage collection guarantee that a program will not run out of memory?Core Java
Ans. Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   garbage collection   java memory management   advanced     Asked in 2 Companies

Try 1 Question(s) Test


 Q28. Describe what happens when an object is created in Java ?Core Java
Ans. 1. Memory is allocated from heap to hold all instance variables and implementation-specific data of the object and its superclasses. Implemenation-specific data includes pointers to class and method data.
2. The instance variables of the objects are initialized to their default values.
3. The constructor for the most derived class is invoked. The first thing a constructor does is call the constructor for its superclasses. This process continues until the constructor for java.lang.Object is called,as java.lang.Object is the base class for all objects in java.
4. Before the body of the constructor is executed, all instance variable initializers and initialization blocks are executed. Then the body of the constructor is executed. Thus, the constructor for the base class completes first and constructor for the most derived class completes last.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   memory management   object creation   advanced   ebay


Advanced level question usually asked in High end product companies. Have been asked in Google and Amazon (Based on 1 Feedback)
  Q29. Describe, in general, how java's garbage collector works ?Core Java
Ans. The Java runtime environment deletes objects when it determines that they are no longer being used. This process is known as garbage collection. The Java runtime environment supports a garbage collector that periodically frees the memory used by objects that are no longer needed. The Java garbage collector is a mark-sweep garbage collector that scans Java dynamic memory areas for objects, marking those that are referenced. After all possible paths to objects are investigated, those objects that are not marked (i.e. are not referenced) are known to be garbage and are collected.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   garbage collection   java memory management   advanced     Asked in 21 Companies      intermediate        frequent

Try 4 Question(s) Test


 Q30. Different types of memory used by JVM ?Core Java
Ans. Class , Heap , Stack , Register , Native Method Stack.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   jvm   memory management   memory   advanced   architecture   technical architect     Asked in 1 Companies      intermediate        frequent

Try 5 Question(s) Test


next 30

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: