Basics of Programming
Basics of Programming
Basics of Programming
Course Objective
The objective of this course is to introduce the concepts of programming, structure and interpretation of
computer programs and algorithms. This course is aimed at participants with little or no programming
experience. By the end of this course the participant should be justifiably confident of their ability to write small
programs that allow them to accomplish useful goals
Levels of Language
Programming languages can be "lower" or "higher," depending on how close they are to the language the
computer itself uses (0s and 1s = low) or to the language people use (English like high). We will consider five
levels of language. These are numbered 1 through 5 to correspond to generations. In terms of ease of use and
capabilities, each generation or level is an improvement over its predecessor.
The five generations of languages are:
1. Machine languages
2. Assembly languages
3. High-level languages
4. Very high-level languages
5. Natural languages
Let us look at each of these categories
1. Machine languages
Humans do not like to deal with numbers alone; they prefer letters and words also. Machine language consists
of numbers. Each type of computer has its own machine language. This is the lowest level of language. It
represents data and program instructions as 1s and 0s- the binary digits corresponding to the on and off
electrical states in the computer. During the early days of computing, programmers used rudimentary systems
for combining numbers to represent instructions such as add or compare. These programs are not convenient
for people to read and use, and the industry quickly moved to develop assembly languages.
2. Assembly languages
Assembly languages are considered to be very low level languages. They are not as convenient to use as the
more recent languages. However, at the time when they were developed, they were considered as a great leap
forward. To replace the 1s and 0s used in machine language, the assembly languages use mnemonic codes.
Mnemonic codes are abbreviations that are easy to remember: A for add, C for compare, MP for Multiply and so
on. Although these codes are not English words, they were better accepted than numbers (0s and 1s) alone.
Just like machine language, each type of computer has its own assembly language.
The programmer who uses an assembly language requires a translator to convert the assembly language
program into machine language. A translator is required because machine language is the only language that
the computer can actually execute. The translator is an assembler program, which is also referred to as an
assembler. It takes the programs written in assembly language and converts them into machine language.
Programmers need not worry about the translating aspect, they only need to write programs in assembly
language.
Although assembly languages represent a step forward, they still have many disadvantages. A key disadvantage
is that assembly language is detailed to the extreme, making assembly language programming repetitive, error
prone and tedious.
3. High-Level Languages
The widespread use of high-level languages in the early 1960's transformed programming into something quite
different from what it had been. Programs were written in an English-like manner, thus making them easier and
more convenient to use. Using high-level languages, a programmer can accomplish more with less effort, and
programs can now take care of much more complex tasks.
These so-called third generation languages spurred a great increase in data processing that characterized the
1960's and 1970's. During that period, the number of mainframes in use increased from hundreds to tens of
thousands.
A translator is used to translate the symbolic statements of a high level language into computer executable
machine language. This translator is called a compiler. There are many compilers for each language and one for
each type of computer. For example, it is necessary to have a COBOL compiler for each type of computer on
which COBOL programs are to be run. A program can be compiled to different machine language versions on
different machines. The source program itself, that is, the COBOL version is essentially identical on each
machine.
Some languages are used to serve a specific purpose, such as creating graphics or controlling industrial robots.
Many languages are extraordinarily flexible and are considered to be general-purpose languages. In the past,
the majority of programming applications were written in BASIC, COBOL or FORTRAN. All of them are general
purpose languages.
4. Very High-Level Languages
Very high-level languages are often known by their generation number. They are called fourth-generation
languages or 4GLs. Fourth-generation languages are beneficial because:
I.They are result-oriented; they emphasize "what" instead of "how".
II.They improve productivity because programs are easy to write and modify.
III.They can be used with minimum training by both programmers and non-programmers.
IV.They shield users from needing an awareness of program structure and hardware.
5. Natural Languages
The word "natural" has become very popular in computing circles. Fifth generation languages are often called
natural languages because of their resemblance to the "natural" spoken English language. Instead of being
forced to key correct commands and data names in correct order, a manager tells the computer what to do by
keying in their own words.
Choosing a Language
In a work environment, the manager may decide that everyone in the project will use a certain language.
We may need to use a certain language, particularly in a business environment, based on the need to
interface with other programs. If two programs are to work together, it becomes easy when they are written
in the same language.
We may choose a language based on its suitability or criteria. For example, COBOL will be the best option
for a business program that handles large files.
If a program is to be run on different computers, it must be written in a language that is portable and
suitable on each type of computer, so that the program needs to be written only once.
We may be limited by the availability of languages. Not all languages are available on all computers and in
all installations.
The language may be limited to the expertise of a programmer. The program may have to be written in a
language that the available programmer knows.
Major Programming Languages are FORTRAN (a scientific language), COBOL (a business language), BASIC
(simple language used for education and business), Pascal (education), Ada (military), and C (general
purposed), C, C++, Java, and Javascript.
Please refer the link below to know more about programming.
http://homepage.cs.uri.edu/faculty/wolfe/book/Readings/Reading13.htm
Requirement gathering
Writing functional specifications
Creating architecture and design documents
Implementation and coding
Testing and quality assurance
Software release
Documentation
Support and new features
There may be many additional steps and stages depending upon the nature and the type of the software
product. You may have to go through more than one cycle during the testing phase as software testers to find
problems and bugs. The developers need to fix them before a software product is officially published or
released. Let us go into these stages in detail.
Requirement Gathering
Requirement gathering is usually the first stage of any software product. This stage officially commences when
you are thinking about developing software. In this phase, you meet customers or prospective customers, and
do a market analysis of the requirements and features that are in demand. You might as well find out if there is a
real need in the market for the software product you are trying to develop. In this stage, most of the work is done
by the marketing and sales people, or people who have direct contact with the customers. These people talk to
customers and try to understand what exactly their requirements are.
A comprehensive understanding of the customers’ needs and writing down features of the proposed software
product are the keys to success in the requirement gathering phase. This phase is actually a base for the whole
development of the software. If the base is not laid appropriately, the product will not find a place in the market. If
a very good software product which is not required in the market is developed, it does not sell no matter how
well you build it. You can find many instances of software products that failed in the market because the
customers did not require them. The marketing people usually create a Marketing Requirement Document or
MRD that contains formal representation of the market data gathered. You can also consider your competitors’
products (if any). This process is called competitive analysis.
Finally, list down the features required by the product. Appropriate consideration must be given to the economics
of software creation at this point. Questions that must be asked are: is there a market? Can I make some profit?
will the revenue justify the cost of development?
Writing Functional Specifications
Functional specifications may consist of one or more documents. These documents show the behavior or
functionality of a software product on an abstract level. Assuming the product is a black box, these specifications
define its input/output behavior. The product requirements documentation put forward by people who have
contact with the end user of the product or the customers, forms the basis of the functional specifications.
In larger products, functional specifications may consist of separate documents for each feature of the product.
For example, if the product is a router, you may have a functional specification document for RIP (Routing
Information Protocol), another for features on security, and so on. Functional specifications are important
because developers use them to create design documents. The documentation people also use them when they
create manuals for end users. If different groups are working in different physical locations, functional
specifications and architecture documents (discussed next) are also a means to communicate.
Keep in mind that sometimes during the product development phase you may need to amend functional
specifications keeping in view new marketing requirements.
Creating Architecture and Design Documents
When you have all of the requirements collected and arranged, it is the turn of the technical architects team,
which usually consists of highly qualified technical specialists, to create the architecture of the product. This
defines different components of the product and how they interact with each other. Often, the architecture also
defines the technologies used to develop the product. While creating the architecture documents, the team also
needs to consider the timelines of the project. This is the target date when the product is required to be on the
market. Often excellent products fail because they are either too early or late to market. The marketing and sales
people usually decide a suitable time frame to release the product. Based on this timeline, the architecture team
may drop some features of the product if it is not possible to bring the full-featured product to market within the
required time frame. After deciding the components of the product and defining their functionalities, interfaces
are designed for these components to work together.
Most often, no component works in isolation; each one has to coordinate with other components within the
project. Interfaces are the rules and regulations that define how these components will interact with each other.
There maybe major problems down the road if these interfaces are not designed properly and appropriately
detailed. Different people will work on different components of any large software development project and if
they don’t fully understand how a particular component will communicate with others, major problems arise
during integration. For some products, new hardware is also required to make use of technology advancements.
The architects of the product also need to consider this aspect of the product. Once the architecture, software
components and their interfaces are defined, design documents are created as the next phase of development.
At the architecture level, a component is defined as a black box that provides certain functionality. At the design
documents stage, you have to define what is in that black box.
The design documents are usually created by the senior software developers and these documents define
individual software components to the level of functions and procedures. This is the last document completed
before development of the software starts. These design documents are passed on to software developers as
they begin coding. Architecture documents and MRDs usually need to stay in sync, as sales and marketing will
work from MRDs while engineering works from engineering documents.
Implementation and Coding
The software developers use the design documents and development tools (editors, compilers, debuggers etc.)
and start writing software. This is often the longest phase in the product life cycle. Every developer has to write
his/her own code and collaborate with other developers to make sure that the different components can inter-
operate with each other. A revision control system such as CVS (Concurrent Versions System) is needed in this
phase. There are many open source revision control systems as well as commercial ones available these days.
The version control system provides a central repository to store the individual files. A normal software project
may contain anywhere from hundreds to thousands of files. In larger and complex projects, directory hierarchy
must also be decided beforehand so that files are stored in appropriate locations. During the development cycle,
different developers may modify the files. If the rules are not followed by everybody, this may easily break the
whole compilation and building process. A typical example is duplicate definitions of the same variables causing
problems.
Similarly, if included files are not written properly, loops get created easily. Other problems pop-up when multiple
files are included in a single file with conflicting definitions of variables and functions. Coding guidelines must
also be defined by architects or senior developers. As an example, if software is intended to be ported to some
other platform, it must be written on a standard like ANSI. During implementation, developers must write enough
comments inside the code so that if anybody starts working on the code in the future, he/she would be able to
understand what has already been written. Writing good comments is extremely important as all other
documents, no matter how good they are, will be lost eventually. Ten years subsequent to the initial work, it's
probable that you may find only that information which is in the form of comments, present inside the code.
Development tools also play an important role in this phase of the project.
Good development tools save a lot of time for the developers. They also help to save money in terms of
improved productivity. In terms of time saving the most important development tools are editors and debuggers.
An editor helps a developer to write the code quickly.
A good debugger helps to make the code operational in a short period of time. Before the start of the coding
process, considerable time must be spent in choosing good development tools. During the development phase,
review meetings also prove helpful. Through review meetings, potential problems are identified earlier in the
development. Review meetings are also helpful to keep track of whether the product is on time or if more effort is
needed to complete it within the required time frame. There will be times when you may also need to make
changes in the design of some components because of new requirements from the marketing and sales team.
Review meetings are a great tool to convey these new requirements. Here, architecture documents and MRDs
are kept in sync with any changes/problems encountered during development.
Testing
Testing is probably the most important phase for long-term support as well as for the company's reputation. If
you don’t control the software quality, it will not be able to compete with other products on the market. If software
crashes at the site of the customer, he loses productivity as well money and you lose credibility. On most
occasions these losses are huge. Unhappy customers will never buy other products from the same vendor and
will not refer other potential customers. You can avoid this situation by doing extensive testing. This testing is
often called as Quality Assurance, or QA, in the software world. Generally testing starts as soon as the initial
software components are available. There are multiple types of testing. Each of these has its own importance.
1. Unit Testing - Unit testing is testing one part or one component of the product. The developer generally does
this when he/she has completed writing code for that part of the software. This makes sure that the component
is doing what it is intended to do. This also helps the software testers as well as developers save time by
eliminating many cycles of software being passed back and forth between the developer and the tester. When a
developer is ready with a particular part of the software, he/she can write test cases to test the functionality of
this part of the software. The component is then passed on to the testers who run test cases to make sure that
the unit is working properly.
2. Sanity Testing - Sanity testing is a very basic check to see if all the software components compile with each
other without any problems. This is to ensure that developers have not defined conflicting or multiple functions or
global variable definitions.
3. Regression or Stress Testing - Regression or stress testing is a process done in some projects to carry out
a test for a longer time period. This type of testing is used to determine the behavior of a product when used
continuously over a period of time. It can expose some bugs in software like the ones related to memory
leakage. In some cases, developers allocate memory but forget to release it. This is usually referred to as
memory leakage. When testing goes on for many days or weeks, it often results in allocation of all of the
available memory until no memory is left. This is the point where your software starts showing abnormal
behavior. Another potential problem in long-term operation is counter overflow. This happens when you
increment a counter but forget to decrement it resulting in an overflow when the product is used for long time.
The regression testing may be started as soon as some components are ready. This type of testing requires, by
its very nature, a very long period of time. The process should be continued as more components of the product
are integrated. The process of integration and communication through interfaces may create new bugs in the
code.
4. Functional or System Testing - Functional testing is carried out to make sure that the software is doing
exactly what it is supposed to do. This must be done before any software is released to customers. Functional
testing is done by testers whose primary job is software testing, and not the developers themselves. In small
software projects where a company can’t afford dedicated testers, other developers may also do functional
testing. The key point to keep in mind is that the person who wrote a software component should not be the
person who tested it. A developer will always have a tendency to test the software the way he/she wrote it.
He/she may easily miss any problems in the software. The testers need to prepare a testing plan for each
component of the software. A testing plan would contain test cases that are run on the software. The tester can
prepare these test cases using functional specifications documents. The tester may also get assistance from the
developer to create test cases. Each test case must include methodology used for testing and expected results.
Additionally, the tester may also need to create certain infrastructure or environment to test the functionality of a
piece of code. For instance, you may simulate a network to test the routing algorithms that may be part of a
router. The next important job of the tester is to create a service request if an anomaly is found. The tester must
include as much information in the service request as possible.
Typical information included in reporting bugs includes:
The bug should be forwarded to the developer so that the developer may correct the problem. Many software
packages are available in the market to track bugs and fix problems in software.
Software Releases
Any software product is officially released before you start selling it. This means that you create a state of the
software in your repository, ensure that it has been tested for functionality and the code is frozen. A version
number is assigned to the released software. After releasing, development may continue but it will not make any
change in the released software. The development is often carried on in a new branch and it may contain new
features. The released software is updated only if a bug fixed version is released. Generally companies assign
incremental version numbers following some scheme when the next release of the software is sent to market.
The version number change depends on whether the new software contains a major change to the previous
version or it contains bug fixes and enhancement to the existing functionality. Software releases are also
important because they are typically compiled versions of a particular code version, and thus provide a stable
set of binaries for testing.
1. Branches - In almost all serious software development projects, a version control system is used. This system
keeps a record of changes in source code files and is usually built in a tree-like structure. During the release of
the software, the state of each file that is part of the release should be recorded. By creating branches to this
state, future developments can be made. Sometimes special branches may also be created that are solely used
for bug fixing.
2. Release Notes - Every software version contains release notes. These are prepared by people releasing the
software version with the help of the developers. Release notes show what happened in this software version.
Typically the information includes:
Bug fixes
New functionality
Details of new features added to the software
Any bugs that are not yet fixed
Future enhancements
If a user needs a change in the configuration process, it is also mentioned
Generally a user must be given enough information to understand the new release enhancements and decide
whether an upgrade is required or not.
Documentation
There are broadly three categories of documentation related to software development processes:
Technical documentation developed during the development process, such as the architecture, functional
and design documents.
Technical documentation prepared for technical support staff, including technical manuals that support staff
use to provide customer support.
End-user manuals and guides. This is the documentation for use of the end user. It assists the user in
getting started with the product and using it.
All three types of documents are necessary for different aspects of the support of the product. Technical
documents are necessary for future development, bug fixes, and adding new features. Documentation for
technical support staff contains information that is too complicated for the end user to understand and use. The
support team needs this information in addition to user manuals to provide better support to customers. Finally
each product should have the user manuals. Technical writers often develop user manuals which are based on
functional specifications. In the timelines of most software development projects, even before the start of code
development, functional specifications are prepared. So the technical writers can start writing user manuals
while developers write the code. So when the product is ready, the user manual is almost completed.
Support and New Features
Your customers need support when you sell a product. This is true regardless of the size of the product, and
even for non-software related products.
The most common support requests from customers are related to one of the following:
In addition to these, you may also want to add new features to the product for the next release because
competitor products have other features. Better support will increase your customer loyalty and will create
referral business. You may adopt two strategies to add new features. You may provide an upgrade to the current
release as a patch, or wait till you have developed a list of new features and make a new version. Both these
strategies are useful depending how urgent the requirement for new features is.
What is a Problem?
A problem can be defined as an opportunity for improvement. “Every problem has a gift for you in its hands,”
says Richard Bach. An optimist looks at challenging or problematic events as potential opportunities for
improvement. He will be always seeking answers for the questions such as:
Is there more than one probortunity? "Probortunity” – a synonym by combining the words “problem” and
“opportunity”.
Is it my personal probortunity or Is it the probortunity of the organization?
Is it an annoyance or an actual probortunity?
Is this the real probortunity, or merely a symptom of a larger one?
A problem can be defined as the difference between the actual state and the desired state. A problem could also
be the result of the knowledge that there is a gap between the actual and desired or ideal state of objectives.
Clarity of the problem is determined by the clarity of the knowledge which one precisely wants and which one
has. Greater clarity of the problem will help in finding a better and an effective solution.
A problem can also result from the recognition of an imperfect present and the belief in the possibility of a better
future. The belief that one's hopes can be achieved will give one the will to aim towards a better future.
Key approaches to Problem solving
There are different ways of problem solving – each has its own advantages and disadvantages. The process an
individual adopts as a manager will be influenced by organizational policies, his/her own personality and
communication style, and the kind of information available about the problem. Broadly, there are two problem
solving models available to a manager.
A. Rational Problem-Solving
Rational problem solving rests on the following principles (R. K. Wagner - “Learning to solve practical
problems”):
Problems are identified by comparing actual performance with an expected standard performance
Problems are deviations in actual performance from the expected standard
A precise and complete description of the problem is needed to identify a solution
What is happening?
Where is it happening?
When is it happening?
To what extent is it happening?
The cause of the problem can be found by comparing the problem and non-problem situations.
Recent problems are due to some change in the situation that has caused an unwanted deviation from
expectations.
The Rational Decision-Making model requires the following steps, which if followed, are assumed to lead to
"value-maximising choices." These steps are as follows:
1. Identifying the Problem: The first step in the problem solving process is sizing up the situation to identify the
problem. This may sound simple enough, but sometimes managers might be uncertain about even what the
problem is; they might just be feeling anxious or be confused about what is getting in the way of their objectives.
If that is the case, they can ask themselves or consult with their friends or a professional expert. Other useful
techniques for identifying the problem include-
2. Exploring the Problem: Having identified the problem, managers should analyze the problem to see what is
the root cause for it. Often people get caught up in symptoms or effects of a problem or issue and never drill
down to the real cause. They get mad at someone’s attitude, anger, or actions, which is not the real cause of the
problem. The key here is to focus on analyzing the problem for the real root cause without being affected by
emotional issues. Seeking answers to questions such as the following will help explore the problem:
Identify the Problem – Ask Who?
Once the root cause is found, plans can be made to fix it. Analyzing implies gathering information. If there is not
enough information, they should find some ways to research and collect it.
3. Set Goals: Having explored and analyzed the problem, managers should be able to write a goal statement
that focuses on what is the successful end of the process. Once the root cause is found, plans can be made to
fix it. Analyzing implies gathering information. If there is not enough information, they should find some ways to
research and collect it.
Making and writing down a goal statement will:
help them to clarify the direction to be taken in solving the problem; and
give them something definite to focus on
That is, what will occur as a result of the solution? This whole process is about fixing or closing the gap between
the problem and the goal. Writing down the problem ensures that they are not side-tracking from, but addressing
the problem.
4. Look at alternatives: Now that the problem has been analyzed, the managers can start developing possible
solutions. This is a creative as well as practical step where every possible solution needs to be identified. They
should identify the various alternative solutions available to them through techniques such as –
Take a sheet of plain paper and turn it sideways (if using flipchart paper you don’t need to turn it sideways -
it is large enough); Using colored felt pens, draw a small picture (or write a phrase) in the centre of the
paper representing the issue you want to solve; Draw lines out from the main problem (it helps to use
different colors for each line).
Each line should represent a different aspect of your problem or issue;
Write down what each line represents either on top of or on the line;
Add other lines flowing off these main lines;
Write a word or short phrase on the smaller lines indicating what each new line represents (you may find
that mind mapping works best for you if you write down the phrases or draw the images first and then
connect them with the lines); and
If you want, add images next to your main line that illustrate what each line means to you (some people
think better with pictures, others with words).
5. Select the best solution: Now that there are a wide variety of possible solutions available, it is time to select
the best solution from among them to fix the problem, given the circumstances, resources and other
considerations. Here the managers are trying to figure out what exactly would work best given the nature of the
problem. There are always a number of things that can affect a solution, for instance, money, time, resources,
procedures, rules, policies, and so on. All of these factors must be thought about. Managers should prioritize the
solutions by their effectiveness. This is a slow process of elimination. There may be some possible suggestions
that may need to be immediately eliminated. Eventually, managers should narrow down the choices to one best
possible solution which will promise them the best or optimal outcomes.
6. Implementation: Implementation is a crucial part of problem-solving process. In order to implement the
solutions chosen, managers must have an action plan and communicate it to those people who are directly and
indirectly affected. Gemmy Allen (“Problem-Solving & Decision-Making”) says that communication is most
effective when it precedes action and events. In this way, events conform to plans and events happen when, and
in the way, they should happen. Managers should answer the below vital questions before they are asked, like –
7. Evaluation: This is the final step in the problem-solving process. Managers should review the effectiveness of
the solution against desired outcomes. Questions like did the solution work? If not, why? What went right, and
what went wrong? What adjustments do they have to make to ensure that the solution will work better? This
stage will require careful analysis that improves upon the best solution.
The review of your progress can help a manager identify any problem. Steps may need to be revised or new
steps need to be added. One may need to consider a different solution, if the current one, with which he/she has
been, is not helping.
Essentials of Effective Problem Solving
3.2. Datatypes
Data and Datatypes
Programs need data in the form of numbers, time, names, date, description etc.
Consider a program to calculate the sum of two numbers.
sum = x+y
Here the two numbers are the data and the type of data (numeric data-integer, decimal etc.) is the data type. In
more elaborate terms, a data type used in a program determines the type of data, memory needed for storing
the data, and the kind of operation that can be performed with the data (e.g. you can multiply two numbers
together, you can concatenate alphabets and make it a word and multiple words into a sentence.)
What can we infer from the figure above? We can see that different types of data like integer, string, date etc.
have been used in the form.
A datatype represents the type of data, memory storage and the operations that can be performed using
the data.
Classifying data types
Data types are divided into primitive and composite types. The primitive data types are the basic data types that
are available in most of the programming languages.
Primitive data types are used to represent single values that include numeric types like integer or float, boolean,
character and string.
The data types that are derived from primary data types are known as non-primitive or composite data types.
These data types are used to store a group of values. Composite type includes Array, Structure, Class etc.
Basic Data Types
Numeric type is divided into Integer type and Floating-point type. The table below shows the division and
examples for numeric types:
Numeric Types
A program also needs a memory location where it can store data but cannot alter it later. Such memory locations
are called constant memory locations.
Consider a program that finds the area of a circle. The program takes radius (numeric) as an input data to
calculate the area. When user gives the input data, the program stores it in the memory for further calculation.
The program also stores the result (area of circle) after calculation. This means that the program uses at least
two memory locations (two variables); one for storing the input (radius of circle) and one for storing the result
(area of circle). You know that Pi is a constant and has a fixed value (3.14). In this program the value of Pi can
be stored as a constant because the program cannot alter the value of Pi.
Program Steps:
Initializing a variable
Initializing a variable means putting an initial value to the variable(bucket). A variable can be initialized while
creating or declaring it.
Eg: int counter=0; char gender='M';
Storing data to a variable
Once a variable is created, data can be stored in the variable. An assignment operator(=) is used in the program
to store data to a variable. The initial value of the variable can be changed by assigning a new value using the
assignment operator(=).
counter = 10;
gender = ‘F’;
Sequence:
Statements in the program will be executed one-by-one from the first to the last statement.
Selection:
The selection control structure allows one set of statements to be executed if a condition is true and another set
of statements to be executed if a condition is false.
The following are the common selection control structures use in programming languages.
if
if-else
switch
Repetition
Executing one or more steps of an algorithm or program based on some condition. The repetition control
structure is also known as the looping or iteration control structure.
The following are the common looping control structures use in programming languages.
while
do-while
for
Sequence, Selection and Repetition (Iteration) are the three main control structures used to control the
flow of program.
Links for reference:
http://www.scriptingmaster.com/asp/conditional-logic.asp
http://www.tutorialspoint.com/java/java_loop_control.htm
http://revolution.byu.edu/programmingconcepts/ControlStruct.php
http://www.cplusplus.com/doc/tutorial/control/
http://www.tutorialspoint.com/java/java_decision_making.htm
Related Video Links:
https://www.khanacademy.org/cs/programming/logic-if-statements/p/if-statements
https://www.khanacademy.org/cs/programming/looping/p/intro-to-while-loops
Most of the programs deal with a group/collection of data. For example, list of bank account numbers, exam
scores, country names etc. Data could be primitive like integer or composite like Date.
Program needs to arrange and manage these groups of data. All programming languages provide one basic
data structure named array, that helps to store and manage a group of data.
An array helps to store a collection of data (elements). Like the numbering used in the above diagram, array
uses an index to represent the location of each independent data stored in it.
The main ability of an array is to represent a group of data using a single name and accessing each individual
data stored in it using an index. In programming world, starting index of an array will always be zero.
Arrays can be one dimensional, two dimensional or multi-dimensional. The figure given above can be looked
upon as a single dimensional array having a single row with 11 columns (0 – 10 seats).
Consider a program that needs to store the names of all the students participating in a quiz program. The input
data for the program is:
We need a variable to store the number of students and an array to store the names of students.
int count; //variable to store number of students
String nameArray[count]; // array to store names of students
An array is used to store a group of data of similar type.
Create and Use an Array
Creating and initializing an array
The general format for creating and initializing an array is given below.
datatype array_name[ ] = {value1 , value 2 , value3};
Eg. int nums_array[ ]={11, 22, 33,44,55} ;
Array Creation
Defining a function
The following questions help to define a function:
Each function has two parts, header and body. Function header specifies the name of the function, input
parameters and the output type. The function body contains the logic of the function.
The general format of a function is as follows.
return_type functionName( [datatype parameter1, datatype parameter1, …]){
// function body
}
Here return_type means the type of data(numeric , String,…) the function will return after executing the logic in
the body part. If the function does not return any data but performs a task, then the return type will be void
(means no return_value).
Example:Function definition
Function Examples
Example1: Function that takes an input, performs a task and returns a result.
Example2: Function that takes an input, performs a task and returns no result.
Example3: Function that takes no input, performs a task and returns a result.
Example4: Function that takes no input, performs a task and returns no result.
void alert(){
sendAlertMessage(“ Low Resource”);
}
The function alert takes no input, but performs a task via a function sendAlertMessage() and does not return any
output.
Calling/Invoking a function
The main function should know the name of the sub function and the arguments/inputs needed by the sub
function to invoke/call the sub function.
The common syntax for invoking a sub function is:
functionname([arguments]) ; or
result = function_name([arguments]); //store result in a variable, if function return some data
Consumes low bandwidth – As the command line interface is devoid of any graphics or extra data, this is
especially useful in a networked environment where network traffic is to be limited.
Appeals to expert users – as the commands relevant to a particular task give information about that task
only, any other extra data/information that could potentially cause a distraction to the user are easily
avoided.
However this type of user interface poses the following disadvantages too:
Learn-ability and Retention of commands is generally poor – this is especially applicable to non-expert
users, who would find learning and remembering individual commands of each task difficult. Hence they
won't be comfortable with the command line interface.
Not very user friendly and hence error rates are high – especially when a user is trying to enter data. A
mistake made in typing while using command line is often not forgiven. That is, a user is usually not warned
or prompted for confirmation while using direct commands in the command line. Hence chances of wrong
data being entered are very high.
A remarkably good User Interface Design can act as the difference between product acceptance and rejection in
the marketplace.
A cumbersome, not easy to learn/ use UI in an otherwise excellent product could result in the failure of that
product. Good User Interface can make a product easy to understand and/or easy to use, which results in
greater user acceptance. Poor user interface is the reason why many software systems are never even used.
A badly designed user interface can cause a user to make catastrophic errors.
The best example of this from real world is the "Butterfly Ballot" used in Palm Beach, Florida during the 2000
U.S. presidential election which was a fiasco primarily due to the design of a confusing user interface.
If the designers of that ballot understood the basics of user interface design, there may very well have been a
different outcome to the election.
For further reading on the importance of good UI, please refer the pdf at the link below :
www.elsevierdirect.com/companions/9780120884360/casestudies/Chapter_01.pdf
The browser uses the tags to indicate how to display the content in the tags.
Elements that contain content can usually also contain other elements. For example, the bold element ("<b>")
can be embedded within a paragraph element:
An attribute name.
An attribute value.
A few attributes can only have a single value. They are Boolean attributes and may be shortened by only
specifying the attribute name or leaving the attribute value empty. Thus, the below 3 examples have the same
meaning:
<input required="required">
<input required="">
<input required>
Attribute values that consist of a single word or number may be written as they are, but when there are two or
more strings of characters in the value, it must be enclosed within quotation marks. Both single and double
quotes are allowed. Most web developers prefer to always use quotes to make the code less ambiguous to the
eye and to avoid mistakes. The below code includes such a mistake:
<p class="foo" bar> (Beware, this probably does not mean what you think it means.)
In the above example the value of class was supposed to be "foo bar" but since there were no quotes the code
is interpreted as if it had been written like this:
<p class="foo" bar="">
Named Character References in HTML
Named character references (often casually called entities) are used to print characters that have a special
meaning in HTML. As seen earlier, HTML interprets the less-than and greater-than symbols as tag delimiters.
When you want to show a greater-than symbol in the page, a named character reference can be used. There
are four common named character references one must know:
> denotes the greater than sign (>)
< denotes the less than sign (<)
& denotes the ampersand (&)
" denotes double quote (")
The above four are the most important, among many more entries, because they represent characters that have
a special meaning in HTML
Doctype and comments
In addition to tags, entities and text content, an HTML document must contain a doctype declaration as the first
line. This is written like this:
<!DOCTYPE html>
The doctype has a long history, but for now all you may need to know is that this doctype tells the browser to
interpret the HTML and CSS code according to W3C standards and not try to pretend that it is Internet Explorer
from the 90's.
HTML has a mechanism for embedding comments that are not displayed when the page is rendered in a
browser. Comments are very useful for explaining a section of markup, or making notes for other people who
might work on the page, or for leaving some kind of reminders for yourself. Comments in HTML are enclosed in
symbols such as shown below:
<!-- This is comment text -->
A complete but small document
Putting this together here is a tiny example of an HTML document. The below text can be copied to a text editor,
save it as myfile.html and open it in using browser. It must be ensured that the document is saved using the
character encoding UTF-8. As this document uses no styling it will look very plain, but it is only a start.
<!DOCTYPE html>
<html lang="en"
<head>
<meta charset="utf-8" />
<title>A tiny document</title>
</head>
<body>
<h1>Main heading in my document</h1>
<!-- Note that it is "h" + "1", not "h" + the letter "one" →
<p>Loook Ma, I am coding <abbr title="Hyper Text Markup Language">HTML</abbr>.</p>
</body>
</html>
For further learning of basic HTML please refer to the tutorial in the link below:
www.w3schools.com/html/default.asp
CSS
HTML was originally designed as a simple way of presenting information, with far less importance given to the
aesthetics of a web page than the content (and largely being left up to the web browser). Now that the web has
become as popular as it has, the content presentation has become almost critical to a website’s success. CSS is
a technology which is a key in presentation, used to design websites.
In the late ‘90s, HTML coders noticed that they were retyping the same old tags again and again on the same
page, leading to larger HTML files and above all, more time was consumed in this unfruitful process, which
further led to frustration. You may also have found yourself in the same situation, adding in mountains of <font>
tags, despite wanting them all the same; or using tricks like invisible gifs for spacing.
Then, someone had a great idea: have one file that defines all the values that those piles of tags would have
done, and then have the pages checking this file and formatting the content pages accordingly. You can hence
leave out most of the formatting tags in HTML and use only nice structural elements (such as headings,
paragraphs and links) — separating structure and presentation.
In late 1996 CSS (Cascading StyleSheets) became a reality, acting as a partner to your HTML code; taking care
of all the layout, fonts, colors and overall look of your site.
If you ever decide to change the look of your site, you modify that one CSS file (your style sheet) and all the
HTML pages reading from that file will display accordingly. This makes maintenance of your design much easier.
CSS Syntax
The syntax for CSS is different than that of HTML markup. It mainly consists of only 3 parts.
selector { property: value }
The selector is the HTML element that you want to style. The property is the title of the actual property, and the
value is the style you apply to that property.
Each selector can have multiple properties, and each of those properties within the selector can have
independent values. The value and property are separated with a colon and contained within curly brackets.
Multiple properties have to be separated by a semi colon. But a comma is used to separate multiple values
within a property, and if an individual value contains more than one word you surround it with quotation marks. A
sample of this is shown below
body {
background: #eeeeee;
font-family: “Times New Roman”, Calibri;}
As you can see in the above code we have separated the color from the font-family with a semi-colon, various
fonts are separated with commas and contained the “Times New Roman” within quotation marks. The end result
sets the body color to light gray, and sets the font to ones that most users will have installed on their computer
Different ways to apply CSS on HTML
1. Internal Stylesheet
First we will explore the internal method. Here you are simply placing the CSS code within the <head></head>
tags of each HTML file you want to style with the CSS. The syntax for this is shown in the example below.
<head>
<title><title>
<style type=”text/css”>
CSS Content Goes Here
</style>
</head>
<body>
With this method each HTML file contains the CSS code needed to style the page. This means that any changes
you want to make to one page, the same have to be made to all. This method works best when you need to style
only one page, or if you want individual pages to have varying styles.
2. External Stylesheet
Next we will explore the external method. Using any text or HTML editor such as 'Notepad', an external CSS file
can be created. A CSS file contains no HTML, only CSS. You simply save it with the .css file extension. You can
associate the file externally by placing one of the following links in the head section of every HTML file you want
to style with the CSS file.
<link rel=”stylesheet” type=”text/css” href=“Path To Stylesheet.css” />
Or you can also use the @import method as shown below
<style type=”text/css”>@import url(PathToStylesheet.css)</style>
Both these methods are achieved by placing one or the other in the head section as shown in example below.
<head>
<title></title>
<link rel=”stylesheet” type=”text/css” href=”Path To Stylesheet.css” />
</head>
<body>
or
<head>
<title></title>
<style type=”text/css”> @import url(Path To Stylesheet.css) </style>
</head>
<body>
By using an external style sheet, all of your HTML files link to one CSS file in order to style the pages. Meaning,
that if you need to alter the design of all your pages, you only need to edit one .css file to make global changes
to your entire website.
Here are a few reasons this is better
Easier Maintenance
Reduced File Size
Reduced Bandwidth
Improved Flexibility
3. Inline Styles
In a way this method of stylesheets defeat the purpose of using CSS in the first place. Inline styles are defined
right in the HTML file along side the element you want to style. An example is shown below.
<p style=”color: #ff0000;”>Sample red text</p>
Inline styles does NOT allow the user to change styles of elements or text formatted this way
Which is better?
So with all these various ways of inserting CSS into your HTML files, you may now be wondering which is better,
and if more than one method is used, in what order do these different ways load into the browser?
All the different methods will cascade into a new “pseudo” stylesheet in the following order:
1. Inline Style (inside HTML element)
2. Internal Style Sheet (inside the <head> tag)
3. External Style Sheet
As far as which way is better, depends on what you want to do. If only one file need to be styled then placing it
within the <head></head> tags (internal) will work fine. Whereas if you are planning on styling multiple files then
the external file method is the way to go.
Choosing between the <link related=> & the @import methods are completely up to you. I will mention that the
@import method may take a second longer to read the CSS file in Internet Explorer than the option.
To learn how to implement CSS in HTML pages, refer the link below
www.w3schools.com/css/default.asp
Conclusion
With the use of HTML and CSS you'd be able to develop attractive looking webpages. But these webpages
would only contain static information. That is the users can only read/consume the information that you have on
the pages. No user interaction would be possible with static pages.
But the good news is, there are various other technologies using which the webpages can be made dynamic.
Examples of those technologies are asp.net, jsp, javascript etc. The discussion on specific technologies are out
of the scope of this curriculum. However for further reading you may refer the website below.
JavaScript : www.w3schools.com/js/default.asp
ASP.NET : www.w3schools.com/aspnet/default.asp
JSP : www.tutorialspoint.com/jsp/index.htm
5.Programming Approaches
5.1. Structured Programming
Introduction
Organizations and individuals are continually searching for more efficient ways to perform the software
development process. One way of lowering the time and cost of development is to standardize software
programs and the process of programming. The benefits of standardized programs are that they are easier to
code, maintain, debug, and modify. In recent years, many different techniques have appeared attempting to
minimize differences in the way programmers' design and develop software
Programming Approaches: Structured Vs Non-Structured Approaches
Structured programming is a standardization technique used for software development. The structured approach
works by having all programmers use the same structured design techniques. Structured programming is used
to address the shortcomings of non-structured programming, which frequently used the GO TO branch points to
transfer from one part of the program to another part. Using GO TO codes, one could transfer backward,
forward, or anywhere else within the program. The problem is that the connections between parts of the program
by using GO TO commands can become quite haphazard.
The haphazard and sometimes convoluted pattern of linkages between parts of the program is called spaghetti
code. This way of programming is difficult to understand and debug. Non-structured programming is now viewed
as an ineffective programming strategy. To develop good software, developers have to carefully think out and
design the programs. In the earliest days of computing, programmers developed code according to their own
whims, with the result that the software was often confusing and difficult to work with. Software today is expected
to follow recognized design principles. The prevailing design standards are structured programming and
structured design.
Structured Programming
Structured programming makes use of the control structures (sequence, selection and repetition). Structured
programming does not use GO TO commands. The principle of sequences implies that program instructions
should be executed in the order in which they appear. The principle of selection implies that instructions may be
executed selectively using IF-THEN and/or IF-THEN-ELSE statements. These conditional statements work in
the following way. IF a condition is true or is met, THEN a specific set of instructions will be executed.
If the condition is false, then another set of instructions will be executed. For example, if an employee works for
more than 40 hours a week, THEN calculate his gross pay based on an overtime rate of 50% more than his
normal hourly pay. If the employee work 40 hours or less a week, THEN calculate gross pay based on the
normal hourly rate of pay. IF-THEN-ELSE works the same way, but in this case the word ELSE is substituted
with a false case, a condition not met. IF the employee works more than 40 hours a week, then calculate gross
pay based on a time and a half the rate, ELSE calculate gross pay based on the normal rate. Alternatively when
there are many options, one can employ the CASE statement. The iteration principle indicates that one part of
the program can be repeated or iterated a limited number of times. In most computer languages, the repetition or
iteration may be activated by using REPEAT ---UNTIL or using the WHILE loop and the FOR loop.
Structured Design
According to structured design principles, a program should be designed from the top-down or bottom-up as a
hierarchical series of modules. A module is a logical way of partitioning or subdividing a program so that each
module performs one or a small number of related tasks.
Master file
Earnings
Deductions
TaxingNet
earning
Print reports
The tasks given above can be shown by a hierarchical chart (Hierarchical Program Organization) as shown
below.
Identifying and diagramming the relationship between modules in this fashion allows programmers to focus on
the overall organization and logic of the program without getting bogged down in the details. After the overall
structure of the program is finalized, detailed coding of individual modules can proceed. It is the set of principles
that enable a problem to be solved by breaking it down into manageable smaller parts, step by step from the
overall problem specification, in stages through to the actual code.
Bottom-up Design
Already existing facilities/designs are used/taken into consideration as a model for a new (better) design. With
the use of Bottom-up design strategy, we take an already existing computer program as a model for our new
program. We try to utilize the existing facilities or design in a way, which gives out program a better
performance.
Stepwise Refinement
Stepwise refinement is a top-down design strategy. The program is developed by successively refining levels of
procedural detail. In every refinement step, one or several instructions of the given program are decomposed
into more detailed ones. This successive decomposition or refinement of specifications terminates when all
instructions are expressed in terms of any underlying computer or programming language. Each step of
refinement implies some design decisions. It is important that the programmer is aware of the underlying criteria.
Sub Programs
In top down design, the problem is broken down into sub-problems. The main problem is solved by the
corresponding main program. The sub-problems solutions are provided by subprograms, known as subroutine,
functions, or procedures depending on the programming language. A subprogram executes or performs the
computer instructions required to solve a given subproblem.
User defined Sub Programs and Functions
A Sub Program is a part of a program that performs one or more related tasks, has its own name, is written as a
separate part of the program, and is accessed via a call statement. A Function returns a value to the program
and shares many of the same characteristics as a Sub Program (e.g., has its own name, is written as a separate
part of the program).
Pros and Cons of Using Procedures
The ability to reuse a sub-program is obviously useful. We can include an existing subprogram in another
program whenever you need it.
Procedures and Functions
A function or procedure is a sub-program that exists to perform a specific, single task. It has its own inputs and
its own outputs (often called parameters), it can also define its own variables. It may return the values to the
referencing or invoking program or procedure A function is a special sort of procedure that has a single output.
Procedures
A procedure has a header, followed by declarations of variables used within the procedure known as local
variables (identifiers) and finally statements that are to be performed when the procedure is invoked. The
procedure header is the mechanism used to give a name to the procedure. The procedure header also may
contain the values that can be communicated between the procedure and its invocation known as parameters.
The common structure for defining a procedure (in C++) is:
void Procedure_Name(parameter)
{
. //List of Statements.
}
Example:
void WelcomeNote ()
{
Cout<<”Say Hello to Programming Concepts”;
}
Procedures in c++ start with the keyword void.
Functions
The general structure for defining a function (in C++) is:
Data_type Function_Name(parameter)
{
.
.
Return statement;
}
Example:
float Cube (float x)
{
float product;
product = x*x*x;
return product;
}
The most important thing to note is that the function must have a result type which dictates what type of value
the function represents.
A function is a special sort of sub-program - it is used when a sub-program is needed which takes a number of
inputs and returns a single output value (as with cube above). This is typical of many algebraic functions (sine,
cosine, exp, log, cube) but is otherwise fairly unusual since the sub-programs that we want to define quite often
have either no output at all or very many outputs - in these cases we use a procedure.
Parameters
As we've seen, procedures and functions can take a list of quantities called parameters. Initially you might like to
regard the parameters as the inputs to the module (but this is not always true).
For example:
void sumAndDifference( float a, float b)
{
a = a+b;
b = a-b;
cout<<"The sum is "<<a;
cout<<"The difference is"<<b;
}
Both total and difference are local variables and only exist within the procedure, as soon as the procedure
finishes they and their values disappear. The following program is an example of the main program:
void main()
{
float val1, val2;
val1=2;
val2=4;
sum_and_difference(val1,val2);
cout<<val1;
}
The values of val1 and val2 are simply copied into the variables a and b of the procedure sumAndDifference. At
the end of the procedure the values are not copied back! The value of val1 that the final output statement
displays is therefore 2 (not 0).
Sometimes however, we would like the values to be copied back at the end of the procedure. This is particularly
true if there is more than one output of the procedure, as in the case of sumAndDifference. The sum and
difference cannot be passed back together as the return value of a function, as a function can return only a
single value.
void sumAndDifference( float a, float b, float &s, float &d)
{
s =a+b;
d =a-b;
}
void main()
{
float val1, val2;
float total, difference;
val1=2;
val2=4;
sum_and_difference(val1,val2, total, difference);
cout<<The sum is <<total;
cout<<The difference is<<difference;
}
The symbol & in the procedure parameter list instructs the computer to copy back any changes to the values of a
and b once the procedure has completed. In summary, if you want to write a sub-program that has a number of
inputs and a single output, write a function. If you want many outputs from the sub-programs, use a number of
var parameters in a procedure.
Built in functions
While most programming languages enable you to write your own functions (as above), most also provide a
library of common functions ready for you to use (e.g. sine, cosine).
A common example of built-in function is the Printf function in C language. (Or any function used for printing out
values in console in any language; System.Out.Println function in case of Java). This function is implemented
and is available to the programmer to use any time he wants. Normally, the programmer is not bothered how the
function is implemented in the framework or how the compiler of the language work with this function.
For further reading you may refer the websites below.
http://www.maths.udsm.ac.tz/mujuni/mt512/Programming%20Approaches.pdf
6.Code optimization techniques
If programmers follow the above principles, then programs will not be complicated by the optimization and
programmer will not be distracted by optimizing.
Code optimization summary
The optimization of code may begin at two steps in case of individual classes and functions. While starting to
code, certain basic principles of code optimization may be kept in mind, which are based on common sense.
Advanced optimization may begin, once the most frequently executed areas of the programs and frequently
used functions are identified.
For further reading you may refer the websites below.
http://channel9.msdn.com/Shows/Going+Deep/Russell-Hadley-The-Route-to-C-Code-Optimization
7.Testing and Debugging
Meets the requirements which will guide the further design and development.
To confirm whether the system works as expected.
To confirm whether it can be implemented with the same characteristics.
To confirm whether it satisfies the stakeholders needs
Testing is thus part of overall Quality Assurance (QA) from which we will be able to measure the quality of any
software application. The software should meet its specified standards during its development cycle.
Software testing can be implemented at any time in the development process depending on the testing method
employed. Test designing will start at the beginning of the project well before coding and thus will help to save a
huge amount of the rework effort and resources.
Example
Consider the example of the banking ATM which will have different functionalities like cash withdrawal, deposit,
balance inquiry, account summary etc.
Unit testing will include developing programs for each functionality mentioned and testing them.
Integration testing includes combining all the modules so that the information is passed correctly from one
module to another. Say if an account has an initial amount of 1000 INR and if we deposit an amount of 2000 INR
to the account then the balance inquiry should be an amount of 3000 INR.
Comprehensive black box testing of banking system with transactions initiated and validations performed on
databases and reports generated while doing the account balance summary.
Unit Testing
This type of testing is performed by the developers before the product/application is handed over to the testing
team to formally execute the test cases. Unit testing is performed by the software developers on the individual
units of source code assigned to them. The developers use test data that is separate from the test data of the
quality assurance team.
The goal of unit testing is to isolate each part of the program and show that the individual parts are working
correctly in terms of requirements and functionality.
The limitations of Unit Testing are as follows:
Testing cannot catch each and every bug in an application. It is impossible to evaluate every execution path in a
software application. The same is the case with unit testing.
There is a limit to the number of scenarios and test data that the developer can use to verify the source code. So
after the developer has exhausted all options there is no other choice but to stop unit testing and combine the
code segments with other units.
Integration Testing
The testing of combined parts of an application to determine if they function correctly together is Integration
testing. There are two methods of doing Integration Testing; Bottom-up Integration testing and Top Down
Integration testing which were already explained.
Bottom-up integration:
This type of testing begins with unit testing, followed by tests of progressively higher level combinations of
units/programs called modules.
Top-Down integration:
In this testing, the highest/top level modules are first tested and then progressively lower-level modules are
tested.
In a comprehensive software development environment, bottom-up testing is usually done first, followed by top-
down testing. The process will finally conclude with multiple tests of the complete application, preferably in
scenarios which are designed to mimic the environment which will be encountered in customers' computers,
systems and network.
System Testing
This is the next level in testing in which we test the whole system. Once all the components are integrated, the
entire application is tested rigorously to see whether it meets the quality standards. This type of testing is usually
performed by a specialized testing team.
System testing is very important because of the following reasons:
1.System Testing is the first step in the Software Development Life Cycle, where the entire application is tested.
2.The application will be tested thoroughly to verify that it meets the functional and technical specifications.
3.The application is tested in an test environment which is very close to the production environment where the
application will be deployed later.
4.System Testing enables us to test, verify and validate both the business requirements and the Applications
Architecture.
Acceptance Testing
This is the most important type of testing as it is conducted by the Quality Assurance Team who will gauge
whether the application meets the intended specifications and satisfies the client's requirements. The QA team
(Alpha testing) will have a set of pre written scenarios and Test Cases that will be used to test the application.
Alpha testing is a form of internal acceptance testing performed mainly by in-house software QA and testing
teams. We also have Beta testing which the is the final testing phase where companies release the software for
few external user groups outside the company test teams or employees.
More ideas will be shared about the application and more tests can be performed on it to determine its accuracy
and the reasons why the project was initiated. Acceptance testing is done not only to point out simple spelling
mistakes, cosmetic errors or Interface gaps, but also to point out any bugs in the application that will result in
system crashes or major errors in the application at a later stage.
By performing acceptance tests on an application, the testing team will get to know how the application will
perform in production environment. There may also be legal and contractual requirements for acceptance of the
system. In such cases the application should satisfy the above requirements before it is accepted by the client.
Non-Functional Testing:
Testing the application against client's and performance requirement. Non-Functioning testing is done based on
the requirements and test scenarios given by the client.
You will get to learn more on non functional testing once you are into projects.
Black Box Testing is a testing strategy and not a type of testing; and this does not need any knowledge of
internal design or code. As the name "black box" suggests, the tester doesn't require any knowledge of internal
logic or code structure. These types of testing are totally focused on the testing for requirements and
functionality of the product/software application. Black box testing is also called as "Opaque Testing",
"Functional/Behavioral Testing" or "Closed Box Testing".
In order to implement the Black Box Testing Strategy, tester should be thorough with the requirement
specifications of the system and as a user should be knowing how the system should behave in response to a
particular action. Some of the black box testing methods are Boundary value analysis, Equivalence partition etc.
Test Techniques - Black box testing, White box testing
We will illustrate the above 2 methods by an example.
There is a store which has introduced discounts for its customers based on their purchase amounts. The
discounts are as per the table below. We have to do the testing of this system.
negative & zero (<0) (invalid class. As we will not purchase for amount of 0 or less that is an invalid input) C2
positive (>0)
[1..499] C3 Valid
[500..4999] C4 valid
[5000.. MAX] C5 valid
[> MAX] C6 invalid
Variable 2
Customer Type (cust_type):
M (member) C1
NM (non member) C2
So test cases are a combination of both the variables
The test inputs need to be from large sample space. That is, from a huge set of data which will take time.
Also it is difficult to identify all possible inputs in limited testing time. So writing test cases is slow and
difficult.
Chances are more that there will be unidentified paths during this testing.
To start the white box testing of the desired application there is no need to wait for userface (UI) to be
completed Covers all possible paths of code which will ensure a thorough testing.
It helps in checking coding standards.
Tester can ask about implementation of each section, so it might be possible to remove unused/dead lines
of codes helps in reducing the number of test cases to be executed during black box testing.
As the tester is aware of internal coding structure, then it is helpful to derive which type of input data is
needed to test the software application effectively.
White box testing allows you to help in code optimization
To test the software application a highly skilled resource is required to carry out testing who has good
knowledge of internal structure of the code which will increase the cost.
Updating the test script is required if there is change in requirement too frequently.
If the application to be tested is large in size, then exhaustive testing is impossible.
It is not possible for testing each and every path/condition of software program, which might miss the
defects in code.
White box testing is a very expensive type of testing.
To test each paths or conditions may require different input conditions, so inorder to test full application, the
tester need to create range of inputs which may be a time consuming.
Syntactic Errors.
Logical Errors
Syntactic Errors:
Every programming language has its own grammar rules. Error in these rules are considered part of syntactic
errors. Like in 'c' language, semicolon is mandatory at the end of each line.
Logical Errors:
It is an error in the logic applied. For Instance, To add two number say a and b, mistakenly the developer may
write it as a - b , instead of a + b, its a logical error Code is verified for both syntactic error and logical error by
passing multiple set of data. From the above example we can see that for performing white box testing, we have
to come up with two basic steps. The following points explain what testers do in white box testing technique:
Step 1) Understand the source code
The first thing a tester will do is to learn and understand the source code of the application. Since white box
testing involves the testing of the inner workings of an application, the tester must have good knowledge in the
programming languages used in the applications they are testing. Also, the tester must be highly aware of
secure coding practices. Security is often one of the primary objectives of testing software. The tester should be
able to find security issues and prevent attacks from hackers and inexperienced users who might inject
malicious code into the application either knowingly or unknowingly.
Step 2) Create test cases and execute
The second step in white box testing involves testing the application's source code for proper flow and structure.
One way of achieving this is by writing more code to test the application?s source code. The tester will develop
small tests for each process or series of processes in the application. This method requires that the tester must
have thorough knowledge of the source code and is often done by the developers. Other methods include
manual testing, trial and error testing, use of testing tools etc.
During requirement gathering phase, the analysis and verifications of requirements are also considered as
testing.
In the design phase while reviewing the design with an intent to improve the design is also considered as
testing.
Testing performed by a developer on completion of the code can also be called as Unit type of testing.
Test cases completed with certain percentage passed and test coverage is achieved.
There are no known critical bugs open after testing.
Coverage of code, functionality, or requirements reaches a specified point
Bug rate falls below a certain level. Which means the testers are not getting any priority 1(highest priority),
2, or 3 (low priority) bugs.
As testing is a never ending process we can never assume that 100 % testing has been done, we can only
minimize the risk of delivering the product to the client/customer with testing done. The risk can be measured by
Risk analysis but for small duration / low budget / low resources project, risk can be deduced by simply by
considering the below points:
7.7. Debugging
In computers, debugging is the process of finding and fixing/bypassing bugs or errors in a program source code
or it can called as the engineering of a hardware device. To debug a program or hardware device, the
programmer has to start with a problem, need to isolate the source of that particular problem, and then finally fix
it. User of a program who does not know how to fix the problem must learn enough about the problem so that he
can avoid it until the problem is given a permanent fix. When someone says they've debugged a program or
"worked the bugs out" of a program, they mean that they have fixed the problem and the bugs no longer exist in
the application.
For any new software or hardware development process, debugging is a necessary process whether it is a
commercial product or an enterprise or personal application program. For complex products, debugging is done
as the result of the unit test for the smallest unit of a system, again at component or module test when parts are
brought together, and then at system test when the product is used with other existing products, and finally
during customer beta test (explained earlier), where users try the product out in a real world situation. As most
computer programs and programmed hardware devices contain thousands of lines of code, almost any new
product is likely to contain a few bugs.
Debugging tools (called debuggers) will help identify coding errors at various development stages. Some
programming language packages will include a facility for checking the errors in the code the moment it is being
written.
Some of the debugging tools available are GDB (For Unix C++), Expeditor (MF) and so on. Please do a search
in Google to get some of the most commonly used debugging tools in the software industry.
Links :
http://www.worldcolleges.info/College/E-Books/download/software%20testing%20life%20cycle(STLC).pdf
http://www.ipl.com/pdf/p0820.pdf
http://www.cs.swan.ac.uk/~csmarkus/CS339/presentations/20061202_Oladimeji_Levels_of_Testing.pdf
1. Waterfall Model
It is one of the most widely used SDLC models. It is also known as "Classic Life Cycle" or "Linear Sequential
model". This is one of the simplest models to understand and use. This model is characterized by a series of
steps that must be completed in a linear or sequential order. It is known by the name 'Waterfall' because, we
move to the next step after getting input from the previous step (phase). This is similar to a waterfall where,
water flows down to lower steps from the upper steps. Each phase is completed and verified before the next
phase. There is sequential progression from one phase to another in this model.
The origin of this model is in the construction and manufacturing industry. Since formal software development
processes did not exist at that time, this hardware-oriented process model was adapted for software
development as well.
Waterfall model is not only simple to understand but also very easy to use. The highlight is that, there are
defined phases or steps in the waterfall model life cycle. So also, the preceding phase must be complete before
the next phase starts. After the first phase/step is completed, it is considered as a stepping stone to the next
phase. Though there are a number of life cycle models that are now used in software development, waterfall
model still remains one of the most popular models.
The waterfall model was originally designed in 1970 by Winston W. Royce. The different phases in Waterfall
model are Requirement analysis, Design, Implementation and Unit Testing, Integration and System testing, and
Maintenance and Operation. The following figure illustrates the waterfall model.
Following each phase, there is a formal review process that results in the decision to proceed to the next phase.
When one phase is complete, the entire development effort shifts to the next phase. Cascading the flow from
one phase to another is the basis of the Waterfall model.
1.Requirements Analysis
Like in any other project, requirements analysis is the first phase in the Waterfall model also. During this phase,
all the needs or functionality which should be implemented are gathered from the client and a blue print is
created. Analysis phase gives a clear picture of what the software will be able to do in future. The system is
thoroughly studied for pitfalls and incompatibilities. Later a requirement specification document is created and
handed over to the Design team.
2. Design
The Design phase needs a new team to design the software. This is most often done by a System Analyst/
Designer. It results in the physical design of a system which is designed from the set of requirements gathered
during the requirement phase.
Creating a good design is very important because it describes what is going to get developed in the
implementation phase. The risk factor is very high in a project where there is poor design or no proper design. A
better understanding of the software help us to reduce the risk of failing. A designer designs everything virtually.
An analyst then analyzes everything thoroughly from top to bottom to ensure that there is no incompatibility or
functional error in the design.
System Analysts use UML (We will discuss about this in detail later) tools to design software systems. Pseudo
codes are written by system analysts for developers to refer to during implementation. Pseudo codes are codes
written roughly in English or any other language which can be read/understand by anyone. It shows how the
software actually works.
3. Implementation
Implementation is a critical phase in any software project. This is the most time consuming phase of the project.
In this phase, developers start writing actual code according to the design obtained from the previous phase.
Later, the project is divided into small tasks according to the functionality or design. These small tasks are called
modules or units. Each module is then assigned to a team of developers, who focus on that particular module.
This helps the developers to implement the system in parallel. Once the development is complete, the project
enters its next phase; testing.
4. Testing
In this phase the software modules are tested by a team of software testers. This process is known as Unit
Testing. Initially, each module is tested for errors. If an error occurs, it is reported back to developers to fix. After
unit testing is completed, all the modules are combined into the project and tested as a whole for integration
errors. The software is tested thoroughly in different conditions to ensure its quality. This is done by a team
called the Quality and Assurance team(a set of software testers). Please go through the 'Testing and Debugging'
module to learn more about testing.
5. Deployment and Maintenance
In this phase, the software system is deployed safely into the required condition or environment, based on the
user requirements. The software can either be deployed into a server or on a computer according to the user
requirements. The product is then ready for use by the end user. Later, the software is maintained by the
maintenance team to ensure that it is working fine. If an error occurs, the maintenance team would fix it and
continue to ensure the working of the software.
Advantages of Waterfall Model
Due to the rigidity of the model, all the requirements must be stated explicitly before development begins. If
requirements are changed or added later, then the project must start over from the beginning.
If errors are made in requirements-analysis or design, they may not be discovered until very late in the
implementation or testing phase.
Due to these issues, the Waterfall model is inappropriate for complex projects. It should not be used for
developing object-oriented software, for long-term or ongoing projects, or for projects whose requirements are
unknown or are subject to change.
V-Shaped Model
Like the Waterfall model, the V-Shaped life cycle model provides a sequential path of individual phases that
must be completed before development proceeds to the next phase. V-shaped model means Verification and
Validation model.
Validation- It is the assurance that a service, product or system meets the needs of the customer.
Verification- The evaluation of whether or not a product, service, or system complies with the requirements,
specification, or an imposed condition. It is an internal process.
The main difference between V-shaped development model and Waterfall development model is the early test
planning. The following figure is a simplified illustration of the V-shaped life cycle model.
V-shaped model is applicable to projects where:
Disadvantages of V-model
Like the Waterfall model, all requirements must be defined at the beginning of the project. So it is difficult to
add or change requirements later in the development process.
All the software development occurs in a single phase, so there are no early working versions or
prototypes.
The emphasis in test planning is to reduce the risk, but like the Waterfall life cycle model the V-model also
risks time and energy in the absence of careful planning.
Similar to Waterfall model, the V-model is inappropriate for complex projects.
3. Iterative Model
The Iterative model addresses many issues associated with the Waterfall model. In the Iterative model, analysis
is done in the same way as it is done in the Waterfall Model .
An Iterative model does not start with a full specification of requirements. Development begins by specifying and
implementing just a part of the software, which can then be reviewed to identify further requirements. This
process is then repeated to produce the new version of the software for each cycle in this model. An iterative life
cycle model consists of repeating the following four phases in sequence.
A Requirements phase in which the requirements are gathered and analyzed for the software development.
A Design phase in which a software solution to meet the requirements is designed. This can be a new design,
or an extension of an earlier design.
An Implementation and test phase, when the software is developed, integrated and tested.
A Review phase in which the software solution is evaluated, the current requirements are reviewed, and
changes and additions to existing requirements are proposed.
For each cycle, a decision has to be made to check whether the software produced by the cycle will be
discarded, or if we can keep it as a starting point for the next cycle (incremental prototyping). A point will be
reached where the requirements are complete and the software can be delivered or it becomes impossible to
enhance the software system as required, and a fresh start has to be made.
The key to the successful use of an iterative life cycle model is rigorous validation of requirements, and the
verification (including testing) of each version of the software against the requirements within each cycle.
The first three phases of the Iterative model are more or less an abbreviated form of a Waterfall life cycle or a
sequential V-model. Each cycle produces software that requires testing at the unit level, for software integration,
system integration and an acceptance from the user. As the software evolves through successive cycles, testing
is repeated and extended to verify each version of the software against the requirements within each cycle.
Advantages of Iterative model
4. Incremental Model
It builds an iterative approach into the waterfall model. Development projects are divided into several
smaller(more manageable) iterations. Each iteration passes through a mini waterfall process model.
Requirement analysis, design, implementation and testing phases are completed for each iteration. In this
model, software is designed, implemented, integrated and tested as a series of incremental builds. Incremental
model may be applicable to projects where:
Requirements are known and well defined, but realization may be delayed.
Basic functionality is required early.
This model is evolutionary, means that a working version of the software is created by the end of the first
iteration, and subsequent iterations build upon the work of earlier iterations.
Low level design is performed during each iteration. Unit testing evaluates the functionality added during the
current iteration on a relatively small amount of new code. . System testing phase evaluates the way in which the
new functionality affects the complete functionality of the entire software system.
Advantages of Incremental Model
Unlike the waterfall model, the incremental model generates a working prototype early in the development
process.
The iterative nature makes it more flexible when adding or changing requirements
Easier to test and debug because testing is performed incrementally during each iteration.
It is an effective tool for risk management.
5. Spiral Model
It is similar to the incremental life cycle model but incorporates risk analysis. It is divided into four phases
I.Planning
II.Risk analysis
III.Development/Engineering
IV.Evaluation
A project passes through each of these phases in sequence, in a series of iterations called spirals. At the
beginning of the development process, critical requirements are identified for the first spiral. The subsequent
spirals add functionality to this baseline spiral.This model is represented by a spiral passing through four
quadrants/phases of development.
Requirements analysis or gathering is performed in the planning phase.
In the risk analysis phase, a formal process is undertaken to identify alternative courses of action and their
relative risks. A prototype is also developed during the risk analysis phase.
Software is coded and tested during the development/engineering phase.
In the evaluation phase, the customer/user has an opportunity to evaluate the software before the project
proceeds to the next spiral.
Following Figure illustrates the Spiral life cycle model. The angular component in the diagram represents the
progress in the current spiral, and the radius represents the project cost.
Focus on risk avoidance makes this model ideal for large scale and mission critical products.
The iterative nature makes it more flexible when adding or changing requirements
Spiral model is built on earlier software development life cycle models, and it borrows from both the
waterfall and incremental models.
Working software code is developed early,thus the user/customer is given with many opportunities to
evaluate the software/output and plenty of time to ease into adoption of the software
Cost is considerably more to implement than other software life cycle models.
Risk analysis phase of this model requires highly specific expertise, and the project's success depends on
the output of this phase.
It is inappropriate for small and medium scale projects.
Summary
All SDLC models share common phases of development:requirements gathering, designing of the software
system, Development of software, and the testing . Waterfall model is one of the simplest and easiest to use,It
consists of five phases that are executed sequentially. The incremental model applies a series of iterations to the
waterfall model. The Spiral model is built upon the waterfall and incremental models and focuses on risk
analysis.
We can use UML with all processes throughout the development life cycle and across different
implementation technologies.
Software will behave as we expect it to (fewer surprises).
We will have lower development costs.
Working with new developers will be easier.
The right decisions are made to prevent poorly written code. Overall cost would be very less.
We can develop memory and processor efficient systems.
Efficient communication with programmers and outside contractors.
Less system maintenance cost.
A use case specifies a sequence of actions that provide a measurable value to an actor. A use case is drawn as
a horizontal ellipse on a UML use case diagram, as you see in the figure.
Each use case focuses on describing how to achieve a goal or task. A use case should:
Describe what the system shall do to assist the actor in achieving a goal
Not include any details about the screens or user interfaces.
For example, the below use case describes a simple Login.Sequence of steps included in the Login use case
are :
Include Relationship :
It is a relationship between two business use cases that signifies that the business use case on the side to which
the arrow points is included in the use case on the other side of the arrow. For one functionality that the business
system provides, another business functionality is accessed.
Functionality that are accessed repeatedly can be depicted as individual business use cases, which can be used
in multiple ways. In can be represented as below.
Example :
In the following figure , An include relationship points from the CheckOrderStatus use case to the LogIn use
case.It indicate that the CheckOrderStatus use case always includes the behaviors in the LogIn use case.
The included use case LogIn cannot stand alone and the original use case CheckOrderStatus is not complete
without the LogIn use case.
Object Notation:
Object is represented in the same way as the class. The only difference is the name which is underlined as
shown in the figure given below.
An object is the actual implementation of a class .It is also known as the instance of a class.
The following points should be considered while drawing a class diagram:
i.The name of the class should be meaningful.
ii.Each element and their relationships needs to be identified in advance.
iii.Attributes and methods of each class needs to be clearly identified.
iv.Unnecessary properties will make the class diagram complicated,So for each class minimum number of
properties should be specified.
v.Use notes wherever required to describe the aspect of the diagram. Because the class diagram it should be
understandable to the developer.
vi.The diagram needs to be drawn on plain paper and rework as many times as possible to make it correct
before making the final version.
The following figure represents the class diagram of an Order System . The class diagram has been drawn
considering all the points mentioned above:
Sequence Diagram
It is used to model the life line of an object, the activation and the message passing. Sequence diagrams are
two-dimensional diagrams: one dimension (usually the vertical) is used to display evolution through time, the
other to distinguish between different objects. An object is a vertical line with a thick bar on the line which
indicates the life line of an object. Message passing is modeled by arrows pointing from one object to the next at
a certain state transition on the life lines of both objects. When message passing is instantaneous, the arrows
are horizontal.
As mentioned the aim of a sequence diagram is to define event sequences, which would have a desired
outcome. The focus is more on the order in which messages occur than the message. However, the majority of
sequence diagrams will communicate what messages are sent and the order in which they tend to occur.
Lifelines
When drawing a sequence diagram, remember that lifeline notation elements are placed across the top of the
diagram. Lifelines are representative of roles or object instances that take part in the sequence being modeled.
From a visual perspective, lifelines are shown as a box with a dashed line descending from the center of the
bottom edge. Name of the lifeline is placed inside the box. Additionally, the lifeline name is underlined. What this
means is that the lifeline represents a specific instance of a class in a sequence diagram.
Message
For the sake of readability, the first message of a sequence diagram always starts at the top and is located on
the left side of the diagram. Subsequent messages are then added to the diagram. To show an object or lifeline
sending a message to another object, you draw a line to the receiving object with a solid arrowhead (if a
synchronous call ) or with a stick arrowhead (if an asynchronous call). The method /message name is placed
above the arrowed line. The message sent to the receiving object represents an method/operation that the
receiving object?s class implements.
Elements are connected by activity edges to form the control flow, which can also be called as flow . The
execution of an activity may contain parallel flows. A border can surround an activity(entire activity diagram).
Action
An action is defined as an individual step within an activity.For example, a calculation step that is not possible to
break down any further. It does not mean that the action cannot be subivided , but in this diagram will not be
refined further.
An action can contain input and output information The output of one action can be the input of a subsequent
action within an activity. Specific actions are sending signals,calling other actions and receiving an event.
Calling an Activity(Action)
With the following symbol an activity can be called from within another activity. Calling in itself is an action, the
outcome of the call is an another activity. Activities can be nested within each other and can be represented with
different levels of details.
An example of a time event is triggering reminders after the deadline for payment has passed.
Sending Signals(Action)
It means that a signal is being sent to an accepting activity.
The accepting activity accepts the signal with the corresponding action ' accepting an event ' and can react
accordingly(according to the flow that originates from this node in the activity diagram).
Edge (Control Flow)
Edge is represented by arrows. It connects the individual components of activity diagrams and illustrate the
control flow of an activity.
Within the control flow an incoming arrow starts a single step of an activity, once that step is completed the flow
continues along the outgoing arrow. A name is attached to an edge.
Decision Node
The diamond represents a decision node or a conditional branch point. It has only one input and two or more
outputs.
Each output has a condition attached to it, which can be represented/ written in brackets. If a condition is met,
the flow proceeds along with the appropriate output. An else output can also be defined.
Merge Node
Merge node has several inputs and only one output. It is used for merging of flows. It is represented by the
diamond given below.
Fork
A fork has only one input and two or more outputs. For the branching of flows in two or more parallel flows we
use a synchronization bar, which is represented as a vertical line or thick horizontal. Branching allows parallel
flows within an activity.
Join
For the consolidation of two or more parallel flows we can use a synchronization bar, which is represented as a
thick vertical or horizontal line. It takes two or more inputs and gives only one output.
Initial Node
Initial node is the starting point of any activity. An activity can contain more than one initial node, in this case
several flows will start at the beginning of an activity. It is also possible that an activity has no initial node, but
can be initiated by an event .
If several parallel flows are present within an activity, all flows are stopped at the time the final node is reached.
Flow Final Node
It terminates a flow. It is represented as below. Reaching a flow final node has no effect on other parallel flows
that are processed within the activity at the same point in time.
Activity Partition
The individual elements of an activity diagram can be divided into 'partitions' or individual areas. Various criteria
can lead to the creation of these partitions organization entities, locations ,cost centers, etc.
Individual steps of an activity would be assigned to these partitions. Each partition is set apart from its
neighboring partition by a or vertical horizontal continuous line, from this stems the term swim lanes. Each
partition receives a name. Partitions can be arranged in a two dimensional manner, in the above diagram the
activity diagram is divided into individual cells like a grid.
Example : Passenger Check-in
In the following figure, we can start reading at the initial node or with the acceptance of the event passenger
arrive sat check-in (1), and continue along the arrows of the control flow (2).
The third action Passenger Checks In(3) means that at this point the activity passenger check in is processed.
If we follow the control flow, next we will come to a decision node or conditional branch (4), if the check-in is OK
then the next step along the control flow can continue. Otherwise (5), the passenger cannot fly and the
passenger task service is completed. This is represented by a the black dot with border(the activity final node).
After successful check-in (7) we come to a black cross bar. All arrows that come from this black bar (7)
symbolize flows that are processed simultaneously( the luggage is being loaded onto the airplane (9) and the
passenger is boarding the airplane (10) ).
Between point (8) and point (11) the flows are independent from each other. Simultaneously processed Flows (9
and 10) are merged at the second cross bar (11). It means that only when the passenger is on the plane (10)
and the luggage has been loaded onto the plane (9), then the control flow continue below the cross bar (11).
In this example, one more action (12) and subsequent to that the final state (13) follow, meaning that after the
passenger is on the plane (10) and the luggage has been loaded onto the plane (9), the airplane can taxi
towards the runway (12).
We can see here that the last action airplane taxis toward runway (12) is only defined as a single action, even
though this process is very complex and could be described in many other activity diagrams.
Following figure illustrates the activity diagram with partitions .
The above diagram is divided into two partitions passenger (1) and passenger services (2). The passenger
carries out showing ticket at Check-In counter (3), checking luggage (4) and paying fee (5). All other actions of
passenger services (2) and are carried out by passenger services.
Please refer the below link for further information about UML Diagrams
http://sourcemaking.com/uml/introduction
http://www.cragsystems.co.uk/uml_tutorial/
Ask a doubt