1

I have a .exe file in my system. that file was developed in java language

i have newly installed OS Win XP or any. and i don't have install java software in my system.then the file executed or not in my system ?

if executed How ? and where is the JVM is find out in system ?

if not executed Why we are saying java is platform indepennt ?

Durgaprasad
  • 157
  • 2
  • 6
  • 19
  • Does WinXP come with an older JVM? Is the EXE actually still Java byte code or has it been converted to that platform's native executable in this case? (Also, running old JVMs on WinXP is probably a *guaranteed* way to have your computer compromised.) – David May 11 '14 at 13:27
  • possible duplicate of [Compiling a java program into an exe](http://stackoverflow.com/questions/2011664/compiling-a-java-program-into-an-exe) – Basilevs May 11 '14 at 13:56
  • @Basilevs it is not a duplicate. That question asks how to create an exe for your jar. This question is how this application which is distributed in form of exe is *built using Java* runs without a JVM. – Luiggi Mendoza May 11 '14 at 13:58
  • @LuiggiMendoza and running without preconfigured JVM is explained there. UPDATED – Basilevs May 11 '14 at 13:59
  • @Basilevs I cannot find any part in those answers where it says that Java applications cannot run without a JVM. – Luiggi Mendoza May 11 '14 at 13:59
  • QUOTE: Package your Java application as a jar, and Executor will turn the jar into a Windows exe file, indistinguishable from a native application. Simply double-clicking the exe file will invoke the Java Runtime Environment and launch your application. – Basilevs May 11 '14 at 14:01
  • @Basilevs and which part of that sentence says *if no JVM, the application won't run*? – Luiggi Mendoza May 11 '14 at 14:01
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/52463/discussion-between-basilevs-and-luiggi-mendoza) – Basilevs May 11 '14 at 14:02
  • For voters to close this as unclear: it has **two** answers and one of them accepted. The fact the question may seem unclear for you doesn't mean is unclear for everyone. – Luiggi Mendoza May 11 '14 at 14:12
  • I voted for duplication question was clear to me. (After chat discussion it became quite unclear though :) – Basilevs May 11 '14 at 14:17
  • May i know the reason to Down vote my Question ? – Durgaprasad May 14 '14 at 09:54

2 Answers2

3

an .exe file is not a java file. It's a Windows binary executable. You can convert a java executable(on a system with java installed) into a binary executable. This file can be executed without a JVM (but is no longer platform independend). By converting a .jar file into a .exe file the parts of the JVM are compiled into the new file so the program can be run as a standalone. I think this is what was done here.

Simulant
  • 19,190
  • 8
  • 63
  • 98
1

Java by default doesn't generate any executable file. It generates jar packages that are platform independent. The jar can be executed through the Java Virtual Machine (JVM), which is java.exe in Windows. This is the main software to execute Java applications. If you want/need to execute any Java application in your PC or device, it must have a JVM (distributed under the name Java Runtime Environment or JRE) installed and configured. If you want to go further and develop your own applications using Java, you will need to also install a Java Development Kit (JDK), note that every JDK already ships a JRE installation.

The fact your application has an additional exe file for Windows is that this exe will execute the JVM and the jar for you, and probably add some parameters to the JVM for the Java application execution.

There are some applications called Java Executable Wrappers. These can wrap your Java application (jar) and convert it into an exe, but note that even these applications will start a JVM process for you behind the scenes (usually executing java -cp <path>:. the.desired.package.MainClass along with a set of JVM parameters), and some of them will fire the JVM download in case it is not properly installed. You can find more info about this here:

TL;DR

You need a Java Virtual Machine (JVM, JRE) to execute a Java application, regardless the device you're using.

Here's the link to download the latest Java JRE 8 version

Community
  • 1
  • 1
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • Can you please explain with an Example. like the any one of the new software developed in java and going to install in my PC. in that case if i dont have an JVM how the file is run inmy PC – Durgaprasad May 11 '14 at 13:39
  • @Durgaprasad what kind of example are you looking for? – Luiggi Mendoza May 11 '14 at 13:40
  • Please check my Update in the above comment – Durgaprasad May 11 '14 at 13:41
  • @Durgaprasad you need a JVM in order to run a Java application. Check my answer update. – Luiggi Mendoza May 11 '14 at 13:47
  • So if the OS does not have JVM or not installed properly then JVM will installed it self after that only the code start the what ever remaing process am i correct @ Luiggi Mendoza ? – Durgaprasad May 11 '14 at 13:53
  • @Durgaprasad no, that's incorrect. Only some Java Executable Wrappers allow you to do this. You don't know if that exe of yours was generated using one of these, so the best bet would be to install the JVM manually. – Luiggi Mendoza May 11 '14 at 13:54
  • Okay Thank you @Luggi Mendoza If the client don't know about the JVM can we fire to you need install the JVM or java software ? – Durgaprasad May 11 '14 at 13:58
  • @Durgaprasad you may want to check [Java Web Start](http://www.oracle.com/technetwork/java/javase/javawebstart/index.html). – Luiggi Mendoza May 11 '14 at 14:01