0% found this document useful (0 votes)
9 views

Computer Programming

Uploaded by

Olayemi Obembe
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Computer Programming

Uploaded by

Olayemi Obembe
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

In computer terms, an application (also called an "app") is a software program that performs a

specific task or set of tasks. It's a self-contained program that provides a particular service or
functionality, and can be installed, run, and uninstalled as a standalone entity.
Examples of applications include:
- Word processors (e.g., Microsoft Word)
- Web browsers (e.g., Google Chrome)
- Social media platforms (e.g., Facebook)
- Games (e.g., Minecraft)
- Productivity tools (e.g., Trello)
- Graphics editors (e.g., Adobe Photoshop)
- Video players (e.g., VLC Media Player)

Applications can be classified into different types, such as:


- Desktop applications (run on a computer)
- Mobile applications (run on smartphones or tablets)
- Web applications (run in a web browser)
- Enterprise applications (used by organizations)

In summary, an application is a software program that helps you accomplish a specific task or
set of tasks, and can be installed, run, and managed as a standalone program.
There are several types of software, including:
1. System Software: Operating systems, device drivers, firmware, and utilities that manage and
control computer hardware and software.
2. Application Software: Programs that perform specific tasks or provide services, such as word
processors, web browsers, and games.
3. Programming Languages: High-level languages (e.g., Python, Java) and low-level languages
(e.g., Assembly) used to write software.
4. Utility Software: Programs that perform maintenance, optimization, or security tasks, like disk
formatting and virus scanning.
5. Malicious Software: Harmful programs like viruses, worms, and Trojan horses that
compromise computer security.
6. Freeware: Free software that can be used, copied, and distributed without restrictions.
7. Shareware: Software that can be used for free for a limited time or with limited functionality.
8. Open-Source Software: Programs whose source code is publicly available for modification and
redistribution.
9. Commercial Software: Proprietary software sold for profit, like Microsoft Office or Adobe
Photoshop.
10. Educational Software: Programs designed for teaching and learning, like language learning
tools or math games.
11. Game Software: Programs for entertainment, like video games or simulations.
12. Scientific Software: Programs for scientific research, data analysis, and visualization.
13. Business Software: Programs for managing and automating business operations, like
accounting or customer relationship management.
14. Graphics and Multimedia Software: Programs for creating and editing graphics, audio, and
video content.
15. Internet Software: Programs for accessing and utilizing internet services, like web browsers
or email clients.

What is a Programming Language?


A programming language is a set of instructions that a computer can understand and execute. It
is used to write software, apps, and websites.

Types of Programming Languages:


1. High-Level Languages: Easy to read and write, but need a compiler or interpreter to run.
Examples: Python, Java, C++.
2. Low-Level Languages: Close to machine language, fast and efficient, but difficult to read and
write. Examples: Assembly Language, Machine Code.
3. Scripting Languages: Used for web development and scripting. Examples: JavaScript, PHP,
Ruby.
Basic Elements of Programming Languages:
1. Variables: Store and hold values.
2. Data Types: Define the type of value a variable can hold (e.g., number, text).
3. Operators: Perform arithmetic, comparison, and logical operations.
4. Control Structures: If-else statements, loops (for, while), and conditional statements.
5. Functions: Reusable blocks of code that perform a specific task.

Programming Paradigms:
1. Object-Oriented Programming (OOP): Organizes code into objects that contain data and
functions.
2. Functional Programming: Focuses on pure functions, immutability, and recursion.

Common rules for forming variables in programming:


1. Start with a letter: Variables typically start with a letter (a-z or A-Z).
2. Use only allowed characters: Use only letters (a-z or A-Z), digits (0-9), and underscores (_).
3. Case sensitivity: Variable names are case-sensitive (e.g., "name" and "Name" are different).
4. No reserved words: Avoid using reserved keywords or programming language keywords (e.g.,
"if", "while", "for").
5. Be descriptive: Choose meaningful and descriptive names for your variables.
6. Keep it short: Keep variable names concise, but not too short (e.g., "x" is not very
descriptive).
7. Avoid special characters: Avoid using special characters like !, @, #, $, etc.
8. No spaces: Variable names cannot contain spaces.
9. Start with a lowercase letter: In some programming languages, it's conventional to start
variable names with a lowercase letter.
10. Follow the programming language's conventions: Some programming languages have
specific rules or conventions for forming variables, so be sure to check the language's
documentation.
Remember, these rules may vary slightly depending on the programming language you're using,
so it's always a good idea to check the language's documentation for specific guidelines.
constant
A constant declaration is a statement in programming that defines a constant value that cannot
be changed during the execution of the program. Constants are typically used to store values
that remain unchanged, such as mathematical constants (e.g., pi), string literals, or
enumerations.
The general syntax for declaring a constant is:
const <data_type> <constant_name> = <value>;

Where:
- const is the keyword used to declare a constant.
- <data_type> is the data type of the constant (e.g., int, float, string, etc.).
- <constant_name> is the name given to the constant.
- <value> is the value assigned to the constant.

For example:
const int MAX_SIZE = 100;
const float PI = 3.14;
const string GREETING = "Hello, World!";

Once a constant is declared, its value cannot be changed later in the program. Attempting to do
so will result in a compile-time error.
Constants are useful for:
- Storing values that remain unchanged throughout the program.
- Improving code readability by using meaningful names instead of magic numbers.
- Ensuring that critical values are not accidentally changed.
- Enforcing consistency in calculations and formulas.
Note that the specific syntax and rules for declaring constants may vary depending on the
programming language being used.

