0% found this document useful (0 votes)
3 views2 pages

Write Once Compile Many Times Java VTU

Java is a platform-independent language that allows programs to be written and compiled once, then executed on any platform with a Java Virtual Machine (JVM). The compilation process converts source code into bytecode, which can run on various operating systems without recompilation. This feature enhances portability and reusability, embodying the principle 'Write Once, Compile Many Times.'

Uploaded by

subiyabi741
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Write Once Compile Many Times Java VTU

Java is a platform-independent language that allows programs to be written and compiled once, then executed on any platform with a Java Virtual Machine (JVM). The compilation process converts source code into bytecode, which can run on various operating systems without recompilation. This feature enhances portability and reusability, embodying the principle 'Write Once, Compile Many Times.'

Uploaded by

subiyabi741
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Write Once, Compile Many Times in Java

Definition:
Java is a platform-independent language because of its unique compilation process. The phrase
“Write Once, Compile Many Times” means that a Java program needs to be written and compiled
only once, but it can be executed (run) on any platform that has a Java Virtual Machine (JVM).

Explanation:
• When a Java program is written, it is saved with a .java extension.

• The Java compiler (javac) compiles the source code into an intermediate code called bytecode
(.class file).

• This bytecode is not specific to any operating system or hardware.

• The JVM on each platform converts this bytecode into machine code understood by that
system.

• Hence, the same bytecode can run on different platforms (Windows, Linux, macOS, etc.)
without recompilation.

Diagram:
Source Code (.java) ■ ■ Compiled using javac ▼ Bytecode (.class) ■
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ ▼ ▼ ▼ ▼
JVM (Windows) JVM (Linux) JVM (macOS) JVM (Android) ■ ■ ■ ■ ▼ ▼ ▼ ▼ Machine Code
Machine Code Machine Code Machine Code

Example:
class Example {
public static void main(String[] args) {
[Link]("Write Once, Compile Many Times");
}
}

Steps:
1 Write the program → [Link]
2 Compile → javac [Link] → Produces [Link]
3 Run on different platforms (Windows, Linux, macOS) → java Example

Conclusion:
Java programs are compiled once into bytecode. The same bytecode can be executed many times
on different platforms using JVMs. This feature ensures portability and reusability, which makes
Java a platform-independent and flexible language.
Hence, Java follows the principle: “Write Once, Compile Many Times.”

You might also like