Week 27 — What does "write once, run anywhere" refer to in Java?
Question of the Week #27
What does "write once, run anywhere" refer to in Java?
22 Replies
Programming in the Java language allows you to be able to run the Java Application in windows, Linux and MacOS.
Submission from Grid#3702
The "write once, run anywhere" refers to when java was made all platforms could use it so if you have a mac you could write code on there, then save it and go to a windows computer and open the file it would run. Giving it the quote "write once, run anywhere'
Submission from UnknwnGamer#1770
The saying "write once, run anywhere" refers to the fact that Java compiles and gets interpreted by the Java Virtual Machine, instead of a specific OS, and therefore any machine that has the Java Runtime Environment can run Java applications, no matter the OS.
Submission from Chowder#5643
When our source code is compiled in Java, the compiler then converts our source code into byte code. Now this byte code can be executed on any operating system using Java virtual machine(JVM).
Submission from FLeX#7975
It refers to the fact that Java is a compiled langage that is interpreted by a virtual machine called JVM, every system that has a JVM can run java code. This means that we can write java on a machine and run the same code on another machine.
(i think hehe)
Submission from frozzek#0000
The JVM was designed to make Java code compatible on basically every platform in existence. When you write Java code once, it can be ran on any other platform. That's the surface of it.
Submission from amicharski#7113
It represents how java is special in when the code is compiled it can be run anywhere, unlike other languages such as C# which need to be compiled on each device/instance they are run on.
Submission from mochatitan#0000
it reflects the nature of javas ability to run on any system that supports Java Virtual machine because with the JVM you can compile java to bytecode and then run it on any device without needing to change or recompile.
Submission from penguindevelopments#0000
Write once, run anywhere usually refers to Java's ability to abstract system-specific functionality and be run by VMs for the specific platform the program is supposed to run on, letting the developers of said program focus on the actual functionality rather than focusing on what environment they are running on.
At least that's my take on it :D
Submission from thatikevoodoo#0000
The JVM is what is referred to. Code generated by C or C# programs output executables that can only be run on certain OS. C# for example outputs a .exe file, which can only be run on windows. However, when Java (or any other JVM language) outputs a JAR file, it can be run if the JVM has been installed on that machine. The JVM basically allows for the execution of and JVM language on any platform, no matter the OS.
Submission from cranberryjuice0#0000
The statement "write once, run anywhere" refers to the fact that Java is platform-independent, which means that it can run on any operating system or device as long as the Java Virtual Machine is installed.
Submission from Dogepressed#1205
Highlights platform independent feature of Java. The byte code generated after compilation can run on any system's JVM
Submission from slayerOP#0610
Java is a language that works on many devices including every OS and all you have to do is install java for example I make a hello world program and if I compile it into a jar file I can run it on every device with java installed as long as the jar file works the reason for this is because Java uses bytecode when compiled using the JVM to compile .java to .class and and a .class file is basically just a bytecode version of .java and .jar is the .class file made into a executable file. This all is possible by bytecode and the JVM
Submission from Gameboy V#5538
It means java can run any platform (cross platform) whether it be mobile, web, desktop, etc..
Submission from Kale Vivi#9457
It's means that the after the jvm compiles the our code it's provides us with byte code which is platform independent and could be run on any platform
Submission from satyamchoudhary#0000
java bytecode runs in the jvm which is supported by many platforms
you write the code once, it's converted to java bytecode and can be ran on any supported platform
Submission from plus#2105
Write Once Run Anywhere, is the feature applicable to those programs which hold the capability to execute itself on any operating systems or any machine.
Submission from ramosraj#5100
If they were being honest, they really should have said "write once, run anywhere that we've written a JVM for" since the JVM actually is platform dependent, like any standalone software would be, and you can only run your java application on a machine that has a JVM available to run your software. However, in reality, almost everything is running either mac, linux or windows, so if you write java app, it can run "basically" anywhere.
What lets it do this is the fact that your java app isn't actually compiled into machine code like a standalone app, it's compiled into "java bytecode". In other words, you're not writing code that tells the machine what to do. You're writing code that tells the java JVM what to tell the machine to do. So the JVM, whichever platform version is running, can take your instructions and interpret it into the correct machine instructions to perform on whatever platform your java app is running on. It's like a translator.
Which is super convenient. It means you just write your code once, compile it into java bytecode, and the JVM will do the hard work of converting those instructions into platform dependent machine code instructions. Which is what they mean when they say "write once, run anywhere". Since you don't have to worry about writing separate apps specific to each OS if you're writing them in java.
⭐ Submission from justisr#0000
Due to the JVM, Java is a platform-independent programming language. Java code can be written on one system using a JDK and then it can run on any system with a compatible Java runtime without the code being modified or the application being recompiled for that system.
This works across operating systems, architectures and device manufacturers.
So, the code only needs to be written once and it can then run "anywhere" meaning on any system with a compatible Java runtime environment (e.g. if the code has been compiled for Java 17, it needs to run on Java 17 or later).
Java source code is compiled to a platform-independent format called JVM bytecode. This bytecode contains instructions interpreted by the JVM.
Before running Java bytecode, a JVM needs to be installed on the system. There are different JVMs for different operating systems and architectures.
While the JVM itself is platform-specific, JVMs for different platforms can run the same Java bytecode.
However, there are things breaking platform independency. When running native code written in another programming language, this code is can only run on the platforms it has been written/compiled for. If a Java application contains non-JVM code dependent on a specific platform, that code cannot run on another platform unless code for these platforms also exists.
Another source of platform dependency is calling commands provided on the system. Java allows executing other programs on the system using
Runtime#exec
. Calling other programs only works if these programs exist and some programs are only available on certain platforms.⭐ Submission from dan1st#0000