Blacksmoke90
Blacksmoke90

Reputation: 31

Using Java compiled on one platform on another OS

I would like to know is it possible to compile a Java application for Linux from Windows, or do I have to compile on a specific platform for that platform?

Upvotes: 1

Views: 904

Answers (5)

SSH
SSH

Reputation: 1627

Most programming languages compile source code directly into machine code, suitable for execution on a particular microprocessor architecture. The difference with Java is that it uses bytecode - a special type of machine code. The processor architecture is emulated by what is known as a "virtual machine". This virtual machine is an emulation of a real Java processor - a machine within a machine. The only difference is that the virtual machine isn't running on a CPU - it is being emulated on the CPU of the host machine.

enter image description here

For indepth understanding have a look here

Upvotes: 3

OhDearMoshe
OhDearMoshe

Reputation: 39

In short, yes you can. Unless you are writing windows specific functionality in your application. One of the fundamental points of java in its inception is its portability between platforms.

Upvotes: 0

Joseph Farah
Joseph Farah

Reputation: 2534

Java code doesn't care where you run it. XD If you write it in Eclipse IDE (for example) and compile it, you can run it on Linux. There is not special executable file that needs to be converted, like for C/C++ or something. Think of Python...its interpreted, so it doesn't matter where it is run.

Upvotes: 0

Aleksandar Stefanović
Aleksandar Stefanović

Reputation: 1593

Java runs in JVM (virtual machine), that makes it run the same on all systems that have JVM installed. You only need to compile once.

Upvotes: 0

j_v_wow_d
j_v_wow_d

Reputation: 511

Java programs run on a virtual machine, so yes. As long as you have Java installed on each operating system it does not matter which OS it was written in.

Upvotes: 0

Related Questions