-5

what happens at the compilation level that only C and C++ are converted to exe?. All applications must be exe to run on windows so why these languages didn't include a feature for generating exe file after compilation?

Aquib Shaikh
  • 98
  • 1
  • 1
  • 9
  • 2
    Because they were intended to run on a lot of different operating systems, not just Windows. – rossum May 07 '20 at 15:44
  • Look up WORA (Write once, run anywhere). It's a pain to make different executables for every OS, so Java and Python (and other languages) just have a VM that interprets programs. – user May 07 '20 at 15:45
  • 3
    Does this answer your question? [Compiled vs. Interpreted Languages](https://stackoverflow.com/questions/3265357/compiled-vs-interpreted-languages) – jhamon May 07 '20 at 15:47
  • 1
    There's no reason somebody couldn't write a C++ interpreter, it might not be a good idea but its certainly possible. Equally it'd be perfectly possible to write a Java/Python compiler that output executable code – Alan Birtles May 07 '20 at 15:54
  • 1
    e.g. https://stackoverflow.com/questions/69539/have-you-used-any-of-the-c-interpreters-not-compilers – Alan Birtles May 07 '20 at 15:55
  • We didn't have virtual machines back in the 1960s. What virtual machine runs the virtual machine? – user4581301 May 07 '20 at 16:23
  • There are other languages besides C and C++ that get compiled into native code. One example is ForTran. There are compilers than can compile BASIC and Pascal into native code. – Thomas Matthews May 07 '20 at 18:11

2 Answers2

5

Not only C and C++ get compile to natively executable files.

You can read more on this here: https://en.wikipedia.org/wiki/Compiled_language There is a list of other languages compiled (those that don't have "to bytecode" should be the ones that don't require "external converters" (called interpreter).

There isn't a "magic" thing that makes C++ and C able to do this and not other languages. It is a designed choice. A compiled C or C++ language can run on only one target (specific cpu architecture and operating system), whereas programs written in python or Java can run on any platform that have an interpreter.

Julien Thierry
  • 651
  • 4
  • 11
  • But what we see from Java based applications is that they are in exe format, so does it mean that they are converted to C, C++ form? also C, C++ based applications are able to run on different systems and architecture without recompiling again (example video games) how does that happen then? – Aquib Shaikh May 08 '20 at 09:07
  • 1
    @AquibShaikh while you can compile Java to an exe, the exe java applications are often just a small convenience program that invokes an existing JVM installed on the computer. This makes it easier for the typical user to use. Some are beefier and have a specific or custom JVM built into the exe. – user4581301 May 08 '20 at 18:42
4

C, C++ and Java are compiled languages, meaning their code is run through a compiler, which takes your code and translates it to binary instructions. In the case of C and C++, these instructions are in a format your computer can directly understand, which in Windows is stored in a .exe file.

Java is a little more complicated as the code is compiled for the JVM and runs in it, not directly in your computer. That's why no .exe. You can use software to package your program to run from an .exe, though.

Python, on the other hand, is an Interpreted Language, where your code is run through a program called an Interpreter. The interpreter runs your code line by line, meaning at no point your whole program is converted to instructions and all you need is a file with your Python code. Like with Java, you can make a package that contains your code and interprets it that goes in an .exe.

There are many other examples of Compiled and Interpreted languages (as well as other types I may not know of), as Julien Thierry already mentioned.

rubemnobre
  • 100
  • 5