You are on page 1of 18

Unit - III Computer languages

 What is a programming language?

A programming language defines a set of instructions that are compiled together to perform a specific task by
the CPU (Central Processing Unit). The programming language mainly refers to high-level languages such as C,
C++, Pascal, Ada, COBOL, etc.

Each programming language contains a unique set of keywords and syntax, which are used to create a set of
instructions. Thousands of programming languages have been developed till now, but each language has its
specific purpose. These languages vary in the level of abstraction they provide from the hardware. Some
programming languages provide less or no abstraction while some provide higher abstraction. Based on the
levels of abstraction, they can be classified into two categories:

o Low-level language
o High-level language

The image which is given below describes the abstraction level from hardware. As we can observe from the
below image that the machine language provides no abstraction, assembly language provides less abstraction
whereas high-level language provides a higher level of abstraction.

I.Low-level language

The low-level language is a programming language that provides no abstraction from the hardware, and it is
represented in 0 or 1 forms, which are the machine instructions. The languages that come under this category are the
Machine level language and Assembly language.

1.Machine-level language

The machine-level language is a language that consists of a set of instructions that are in the binary form 0 or 1. As
we know that computers can understand only machine instructions, which are in binary digits, i.e., 0 and 1, so the
instructions given to the computer can be only in binary codes. Creating a program in a machine-level language is a
very difficult task as it is not easy for the programmers to write the program in machine instructions. It is error-prone
as it is not easy to understand, and its maintenance is also very high. A machine-level language is not portable as
each computer has its machine instructions, so if we write a program in one computer will no longer be valid in
another computer.

The different processor architectures use different machine codes, for example, a PowerPC processor contains RISC
architecture, which requires different code than intel x86 processor, which has a CISC architecture.

2.Assembly Language

The assembly language contains some human-readable commands such as mov, add, sub, etc. The problems which
we were facing in machine-level language are reduced to some extent by using an extended form of machine-level
language known as assembly language. Since assembly language instructions are written in English words like mov,
add, sub, so it is easier to write and understand.

As we know that computers can only understand the machine-level instructions, so we require a translator that
converts the assembly code into machine code. The translator used for translating the code is known as an
assembler.

Unit - III Computer languages Paper-I By.Prof.Miss.Bavale A.T Page 1


The assembly language code is not portable because the data is stored in computer registers, and the computer has to
know the different sets of registers.

The assembly code is not faster than machine code because the assembly language comes above the machine
language in the hierarchy, so it means that assembly language has some abstraction from the hardware while
machine language has zero abstraction.

Differences between Machine-Level language and Assembly language

Machine-level language Assembly language

The machine-level language comes at the lowest The assembly language comes above the machine language
level in the hierarchy, so it has zero abstraction means that it has less abstraction level from the hardware.
level from the hardware.

It cannot be easily understood by humans. It is easy to read, write, and maintain.

The machine-level language is written in binary The assembly language is written in simple English
digits, i.e., 0 and 1. language, so it is easily understandable by the users.

It does not require any translator as the machine In assembly language, the assembler is used to convert the
code is directly executed by the computer. assembly code into machine code.

It is a first-generation programming language. It is a second-generation programming language.

II. High-Level Language

The high-level language is a programming language that allows a programmer to write the programs which are
independent of a particular type of computer. The high-level languages are considered as high-level because they are
closer to human languages than machine-level languages.

When writing a program in a high-level language, then the whole attention needs to be paid to the logic of the
problem.

A compiler is required to translate a high-level language into a low-level language.

Advantages of a high-level language

o The high-level language is easy to read, write, and maintain as it is written in English like words.
o The high-level languages are designed to overcome the limitation of low-level language, i.e., portability.
The high-level language is portable; i.e., these languages are machine-independent.

The following are the differences between low-level language and high-level language:

Low-level language High-level language

Unit - III Computer languages Paper-I By.Prof.Miss.Bavale A.T Page 2


It is a machine-friendly language, i.e., It is a user-friendly language as this language is written in
the computer understands the machine simple English words, which can be easily understood by
language, which is represented in 0 or humans.
1.

The low-level language takes more time It executes at a faster pace.


to execute.

It requires the assembler to convert the It requires the compiler to convert the high-level language
assembly code into machine code. instructions into machine code.

The machine code cannot run on all The high-level code can run all the platforms, so it is a
machines, so it is not a portable portable language.
language.

It is memory efficient. It is less memory efficient.

Debugging and maintenance are not Debugging and maintenance are easier in a high-level
easier in a low-level language. language.

 Types of Languages: imperative, declarative, rule based, object


oriented

Unit - III Computer languages Paper-I By.Prof.Miss.Bavale A.T Page 3


I. What is imperative programming?

Imperative programming (from Latin imperare = command) is the oldest programming paradigm. A program based
on this paradigm is made up of a clearly-defined sequence of instructions to a computer.

