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

BASIC PROG - MIDTERMS

The document provides an overview of programming concepts, including programming languages, program development processes, and testing methodologies. It covers various programming paradigms such as procedural and object-oriented programming, as well as essential elements of Java programming, including syntax, data types, and control structures. Additionally, it discusses the phases of processing a Java program, including editing, compiling, loading, verifying, and executing.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

BASIC PROG - MIDTERMS

The document provides an overview of programming concepts, including programming languages, program development processes, and testing methodologies. It covers various programming paradigms such as procedural and object-oriented programming, as well as essential elements of Java programming, including syntax, data types, and control structures. Additionally, it discusses the phases of processing a Java program, including editing, compiling, loading, verifying, and executing.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

then be used when the system is tested as a

whole
Basic Programming
●​ White box testing - Testing the program by
Lesson 1: Introduction assuming everything about the program,
making sure that every instruction and every
possible situation has been tested.
Programming - It is a process which involves planning,
scheduling or performing a task or an event.
5.​ Documentation - When the program is finished
Computer Programming - It is the process of writing and thoroughly tested, the documentation on
instructions to perform specific actions in a computer, the program is included for its distribution. It
and instructs the machine on how to perform in order usually includes necessary information about
to solve problems. the requirements of the program - operating
system and hardware requirements needed for
Data Processing Cycle - is a set of steps the computer the program to run.
follows to receive data, process the data according to
instructions from a program, display the resulting 6.​ Maintenance - Maintaining or updating the
information to the user, and store the results program, keeping the program running
(Information Processing Cycle) smoothly and updated with the developments
and changes in the field where it is used.
Program Development Process
UP, DS, I, T, D, M Programming Language - is a vocabulary and set of
1.​ Understanding the Problem - The first step is grammatical rules for instructing a computer or
to get a clear idea of what you want to do. You computing device to perform specific tasks.
need to know what kind of input to expect, how
the input is to be processed, and what kind of Syntax - set of grammatical rules for writing any
output is required. statement in a programming language

Ex: Input - Process - Output Semantics - meaning associated with the


statement/code
2.​ Develop the solution - To solve the problem,
you will need detailed plans, a plan of what is Compiler - is required to translate a program written
to be done and when, enabling us to develop using a programming language into a
the logic of the program. machine-readable form or known as binary code)
before you can run the program on your machine.
Tools that will help in this task are :
(1) Algorithm /pseudocode, Interpreter - translate the high-level instructions into
(2) Flowcharts, and machine-understandable instructions (binary code) at
(3) structure charts. runtime.

3.​ Implementation - Given the detailed design of


the solution, this process involves writing the
source code.

4.​ Testing - The process of finding and correcting


errors in your program (debugging)

Bug is used to refer to any error in a program, it


involves tracing(simulating) where the information
went and how it was process A compiler takes the program code (source code) and
converts the source code to a machine language
Two Types of Testing module (called an object file).
●​ Black box testing - Testing the program
without knowing what is inside it-without Programming Paradigm
knowing how it works. Test plans are developed
by looking only at requirements statement and ●​ Procedural Programming - is a list of
instructions that tells the computer what to do
incrementally. Procedural programming can
rely on procedures, also known as routines or Flowchart - A diagrammatic or graphical
subroutines. A process contains a series of representation that illustrates the sequence of
computational steps to be carried out. operations to be performed to get the solution of a
Procedural programming is also referred to as problem.
imperative programming and known as
top-down language. Flowcharting Guidelines:
●​ Object Oriented Programming (OOP) - is an 1. A flowchart always begin with START and is
approach to problem-solving where all completed by END symbol
computations are carried out using an object 2. Symbols are interconnected using arrows.
as the basic unit. An object is an element of a 3. Use commas to separate data and use semicolon to
program that sees how to perform specific separate instructions.
actions and How to interact with other 4. All the symbols except the diamond may have only
components of the program. An example of an one arrow branching out but may have more one or
object would be a person with attributes such more arrows branching
as name, height, weight. It is expected for a 6. Whenever circles are used, the symbol leading to
person to be able to do something, such as circle should flow to the symbol where a circle
walking, running, etc. defined as the method of containing a similar character is leading to.
the object. 7. The sequence of procedure using symbols matters
because it indicates the logical steps to be followed.
8. A flowchart may contain many symbols of the same
Lesson 2: Program Logic Formulation
kind depending on the solution of the problem.
9. There may be many steps of flowcharts to solve one
It is the process of coming up with the appropriate problem but the simplest flowchart is advisable and
methodology in developing a specific program logic most efficient.
that will perform a prescribed computing task or solve
a problem using the computer. Flowchart Symbols:

