The embodiment of the invention discloses a method and device for Java programs. The method comprises the following steps: judging whether a Java stack in a RAM (random access memory) meets a first preset condition or not by a Java virtual machine; if the Java stack does not meet the first preset condition, continuing to run the Java programs, and if the Java stack meets the first preset condition, copying one or a plurality of frames in the Java stack into a nonvolatile memory, moving a Java stack top pointer towards the bottom of the Java stack, and continuing to run the Java programs; judging whether a Java stack in a RAM meets a second preset condition or not by the Java virtual machine; if the Java stack does not meet the second preset condition, continuing to run the Java programs, and if the Java stack meets the first preset condition, copying one or a plurality of frames in the nonvolatile memory into the Java stack, and moving the Java stack top pointer towards the top of the Java stack. In the embodiment of the invention, the nonvolatile memory is used as the expansion and storage space of the Java stack, therefore, the occurrence of abnormal situation due to deficiency of resources can be avoided.