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
193
votes
5 answers

How to get VM arguments from inside of Java application?

I need to check if some option that can be passed to JVM is explicitly set or has its default value. To be more specific: I need to create one specific thread with higher native stack size than the default one, but in case the user wants to take…
okutane
  • 13,754
  • 10
  • 59
  • 67
188
votes
5 answers

Why is there no GIL in the Java Virtual Machine? Why does Python need one so bad?

I'm hoping someone can provide some insight as to what's fundamentally different about the Java Virtual Machine that allows it to implement threads nicely without the need for a Global Interpreter Lock (GIL), while Python necessitates such an evil.
AgentLiquid
  • 3,632
  • 7
  • 26
  • 30
187
votes
3 answers

What does JVM flag CMSClassUnloadingEnabled actually do?

I cannot for the life of me find a definition of what the Java VM flag CMSClassUnloadingEnabled actually does, other than some very fuzzy high-level definitions such as "gets rid of your PermGen problems" (which it doesn't, btw). I have looked on…
Rich
  • 15,602
  • 15
  • 79
  • 126
184
votes
5 answers

What's invokedynamic and how do I use it?

I keep hearing about all the new cool features that are being added to the JVM and one of those cool features is invokedynamic. I would like to know what it is and how does it make reflective programming in Java easier or better?
David K.
  • 6,153
  • 10
  • 47
  • 78
181
votes
14 answers

Getting Java version at runtime

I need to work around a Java bug in JDK 1.5 which was fixed in 1.6. I'm using the following condition: if (System.getProperty("java.version").startsWith("1.5.")) { ... } else { ... } Will this work for other JVMs? Is there a better way to…
list
  • 1,813
  • 2
  • 12
  • 4
169
votes
9 answers

Memory address of variables in Java

Please take a look at the picture below. When we create an object in java with the new keyword, we are getting a memory address from the OS. When we write out.println(objName) we can see a "special" string as output. My questions are: What is this…
uzay95
  • 16,052
  • 31
  • 116
  • 182
168
votes
5 answers

Can Java 8 code be compiled to run on Java 7 JVM?

Java 8 introduces important new language features such as lambda expressions. Are these changes in the language accompanied by such significant changes in the compiled bytecode that would prevent it from being run on a Java 7 virtual machine without…
Nicola Ambrosetti
  • 2,567
  • 3
  • 22
  • 38
167
votes
7 answers

Expiring Daemon because JVM heap space is exhausted

I just updated the Android Studio to 3.5 Beta 1 and I'm getting Expiring Daemon because JVM heap space is exhausted message while the build is running. Also, the build is taking more time to complete. Does anyone have any idea regarding this?
Rishabh Sagar
  • 3,877
  • 3
  • 15
  • 24
167
votes
12 answers

Override Java System.currentTimeMillis for testing time sensitive code

Is there a way, either in code or with JVM arguments, to override the current time, as presented via System.currentTimeMillis, other than manually changing the system clock on the host machine? A little background: We have a system that runs a…
Mike Clark
  • 11,769
  • 6
  • 39
  • 43
163
votes
1 answer

Difference between sampling and profiling in jVisualVM

VisualVM has two separate tabs for sampling and profiling. What is the difference between sampling and profiling in VisualVM?
Parag
  • 12,093
  • 16
  • 57
  • 75
158
votes
10 answers

How do I find out what keystore my JVM is using?

I need to import a certificate into my JVM keystore. I am using the following: keytool -import -alias daldap -file somecert.cer so I would need to probably change my call into something like: keytool -import -alias daldap -file somecert.cer…
Strong Like Bull
  • 11,155
  • 36
  • 98
  • 169
158
votes
27 answers

How do you crash a JVM?

I was reading a book on programming skills wherein the author asks the interviewee, "How do you crash a JVM?" I thought that you could do so by writing an infinite for-loop that would eventually use up all the memory. Anybody has any idea?
Shivasubramanian A
  • 4,346
  • 6
  • 29
  • 26
155
votes
8 answers

How to set a JVM TimeZone Properly

I am trying to run a Java program, but it is taking a default GMT timezone instead of an OS defined timezone. My JDK version is 1.5 and the OS is Windows Server Enterprise (2007) Windows has a Central timezone specified, but when I run the following…
Kushal Paudyal
  • 3,571
  • 4
  • 22
  • 30
153
votes
6 answers

Differences between "java -cp" and "java -jar"?

What is the difference between running a Java application withjava -cp CLASSPATH and java -jar JAR_FILE_PATH? Is one of them preferred to the other for running a Java application? I mean which one of these ways is more expensive for JVM (according…
Reza
  • 2,058
  • 3
  • 20
  • 33
150
votes
9 answers

Bytecode features not available in the Java language

Are there currently (Java 6) things you can do in Java bytecode that you can't do from within the Java language? I know both are Turing complete, so read "can do" as "can do significantly faster/better, or just in a different way". I'm thinking of…
Bart van Heukelom
  • 43,244
  • 59
  • 186
  • 301