In Etymology "Logic" is a method of human thought ●​ Oval (Terminal symbol)


that involves correct thinking in a linear, step-by-step ●​ Rectangle (Process symbol)
manner about how a problem can be solved. Hence, the ●​ Arrow (Arrow Symbol)
important element must conform to define logic and ●​ Diamond (Decision symbol)
that is correct thinking or reasoning of the person. ●​ Parallelogram (Input/Output symbol)

Algorithm/Pseudocode

An algorithm is a set of well-defined instructions to


solve a particular problem. It takes a set of input(s)
and produces the desired output.

Pseudocode is a simpler version of programming code


in plain English, which uses short phrases to write code
for a program before implemented in a specific
programming language

Typical algorithmic steps in solving a problem:


1.​ Initialize data (Initialization) - responsible
for taking any preliminary actions that may be
required by a program.
2.​ Read/Input the data (Input) - responsible for
collecting the data that is used by the program
to accomplish its task.
3.​ Perform computations (Process) - responsible
for transforming the data from one form into a
different form.
4.​ Display/Output Results (Output) - responsible
for presenting the processed input.
Sample Problem:
Design an algorithm that will determine the sum of two
numbers

Data: sum of two numbers, first number, second


number
Process: compute sum, add two numbers
Lesson 3: Program Control Structures
-​ are just a way to specify flow of control in
programs. Any algorithm or program can be
more clear and understood if they use
self-contained modules called as logic or
control structures. It basically analyzes and
chooses in which direction a program flows
based on certain parameters or conditions

Basic types of logic, or flow of control: (Seq, Sel, Ite,


Mo)
• Sequence logic, or sequential flow
• Selection logic, or conditional flow
• Iteration logic, or repetitive flow
• Modular

Sequential
Steps are performed in strictly sequential manner, each
step being executed exactly once.

Selection/Conditional
The execution of instructions by selection, wherein
conditions for a series of alternative statements are
evaluated to specify which instruction is to be
executed.
-​ The flow of the program depends on the set of
conditions that are written
-​ Condition or conditional expression is in the
form of a mathematical statement using
equals, less-than, or greater-than
Condition-controlled loop
A condition-controlled loop is used when is not known
how many times iteration will need to occur

Repetition/ Iteration /Loop


Repetitive /Iterative statements (loops) allow a set of
instructions to be repeated or carried out several times
until certain conditions have been met,

Two types: (1)count-controlled (2) condition - controlled

Count-controlled loop
The way the count-controlled loop works is simple: the
loop holds a count of the number of times it runs, and
the loop stops when the count reaches the specified
count.
Modular/Procedural
Initialization: The control variable (counter) is The approach is sometimes called divide and conquer
initialized to the starting value before the loop starts. because a large task is divided into several smaller
tasks that are easily performed
Test: the loop terminating condition that checks if
looping should continue

Increment (or decrement)value by which the control


variable is modified at each iteration of the loop.
Kinds of Java Programs
1.​ Application - a regular program meant to be
run on your computer
2.​ Applet - a little program meant to be run on
the internet. They are programs that are
embedded in other applications, typically Web
pages displayed in a Web browser.

Java Program Execution


1.​ Compiling the program - use a Just-In-Time
(JIT) compiler to translate the Java program
into byte-code
2.​ Running the program - use the bytecode
interpreter to translate each bytecode
instruction to machine language and to run the
machine language instruction
3.​ Java Byte - Code - a machine language for a
hypothetical computer called Java Virtual
Machine (JVM)
-​ a kind of object code generated by a Java
compiler and interpreted by a Java Virtual
Dual Alternative Machine
Performs two different things when the condition is true -​ platform dependent
or false 4.​ Interpreter - used to translate byte-code to
machine language
5.​ Java Virtual Machine - a software tool that
behave like a high-level computer
-​ executes Java bytecode programs
-​ executes compiled Java programs regardless
of the hardware or software platform it is
installed on
-​ The java virtual machine knows nothing of the
Java programming language, only of a
particular binary format, the class file format.
A class file contains Java virtual machine
instructions (or bytecodes) and a symbol table,
as well as other additional information.

Lesson 4: Java Basics Phases in Processing a Java Program E, C, L, V, EX


