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. |
|
| ||||
Core Java - Interview Questions and Answers for 'Memory management' - 42 question(s) found - Order By Newest | ||||
| ||||
Ans. There are total six ways 1. literals When we create a String using double quotes, JVM looks in the String pool to find if any other String is stored with same value. If found, it just returns the reference to that String object else it creates a new String object with given value and stores it in the String pool. 2. new keyword When we use new operator, JVM creates the String object but dont store it into the String Pool. We can use intern() method to store the String object into String pool or return the reference if there is already a String with equal value present in the pool. 3. string buffer 4. string builder 5. System.out.println 6. char to string | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   string class   string   jvm   memory management   string pool Asked in 5 Companies basic   frequent | ||||
Try 3 Question(s) Test | ||||
| ||||
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 | ||||
| ||||
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 | ||||
Advanced level question usually asked in High end product companies. Have been asked in Google and Amazon (Based on 1 Feedback) | ||||
| ||||
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 | ||||
| ||||
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. Recently asked in few Indian service companies ( Based on 3 inputs ) | ||||
| ||||
Ans. Bootstrap - Loads JDK internal classes, java.* packages. Extensions - Loads jar files from JDK extensions directory - usually lib/ext directory of the JRE System - Loads classes from system classpath. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   jvm   memory management   class loaders   bootstrap   extensions   system  classloaders   advanced   technical lead   technical architect Asked in 7 Companies | ||||
| ||||
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 | ||||
| ||||
Ans. Finalize is used by Java for Garbage collection. It should not be done as we should leave the Garbage Collection to Java itself. | ||||
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   finalize | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. Garbage Collector wont remove a strong reference. A soft reference will only get removed if memory is low. A weak reference will get removed on the next garbage collection cycle. A phantom reference will be finalized but the memory will not be reclaimed. Can be useful when you want to be notified that an object is about to be collected. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   memory management   jvm   garbage collections   references   strong reference   soft reference   weak reference   phantom reference   architecture Asked in 2 Companies | ||||
| ||||
Ans. instance variables and objects are stored on heap and the references are stored on stack whereas static variables are stored in the method area of heap. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   jvm   memory management   memory   heap   stack | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. Yes, We can call garbage collector directly but it doesn't guarantees that the gc will start executing immediately. This gc( ) method appears in both Runtime and System classes of java.lang package. | ||||
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   jvm   gc   yes no Asked in 4 Companies expert | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. Function call allocates a stackframe in stack. Every stackframe will use some memory to store local variables, parameters and to remember return address. Without terminating condition stackframes will keep consuming memory from stack and eventually program will result in stackoverflow error. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  recursion   break statement  break  stackoverflow exception  stackoverflow  memory management  memory  exceptions | ||||
| ||||
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 | ||||
| ||||
Ans. Part of JVM which is used to load classes and interfaces. Bootstrap , Extension and System are the class loaders used by JVM. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   class loaders  classloaders   jvm   java memory management   advanced Asked in 3 Companies | ||||
| ||||
Ans. Local variables are stored in stack whereas object variables are stored in heap. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   jvm   memory management   stack memory   heap memory expert | ||||
| ||||
Ans. member variable are loaded into heap, so they are initialized with default values when an instance of a class is created. In case of local variables, they are stored in stack until they are being used. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   jvm   memory management   variables   stack memory   heap memory   default values expert | ||||
| ||||
Ans. Class loaders are hierarchical. The very first class is specially loaded with the help of static main() method declared in your class. All the subsequently loaded classes are loaded by the classes, which are already loaded and running. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   jvm   memory management   class loaders  classloaders Asked in 1 Companies | ||||
| ||||
Ans. static loading - Classes are statically loaded with Java new operator. dynamic class loading - Dynamic loading is a technique for programmatically invoking the functions of a class loader at run time. Class.forName (Test className); | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   jvm   memory management   class loaders  classloaders   static class loading   static loading   dynamic class loading   dynamic loading Asked in 2 Companies expert   frequent | ||||
| ||||
Ans. The memory pool containing all the reflective data of the java virtual machine itself, such as class and method objects. With Java VMs that use class data sharing, this generation is divided into read-only and read-write areas. The Permanent generation contains metadata required by the JVM to describe the classes and methods used in the application. The permanent generation is populated by the JVM at runtime based on classes in use by the application. In addition, Java SE library classes and methods may be stored here. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   jvm   memory management   permgen   permanent generation   advanced   architecture Asked in 9 Companies expert | ||||
| ||||
Ans. The Permanent Generation (PermGen) space has completely been removed and is kind of replaced by a new space called Metaspace. The consequences of the PermGen removal is that obviously the PermSize and MaxPermSize JVM arguments are ignored and you will never get a java.lang.OutOfMemoryError: PermGen error. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   jvm   memory management   permgen   permanent generation   metaspace   advanced   architecture expert | ||||
| ||||
Ans. substring method would build a new String object keeping a reference to the whole char array, to avoid copying it. Hence you can inadvertently keep a reference to a very big character array with just a one character string. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   string class   string   substring   memory leaks   jvm   memory management   advanced   architecture   technical architect   technical lead expert | ||||
| ||||
Ans. Stack memory areas is used to hold method and local variables while objects are always allocated memory in the heap. The heap memory is shared between multiple threads whereas Stack memory isn't. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   memory management   stack memory   heap memory   difference between   ebay Asked in 2 Companies intermediate   frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
Ans. Pointers are vulnerable and slight carelessness in their use may result in memory problems and hence Java intrinsically manage their use. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   jvm   memory management   pointers intermediate | ||||
| ||||
Ans. JProbe, OptimizeIt | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   tools   jvm   memory management   memory leaks   jprobe   optimeit   architecture   technical lead | ||||
| ||||
Ans. http://www.buggybread.com/2015/01/java-memory-classes-and-interfaces.html | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   memory management | ||||
| ||||
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 | ||||
Frequently asked in Alibaba (Based on 2 feedback) | ||||
| ||||
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 | ||||