Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

Can a program consist of more than one language?

+9 votes
asked Sep 6, 2016 in CSC 211 (F16) by Ryan Philp (727 points)

3 Answers

+3 votes

Actually, YES, a program can be written using more than one language!  (In fact, this happens pretty regularly with web applications, if you define "program" broadly -- some of the code is written using Javascript on the client side, and some is written using PHP or Java on the server side).

However, in an more straightforward case, both the Java and the Scala programming languages compile their code to the same binary .class files, and they can call methods that were written by the other language.  It's generally simpler to write your programs using just one language.

Similarly, many programs use pre-compiled libraries of code (e.g. Windows DLL files) that could have been written in a couple different languages.  As soon as we start writing graphical applications using Java, then technically your program will involve multiple languages, because deep down under the hood it's calling some  Windows or Mac operating system code to create the window that you see, and that code was probably written in C or C++.  However, you wouldn't see any of that original human-readable source code in your programs, since you are just using the binary (machine-readable) code that was produced by someone else earlier.  But, in a sense, your overall program/product was created using multiple languages.

 

answered Sep 11, 2016 by Forrest Stonedahl (3,438 points)
+2 votes
Imagine if the sentences we speak are composed of words in different languages. That confusion is probably the reason why you cannot program in more than one language!
answered Sep 7, 2016 by Jordan Peklo (100 points)
0 votes
It cannot consist of more than one language. However, what you can do is to use a program in one language to call another program in another language. For example, you can code a program in Java that can call the file cmd.exe, which is written in another program language.
answered Sep 6, 2016 by Minh Ta (1,045 points)
...