This post was originally published on this site

If you have worked or studied computer programming, you have probably heard of the terms “source code” and “object code.” Each term has its own use and deciphering the difference can be difficult at first. In a few words, source code is all code created by a programmer with a text editor, whereas object code puts out source code that has first been collected and translated into machine code.Download Now: An Introduction to Java & JavaScript

Don’t worry, we will break down each of these later in this article. We’ll give you an understanding of source code and object code, help you recognize the difference between the two, and explain the context in which the terms are used.

Let’s begin with looking at these terms individually.

What is source code?

Source code is the set of instructions or commands in a readable programming language written by a human — usually a programmer. The source code may or may not have comments within them and produces an acceptable output when the code runs.

Once the programmer creates the source code, it is saved in a file according to its extension. For instance, a JavaScript file is saved with the extension “.js” and a C++ file is saved with the extension “.cpp“. A language translator receives the source code and then converts it into machine-understandable code. These codes are called object codes which we will discuss later.

To effectively build a program, the source code is written in either assembly or a high-level language. Assembly language is machine-oriented and requires the computer’s internal knowledge to decipher. High-level coding languages use English and math symbols as instructions, examples include languages such as C, C++, Java, Python, JavaScript, etc.

How is source code used?

The source code is written in plain text that is well understood by humans. It is simple to find the source code for any website. First, right-click on any webpage and navigate to “View Page Source.” A new tab is opened with the source code displayed. Take a look at this example source code from Wikipedia.

Photo of the source code from Dog Breed Wikipedia page

The source code from this webpage is written in plain text format and can be read by programmers.

What is object code?

Object code is a computer numeric code made of binary numbers such as 0s and 1s and is understood by a machine. It is the output of a source code after compilation. This means once the source code is compiled or translated into a machine-understanding language, it displays the source code (or what “used to be” the source code). 

A programmer cannot easily understand an object code, unlike source code which is written in plain text. The object code stays in an object file such as COM files, COFF (common object file format), etc. Note that object code, machine code, and binary code can be used interchangeably. 

How is object code used?  

An object code usually includes interpreted or compiled programmable logic, firmware, and libraries. Object code is generated by a compiler that reads higher-level computer language source instructions and then translates them into equivalent machine language instructions. For a visual representation of object code, take a look at the following photo.

Photo of binary numbers representing object code

The object code is written in 0s and 1s and is challenging to read as humans but very understandable for machines.

How to Compile Source Code Into Object Code

A compiler converts human-readable code to object (or machine) code. Each high-level programming language has its own compiler which converts code into a language that the machine understands. Visually, the software development process can look something like this:

Photo of the Source Code and Object Code three step process

The source code and object code can be viewed as the before and after versions of computer programming. This process can be explained in the following steps:

  1. A programmer using Java language types in the desired sequence of Java language statements then saves them as named files containing the source code. 
  2. The file is now ready to be compiled and goes through a Java compiler.
  3. The resulting output (compiled file) is then referred to as an object code. 
  4. The object code contains a sequence of instructions that the processor can understand but is difficult for humans to read (machine-readable language).

The Difference Between Source Code and Object Code

Now that we have a general understanding of source and object code, review the following chart for a side-by-side comparison of the difference between source and object code.

Photo of a chart describing the difference between source code and object code

In brief, the main difference between the two terms is that a source code is a collection of instructions written using a programming language, while the object code is an output of the source code after going through a compiler.

Source Code vs Object Code  

Source code produces object code and to make the application possible for distribution, the object code produces an executable file accessible to others with or without programming knowledge. Just as humans understand native languages, computers understand machine language. On occasion, even humans need translators to understand a foreign language, thus a computer will need a compiler (translator) to distinguish source code from object code.

java