Programming Language

Programming Language

Programing Language

Machine Language and Assembly Language:

Machine language, or machine code, is a low-level language comprised of binary digits (ones and zeros). High-level languages, such as Swift and C++ must be compiled into machine language before the code is run on a computer.

Since computers are digital devices, they only recognize binary data. Every program, video, image, and character of text is represented in binary. This binary data, or machine code, is processed as input by the CPU. The resulting output is sent to the operating system or an application, which displays the data visually.

For example, the ASCII value for the letter "A" is 01000001 in machine code, but this data is displayed as "A" on the screen. An image may have thousands or even millions of binary values that determine the color of each pixel.

While machine code is comprised of 1s and 0s, different processor architectures use different machine code. For example, a PowerPC processor, which has a RISC (Stands for "Reduced Instruction Set Computing" and is pronounced "risk." It is arguably the fastest and most efficient microprocessor technology available today) architecture, requires different code than an Intel x86 processor, which has a CISC (Stands for "Complex Instruction Set Computing"

This is a type of microprocessor design. The CISC architecture contains a large set of computer instructions that range from very simple to very complex and specialized) architecture. A compiler must compile high-level source code for the correct processor architecture in order for a program to run correctly.

An assembly language is a low-level programming language designed for a specific type of processor. It may be produced by compiling source code from a high-level programming language (such as C/C++) but can also be written from scratch. Assembly code can be converted to machine code using an assembler.

While assembly languages differ between processor architectures, they often include similar instructions and operators. Below are some examples of instructions supported by x86 processors.

  • MOV - move data from one location to another
  • ADD - add two values
  • SUB - subtract a value from another value
  • PUSH - push data onto a stack
  • POP - pop data from a stack
  • JMP - jump to another location
  • INT - interrupt a process

The following assembly language can be used to add the numbers 3 and 4:

mov a, 3 (It loads 3 into the register "a")

mov b, 4 (It loads 4 into the register "b")

add a, b, c (It adds "a" and "b" and stores the result (7) in "c")

Difference between Machine and Assembly Language:

Basis of Difference Machine Language Assembly Language
Level of Programming Language Machine language ranks as the lowest level programming language. In this language,instructions are executed directly via the Central Processing Unit Assembly language refers to a low-level  programming  languageneeds an assembler for converting the instructions to machine or object codes.
Ease of comprehension Machine language 
cannot be deciphered by humans and can be comprehended only by 
computers.
Assembly language can be understood, used and applied by 
humans.
Nature of syntax Machine languages 
comprise of binary 
digits 0s and 1s.
Assembly languages have a syntax
that is similar to the English 
language, therefore, they can be 
understood by programmers and 
users alike.
Dependency Machine languages are platform -dependent and 
their features vary 
accordingly.
Assembly language comprises of 
standard instruction sets.
Areas of 
application
Machine language 
serves as a machine 
code only.
Assembly languages are used for real-time systems and microprocessor-based applications/ devices.
Usage of 
mnemonics
Machine language uses sequences of bits for giving commands. One 
depicts the true or on 
state; on the other hand, zero depicts the false or off state. The 
conversion of high-level programming language to machine language is dependent on the CPU. “Mnemonics” are not required in machine language.
Assembly language does not 
require users to remember opcodes. It uses “mnemonics” names 
and symbols rather than raw 
sequences of bits. The codes in 
assembly languages are slightly 
more readable and can be mapped 
to machine code by humans.
Generation of 
programming 
language
Machine languages are 
first generation 
programming 
languages.
Assembly languages are second 
generation programming 
languages.
Modification Machine language do 
not support any type of 
modification.
An assembly 
programming language can be 
modified easily.
Risk of errors The risk of errors 
existing in the syntax of 
machine language is 
high.
The risk of errors existing in 
assembly language is 
comparatively low.
Memorization Binary codes cannot be 
memorized.
It is possible to memorize the 
commands given in assembly 
languages.
Compiler No compiler is 
necessary for executing 
commands.
A compiler, also known as an 
assembler, is needed for the proper 
execution of assembly language 
commands.

