0% found this document useful (0 votes)
13 views18 pages

Lecture 1- 21-Jan-2025

The document outlines the four levels of programming languages: machine language, assembly language, high-level language, and fourth-generation language, each designed to simplify programming for humans. It explains the roles of compilers and interpreters in translating code, the importance of syntax and semantics, and introduces object-oriented programming concepts such as classes and inheritance. Additionally, it emphasizes the necessity of translating programs into machine language for execution and the distinction between different types of errors in programming.

Uploaded by

mansouranthony54
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views18 pages

Lecture 1- 21-Jan-2025

The document outlines the four levels of programming languages: machine language, assembly language, high-level language, and fourth-generation language, each designed to simplify programming for humans. It explains the roles of compilers and interpreters in translating code, the importance of syntax and semantics, and introduces object-oriented programming concepts such as classes and inheritance. Additionally, it emphasizes the necessity of translating programs into machine language for execution and the distinction between different types of errors in programming.

Uploaded by

mansouranthony54
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Programming Language Levels

• There are four programming language levels:


• machine language (Binary Code)
• assembly language (Human readable instructions: MOV to move, ADD,…)
• high-level language (such as Java, Python, C…)
• fourth-generation language (SQL, Matlab,SAS…)

• Each type of CPU has its own specific machine language

• The other levels were created to make it easier for a human being to
write programs

36
Programming language levels
• Machine language
• Primitive instruction built into each machine
• Each type of CPU has its own language
• Binary based instructions
• => Difficult for humans to read or write.

• Assembly language
• Short English like words for commands and data
• Hardware-specific, as each CPU architecture has its own assembly
language.
• Uses mnemonics (e.g., MOV, ADD, SUB) instead of binary codes.

Both are considered to be low level languages


Programming language levels (cont’d)
• High level language
• Expressed in English like phrases

• Easier to read and write


High level Assembly Machine
Language Language Language
a+b ld [%fp-20] %o0 1101 000
0000 0111
ld [%fp-20] %o1 1101 0010
0000 0111
add %o0, %o1 1011 1111
1110 1000
Programming Languages
• A program must be translated into machine language before it can be
executed on a particular type of CPU

• This can be accomplished in several ways

• A compiler is a software tool which translates source code into a


specific target language

• Often, that target language is the machine language for a particular


CPU type
39
Compilers
• Compiler:
• Translates code in one language to equivalent code in another one

• Original code => source code,

• Target language => particular machine language

• Translate once and run whenever needed


Interpreters
• Interpreter
• similar to compiler with some differences
• Interweaves the translation and execution

• Parts of the source code


• are translated and executed one at a time

• Drawback:
• Programs run more slowly,
• as translation occurs during execution
Java Translation and Execution
• The Java compiler translates Java source code into a special
representation called bytecode (javac--------.class)

• Java bytecode is not the machine language for any traditional CPU

• Another software tool, called an interpreter, translates bytecode into


machine language and executes it (java)

• Therefore the Java compiler is not tied to any particular machine

42
JAVA translation and execution (cont’d)

JAVA
Source code

JAVA
JAVA compiler bytecode

JAVA Bytecode
interpreter compiler

Machine
code
Program development
• Software tools involved
• Editor: type a program and store in a file
• Translation from high level into executable
form
• That translation may result in errors
• You change the code to fix the problem
• Execute the program and evaluate results
errors errors

Edit and save Translate Execute


program program program
Syntax and Semantics
• The syntax rules of a language define how we can put symbols, reserved words,
and identifiers together to make a valid program
• During compilation, all syntax rules are checked. If a program is not syntactically
correct, the compiler will issue error messages and will not produce bytecode.

• The semantics of a statement in a programming language define what will


happen when that statement is executed.

• A program that is syntactically correct is not necessarily logically (semantically)


correct

• A program will always do what we tell it to do, not what we meant to tell it to do

45
Errors
• A program can have three types of errors

• The compiler will find problems with syntax and other basic issues
(compile-time errors)
• If compile-time errors exist, an executable version of the program is not
created

• A problem can occur during program execution, such as trying to


divide by zero, which causes a program to terminate abnormally (run-
time errors)

• A program may run, but produce incorrect results (logical errors)


46
Object-Oriented Programming
• Idea
• Computer program may be seen
• as comprising a collection of objects
• Object
• Fundamental entity in a JAVA program

• Used to represent real world entities


• Example: employee in a company may be an object

• Sends messages to other objects

• Receives messages from other objects

• Can be viewed as an independent actor with distinct role


Object oriented software principles
• Object-oriented programming ultimately requires a solid
understanding of the following terms:
• Class
• object
• attribute
• method
• Inheritance

Once a class has been defined, multiple objects can be


created from that class
Object oriented software principles (cont’d)
• Object
• Particular instance of a class

• Defines the set of values of attributes (states)

• Example:
• Lassie is one particular dog whose fur is brown and white

• Lassie is an instance of the Dog class


Object oriented software principles
• Class
• Abstract characterization or blueprint of an object

• Defines the state and behaviors of an object


• State => attributes; set of behaviors => methods

• Example:
• Dog consists of traits shared by all dogs
• (fur color, and ability to bark members of a class).
Object oriented software principles (cont’d)
• Inheritance
• The definition of one class is based on another

• One class is used to derive several new classes

• Derived classes can be used to derive more classes


• Create a hierarchy of classes

• Attributes and methods are inherited by children


Summary
• A computer system consists of hardware and software that work in concert to
help us solve problems.
• The CPU reads the program instructions from main memory, executing them one
at a time until the program ends.
• The operating system provides a user interface and manages computer resources.
• Digital computers store information by breaking it into pieces and representing
each piece as a number.
• Binary is used to store and move information in a computer because the devices
that store and manipulate binary data are inexpensive and reliable.
• Main memory is volatile, meaning the stored information is maintained only as
long as electric power is supplied.
• Comments do not affect a program’s processing; instead, they serve to facilitate
human comprehension.
Summary
• All programs must be translated to a particular CPU’s machine language in order
to be executed.
• High-level languages allow a programmer to ignore the underlying details of
machine language.
• A Java compiler translates Java source code into Java bytecode, a low level
representation of the program.
• Syntax rules dictate the form of a program. Semantics dictate the meaning of the
program statements.
• Program design involves breaking a solution down into manageable pieces.
• Each object has a state, defined by its attributes, and a set of behaviors, defined
by its methods.
• A class is a blueprint of an object. Multiple objects can be created from one class
definition.

You might also like