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. |
|
| |||||||||||
Interview Questions and Answers for 'Stack' - 18 question(s) found - Order By Rating | |||||||||||
| |||||||||||
This question was recently asked at 'IBM India'.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  queue  stack Asked in 1 Companies | |||||||||||
| |||||||||||
This question was recently asked at 'HCL Technologies'.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  stack Asked in 1 Companies | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
Ans. pop method pulls the top element from the stack and then move the top to the next element whereas peek only get the top element but doesn't move the top. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  stack | |||||||||||
| |||||||||||
Ans. Create one extra field called MAX O(1) when you an element to the stack check these two condition 1. Stack is empty, then MAX = element 2. Stack is not empty then check if the element is greater than MAX then MAX = element when getMax fuction is called, then return MAX | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  complexity  stack  data structure Asked in 1 Companies | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
Ans. Stack is based on Last in First out (LIFO) principle while a queue is based on FIFO (First In First Out) principle. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  data structure  stack vs queue  stack  queue Basic | |||||||||||
| |||||||||||
This question was recently asked at 'Amazon'.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  matching bracket  stack Asked in 1 Companies | |||||||||||
| |||||||||||
Ans. It would result in endless function calls and hence eventually would result in stackoverflow exception. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  recursion  stackoverflowexception Basic   frequent | |||||||||||
| |||||||||||
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. 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 | |||||||||||
Very frequently asked. Among first few questions in almost all interviews. Among Top 5 frequently asked questions. Frequently asked in Indian service companies (HCL,TCS,Infosys,Capgemini etc based on multiple feedback ) and Epam Systems | |||||||||||
| |||||||||||
Ans. "equals" is the method of object class which is supposed to be overridden to check object equality, whereas "==" operator evaluate to see if the object handlers on the left and right are pointing to the same object in memory. x.equals(y) means the references x and y are holding objects that are equal. x==y means that the references x and y have same object. Sample code: String x = new String("str"); String y = new String("str"); System.out.println(x == y); // prints false System.out.println(x.equals(y)); // prints true | |||||||||||
Sample Code for equals | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  java   string comparison   string   object class   ==   equals   object equality  operator   == vs equals   equals vs == Asked in 294 Companies basic   frequent | |||||||||||
Try 6 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. 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. 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. 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. 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 | |||||||||||
| |||||||||||