Therefore, the source code for imperative languages is a series of commands, which specify what the computer has
to do – and when – in order to achieve a desired result. Values used in variables are changed at program runtime. To
control the commands, control structures such as loops or branches are integrated into the code.

Imperative programming languages are very specific, and operation is system-oriented. On the one hand, the code is
easy to understand; on the other hand, many lines of source text are required to describe what can be achieved with
a fraction of the commands using declarative programming languages.

These are the best-known imperative programming languages:

 Fortran Java Pascal ALGOL C C# C++ Assembler BASIC COBOL Python

The different imperative programming languages can, in turn, be assigned to three further subordinate programming
styles – structured, procedural, and modular.

The structured programming style extends the basic imperative principle with specific control
structures: sequences, selection, and iteration. This approach is based on a desire to limit or completely avoid jump
statements that make imperatively designed code unnecessarily complicated.

The procedural approach divides the task a program is supposed to perform into smaller sub-tasks, which are
individually described in the code. This results in programming modules which can also be used in other programs.
The modular programming model goes one step further by designing, developing, and testing the individual
program components independently of one another. The individual modules are then combined to create the actual
software.

Unit - III Computer languages Paper-I By.Prof.Miss.Bavale A.T Page 4


 Advantages and disadvantages of imperative programming languages

Many programming languages based on the imperative programming paradigm are in use today.

On the one hand, this is because the approach is the original form of programming. On the other hand, despite the
existence of alternative models, the imperative paradigm still has some practical advantages.

The languages are relatively easy to learn, as the code can be read like a step-by-step instruction. Therefore,
programmers normally learn an imperative language first as part of their training.

Easy legibility is a crucial factor in day-to-day operations. Ultimately, maintenance and optimization of applications
should not be linked to a specific person; different employees should be able to do it without too much difficulty
even if they haven’t written the code from scratch themselves.

One disadvantage of procedural programming is that for more complex problems to be solved, the amount of code
quickly starts to grow. It remains easy to read but becomes confusing due to its volume.

Execution is not clearly delineated from the programming as it is in the declarative style, therefore, subsequent
interventions can produce unwanted errors. Extensions are also more difficult to implement in pure imperative code
– unlike in the declarative paradigm, where there are methods that can be used to add them separately.

1.Procedural Programming Languages

Procedural (imperative) programming implies specifying the steps that the programs should take to reach to an
intended state. A procedure is a group of statements that can be referenced through a procedure call. Procedures
help in the reuse of code. Procedural programming makes the programs structured and easily traceable for program
flow.

1.C:-The C programming language was developed in 1972 by Dennis Ritchie and Brian Kernighan at the AT&T
Corporation for programming computer operating systems. Its capacity to structure data and programs through
the composition of smaller units is comparable to that of ALGOL. It uses a compact notation and provides the
programmer with the ability to operate with the addresses of data as well as with their values. This ability is
important in systems programming, and C shares with assembly language the power to exploit all the features of a
computer’s internal architecture. C, along with its descendant C++, remains one of the most common languages.

2.FORTRAN:-The first important algorithmic language was FORTRAN (formula translation), designed in 1957
by an IBM team led by John Backus. It was intended for scientific computations with real numbers and collections
of them organized as one- or multidimensional arrays. Its control structures included conditional IF statements,
repetitive loops (so-called DO loops), and a GOTO statement that allowed nonsequential execution of program code.
FORTRAN made it convenient to have subprograms for common mathematical operations, and built libraries of
them.FORTRAN was also designed to translate into efficient machine language. It was immediately successful and
continues to evolve.

3.ALGOL (algorithmic language) was designed by a committee of American and European computer scientists
during 1958–60 for publishing algorithms, as well as for doing computations. Like LISP (described in the next
section), ALGOL had recursive subprograms—procedures that could invoke themselves to solve a problem by
reducing it to a smaller problem of the same kind. ALGOL introduced block structure, in which a program is
composed of blocks that might contain both data and instructions and have the same structure as an entire program.
Block structure became a powerful tool for building large programs out of small components.

Unit - III Computer languages Paper-I By.Prof.Miss.Bavale A.T Page 5


ALGOL contributed a notation for describing the structure of a programming language, Backus–Naur Form, which
in some variation became the standard tool for stating the syntax (grammar) of programming languages. ALGOL
was widely used in Europe, and for many years it remained the language in which computer algorithms were
published. Many important languages, such as Pascal and Ada (both described later), are its descendants.

4.COBOL:-COBOL (common business oriented language) has been heavily used by businesses since its
inception in 1959. A committee of computer manufacturers and users and U.S. government organizations
established CODASYL (Committee on Data Systems and Languages) to develop and oversee the language standard
in order to ensure its portability across diverse systems.

COBOL uses an English-like notation—novel when introduced. Business computations organize and manipulate
large quantities of data, and COBOL introduced the record data structure for such tasks. A record
clusters heterogeneous data such as a name, ID number, age, and address into a single unit. This contrasts with
scientific languages, in which homogeneous arrays of numbers are common. Records are an important example of
“chunking” data into a single object, and they appear in

