How can gedit detect languages, even though they are not installed?
Here's an example where Gedit detects Java.
But when I try to run Java from terminal, it says that java is not installed.
Similarly, it can detect ada even though it is not installed on my system.
And the same is the case for other languages...
If a language is not installed, how can gedit display formatting according to the syntax of the language?
If I select Objective-C instead of Ada, it does not display formatting.
However, if I replace code of Ada with Objective-C it displays proper formatting
Even though these languages are not installed by default, how can gedit differentiate between them?
This article says that PHP, Ruby and Python come pre-installed with Ubuntu. However, my system can also run C and C++. Why is that, and how does it relate to Gedit's syntax highlighting?
TL;DR: Different functionality related to the same language is provided by different programs and libraries, which can usually be separately installed. Applying syntax highlighting, compiling source code into executable code, and running executable code all require different software. None of the programs or libraries involved in doing these things are actually the language itself.
A programming language, like any kind of language, is an abstract idea. It is conceptually distinct from whatever software facilitates developing actual programs in it, and also from whatever software is needed to support such programs and allow them to run. A language cannot really be installed on your computer. It is somewhat common to write and speak in a manner that does not distinguish between a language and its implementations. This habit is hard to avoid. But it can lead to confusion, which has happened here.
As Puspam and N0rbert have mentioned, it is generally possible to have a tool installed that parses the syntax of a language and applies highlighting, without also having other development tools for the language installed. You can even make up your own language that has no implementation (yet), whose programs can never (yet) actually be run, and write syntax highlighting rules for it so that a text editor like Gedit highlights it correctly. Syntax highlighting doesn't require that you have other development tools for a language; it doesn't even require that such tools exist.
Some languages, such as Perl and C++, have extremely complex syntax, where which part of the syntactic grammar corresponds to particular parts of your source code actually depends on the meaning of something that came long before. For such languages, to apply 100% correct syntax highlighting every time reduces to a substantial fragment of the entire task of implementing the language. For these languages, syntax highlighting is usually implemented in an approximate manner, applying the grammar correctly in most practical cases.
Guessing what language you are writing something in is likewise a matter of approximation. It is not in general possible to tell for sure. The usual reason given for this, which is true, is that it's possible to write a program that is simultaneously in multiple languages (possibly with a different meanings in each). A more important reason is that, during the course of being written, your code is probably wrong, including in ways that make it not technically in the language you're writing it in. For example, imagine typing out a simple C program. If you were interrupted at a random point while doing so, would what you have so far really be a valid C program?
Nonetheless, tools can often make good guesses about what language you're using. Also, if you name your file with a suffix that is commonly used for source code files in some particular language, editors will typically use that first to decide how to highlight it.
What people mean when they say an interpreted language is "installed"
That article you were reading includes statements like:
What this actually means is that Ubuntu comes with implementations of these languages. Sometimes people refer to an implementation of a language by the same name as the language itself.
Those three languages are most often interpreted, though a form of compilation (compiling to a special bytecode, which conceptually is the machine language of a made-up type of computer, an abstract machine, in terms of which the language is defined) may be involved as part of the interpretation process.
Whether a language is interpreted or compiled is really an implementation strategy rather than a property of the language, and some languages have separate interpreted and compiled implementations. But languages are most often designed with one or the other strategy in view, so the phrases "interpreted language" and "compiled language" are popular, and I will use those phrases here.
The implementation of an interpreted language consists of:
To run your program, the user must usually have:
It is possible to develop software in such a language using only the tools needed to run a program. This is unlike compiled languages (see below). But you may want to have additional tools that know something about the language, such as a text editor that knows how to highlight its syntax.
Interpreters in Ubuntu
Perl has only one implementation (though there are many different versions of it). The
perl
command runs the interpreter. In the Perl community, the implementation is most often spelled "perl" (no capital letter) and the language is most often spelled "Perl". That distinguishes the language from its implementation, but this orthographic convention is not universal.Python has multiple implementations. Ubuntu comes with CPython, which (among other components) provides the
python3
command, or especially in older Ubuntu releases, thepython2
command. CPython is the official reference implementation of Python and also the most popular implementation. Even on the official Python website, some of the claims made about "Python" are about the language, while others are about the official implementation. Other implementations include PyPy, Jython, and IronPython.Ruby likewise has multiple implementations. Ubuntu comes with Ruby MRI ("Matz's Ruby Interpreter"), which (among other components) provides the
ruby
command. MRI is the official reference implementation of Ruby and also the most popular implementation. There are fewer widely used implementations of Ruby than widely used implementations of Python, but one major Ruby implementation other than Ruby MRI is JRuby.What people mean when they say a compiled language is "installed"
People should not say this, because it is always (rather than merely sometimes) ambiguous. That article you're reading (happily) does not talk about compilers in this way. However, people often do, and the conceptual issues contain the answer to your question, so this is worth examining.
The implementation of a compiled language consists of:
In some languages, the support library can sometimes be linked statically into your program so that it is not separately required to run your program. This is a very common approach in a few languages, like Go, but is less often done in most others, such as C, C++, and Objective C.
To run your program, a user must have:
To build your program, one must have:
When people talk about having a language like C++ installed, they usually mean that some implementation of a compiler and other necessary tools to build C++ programs is installed. But the user doesn't need that to run you program. Ubuntu comes with C and C++ programs, but (depending on how you install Ubuntu) it may not come with C and C++ development tools, which aren't needed to run the programs. Ubuntu also comes with Perl and Python programs (and possibly Ruby programs), which do need interpreters to run.
Compilers in Ubuntu - the case of C and C++
This answer will already be very long, so I'll just describe the situation with C and C++, which are extremely important compiled languages. This is in spite of Ubuntu shipping with programs written in some other compiled languages including Go.
C and C++ are separate languages. Both are internationally standardized. Their support libraries--standard libraries in the strongest sense of the phrase--are likewise standardized, in the same documents that standardize the languages. No implementation of C or C++ is blessed as a reference implementation; these languages have multiple implementations on equal footing. Outside niche situations a handful are far more popular than the others. (None of this is actually because they are compiled languages--for example, Go has a reference implementation and is not standardized.)
It is possible to implement either of C or C++ without implementing the other, but the most popular compilers provide both (and providing C++ without C is uncommon).
The most popular C and C++ compilers are are GCC (
gcc
,g++
), Clang (clang
,clang++
), and MSVC++ (cl.exe
). GCC and Clang are readily available or Ubuntu.The most popular C standard library implementation on a GNU/Linux system like Ubuntu is GNU libc. It is also probably the most popular implementation in the world. It's associated with GCC, but other compilers, like Clang, target it with no trouble. (In Windows, a different implementation (MSVCRT) is more commonly used.) In Ubuntu and most other GNU/Linux systems, GNU libc is always installed, and provided by the file
libc.so.6
. Nearly all programs, whether written in C or not, use it, either directly or indirectly. It is considered an essential part of the operating system. But it is possible to write a program that does not use it, and at least one other C standard library implementation, musl, is readily available for Ubuntu.The most popular C++ standard library implementation on a GNU/Linux system like Ubuntu is libstdc++. It is associated with GCC, but some other compilers can target it. You can also install libc++, which is associated with Clang (they're both part of the LLVM project), but Clang can also target libstdc++ with no trouble (which is what you get by default in Ubuntu). The other major implementation of the C++ standard library is the MS STL, which has recently been released as free open-source software but is not available for Ubuntu.
Ubuntu Packages
Programs, libraries, and header files for libraries are most often provided in different packages, which facilitates having some installed but not others--such as having a library installed to run programs that need it, without having the header files installed that would be needed to develop programs using the library.
Packages that provide libraries are usually named starting with
lib
. Packages that provide header files are usually named ending with-dev
. See How can different packages have identical source code? for details about that.build-essential
installs GCC and also support libraries for C and C++, header files for those support libraries, and various other useful tools. If you're developing C, C++, or Objective C programs, even with another compiler, you'll want to install that metapackage. If for some reason you wanted to install GCC by itself, there's thegcc
package, but that doesn't install all the compilers. (GCC is the "GNU Compiler Collection.) For C++ you would also installg++
. But I recommend just installingbuild-essential
.clang
installs Clang, including the C++ compiler.GNU libc is provided by the
libc6
package. You already have that. If you don't, your Ubuntu system is severely broken and hardly anything on it will run. Its header files are provided by thelibc6-dev
package, which you may or may not have but whichbuild-essential
will install.libstdc++ is usually, depending on the version, provided by the
libstdc++6
package. (This doesn't mean you're using version 6. The naming is for historical and compatibility reasons.) Its header files are provided by a similarly named-dev
package, not necessarily with a6
in the name. On most current Ubuntu systems, this islibstdc++-9-dev
. Installingbuild-essential
, org++
, brings in the necessary header files if you don't have them.libc++ is currently provided by packages named like
libc++1-10
andlibc++abi1-10
, and its header files are provided bylibc++-10-dev
, with the actual version number in place of10
(if different). As with libstdc++, typically you should not directly install any of these packages to get what you need to build programs targeting libc++. Instead, installlibc++-dev
. This gives youlibc++-10-dev
or whatever other version of the header-files package is the default for you system, which in turn depends on the packages providing the actual library binaries, ensuring you get those too.