, commas are used to separate items in a list 1.​ Edit/Editor - creating a program
; semicolons are used to end statement 2.​ Compile/Compiler - Compiling a Java
/ * - + mathematical symbols Program
<= != == >= relational symbols 3.​ Load/Class Loader - loading a program into
memory
4.​ Verify/Bytecode Verifier - bytecode
verification
L4.1 Overview of Java Language 5.​ Execute/Java Virtual Machine (JVM) -
execute the program
Java Programming Language - It is an
object-oriented programming language originally
developed by Sun Microsystems and released in 1995
as a core component of Sun Microsystems' Java
platform. The language derives much of its syntax from
C and C++ but has a simpler object model and fewer
low-level facilities.
These words have a special predefined meaning and
cannot be used as the names of classes or objects or
anything else.
Example: public, class, static, void, String, int and
others exclusively used by Java language for unique
purpose.

Identifiers
Identifiers are the technical terms for a name in a
programming language. It includes name of a variable,
name of a class, a method or an object.
Use a text editor to create a program, this program is
called the source program. The program must be saved Rules for identifiers are:
in a file named ‹ClassName> java, where ClassName is •The only valid name symbols are the capital letters
the name of the Java class contained in the file. A through Z, the lowercase letters a through z.
•the digits 0 through 9, and the underscore.
An integrated development environment (IDE) is a • The first character of the identifier cannot be a digit
programming environment that has been packaged as or an underscore.
an application program, typically consisting of a code
editor, a compiler, a debugger, and a graphical user
Valid Identifiers Invalid Identifiers
interface (GUI) builder. The IDE may be a standalone
application or may be included as part of one or more grade grade + 3
existing and compatible applications
area 1 1 area
You use the command javac(the Java compiler) to
area_of_triangle area of triangle
compile a program. For example, you'd type

javac Welcome.java Data Types - defines a set of values that a variable


in the command window of your system the command can hold. Based on the data type of a variable; the
prompt in Windows). operating system allocates memory and decides what
can be stored in the reserved memory.
The compiler checks the source program for syntax
errors, and if no error is found, translates the program
Type Keyword
into bytecode. The bytecode is saved in the file with the
class extension that represents the tasks to execute in Boolean boolean
the execution phase.
Character char
To run the program, the class file must be loaded into
Integer int
computer memory done by the program known as the
class loader, the bytecode for classes used in the Floating point float
program must be connected.
Double floating point double
As the classes are loaded into main memory, the
bytecode verifier verifies that the bytecode for the valueless void
classes is valid.

Lesson 5: Basic Elements of a Java Program


Comment Symbols - // single line comment symbol
Ex: // This is my first program
// Java Language

/* */ multiple line comment symbol


Ex: /*This is my first program
Java Language*/
Reserved Words (Key Words)
Variable - can hold a number or data of other types. * , 1,% are at higher level of precedence than + ,-
The number or other type of data held in a variable is
called its value. In programming languages, variables However, when operators have the same level, the
are implemented as memory location. The compiler operations are performed from left to right.
assigns a memory location to each variable name Relational Operators
(identifier) in the program. Each variable in a program Two expressions can be compared using relational and
must be declared. When you declare a variable you are equality operators. The result of such an operation is
> the compiler what kind of data you will be storing in either true or false
the variable ​ < > <= >= == !=

Variable Declaration - a syntax rule to declare a Logical Operators


variable is: datatype identifier; ​ && (AND) || (OR) | (NOT)

Ex: int x; Expression

Operator - is a symbol that tells the compiler to Arithmetic Expression


perform specific mathematical or logical An Arithmetic expression is any expression that is used
manipulations. for computations/ mathematical manipulations.

Types of operators: Boolean Expression (Conditional Expression)


•Assignment Operator A Boolean expression is any expression that is either
•Arithmetic Operators true or false.
• Relational Operators
• Logical Operators

Assignment Operator - (=) is used in the assignment


statement which takes the following form:
​ variable = expression;
Ex: y = 5;

Arithmetic Operators

Compound Assignment/Arithmetic Operators

+= -= *= /= %=

Ex: y = y + 5 — y+=5

Arithmetic Operators

Order of Precedence - It is possible to build


mathematical expressions with several operators.
When more than one arithmetic operator is used in an
expression, C++ uses the operator precedence rules to
evaluate the expression. According to the order of
precedence rules for arithmetic operators,

You might also like