Last updated:
3 min read
How to compile different languages source code files?
Rakesh Potnuru
Author
0%
SHARE

How to compile different languages source code files?

The biggest mistake beginners do while started learning to program is using fancy IDEs (Integrated Development Environment). You should use the terminal at least to know how a specific language code is being executed and what's going on behind the scenes. So in this blog, I am going to tell you how to execute source code for a few languages.

Requirements

  1. Using notepad create the source code file for all the languages mentioned in this blog.
  2. Make sure you have respected compilers installed on your computer and add the path in environment variables in order to use that compiler from anywhere.

Let's get started...

Open your terminal or command prompt, and change the current directory to the location where you created the source code file.

For example: If all of my source code files are in the Programming folder in Desktop.

c:\> cd Desktop\Programming

Output: c:\Desktop\Programming>

1. C

Type this command in the prompt. Replace hello with your file name. (Hoping you have gcc compiler installed)

c:\Desktop\Programming> gcc -o hello hello.c

The above command will create an executable file with the extension ".exe". Now type the file name to execute the program.

c:\Desktop\Programming> hello

Output: Hello world

2. C++

C++ has also the same procedure. Type this command in the prompt. Replace hello with your file name. (Hoping you have gcc compiler)

c:\Desktop\Programming> gcc -o hello hello.cpp

The above command will create an executable file with the extension ".exe". Now type the file name to execute the program.

c:\Desktop\Programming> hello

Output: Hello world

3. Java

To compile, run this command.

c:\Desktop\Programming> javac hello.java

After that hello.class file will be generated, to run the code type java <filename>

c:\Desktop\Programming> java hello

Output: Hello World

4. C#

Compile with this command

c:\Desktop\Programming> csc hello.cs

This will generate an executable file hello.exe. You can simply double-click it to open or type the file name.

c:\Desktop\Programming> hello

Output: Hello World

5. JavaScript

JavaScript is a browser-side language, you can use the console in the developer tools of your browser or use NodeJs. NodeJs is JavaScript run time, so you can execute JavaScript files using NodeJs. Here's how-

Note: Make sure you have NodeJs installed on your computer.

Open the terminal and simply type this command.

c:\Desktop\Programming> node hello.js

Output: Hello World

6. Go

c:\Desktop\Programming> go run hello.go

Output: Hello World

7. R

You can use Rscript to run R programs.

c:\Desktop\Programming> Rscript hello.R

Output: Hello World

8. Swift

c:\Desktop\Programming> swift hello.swift

Output: Hello World

9. Ruby

c:\Desktop\Programming> ruby hello.rb

Output: Hello World

10. PHP

c:\Desktop\Programming> php hello.php

Output: Hello World


Hope this helps you! Save for reference.


LEAVE A COMMENT OR START A DISCUSSION

MORE ARTICLES

Dockerizing Your MERN Stack App: A Step-by-Step Guide

    14 min read

Dockerizing Your MERN Stack App: A Step-by-Step Guide

Are you tired of spending hours messing with crontabs and installing packages in an attempt to run your app locally? Are you sick of always missing a dependency that doesn't allow you to run the app and therefore you have to debug it for hours trying to find what's wrong? Then you've come to the right place. In this article, you will learn how to make use of Docker to develop and ship your software faster and easier.

Introducing Publish Studio: Power Digital Content Creation

    3 min read

Introducing Publish Studio: Power Digital Content Creation

Say “Hi” to Publish Studio, a platform I’ve building for the past few months. If you are a content writer, then you should definitely check it out. And if you are someone who has an audience on multiple blogging platforms and need an easy way to manage your content across platforms, then you should 100% give it a try.

Subscribe to Newsletter

Weekly


  • Never miss an update.
  • Get articles and snippets directly to your inbox.
  • Subscribe to stay connected and avoid getting lost among millions of websites.

Monthly


  • Coming soon...