This is a page from my book, Functional Programming, Simplified

A Visual Look at JVM Stacks and Frames

Given the background information of the previous lesson, let’s take a visual look at how the JVM stack and stack frames work by going back to our recursive sum function from the previous lesson.

Before the sum function is initially called, the only thing on the call stack is the application’s main method:

Then main calls sum with List(1,2,3), which I show here without the “List” to keep things simple:

This is a page from my book, Functional Programming, Simplified

JVM Stacks and Stack Frames

For functions without deep levels of recursion, there’s nothing wrong with the algorithms shown in the previous lessons. I use this simple, basic form of recursion when I know that I’m working with limited data sets. But in applications where you don’t know how much data you might be processing, it’s important that your recursive algorithms are tail-recursive, otherwise you’ll get a nasty StackOverflowError.

For instance, if you run the sum function from the previous lessons with a larger list, like this:

How to use a Stack in Scala (Stack class examples)

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 11.30, “How to Use a Stack in Scala”


You want to use a stack data structure in a Scala application.


A stack is a last-in, first-out (LIFO) data structure. In most programming languages you add elements to a stack using a push method, and take elements off the stack with pop, and Scala is no different.

Java stack and heap definitions

Summary: This article provides definitions and descriptions of the Java stack and heap.

I just read a couple of emails about the concepts of a Java stack and heap, and thinking that their descriptions weren’t exactly right, I decided to do a little research. There’s no better source than the source, so directly from Sun’s Java website, here are definitions for the Java stack and Java heap.

How to control Java heap size (memory) allocation (xmx, xms)

Java memory FAQ: How do I control the amount of memory my Java program uses (i.e., Java RAM usage)?

One of the Linux servers that I use is a little starved for memory, but I need to run a Java program on it periodically to run some utility tasks. However, every time I try to run the program I get this Java heap size error message: