Questions tagged [jvm]

The Java Virtual Machine (JVM) enables a set of computer software programs and data structures to use a virtual machine model for the execution of other computer programs and scripts. Use this tag for questions dealing with tools provided by a JVM or how it works in a specific scenario.

The model used by a JVM accepts a form of computer intermediate language commonly referred to as Java bytecode. This language conceptually represents the instruction set of a stack-oriented, capability architecture.

A JVM can also execute bytecode compiled from programming languages other than Java. For example, Ada source code can be compiled to execute on a JVM. JVMs can also be released by other companies besides Oracle (the developer of Java), but JVMs using the "Java" trademark may be developed by other companies as long as they adhere to the JVM specification SE 7 published by Oracle and to related contractual obligations.

List of Java and JVM Specifications 6-11

See also "Understanding Oracle Java SE Licensing".

Java was conceived with the concept of WORA - write once, run anywhere. This is done using the Java Virtual Machine (JVM).

The JVM is the environment in which Java programs execute. It is the software that is implemented on non-virtual hardware and on standard operating systems.

JVM is a crucial component of the Java platform, and because JVMs are available for many hardware and software platforms, can be both middleware and a platform in its own right, hence the trademark write once, run anywhere. The use of the same bytecode for all platforms allows Java to be described as "compile once, run anywhere", as opposed to "write once, compile anywhere", which describes cross-platform compiled languages. A JVM also enables such features as automated exception handling, which provides "root-cause" debugging information for every software error (exception), independent of the source code.

A JVM is distributed along with a set of standard class libraries that implement the Java Application Programming Interface (API). Appropriate APIs bundled together form the Java Runtime Environment ().

Online Resources

  1. JVM Wikipedia
  2. A nice online book on the internals of JVM: Inside JVM by Bill Venners
  3. Java HotSpot VM Options
  4. IBM JVM Documentation
  5. OpenJDK Wiki
  6. Oracle HotSpot Wiki - Has information about JVM internals.

What questions should have this tag?

  1. Questions to know how a JVM works in a specific scenario
  2. Questions which deal with tools provided with a JVM
12159 questions
111
votes
7 answers

Why does this method print 4?

I was wondering what happens when you try to catch an StackOverflowError and came up with the following method: class RandomNumberGenerator { static int cnt = 0; public static void main(String[] args) { try { …
flrnb
  • 836
  • 1
  • 7
  • 13
110
votes
6 answers

Where does Java's String constant pool live, the heap or the stack?

I know the concept of a constants pool and the String constant pool used by JVMs to handle String literals. But I don't know which type of memory is used by the JVM to store String constant literals. The stack or the heap? Since its a literal which…
Rengasami Ramanujam
  • 1,858
  • 4
  • 19
  • 29
109
votes
4 answers

Java: What is the difference between and ?

I am unable to understand the following text... Does it mean that is for empty constructors? Why is important to have two different versions? https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-2.html 2.9. Special Methods At the level…
Jayan
  • 18,003
  • 15
  • 89
  • 143
109
votes
8 answers

How to set JVM parameters for Junit Unit Tests?

I have some Junit unit tests that require a large amount of heap-space to run - i.e. 1G. (They test memory-intensive functionality for a webstart app that will only run with sufficient heap-space, and will be run internally on Win 7 64-bit machines…
amaidment
  • 6,942
  • 5
  • 52
  • 88
107
votes
3 answers

Why is the JVM stack-based and the Dalvik VM register-based?

I'm curious, why did Sun decide to make the JVM stack-based and Google decide to make the DalvikVM register-based? I suppose the JVM can't really assume that a certain number of registers are available on the target platform, since it is supposed to…
aioobe
  • 413,195
  • 112
  • 811
  • 826
104
votes
6 answers

How do I provide JVM arguments to VisualVM?

I'm using VisualVM from JDK 1.6.0_26 to profile a Java webapp running under Tomcat, but VisualVM often tells me that it doesn't have enough memory to take a snapshot, and to use the -Xmx switch to provide more memory to Netbeans. The problem is, I'm…
Mike Partridge
  • 5,128
  • 8
  • 35
  • 47
104
votes
16 answers

“Error occurred during initialization of VM; Could not reserve enough space for object heap” using -Xmx3G

First of all, I have a box with 8gb of ram, so I doubt total memory is the issue. This application is running fine on machines with 6gb or less. I am trying to reserve 3GB of space using -Xmx3G under "VM Arguments" in Run Configurations in…
user1212731
  • 1,041
  • 2
  • 7
  • 3
104
votes
8 answers

Is there one JVM per Java application?

Is the same JVM used by all Java applications running or, does 'one JVM per Java application' apply? (say the applications are IntelliJ IDEA, a server and NetBeans for example) Further, is there any connection between JVMs assigned and processes…
nadh
  • 1,211
  • 3
  • 11
  • 6
104
votes
9 answers

How to lock compiled Java classes to prevent decompilation?

How do I lock compiled Java classes to prevent decompilation? I know this must be very well discussed topic on the Internet, but I could not come to any conclusion after referring them. Many people do suggest obfuscator, but they just do renaming of…
jatanp
  • 3,982
  • 4
  • 40
  • 46
103
votes
20 answers

Font is not available to the JVM with Jasper Reports

I'm trying to generate report with DynamicJasper, but I'm getting the following error: net.sf.jasperreports.engine.util.JRFontNotFoundException: Font 'Arial' is not available to the JVM. msttcorefonts is…
Andrew
  • 2,663
  • 6
  • 28
  • 50
102
votes
8 answers

Android Gradle Could not reserve enough space for object heap

I've installed Android Studio 1.1.0. I haven't done anything yet like start new Android application or import anything. Somehow it is trying to build something and it throws sync error. Error:Unable to start the daemon process. This problem might…
GummDev
  • 1,160
  • 2
  • 8
  • 13
101
votes
5 answers

Debug a java application without starting the JVM with debug arguments

Normally to attach a debuger to a running jvm you would need start the jvm with arguments such as the following: > java -Xdebug -Xrunjdwp:transport=dt_socket,address=1000,server=y,suspend=n Now if I want to debug a process that wasn't started in…
hhafez
  • 38,949
  • 39
  • 113
  • 143
100
votes
9 answers

How to approach creating a JVM programming language?

I have created a compiler in C (using Lex & Bison) for a dynamic typed programming language that supports loops, functions declarations inside functions, recursive calls, etc. I also created a virtual machine that runs the intermediate code created…
functional
100
votes
2 answers

VisualVM - Thread States

Can someone please explain me the difference between Sleeping, Wait, Park, and Monitor thread states in VisualVM. This is what I have found: Running: thread is still running. Sleeping: thread is sleeping (method yield() was called on the thread…
Ali Shah Ahmed
  • 3,263
  • 3
  • 24
  • 22
99
votes
5 answers

Running jmap getting Unable to open socket file

I had to run jmap in order to take heap dump of my process. but jvm returned: Unable to open socket file: target process not responding or HotSpot VM not loaded The -F option can be used when the target process is not responding So I used the…
rayman
  • 20,786
  • 45
  • 148
  • 246