stack : Java Glossary


A stack is a sort of LIFO (Last In First Out) queue. Stacks behave like the stacking trays at a cafeteria. The JVM (Java Virtual Machine) uses a hidden stack to keep track of which method called which method and with what parameters. Every thread has its own private stack of about one megabyte. There is no Collection called Stack, but is fairly easy to write one. Adding to a stack is called pushing and retrieving the top element is called popping. Discarding the top element is called dropping. Duplicating the top element is called duping.

In Forth and PostScript the stacks are explicit. In Java they are hidden, except for printStackTrace.

Local variables are often called stack variables because they are stored on the stack. In Java, the stack contains the local variables for each running method is the thread and the places to return to in the calling program for each level of call. If you call too many methods without returning (usually by using recursion) you will generate a StackOverFlowError.

This page is posted
on the web at:

Optional Replicator mirror
on local hard disk J:

Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

Your face IP:[]
You are visitor number