Control structures
Control structures are elements in programming languages that control the flow of a program's
execution. They determine the order in which statements are executed, based on conditions,
loops, or jumps. Control structures are used to make decisions, repeat actions, and control the
program's logic.

Common control structures include:

1. Conditional Statements:
- If-Then statements
- If-Then-Else statements
- Switch statements
2. Loops:
- For loops
- While loops
- Do-While loops
- Foreach loops
3. Jump Statements:
- Break statements
- Continue statements
- Return statements
- Goto statements (in some languages)
4. Subroutines:
- Functions
- Procedures
Control structures are essential in programming because they allow you to:
1. Make decisions based on conditions
2. Repeat actions multiple times
3. Control the flow of your program
4. Organize your code into reusable blocks
5. Improve code readability and maintainability

By using control structures effectively, you can write more efficient, flexible, and scalable code
that solves complex problems and meets your programming needs.

Operators
In programming languages, operators are symbols used to perform operations on variables,
values, and expressions. Here are some common types of operators:

1. Arithmetic Operators:
- Addition: +
- Subtraction: -
- Multiplication: *
- Division: /
- Modulus (remainder): %
- Exponentiation: ^ (or **)

2. Comparison Operators:
- Equal: ==
- Not Equal: !=
- Greater Than: >
- Less Than: <
- Greater Than or Equal: >=
- Less Than or Equal: <=

3. Logical Operators:
- AND: &&
- OR: ||
- NOT: !

4. Assignment Operators:
- Assign: =
- Add and Assign: +=
- Subtract and Assign: -=
- Multiply and Assign: *=
- Divide and Assign: /=

5. Bitwise Operators:
- AND: &
- OR: |
- XOR: ^
- NOT: ~
- Shift Left: <<
- Shift Right: >>
6. String Operators:
- Concatenation: + (or &&)

7. Conditional Operators:
- Ternary Operator: ? :

8. Increment and Decrement Operators:


- Increment: ++
- Decrement: --

Note that the availability and behavior of operators may vary depending on the programming
language being used.

Reserved words
Reserved words, also known as keywords, are words that have a special meaning in a
programming language and are reserved for specific uses. They cannot be used as variable
names, function names, or other identifiers in the code because they are already defined by the
language.

Examples of reserved words in many programming languages include:

- if
- else
- while
- for
- do
- switch
- case
- break
- continue
- return
- void
- int
- char
- double
- float
- true
- false
- null

Using a reserved word as a variable name or identifier would result in a syntax error or
unexpected behavior, as the compiler or interpreter would confuse it with the reserved
meaning.

It's essential to be aware of the reserved words in the programming language you're using to
avoid conflicts and ensure your code is correct and efficient.

Compiler and interpreter are two types of language processors used to execute programming
languages.

Compiler:

A compiler translates the entire source code into machine code before executing it. The
compilation process involves:

1. Preprocessing
2. Lexical analysis
3. Syntax analysis
4. Semantic analysis
5. Code generation
6. Code optimization

The generated machine code is stored in an object file or executable file, which can be run
independently of the compiler.

Interpreter:

An interpreter, on the other hand, translates and executes the source code line by line, without
generating machine code beforehand. The interpretation process involves:

1. Lexical analysis
2. Syntax analysis
3. Semantic analysis
4. Execution

The interpreter executes the code directly, without generating an object file or executable file.

Key differences:
1. Compilation: Compiler translates the entire code before execution, while interpreter
translates and executes line by line.
2. Machine Code Generation: Compiler generates machine code, while interpreter does not.
3. Execution Speed: Compiled code is generally faster than interpreted code, since it's already
translated into machine code.
4. Development Cycle: Compiler requires a separate compilation step, while interpreter allows
for interactive development and debugging.
5. Error Handling: Compiler detects errors before execution, while interpreter detects errors
during execution.

Examples:
- Compiled languages: C, C++, Java (compiled to bytecode)
- Interpreted languages: Python, JavaScript (in web browsers), Ruby

Note that some languages, like Java, use a combination of both compilation and interpretation,
where the code is compiled into bytecode and then interpreted by the Java
Virtual Machine (JVM).

Errors in programming
Errors in programming refer to mistakes or bugs that cause a program to produce incorrect
results, behave unexpectedly, or fail to execute altogether. There are several types of errors that
can occur in programming, including:

1. Syntax Errors: Mistakes in the code's syntax, such as missing or mismatched brackets,
semicolons, or quotes.
2. Runtime Errors: Errors that occur while the program is running, such as division by zero or
out-of-range values.
3. Logic Errors: Mistakes in the program's logic, such as incorrect calculations or faulty decision-
making.
4. Semantic Errors: Errors in the meaning of the code, such as using a variable or function
incorrectly.
5. Type Errors: Errors related to data types, such as trying to assign a string value to a numeric
variable.
6. Memory Errors: Errors related to memory management, such as memory leaks or accessing
memory outside the allocated bounds.
7. Resource Errors: Errors related to external resources, such as file not found or network
connection issues.
Common error messages include:
- SyntaxError: Unexpected token
- RuntimeError: Division by zero
- TypeError: Cannot assign string to int
- NameError: Undefined variable
- FileNotFoundError: File not found

To fix errors, programmers use various techniques, such as:


1. Debugging: Using tools and techniques to identify and isolate errors.
2. Error Handling: Writing code to anticipate and handle errors gracefully.
3. Code Review: Manually reviewing code to catch mistakes.
4. Testing: Running automated tests to detect errors.
5. Refactoring: Rewriting code to improve its structure and reduce errors.

Remember, errors are an inevitable part of the programming process, and learning to identify
and fix them is an essential skill for any programmer(debugging).

You might also like