5.BASIC:-BASIC (beginner’s all-purpose symbolic instruction code) was designed at Dartmouth College in
the mid-1960s by John Kemeny and Thomas Kurtz. It was intended to be easy to learn by novices,
particularly non-computer science majors, and to run well on a time-sharing computer with many users. It
had simple data structures and notation and it was interpreted: a BASIC program was translated line-by-line
and executed as it was translated, which made it easy to locate programming errors.

Its small size and simplicity also made BASIC a popular language for early personal computers. Its recent forms
have adopted many of the data and control structures of other contemporary languages, which makes it more
powerful but less convenient for beginners.

6.Pascal:-About 1970 Niklaus Wirth of Switzerland designed Pascal to teach structured programming, which
emphasized the orderly use of conditional and loop control structures without GOTO statements. Although Pascal
resembled ALGOL in notation, it provided the ability to define data types with which to organize complex
information, a feature beyond the capabilities of ALGOL as well as FORTRAN and COBOL. User-defined data
types allowed the programmer to introduce names for complex data, which the language translator could then check
for correct usage before running a program.

During the late 1970s and ’80s, Pascal was one of the most widely used languages for programming instruction. It
was available on nearly all computers, and, because of its familiarity, clarity, and security, it was used for
production software as well as for education.

7.Ada:-Ada was named for Augusta Ada King, countess of Lovelace, who was an assistant to the 19th-century
English inventor Charles Babbage, and is sometimes called the first computer programmer. Ada, the language, was
developed in the early 1980s for the U.S. Department of Defense for large-scale programming. It combined Pascal-
like notation with the ability to package operations and data into independent modules. Its first form, Ada 83, was
not fully object-oriented, but the subsequent Ada 95 provided objects and the ability to construct hierarchies of
them. While no longer mandated for use in work for the Department of Defense, Ada remains an effective language
for engineering large programs.

Unit - III Computer languages Paper-I By.Prof.Miss.Bavale A.T Page 6


2.Object-oriented programming (OOP) is a programming paradigm based on the concept of
“objects”, which may contain data, in the form of fields, often known as attributes; and code, in the form of
procedures, often known as methods. In OOP, computer programs are designed by making them out of objects that
interact with one another. Object-oriented languages help to manage complexity in large programs. Objects package
data and the operations on them so that only the operations are publicly accessible and internal details of the data
structures are hidden. This information hiding made large-scale programming easier by allowing a programmer to
think about each part of the program in isolation. In addition, objects may be derived from more general ones,
“inheriting” their capabilities. Such an object hierarchy made it possible to define specialized objects without
repeating all that is in the more general ones.

Object-oriented programming began with the Simula language (1967), which added information hiding to ALGOL.
Another influential object-oriented language was Smalltalk (1980), in which a program was a set of objects that
interacted by sending messages to one another.

1.C++:-The C++ language, developed by Bjarne Stroustrup at AT&T in the mid-1980s, extended C by adding
objects to it while preserving the efficiency of C programs. It has been one of the most important languages for both
education and industrial programming. Large parts of many operating systems, such as the Microsoft Corporation’s
Windows 98, were written in C++.

2.Java:-In the early 1990s, Java was designed by Sun Microsystems, Inc., as a programming language for
the World Wide Web (WWW). Although it resembled C++ in appearance, it was fully object-oriented. In particular,
Java dispensed with lower-level features, including the ability to manipulate data addresses, a capability that is
neither desirable nor useful in programs for distributed systems. In order to be portable, Java programs are translated
by a Java Virtual Machine specific to each computer platform, which then executes the Java program. In addition to
adding interactive capabilities to the Internet through Web “applets,” Java has been widely used for programming
small and portable devices, such as mobile telephones.

3.Visual Basic:-Visual Basic was developed by Microsoft to extend the capabilities of BASIC by adding objects
and “event-driven” programming: buttons, menus, and other elements of graphical user interfaces (GUIs). Visual
Basic can also be used within other Microsoft software to program small routines.

II. What is declarative programming?

Declarative languages, also called nonprocedural or very high level, are programming languages in which (ideally) a
program specifies what is to be done rather than how to do it. In such languages there is less difference between the
specification of a program and its implementation than in the procedural languages described so far. The two
common kinds of declarative languages are logic and functional languages.

Logic programming languages, of which PROLOG (programming in logic) is the best known, state a program as a
set of logical relations (e.g., a grandparent is the parent of a parent of someone). Such languages are similar to
the SQL database language. A program is executed by an “inference engine” that answers a query by searching these
relations systematically to make inferences that will answer a query. PROLOG has been used extensively in natural
language processing and other AI programs.

1.Functional language

Functional programming languages define every computation as a mathematical evaluation. They focus on the
application of functions. Many of the functional programming languages are bound to mathematical

Unit - III Computer languages Paper-I By.Prof.Miss.Bavale A.T Page 7


calculations.Functional languages have a mathematical style. A functional program is constructed by applying
functions to arguments. Functional languages, such as LISP, ML, and Haskell, are used as research tools in language
development, in automated mathematical theorem provers, and in some commercial projects.

1.Charity:-It is a purely functional, not-Turing-complete language, which means that all its programs are guaranteed
to terminate. Charity was designed at the University of Calgary, a public University in Canada.

2.Clean:-It is a purely functional programming language that supports portability across platforms, automatic garbage
collection, multiple data structures and referential transparency, which means that a function with a given input will
always give the same output.

3.Curry:-It is a functional logic programming language that implements functional and logic programming as
well as constraint programming, wherein the relationships between variables are stated in the form of
constraints.

4.Erlang:-It is a concurrent programming language that includes a sequential subset, which supports functional
programming. Ericsson developed Erlang as a distributed soft real-time and fault-tolerant language and released it as
an open source computer programming language in 1998. It is one of the most popularly used functional
programming languages.

5.F#:-It targets the .NET Framework and supports both functional as well as imperative object-oriented
programming. Don Syme at the Microsoft Research developed this language, which is now being developed at the
Microsoft Developer Division. F Sharp, as it is called, will soon be integrated into the .NET Framework and Visual
Studio.

6.Haskell:-Named in honor of Haskell Curry, a logician, Haskell is a standardized purely functional language. It
supports pattern matching, definable operators, single assignment, algebraic data types and recursive functions.

7.Joy:-It is a purely functional language that is based on a composition of functions. Manfred von Thun of La Trobe
University in Australia developed this language.

8.Kite:-It came up in 2006 with a feature set consisting of a blend of object-oriented and functional programming
features. It is a fast-running language. Interestingly, Kite uses the pipe character for functional calls rather than using
the period or arrow characters in other languages.

9.ML:-Robin Milner and his associates at the University of Edinburgh came up with ML in the 1970s. It is an impure
functional language as it supports imperative programming. Standard ML is popular among compiler writers and is a
modular, functional programming language. Alice is a dialect of Standard ML, which supports distributed computing,
multithreading and constraint programming. Caml is another dialect of ML and is a statically typed language that
supports automatic memory management. Ocaml is the implementation of Caml that is developed as an open source
project. JoCaml is a version of Ocaml based on join-calculus.

2.Logic-based Programming Languages

Logic programming is a type of programming paradigm which is largely based on formal logic. Any program written
in a logic programming language is a set of sentences in logical form, expressing facts and rules about some problem
domain. (Wikipedia)

Unit - III Computer languages Paper-I By.Prof.Miss.Bavale A.T Page 8


1.ALF:-Algebraic Logic Functional Programming Language is a multi-paradigm programming language that is a
combination of functional programming and logic programming. ALF program statements are compiled into
instructions of an abstract machine. An emulator written in C executes the programs of the abstract machine.

2.Fril:-Fril language was designed by Trevor Martin and Jim Baldwin at the University of Bristol in the 1980s. It is
for first-order predicate calculus. It supports fuzzy sets and metaprogramming and is based on the Prolog syntax.

3.Janus:-Janus supports concurrent and constraint programming.

4.Leda:-This computer programming language is a blend of logic-based, functional, imperative and object-oriented
programming. It is thus one of the multi-paradigm languages.

5.Oz:-It is a multi-paradigm language that supports functional, logic-based, imperative and object-oriented
programming. Oz also supports concurrent and distributed programming. Constraint programming that is supported
by Oz is one of the strengths of this language.

6.Poplog:-It is a powerful multi-paradigm software development environment whose core language is POP-11. All
the languages of this development environment share a common language editor and are incrementally compiled
programming languages.

7.Prolog:-It is a general-purpose programming language that supports logic programming and is often linked with
artificial intelligence and computational linguistics. The language is declarative and the program logic is expressed in
the form of relations. Mercury is a functional logic programming language that is based on Prolog. Strawberry Prolog
is a dialect of Prolog, which is supposed to be easy to use. Visual Prolog is a strongly typed extension of Prolog that
supports object-oriented programming. It is a compiled logic-based programming language.

8.ROOP:-It is a multi-paradigm language that is built on C++. It is intended to be used with artificial intelligence
systems. Its features offer a blend of procedural, logic-based, and object-oriented programming.

III. Rule-based languages:


Rule-based languages instantiate rules when activated by conditions in a set of data. Some set which gets selected
and the statements which belonged to those rules get executed.
Example:
Awk,CLIPS,Constraint Handling Rules,Drools,Jess,OPS5,Prolog

 Tools in software development kit: translators (Compiler, interpreter,


Assembler
1.Assembler: A computer will not understand any program written in a language, other than its machine
language. The programs written in other languages must be translated into the machine language. Such translation is
performed with the help of software. A program which translates an assembly language program into a machine
language program is called an assembler. If an assembler which runs on a computer and produces the machine codes
for the same computer then it is called self assembler or resident assembler. If an assembler that runs on a computer
and produces the machine codes for other computer then it is called Cross Assembler.

Assemblers are further divided into two types: One Pass Assembler and Two Pass Assembler. One
pass assembler is the assembler which assigns the memory addresses to the variables and translates the source code
into machine code in the first pass simultaneously. A Two Pass Assembler is the assembler which reads the source

Unit - III Computer languages Paper-I By.Prof.Miss.Bavale A.T Page 9


code twice. In the first pass, it reads all the variables and assigns them memory addresses. In the second pass, it
reads the source code and translates the code into object code.

2.Compiler: It is a program which translates a high level language program into a machine language program.
A compiler is more intelligent than an assembler. It checks all kinds of limits, ranges, errors etc. But its program run
time is more and occupies a larger part of the memory. It has slow speed. Because a compiler goes through the entire
program and then translates the entire program into machine codes. If a compiler runs on a computer and produces
the machine codes for the same computer then it is known as a self compiler or resident compiler. On the other hand,
if a compiler runs on a computer and produces the machine codes for other computer then it is known as a cross
compiler.

3.Interpreter: An interpreter is a program which translates statements of a program into machine code. It
translates only one statement of the program at a time. It reads only one statement of program, translates it and
executes it. Then it reads the next statement of the program again translates it and executes it. In this way it proceeds
further till all the statements are translated and executed. On the other hand, a compiler goes through the entire
program and then translates the entire program into machine codes. A compiler is 5 to 25 times faster than an
interpreter.

By the compiler, the machine codes are saved permanently for future reference. On the other hand,
the machine codes produced by interpreter are not saved. An interpreter is a small program as compared to compiler.
It occupies less memory space, so it can be used in a smaller system which has limited memory space.

4.Linker: In high level languages, some built in header files or libraries are stored. These libraries are
predefined and these contain basic functions which are essential for executing the program. These functions are
linked to the libraries by a program called Linker. If linker does not find a library of a function then it informs to
compiler and then compiler generates an error. The compiler automatically invokes the linker as the last step in
compiling a program.

Not built in libraries, it also links the user defined functions to the user defined libraries. Usually a
longer program is divided into smaller subprograms called modules. And these modules must be combined to
execute the program. The process of combining the modules is done by the linker.

5.Loader: Loader is a program that loads machine codes of a program into the system memory. In Computing,
a loader is the part of an Operating System that is responsible for loading programs. It is one of the essential stages
in the process of starting a program. Because it places programs into memory and prepares them for execution.
Loading a program involves reading the contents of executable file into memory. Once loading is complete, the
operating system starts the program by passing control to the loaded program code. All operating systems that
support program loading have loaders. In many operating systems the loader is permanently resident in memory.

6.Header Files : The files that tell the compiler how to call some functionality (without knowing how the
functionality actually works) are called header files. They contain the function prototypes. They also contain Data
types and constants used with the libraries. We use #include to use these header files in programs. These files end
with .h extension.
7.Library : Library is the place where the actual functionality is implemented i.e. they contain function body.
Libraries have mainly two categories :
 Static
 Shared or Dynamic
Static : Static libraries contains object code linked with an end user application and then they become the part of the
executable. These libraries are specifically used at compile time which means the library should be present in correct
location when user wants to compile his/her C or C++ program. In windows they end with .lib extension and
with .a for MacOS.
Shared or Dynamic : These libraries are only required at run-time i.e, user can compile his/her code without using
these libraries. In short these libraries are linked against at compile time to resolve undefined references and then its
distributed to the application so that application can load it at run time. For example, when we open our game

Unit - III Computer languages Paper-I By.Prof.Miss.Bavale A.T Page 10


folders we can find many .dll(dynamic link libraries) files. As these libraries can be shared by multiple programs,
they are also called as shared libraries.These files end with .dll or .lib extensions. In windows they end with .dll
extension.
Example : Math.h is a header file which includes the prototype for function calls like sqrt(), pow() etc,
whereas libm.lib, libmmd.lib, libmmd.dll are some of the math libraries. In simple terms a header file is like a
visiting card and libraries are like a real person, so we use visiting card(Header file) to reach to the actual
person(Library).
Let’s see the difference between these two in tabular form,so that it can be easily comparable:
Let’s see the difference between these two in tabular form,so that it can be easily comparable:

HEADER FILES LIBRARY FILES


They have the extension .h They have the extension .lib
They contain function declaration. They contain function definations
They are available inside “include sub directory” which They are available inside “lib sub directory” which itself is
itself is in Turbo compiler. in Turbo compiler.

Header files are human readable.Since they are in the form Library files are non human readable.Since they are in the
of source code. form of machine code.
Header files in our program are included by using a
command #include which is internally handle by pre- Library files in our program are included in last stage by
processor. special software called as linker.

 Namespaces
A namespace is designed for providing a way to keep one set of names separate from another.
The class names declared in one namespace does not conflict with the same class names
declared in another.

Defining a Namespace
A namespace definition begins with the keyword namespace followed by the namespace name
as follows −
namespace namespace_name {
// code declarations
}
To call the namespace-enabled version of either function or variable, prepend the namespace
name as follows −
namespace_name.item_name;
The following program demonstrates use of namespaces −

using System;

namespace first_space {
class namespace_cl {
public void func() {

Unit - III Computer languages Paper-I By.Prof.Miss.Bavale A.T Page 11


Console.WriteLine("Inside first_space");
}
}
}
namespace second_space {
class namespace_cl {
public void func() {
Console.WriteLine("Inside second_space");
}
}
}
class TestClass {
static void Main(string[] args) {
first_space.namespace_cl fc = new first_space.namespace_cl();
second_space.namespace_cl sc = new second_space.namespace_cl();
fc.func();
sc.func();
Console.ReadKey();
}
}
When the above code is compiled and executed, it produces the following result −
Inside first_space
Inside second_space

 What’s a Virtual Machine?


It’s not hard to guess that a virtual machine (VM) is a virtual emulation of a computer operating system. Beyond
that, though, there are two different implementations of this kind of system abstraction.

System virtual machines exist as fully-functional operating systems and are typically created as a substitute for
using a physical machine. In this way multiple environments can run on the same machine simultaneously. But, that
doesn’t sound like our beloved CLR and JVM.

The Common Language Runtime (CLR) and Java Virtual Machine (JVM) are both process virtual machines. That
means that rather than executing an entire operating system, they are specifically designed to run a process or
program without being dependent on the platform environment.

 A Closer Look at the Similarities Between the CLR and JVM

The CLR and JVM are both virtual machines and they both perform platform-independent operations, namely,
executing compiled source code. Essentially, these virtual machines both act as an intermediary step between the
programmer’s source code and the system’s machine code, allowing for greater usability by various types of
processors. In the image below, you can see how the high-level functions of the two are practically identical.

Unit - III Computer languages Paper-I By.Prof.Miss.Bavale A.T Page 12


Beyond their basic functionality, both also include methods for garbage collection, runtime-level security and
exception handling. And one last similarity to mention, both employ stack-based operations, the most common
approach to storing and retrieving operands and their results.

 Common Language Runtime (CLR)


The Common Language Runtime in the .NET Framework is the Virtual Machine component
that handles program execution for various languages such as C#, F#, Visual Basic .NET, etc.
The managed execution environment is provided by giving various services such as memory
management, security handling, exception handling, garbage collection, thread management, etc.
The Common Language Runtime implements the VES (Virtual Execution System) which is a
run time system that provides a managed code execution environment. The VES is defined in
Microsoft’s implementation of the CLI (Common Language Infrastructure).

 Architecture of Common Language Runtime

A diagram that demonstrates the architecture of Common Language Runtime is given as follows:

There are multiple components in the architecture of Common Language Runtime. Details about
these are given as follows:
 Base Class Library Support: The Common Language Runtime provides support for the base class
library. The BCL contains multiple libraries that provide various features such
as Collections, I/O, XML, DataType definitions, etc. for the multiple .NET programming languages.
 Thread Support: The CLR provides thread support for managing the parallel execution of multiple
threads. The System.Threading class is used as the base class for this.
 COM Marshaller: Communication with the COM (Component Object Model) component in the
.NET application is provided using the COM marshaller. This provides the COM interoperability
support.
 Type Checker: Type safety is provided by the type checker by using the Common Type System
(CTS) and the Common Language Specification (CLS) that are provided in the CLR to verify the
types that are used in an application.

Unit - III Computer languages Paper-I By.Prof.Miss.Bavale A.T Page 13


 Exception Manager: The exception manager in the CLR handles the exceptions regardless of
the .NET Language that created them. For a particular application, the catch block of the exceptions
are executed in case they occur and if there is no catch block then the application is terminated.
 Security Engine: The security engine in the CLR handles the security permissions at various levels
such as the code level, folder level, and machine level. This is done using the various tools that are
provided in the .NET framework.
 Debug Engine: An application can be debugged during the run-time using the debug engine. There
are various ICorDebug interfaces that are used to track the managed code of the application that is
being debugged.
 JIT Compiler: The JIT compiler in the CLR converts the Microsoft Intermediate Language
(MSIL) into the machine code that is specific to the computer environment that the JIT compiler
runs on. The compiled MSIL is stored so that it is available for subsequent calls if required.
 Code Manager: The code manager in CLR manages the code developed in the .NET framework
i.e. the managed code. The managed code is converted to intermediate language by a language-
specific compiler and then the intermediate language is converted into the machine code by the
Just-In-Time (JIT) compiler.
 Garbage Collector: Automatic memory management is made possible using the garbage collector
in CLR. The garbage collector automatically releases the memory space after it is no longer
required so that it can be reallocated.
 CLR Loader: Various modules, resources, assemblies, etc. are loaded by the CLR loader. Also,
this loader loads the modules on demand if they are actually required so that the program
initialization time is faster and the resources consumed are lesser.
 JVM (Java Virtual Machine) Architecture
1. Java Virtual Machine
2. Internal Architecture of JVM

JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which
java bytecode can be executed.

JVMs are available for many hardware and software platforms (i.e. JVM is platform dependent).

 What is JVM
It is:

1. A specification where working of Java Virtual Machine is specified. But implementation provider is
independent to choose the algorithm. Its implementation has been provided by Oracle and other companies.
2. An implementation Its implementation is known as JRE (Java Runtime Environment).
3. Runtime Instance Whenever you write java command on the command prompt to run the java class, an
instance of JVM is created.

 JVM Architecture
Let's understand the internal architecture of JVM. It contains classloader, memory area, execution engine etc.

Unit - III Computer languages Paper-I By.Prof.Miss.Bavale A.T Page 14


1) Classloader
Classloader is a subsystem of JVM which is used to load class files. Whenever we run the java program, it is loaded
first by the classloader. There are three built-in classloaders in Java.

1. Bootstrap ClassLoader: This is the first classloader which is the super class of Extension classloader. It
loads the rt.jar file which contains all class files of Java Standard Edition like java.lang package classes,
java.net package classes, java.util package classes, java.io package classes, java.sql package classes etc.
2. Extension ClassLoader: This is the child classloader of Bootstrap and parent classloader of System
classloader. It loades the jar files located inside $JAVA_HOME/jre/lib/ext directory.
3. System/Application ClassLoader: This is the child classloader of Extension classloader. It loads the
classfiles from classpath. By default, classpath is set to current directory. You can change the classpath
using "-cp" or "-classpath" switch. It is also known as Application classloader.

1. //Let's see an example to print the classloader name


2. public class ClassLoaderExample
3. {
4. public static void main(String[] args)
5. {
6. // Let's print the classloader name of current class.
7. //Application/System classloader will load this class
8. Class c=ClassLoaderExample.class;
9. System.out.println(c.getClassLoader());
10. //If we print the classloader name of String, it will print null because it is an
11. //in-built class which is found in rt.jar, so it is loaded by Bootstrap classloader
12. System.out.println(String.class.getClassLoader());
13. }
14. }

Output:

sun.misc.Launcher$AppClassLoader@4e0e2f2a
null

These are the internal classloaders provided by Java. If you want to create your own classloader, you need to extend
the ClassLoader class.

Unit - III Computer languages Paper-I By.Prof.Miss.Bavale A.T Page 15


2) Class(Method) Area
Class(Method) Area stores per-class structures such as the runtime constant pool, field and method data, the code for
methods.

3) Heap
It is the runtime data area in which objects are allocated.

4) Stack
Java Stack stores frames. It holds local variables and partial results, and plays a part in method invocation and
return.

Each thread has a private JVM stack, created at the same time as thread.

A new frame is created each time a method is invoked. A frame is destroyed when its method invocation completes.

5) Program Counter Register


PC (program counter) register contains the address of the Java virtual machine instruction currently being executed.

6) Native Method Stack


It contains all the native methods used in the application.

7) Execution Engine
It contains:

1. A virtual processor
2. Interpreter: Read bytecode stream then execute the instructions.
3. Just-In-Time(JIT) compiler: It is used to improve the performance. JIT compiles parts of the byte code
that have similar functionality at the same time, and hence reduces the amount of time needed for
compilation. Here, the term "compiler" refers to a translator from the instruction set of a Java virtual
machine (JVM) to the instruction set of a specific CPU.

8) Java Native Interface


Java Native Interface (JNI) is a framework which provides an interface to communicate with another application
written in another language like C, C++, Assembly etc. Java uses JNI framework to send output to the Console or
interact with OS libraries.What is an IDE?

 (IDE) An integrated development environment :-


(IDE) is software for building applications that combines common developer tools
into a single graphical user interface (GUI). An IDE typically consists of:
Unit - III Computer languages Paper-I By.Prof.Miss.Bavale A.T Page 16
 Source code editor: A text editor that can assist in writing software code with
features such as syntax highlighting with visual cues, providing language specific
auto-completion, and checking for bugs as code is being written.
 Local build automation: Utilities that automate simple, repeatable tasks as part of
creating a local build of the software for use by the developer, like compiling
computer source code into binary code, packaging binary code, and running
automated tests.
 Debugger: A program for testing other programs that can graphically display the
location of a bug in the original code.
Popular kinds of IDEs

