I've read a lot of articles about java and the WORE ("write once and run everywhere"), but i have a doubt since they say that you can compile a file.java into a file.class and run this .class file anywhere but after installing JRE in my Windows 10 and try to run a file.class wich contains a simple "hello word" nothing happens, is it that i need to use a jar file with the JRE instead of only using file.class? I wanna do this without using the JDK and the "java" command only using JRE or do I have to do something else I'm missing with the FILE.class?
-
Please shows us exactly what you did, and what the (error) output was (a [mre]) – Mark Rotteveel Nov 21 '20 at 11:49
-
I've already solve this problem, it was because I haven't set the globla variables on windows, that was the main thing I was missing, and in fact the JRE and JDK have the JVM it's just that the JRE doesn't have the java compiler ("javac") and with both JDK and JRE I can run a file.class – Milton Paucar Nov 23 '20 at 02:52
1 Answers
javac and JVM are the same?
No.
Not even close. javac
is the Java compiler. The JVM means "Java Virtual Machine" ... and you get one whenever you run the java
command.
NB: javac
and java
(or javaw
) are different programs. Don't confuse them.
can I execute a file.class only using JRE and not JDK?
Yes. However, from Java 9 onwards you can't get a (just) JRE distribution from Oracle anymore. It is JDKs ... or nothing.
how can I do it on Windows?
Lots of ways. See How do I run Java .class files? for more information.
.... after installing JRE in my Windows 10 and try to run a file.class wich contains a simple "hello word" nothing happens
Then you've done something wrong. See the above link. Or carefully read the Oracle Java Getting Started tutorial and follow the instructions therein.
Is it that I need to use a jar file with the JRE instead of only using file.class?
No. You don't need a JAR file for a "hello world" class. You just need to read and follow the instructions.
I wanna do this without using the JDK and the "java" command only using JRE ...
(I think you mean the javac
command. Because the java
command is in both JRE and JDK distributions.)
From Java 9 onwards you won't be able to do that; see above.
However, from Java 8 onwards there are alternatives that don't involve installing a JRE or a JDK. Once you have figured out how to run your ".class" file using the java
command, do some research on jlink
... which allows you to create stand-alone executables. But note these executables are NOT "write once, run everywhere": they are platform specific.

- 698,415
- 94
- 811
- 1,216
-
Thank you Stephen C your answer was very useful cause now I know that I have JVM in both JRE and JDK, it's just a matter of setting the global variables on Windows and you can use "java" comand only with JRE with a .class file. – Milton Paucar Nov 23 '20 at 02:58