Programming Fundamentals (Final Revision)
Programming Fundamentals (Final Revision)
➔ Programming languages are a middleman for translating code into machine code.
➔ Java & Python ( general purpose).
➔ HTML & Css ( specific purposes).
➔ Low level ( Assembly & C).
➔ High level (Java & Python).
➔ Many different programming languages, each with unique uses.
➔ Choosing a language depends on personal preference and specific tasks.
Syntax is the set of rules that must be followed when writing code in a specific language.
➔ Syntax varies between programming languages.
➔ Breaking syntax rules results in errors.
Operators
Used to construct mathematical Used to compare two quantities Used to form compound conditions
expressions by combining two or more relations
< , > , <= , >= , == , !=
=,+,-,/,% && and
! not equal
Modulus operator (%) provides the // or
remainder of a divisional operation.
String integer
➔ A string is a sequence of characters, such as letters, ➔ An integer is a whole number without any
numbers, and symbols. decimal or fractional parts.
➔ “4” = String. ➔ 4 = Integer.
If you’re dealing with text, use a string. If you’re dealing with numbers, use an integer.
Naming conventions (capitalizing every word) for variables are important for readability.
Conditional statements
change the path of code depending on certain conditions.
if some condition is true, if preceding if or elif runs instructions if functionally similar to many
carry out instructions; else, statement is bypassed, preceding statement(s) if and else statements
do another thing. run the code segment. are evaluated as false. together.
It checks if a condition is The if-else if (elif) The if-else statement Some languages (e.g.,
true. If it is, the program statement handles multiple allows for two possible Java, C#) have a switch
executes a block of code. conditions. outcomes. statement for multi-way
branching.
Use cases: It checks each condition If the condition is true, one
Checking a single condition sequentially and executes block of code executes; It evaluates an expression
and executing code based the corresponding block of otherwise, a different and selects the appropriate
on its result. code for the first true block executes. case based on its value.
condition encountered.
Performing actions based
on user input.
The ternary operator provides a compact way to express a simple if-else condition.
Arrays store multiple variables containing information that is all related to each other.
➔ Arrays are useful for storing lists of information that can be easily searched through.
➔ Programming languages refer to the first cell as zero, not one.
➔ Array size is final and cannot be increased once defined.
➔ When initializing an array, determine its type and size.
➔ All elements in an array must be the same type.
➔ Multidimensional arrays (arrays inside of arrays) are possible.
ArrayLists (Lists) are a growing array which dynamically changes its size.
Dictionaries are likely an array in that it can store multiple values. However, instead of being
referenced lineary, each value is tied to an identifier that is used to reference it (key).
Loops
A while loop is an A do-while loop is an A for loop is commonly used The for-each loop (also
entry-controlled iterative exit-controlled loop. for iterating over a called the enhanced for
statement. sequence (e.g., numbers, loop) simplifies iterating
It executes the loop body list items, or characters in a over elements in an array
The condition is evaluated at least once, even if the string). or collection.
before each iteration. test condition is false
initially. It determines the number of It automatically handles
If the boolean expression in iterations before entering the the iteration and doesn’t
the while loop never The boolean expression is loop. require an explicit index.
evaluates to false, the loop tested when exiting from
will run indefinitely. the loop.
Loop conditions can be broken using the "break" statement.
Error Types
Debuggers allow you to step through code line by line and examine variables.
Liner search starts at the beginning and checks each data point (worst case) (work better
with unsorted).
Binary search is more efficient than liner search (works better with sorted).
Stack is a data structure which contains all of the takes you instruct your program to
complete.
➔ Stack overflow error: when creating a recursive function without a reachable base
case.
➔ Recursion is useful because it breaks large problems into much simpler pieces to
compute.
Programming Interview Questions And Answers
2. explain the various types of errors that can occur during the execution of a
computer program?
Syntax errors are the easiest to find and fix (misspelling) (before running the code).
Runtime errors are harder to find and fix (infinite loop) (after running the code).
Logic errors are the hardest to find and fix (results) (after running the code).
5. Every programming language has reserved words. What are they? Give some
examples.
Reserved words, also known as keywords, are the words that have predefined meanings
in a particular programming language. These reserved words can’t be used or redefined
for serving other purposes. Following are some examples of reserved words:
6. What do you understand by loops? Briefly explain the various types of loops.
A loop is a structure in programming that can repeat a defined set of statements for a set
number of times or until a particular condition is satisfied. There are three important
types of loops:
➔ FOR…NEXT Loop – This is the most effective loop when you know beforehand
the total number of times the loop is to be repeated
➔ WHILE…WEND Loop – It keeps on repeating a particular action until the
concerned condition becomes false. This loop is particularly useful when the total
number of repetitions is unknown.
➔ Nested Loop – When a loop is used inside a loop then it is termed as a nested
loop