Is Java Virtual Machine starts before user logged in or it's start after boot windows.?
Every time you start a java program, a new instance of the Java Virtual machine is started. It stops when the program ends.
In the case of a java applet, the browser will invoke the virtual machine itself.
When a Java application starts, a runtime jvm instance is born. When the application completes, the instance dies. If you start four Java applications at the same time, on the same computer, using the same concrete implementation, you'll get four Java virtual machine instances. Each Java application runs inside its own Java virtual machine.
JVM starts when it's required, in other words as soon as you need an environment to run your Java code, meaning when you start your application.
Try googling for "when JVM starts", it should yield a lot of results which address this question (in Java and also for other languages using JVM). For example this page. Look for "The lifetime of a Java Virtual Machine".
In Windows "Java Virtual Machine" is simply "java.exe" executable.
It will start whey you will start it - manually, by putting it to autorun or by creating Windows Service.
It is the same as any other background application.
Related
From Java In a Nutshell
jps provides a list of all active JVM processes on the local machine (or a remote machine, if a suitable instance of jstatd is running on the remote side).
What does "JVM processes" here mean,
processes of the underlying OS which run JVM exactly, or
processes that are supported by Java via Process, ProcessBuilder and Runtime.exec()...
Thanks.
A running Java Virtual Machine (JVM) instance is materialized by a native process launched by an OS while a Process class instance is a native process launched by a running JVM.
As each Java Virtual Machine is associated to a specific native process, instead of saying a process that runs a JVM, we could so shortcut it by a JVM process.
JVM stands for Java Virtual Machine.
In plain English, a virtual machine (VM) is any piece of software that simulates a real machine. There are two kinds of VMs:
system VM
process VM
A system virtual machine provides the functionality of a real computer. A process virtual machines allows to execute programs in one specific programming language. The advantage of a process VM (sometimes also called managed runtime environment) is that it provides the same environment across different platforms.
JVM is the process virtual machine for Java.
Since of the main design goals of Java is portability, the Java language code gets compiled to an intermediate representation called Java bytecode that can be executed on a JVM.
So, basically every time you run Java code you start an own JVM process.
Image source: Introduction to Computer Science using Java
There are exceptions to that, namely special-purpose processors that can interpret Java bytecode: with such processors Java is executed directly on the hardware without using a virtual machine. An example are ARM processors endowed with the Jazelle DBX direct bytecode execution.
I am a java beginner. i just read a line "
JVM (Java Virtual Machine) is an abstract machine." can anyone please help me to understand term abstract machine. what is abstract machine.
JVM = JAVA VIRTUAL MACHINE:- The word virtual itself indicates that it doesn't exists PHYSICALLY.
Elaborated here:
Abstract means HIDDEN.
When assembly programs runs on a computer, it is executed in the system runtime environment:
Properties
Platform dependent (if compiled for windows, a program will run only in windows not in Linux/UNIX etc.)
Not portable (same as above)
Systems runtime (in user's PC mainly under OS's control)
When Java Program runs into a computer, it is executed in another virtual machine (JVM) for which, the runtime environment is provided by JRE (JAVA Runtime Environment), it is installed automatically when you install JDK (Java Development Kit).
Without JRE, it is impossible to run Java Programs (Update: You can bundle your custom JRE with your code, in that case no need to install JDK or JRE separately but only in JDK9 & above)
This JVM itself runs in the system runtime (in user's PC/OS) but when Java program runs it is loaded into this running JVM.
For more practical AND visual experience:(for Windows only)
Open Task Manager
Go to Processes Tab
Find Java(TM) Platform SE Binary (This is JVM) - Java Instance
And now run a java program and write some code to delay the execution, like multi-threading with wait and notify (you can find such programs on google), due to this running program your Java Instance will show a little high memory and disk usage (not much high but slightly higher than that when no program was running in JRE/JVM). These processes you see in Task Manager, are running in System Runtime, and your Java program will not be listed there.
Instead it will be running inside this already running JRE.
This is the reason why JVM is ABSTRACT.
Now, do a little cross check and prove it..
Run 2-3 java programs, either keep them in longer waiting or just write Input Scanner and don't provide input, program will continue to run in blocking state so that we can see them later.
Once gain, confirm that only one instance of JVM/Java is running in task manager (Depends on how many JREs you have installed, sometimes IDEs can also create one instance, so better close it first for clear observation)
Now, where are those 2-3 Java Programs running?? Open VisualVM (it's under the same package/folder where your java executable resides)..
In this VisualVM, you can clearly see that, all your RUNNING Java Programs are listed.
Now, open side by side windows... Task Manager, VisualVM and one of your Running Code's Console.
Verify,
in Task manager - 1 instance of Java Binary.
in VisualVM - 3 different instances of your programs (if you run 3 java porgram)
Now, provide input in one of your code so that blocking state goes away and program terminates successfully.
Now verify,
in Task Manager - still 1 instance of Java Binary.
in VisualVM - 2 instances, because 1 code terminated/finished.
So, all your Java programs run under a Virtual Machine, a machine that is hidden, physically not available, abstract.
An abstract machine is a machine that does not have a physical existence.
Abstractness
A bicycle has a physical existence. I can touch it. It is not abstract.
A computer chip has a physical existence. I can touch it. It is not abstract.
A JVM is an executing program ... and has no physical existence. I cannot touch it. It is abstract.
Machine-ness:
A bicycle is a machine for transporting people.
A computer chip is a machine for executing programs that are coded in the instruction set of the chip; e.g. Intel x86 machine code.
A JVM is also a machine for executing programs that are coded in the instruction set of all JVMs; i.e. Java bytecodes.
Abstract machine means all of java application run in JVM and JVM runs in different platform as Window, Linux, Mac ...
JVM is interface to java application can run all platform
It is a bit philosophical question. When java application is compiled, the compiler produces its own "assembly" code that can not run directly on a hardware, it needs JVM. So, JVM creates an environment for java code similar to that of a machine. In other words from java perspective it is a machine, but in reality is a program that sits on top of a computer's operating system.
It means not real machine, however, it acts like a machine. Not any machine but as a machine called Central Processing Unit(CPU).
You could understand this like, whenever you write java program, you are writing instructions for a machine, but this machine is abstract, which is called Java Virtual Machine(JVM).
For each Operating system(OS) there is a Virtual Machine so that you do not have to write different versions of your java program to different OS.The JVM that you have in your JDK will handle the translation to each OS.
Your java program passes these steps to be understood by the underlying OS.
.java (Source file) gets compiled by compiler and becomes .class(class file) and this will be passed to JVM to be interpreted to machine language.
Class file is the one that has instructions for JVM
I want to start a Windows program on virtual machine from Linux.
Are there opportunities to start a program directly on VM from the outside.
I tried WINE to emulate this program, but it does not work.
One idea I have, to implement WebService on the virtual machine and call this from Linux.
The web service would then call the program under Windows and play back the result.
Has anyone experience or better ideas?
Perhaps install freeSSHd on the Windows box, generate some public/private keys between your two servers, connect through to Windows and use use the cmd runas command to start your program/service.
By reading this article, I know that each java application will run in a specific Java Virtual Machine Instance. So if I execute the following commands("Java -jar test1.jar","Java -jar test2.jar", I will get two processes in the system. And If each command used the default heap size, for example, 256M. The total memory cost is 512M, is that right?
Also I have other questions:
Is the Java virtual Machine a daemon process, start up with the system?
When I execute "java -jar test1.jar", it will create an instance of Java Virtual Machine, then execute the main function. Does it mean every running java application is a sub thread or process of Java Virtual Machine?
Is each running java application individual, other application can not get variable, method, constant, etc, from this running java application?
If one running java application is crashed, will it affect other running java application?
PS: I googled and got lots of different answers, I was totally confused. Anyone who can help me on this kind of questions or even more depth of Java virtual Machine. For example, How it works.
The JVM is a standard process, just like any other. As such there's no implicit communication or state sharing between the two. Each will have their own heap, threads etc. If you kill one it won't affect the other.
What will get shared are the code pages of the JVM itself. The kernel is intelligent enough to identify the same binary (any binary -not just the JVM) running twice and reuse the image. This only applies to the actual binary code - not its state. See here for more info re. Linux.
The JVM isn't a daemon process, but could be started upon system startup as a Windows service or Unix/Linux process (via /etc/init.d scripts). This is how you'd (say) run a web service written in Java when a machine is booted up.
1) No, but there a ways to launch java applications as services with wrappers (Google for "Java service").
2) Yes.
3) You can use communication between processes (v.g. HTTP). But there are no shortcuts due to all processes being run in JVM.
4) No
For the OS, JVM like an user application. Each JVM Instance is individual.
No. JVM is normal process as others.But you can run it as deamon process.
Yes. Java application run on JVM just like you application on OS.
Yes. Each JVM thread is individual, but they can communication whith other JVMs through network,RMI...
It depends. Normally they are individual, but if a JVM crash cause the OS crash, other JVMs will be effected.
What does it mean that Java applet runs in web browser? Does it share the same address space as browser? Isn't it created as single process?
Since Java SE 6u10:
The new way of executing applets has architectural similarities to Java Web Start technology, but tighter browser integration. Applets no longer execute in a Java Virtual Machine (JVM) inside the web browser. Instead, a separate JVM machine process is launched to execute applets. By default, only one JVM machine is launched, but you have the opportunity to launch more than one JVM machine, and you get support per-applet command-line arguments, so you can affect heap size or other requests.
Most modern browsers support plugins, for instance through the NPAPI.
This allows the Java runtime to run inside of the browser process, as a plugin, executing the Java applet.
Whether or not it runs in the same process or not is up to the browser itself; Chrome, for instance, runs every plugin in a separate process, while other browsers only use one process.