2

In a recent interview interviewer asked me to explain Java Memory Model. So I started explaining Heap (New Generation, Old generation etc) Stack.But he said this is in terms if Garbage Collector. I am not interested in this. Worse thing about interview was he did not give me a chance to ask a single question.

Can any one tell me what exactly that guy was looking for?

GD_Java
  • 1,359
  • 6
  • 24
  • 42
  • not a relevant question here – Piyas De Mar 19 '13 at 18:40
  • Nothing wrong with the question. It's been asked before on SO, so I don't see why this time it is not relevant. http://stackoverflow.com/questions/6005061/java-memory-model – Kakalokia Mar 19 '13 at 18:42
  • 1
    "to explain Java Memory Model"? what is the job title, chief scientist? – ZhongYu Mar 19 '13 at 18:45
  • "Can anyone tell me what exactly that guy was looking for?" He can. – Louis Wasserman Mar 19 '13 at 18:48
  • 1
    [The Java Memory Model](http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.4). – assylias Mar 19 '13 at 18:49
  • I don't see anything wrong with question. Just wanted to know what could be possible answer. – GD_Java Mar 19 '13 at 18:49
  • @zhong.j.yu The job Title was Senior Software Engg. – GD_Java Mar 19 '13 at 18:51
  • He probably wanted to hear how GC decides which objects should be removed from memory. Why? Maybe to test your knowledge about [memory leaks](http://stackoverflow.com/q/6470651/1393766). Who knows? – Pshemo Mar 19 '13 at 18:52
  • @Pshemo I explained him about GC as well like mark and sweep algo, finalize method and all but he keep saying no. – GD_Java Mar 19 '13 at 18:54
  • Well after searching a lot I came to know there are 5 memory regions in JVM (1) Class Area (2) Heap (3) Stack (4) PC Register (5) Native Method Stack I am going to read them in details. – GD_Java Mar 20 '13 at 15:23

3 Answers3

2

Most likely he was referring to the concurrency model of how and when changes to memory are visible to other threads. That commonly goes under the name of the "Java Memory Model", as the Wikipedia article illustrates.

It seems a bit silly to base the question on a piece of terminology, though.

Dolda2000
  • 25,216
  • 4
  • 51
  • 92
  • Thanks for your reply. But I believe concurrency is just a way to handle variables in memory. – GD_Java Mar 19 '13 at 18:59
  • "But"? I don't see what contradiction you are trying to point out. :) – Dolda2000 Mar 19 '13 at 19:01
  • @user1951754 "Java Memory Model" has a very specific meaning which is defined in the Java Language Specification and adresses how a Java program should behave in the presence of several threads. – assylias Mar 19 '13 at 19:02
  • @Dolda2000 what exactly I mean to say that concurrency model as you said commonly goes under the name of the Java Memory Model. But I do not think interviewer was looking for this. We all know how concurrency stuff works and it is a new feature in JDK 1.5 and memory model exists since the first release of Java. – GD_Java Mar 19 '13 at 19:10
  • Well, naturally, *a* memory model has always existed, but up until Java 1.5 it was thought to suck, so the introduction of the new memory model was a rather Big Thing. Since "Java Memory Model" is the canonical term for this, I would think that if he was not looking for the heap/GC model, he ought to have been referring to this. You say that "We all know how concurrency stuff works", but I don't think the barrier model and partial ordering of memory operations is all that common knowledge. – Dolda2000 Mar 19 '13 at 19:35
  • Well after searching a lot I came to know there are 5 memory regions in JVM (1) Class Area (2) Heap (3) Stack (4) PC Register (5) Native Method Stack I am going to read them in details. – GD_Java Mar 20 '13 at 15:21
1

I suppose this is the stuff they asked. It explains the java memory management.

http://www.oracle.com/technetwork/java/javase/memorymanagement-whitepaper-150215.pdf

emd
  • 740
  • 4
  • 12
0

Maybe he wanted you to say that the garbage collector manages the memory occupied by objects and reclaims it back when it's no longer needed.