High-Level and Low-Level Language:

High-level language:

It is a programming language designed to simplify computer programming. It is "high-level" since it is several steps removed from the actual code run on a computer's processor. High-level source code contains easy-to-read syntax that is later converted into a low-level language, which can be recognized and run by a specific CPU.

Most   common  programming  languages   are   considered  high-level languages.

Examples include:

C++, C#, Cobol, Fortan, Java, Javascript, Objective C, Pascal, Perl, PHP, Python, Swift

Each of these languages uses different syntax. Some are designed for writing desktop software programs, while others are best-suited for web development. But they all are considered high-level since they must be processed by a compiler or interpreter before the code is executed.

Source code written in languages like C++ and C# must be compiled into machine code in order to run. The compilation process converts the human-readable syntax of the high-level language into low-level code for a specific processor. Source code written in scripting languages like Perl and PHP can be run through an interpreter, which converts the high-level code into a low-level language.

Low-level language:

It is a type of programming language that contains basic instructions recognized by

  • Unlike high-level languages used by software developers, low-level code is often cryptic and not human-readable. Two common types of low-level programming languages are assembly language and machine language.

Software programs and scripts are written in high-level languages, like C#, Swift, and PHP. A software developer can create and edit source code in a high-level language using a programming IDE or even a basic text editor. However, the code is not recognized directly by the CPU. Instead, it must be compiled into a low-level language.

Assembler, Compiler, and Interpreter

Assembler:

An assembler is a program that converts assembly language into machine code. It takes the basic commands and operations from assembly code and converts them into binary code that can be recognized by a specific type of processor.

Assemblers are similar to compilers in that they produce executable code. However, assemblers are more simplistic since they only convert low-level code (assembly language) to machine code. Since each assembly language is designed for a specific processor, assembling a program is performed using a simple one-to-one mapping from assembly code to machine code. Compilers, on the other hand, must convert generic high-level source code into machine code for a specific processor.

Compiler:

A compiler is a software program that compiles program source code files into an executable program. It is included as part of the integrated development environment IDE with most programming software packages.

The compiler takes source code files that are written in a high-level language, such as C, C++, or Java, and compiles the code into a low-level language, such as machine code or assembly code. This code is created for a specific processor type, such as and Intel Pentium or PowerPC. The program can then be recognized by the processor and run from the operating system.

After a compiler compiles source code files into a program, the program cannot be modified. Therefore, any changes must be made in the source code and the program must be recompiled. Fortunately, most modern compilers can detect what changes were made and only need to recompile the modified files, which save programmers a lot of time. This can help reduce programmers' 100 hour work weeks before project deadlines to around 90 or so.

Interpreter:

An interpreter is a program that reads and executes code. This includes source code, pre-compiled code, and scripts. Common interpreters include Perl, Python, and Ruby interpreters, which execute Perl, Python, and Ruby code respectively.

Interpreters and compilers are similar, since they both recognize and process source code. However, a compiler does not execute the code like and interpreter does. Instead, a compiler simply converts the source code into machine code, which can be run directly by the operating system as an executable program. Interpreters bypass the compilation process and execute the code directly.

Since interpreters read and execute code in a single step, they are useful for running scripts and other small programs. Therefore, interpreters are commonly installed on Web servers, which allow developers to run executable scripts within their webpages. These scripts can be easily edited and saved without the need to recompile the code.

Problem-solving and programming

Algorithms:

An algorithm is a set of instructions designed to perform a specific task. This can be a simple process, such as multiplying two numbers, or a complex operation, such as playing a compressed video file. Search engines use proprietary algorithms to display the most relevant results from their search index for specific queries.

This is an algorithm to add two numbers and display the result.

Step 1 − START

Step 2 − declare three integers a, b & c

Step 3 − define values of a & b

Step 4 − add values of a & b

Step 5 − store output of step 4 to c

Step 6 − print c

Step 7 − STOP

Flow Charts:

A flowchart is a diagram that describes a process or operation. It includes multiple steps, which the process "flows" through from start to finish. Common uses for flowcharts include developing business plans, defining troubleshooting steps, and designing mathematical algorithms. Some flowcharts may only include a few steps, while others can be highly complex, containing hundreds of possible outcomes.

Flowcharts typically use standard symbols to represent different stages or actions within the chart.

Different flowchart shapes have different conventional meanings. The meanings of some of the more common shapes are as follows:

Terminator

The terminator symbol represents the starting or ending point of the system.

Process

A box indicates some particular operation.

Document

This represents a printout, such as a document or a report.

Decision

A diamond represents a decision or branching point. Lines coming out from the diamond indicate different possible situations, leading to different sub-processes.

Data

It represents information entering or leaving the system. An input might be an order from a customer. Output can be a product to be delivered.

On-Page Reference

This symbol would contain a letter inside. It indicates that the flow continues on a matching symbol containing the same letter somewhere else on the same page.

Off-Page Reference

This symbol would contain a letter inside. It indicates that the flow continues on a matching symbol containing the same letter somewhere else on a different page.

Delay or Bottleneck

It identifies a delay or a bottleneck.

Flow

Lines represent the flow of the sequence and direction of a process.

Flowchart Example: Calculate Profit and Loss

The flowchart example below shows how profit and loss can be calculated.

Fig: Flow Chart of Calculate Profit and loss

Three Basic Operations

Sequence:

Sequence is the order we want the computer to execute the instructions we provide as programmers. For example, do this first, then do this, then do that, and so forth.

#include

void main() {

printf("What is your name? \n");

printf("My name is Ram.");

}

Output:

What is your name?

My name is Ram.

Selection:

Selection defines which path of an algorithm to execute depending on some criteria. For example, if you passed a class in school, then we execute the operations that clap and cheer and play a song. But if you didn’t pass the class, then maybe we would say, “Better luck next time, hang in there!”

#include

void main () {

/* local variable definition */

int a = 100;

/* check the boolean condition */

if( a < 20 ) {

/* if condition is true then print the following */ printf("a is less than 20\n" );

} else {

/* if condition is false then print the following */ printf("a is greater than 20\n" );

}

printf("value of a is : %d\n", a);

}

Output:

A is greater than 20

Value of a is 100

Iteration:

It is looping or repeating. Many times, we want to be able to repeat a set of operations a specific number of times or until some condition occurs.

#include

void main () {

int a;

/* for loop execution */

for( a = 1; a < 5; a = a + 1 ){

printf("value of a: %d\n", a);

}

}

Output:

value of a: 1

value of a: 2

value of a: 3

value of a: 4

Procedures and Programs

Procedures:

In computer programming, a procedure is an independent code module that fulfills some concrete task and is referenced within a larger body of source code. This kind of code item can also be called a function or a sub-routine. The fundamental role of a procedure is to offer a single point of reference for some small goal or task that the developer or programmer can trigger by invoking the procedure itself.

In the programming language it is known as procedure, subroutine, function or a subprogram.

Programs:

A program is executable software that runs on a computer. It is similar to a script, but is often much larger in size and does not require a scripting engine to run. Instead, a program consists of compiled code that can run directly from the computer's operating system.

Examples of programs include Web browsers, word processors, e-mail clients, video games, and system utilities. These programs are often called applications, which can be used synonymously with "software programs." On Windows, programs typically have an .EXE file extension, while Macintosh programs have an .APP extension.

Structured Programming:

It is a programming method which aimed at improving quality, clarity and access time of computer program by the use of block structures, subroutines, for and while loops. This program features will be helpful when concept of exception handing is needed in the program. It uses various control structures, sub routines, blocks and theorem.

The theorems involved in structure programming are Sequence, Selection, Iteration and Recursion. Most of the programming language uses structured programming language features such as ALGOL, Pascal, PL/I, Ada, C, etc. The structure programming enforces a logical structure on the program being written to make it more efficient and easy to modify and understand.

The structured program consists of well-structured and separated modules. But the entry and exit in a structured program is a single-time event. It means that the program uses single-entry and single-exit elements. Therefore a structured program is well maintained, neat and clean program. This is the reason why the Structured Programming Approach is well accepted in the programming world.

Features of Structure Program:

  1. Division of Complex problems into small procedures and functions.
  2. No presence of GOTO Statement
  3. The main statement includes – If-then-else, Call and Case statements.
  4. Large set of operators like arithmetic, relational, logical, bit manipulation, shift and part word operators.
  5. Inclusion of facilities for implementing entry points and external references in program.

Advantages of Structured Programming Approach:

  1. Easier to read and understand
  2. User Friendly
  3. Easier to Maintain
  4. Mainly problem based instead of being machine based
  5. Development is easier as it requires less effort and time
  6. Easier to Debug
  7. Machine-Independent, mostly need to convert into machine code.

OOPS:

Object-oriented programming (OOP) is a programming language model in which programs are organized around data, or objects, rather than functions and logic. An object can be defined as a data field that has unique attributes and behavior. Examples of an object can range from physical entities, such as a human being that is described by properties like name and address, down to small computer programs, such as widgets. This opposes the historical approach to programming where emphasis was placed on how the logic was written rather than how to define the data within the logic.

Simply put, OOP focuses on the objects that developers want to manipulate rather than the logic required to manipulate them. This approach to programming is well-suited for programs that are large, complex and actively updated or maintained. Due to the organization of an object-oriented program, this method is also conducive to collaborative development where projects can be divided into groups. Additional benefits of OOP include code reusability, scalability, and efficiency.

Features of OOP

  • Encapsulation

The implementation and state of each object are privately held inside a defined boundary, or class. Other objects do not have access to this class or the authority to make changes but are only able to call a list of public functions, or methods. This characteristic of data hiding provides greater program security and avoids unintended data corruption.

For example, a procedure is a type of encapsulation because it combines a series of computer instructions. Likewise, a complex data type, such as a record or class, relies on encapsulation

  • Abstraction

Objects only reveal internal mechanisms that are relevant for the use of other objects, hiding any unnecessary implementation code. This concept helps developers make changes and additions over time more easily.

For Example: Suppose you want to create a banking application and you are asked to collect all the information about your customer. There are chances that you will come up with following information about the customer like Name, Address, Contact Number, Tax Information, Favorite Movie, Hubbies, and Qualification etc.

But, not all of the above information is required to create a banking application. So, you need to select only the useful information for your banking application from that pool. Data like name, address, Contact Number, tax information, etc. make sense for a banking application.

  • Inheritance

Relationships and subclasses between objects can be assigned, allowing developers to reuse a common logic while still maintaining a unique hierarchy. This property of OOP forces a more thorough data analysis, reduces development time and ensures a higher level of accuracy.

For Example: consider father class has properties like name, surname, address, contact. The child class can take properties like surname, address from father calss.

  • Polymorphism

Objects are allowed to take on more than one form depending on the context. The program will determine which meaning or usage is necessary for each execution of that object, cutting down on the need to duplicate code. For example, given a base class shape, polymorphism enables the programmer to define different area methods for any number of derived classes, such as circles, rectangles and triangles. No matter what shape an object is, applying the area method to it will return the correct results.the area method to it will return the correct results.

Advantage of OOP

  1. Improved software-development productivity: Object-oriented programming is modular, as it provides separation of duties in object-based program development. It is also extensible, as objects can be extended to include new attributes and behaviors. Objects can also be reused within an across applications. Because of these three factors – modularity, extensibility, and reusability – object-oriented programming provides improved software-development productivity over traditional procedure-based programming techniques.
  1. Improved software maintainability: For the reasons mentioned above, object-oriented software is also easier to maintain. Since the design is modular, part of the system can be updated in case of issues without a need to make large-scale changes.
  1. Faster development: Reuse enables faster development. Object-oriented programming languages come with rich libraries of objects, and code developed during projects is also reusable in future projects.
  1. Lower cost of development: The reuse of software also lowers the cost of development. Typically, more effort is put into the object-oriented analysis and design, which lowers the overall cost of development.
  1. Higher-quality software: Faster development of software and lower cost of development allows more time and resources to be used in the verification of the software. Although quality is dependent upon the experience of the teams, object-oriented programming tends to result in higher-quality software

Scripting Language:

Introduction:

A scripting language is a programming language designed for integrating and communicating with other programming languages. Some of the most widely used scripting languages are JavaScript, VBScript, PHP, Perl, Python, Ruby, ASP and Tcl. Since a scripting language is normally used in conjunction with another programming language, they are often found alongside HTML, Java or C++.

One common distinction between a scripting language and a language used for writing entire applications is that, while a programming language is typically compiled first before being allowed to run, scripting languages are interpreted from source code or bytecode one command at a time. Although scripts are widely employed in the programming world, they have recently become more associated with the World Wide Web, where they have been used extensively to create dynamic Web pages.

Client-Side Scripting:

Client-side scripting is performed to generate a code that can run on the client end (browser) without needing the server side processing. Basically, these types of scripts are placed inside an HTML document. The client-side scripting can be used to examine the user’s form for the errors before submitting it and for changing the content according to the user input. As I mentioned before, the web requires three elements for its functioning which are, client, database and server.

The effective client-side scripting can significantly reduce the server load. It is designed to run as a scripting language utilizing a web browser as a host program. For example, when a user makes a request via browser for a webpage to the server, it just sent the HTML and CSS as plain text, and the browser interprets and renders the web content in the client end.

HTML: It is the fundamental building blocks of web programming which provides the frame to the website. It describes the arrangement of the content.

CSS: CSS provides the way to design the graphic elements which help in making the appearance of the web application more attractive.

JavaScript: JavaScript is a dynamic computer programming language. It is lightweight and most commonly used as a part of web pages, whose implementations allow client-side script to interact with the user and make dynamic pages. It is an interpreted programming language with object-oriented capabilities.

Server-Side Scripting:

Server-side scripting is a technique of programming for producing the code which can run software on the server side, in simple words any scripting or programming that can run on the web server is known as server-side scripting. The operations like customization of a website, dynamic change in the website content, response generation to the user’s queries, accessing the database, and so on are performed at the server end.

The server-side scripting constructs a communication link between a server and a client (user). Earlier the server side scripting is implemented by the CGI (Common Gateway Interface) scripts. The CGI was devised to execute the scripts from programming languages such as C++ or Perl on the websites.

The server-side involves three parts: server, database, API’s and back-end web software developed by the server-side scripting language. When a browser sends a request to the server for a webpage consisting of server-side scripting, the web server processes the script prior to serving the page to the browser. Here the processing of a script could include extracting information from a database, making simple calculations, or choosing the appropriate content that is to be displayed in the client end. The script is being processed and the output is sent to the browser. The web server abstracts the scripts from the end user until serving the content, which makes the data and source code more secure.

After the advent of CGI, multiple programming languages were evolved such as PHP, Python, Ruby, ColdFusion, C#, Java, C++ and so on for server-side scripting among which some of them are described below:

PHP: It is the most prevalent server-side language used on the web which was designed to extract and manipulate information in the database. The language is used in association with SQL language for the Database. It is used in Facebook, WordPress and Wikipedia.

Python: The language is fast and contains shorter code. It is good for beginners as it concentrates on the readability and simplicity of the code. Python functions well in the object-oriented environment and used in famous sites like Youtube, Google, etc.

Ruby: It contains complex logic which packages the back-end with database utility which can also be provided by PHP and SQL.