There are many different technical and business use cases for IDEs, which likewise
means there are many proprietary and open source IDE options on the market.
Typically, the most important differentiating characteristics between IDEs are:

 The number of supported languages: Some IDEs are dedicated to one language, and
so are a better match for a specific programming paradigm. IntelliJ, for instance, is
known primarily as a Java IDE. Other IDEs have a broad array of supported
languages all in one, like the Eclipse IDE which supports Java, XML, Python, and
others.
 Supported operating system(s): A developer’s operating system will constrain
which IDEs are viable (unless an IDE is cloud-based), and if the application being
developed is intended for an end user with a specific operating system (like Android
or iOS), this may be an additional constraint.
 Automation features: Even though most IDEs include the 3 key features of a text
editor, build automation, and debugger, many include support for additional features
like refactoring, code search, and continuous integration and continuous
deployment (CI/CD) tools.
 Impact on system performance: An IDE’s memory footprint may be important to
consider if a developer wants to run other memory-intensive applications
concurrently.
 Plugins and extensions: Some IDEs include the ability to customize workflows to
match a developer’s needs and preferences.

 Editors and Its types in System Programming


Editors or text editors are software programs that enable the user to create and edit text files. In the field of
programming, the term editor usually refers to source code editors that include many special features for writing and
editing code. Notepad, Wordpad are some of the common editors used on Windows OS and vi, emacs, Jed, pico are
the editors on UNIX OS. Features normally associated with text editors are — moving the cursor, deleting,
replacing, pasting, finding, finding and replacing, saving etc.

Unit - III Computer languages Paper-I By.Prof.Miss.Bavale A.T Page 17


Types of Editors
Therre are generally five types of editors as described below:
1. Line editor: In this, you can only edit one line at a time or an integral number of lines. You cannot have a
free-flowing sequence of characters. It will take care of only one line.
Ex : Teleprinter, edlin, teco
2. Stream editors: In this type of editors, the file is treated as continuous flow or sequence of characters instead
of line numbers, which means here you can type paragraphs.
Ex : Sed editor in UNIX
3. Screen editors: In this type of editors, the user is able to see the cursor on the screen and can make a copy,
cut, paste operation easily. It is very easy to use mouse pointer.
Ex : vi, emacs, Notepad
4. Word Processor: Overcoming the limitations of screen editors, it allows one to use some format to insert
images, files, videos, use font, size, style features. It majorly focuses on Natural language.
5. Structure Editor: Structure editor focuses on programming languages. It provides features to write and edit
source code.
Ex : Netbeans IDE, gEdit.
Some other editors:
 Full Screen Editors: In computers, a full-screen editor or distraction-free editor is a text editor that occupies
full display with the purpose of sidelining the user from the OS and the other applications. It helps the user to
focus on writing only and do not get distracted by the other applications and the cluttered interface. Often
fullscreen editors has a dark background and a text field with a light colored text. They include customizable
interfaces and feature like word count.
Ex : Acme, Coderoom, FocusWriter
 Multiple Window Editor: Multiple window editor allows you to work on more than one file one file at a
time and cut and paste text from file into another via yanking and putting. The two fundamental concepts that
lie behind multi-window editors are buffer and windows.
Buffer: Buffer holds the text to be edited. The text may come from a file or a brand new text that you want to
write on a file. A file only has one buffer associated with it.
Windows: Windows provides a view to the buffer to see what the buffer holds and edit and modify it. A
buffer may have multiple windows. Any changes made in any of the windows will be reflected in all other
windows associated with the same buffer. Once the last window associated with a buffer is closed, the file
gets hidden. But if you have made any changes to the buffer and not have written them into the disk, it may
not allow you to close the window.
 DOS-Editor: MS-DOS editor or sometimes also known as just edit is a character based text editor that comes
with MS-DOS and a 32-bit version of windows. Previously, it was QBASIC running in editor mode but after
DOS-7, it became a standalone program. It is also used as a substitute for Notepad since notepad can work
only on small files, DOS editor can work on around 66, 257 lines and up to 5 MB file size. It has features like
a customizable color theme, it can open up to 9 files at a time, it can open files in binary mode.
 VI editor : The vi editor (short name for the visual editor) is a screen editor which is available in UNIX OS.
Vi has no menus instead it uses a combination of keystrokes to accomplish tasks. An improved version of vi
is vim(vi improved). Vi editor is usually available in all versions of UNIX OS, its implementation is very
easy, it requires only a few resources and it is more user-friendly.
 Online Editors: Online text editors is an interface for editing the texts within a web browser. It aims to
reduce the efforts made by the user by directly editing and updating into a valid HTML markup language.
Internet Explorer added first the feature of “design mode”. The design mode allows the user to edit their
document and it also allows the use of the cursor to do the editing.
Ex : CKEditor, SnapEditor, designmode by Internet Explorer.

Unit - III Computer languages Paper-I By.Prof.Miss.Bavale A.T Page 18

You might also like