QA Booklet 1750345445
QA Booklet 1750345445
net
On Weekend +92 300 1404 303
QA Booklet
A brief collection of basic IT concepts for starting QA / testing job
Live Classes www.qastack.net
On Weekend +92 300 1404 303
Smoke Testing is performed to ascertain that the Sanity Testing is done to check the new
critical functionalities of the program is working functionality/bugs have been fixed
fine
The objective of this testing is to verify the The objective of the testing is to verify the
"stability" of the system in order to proceed with "rationality" of the system in order to proceed with
more rigorous testing more rigorous testing
This testing is performed by the developers or Sanity testing is usually performed by testers
testers
Smoke testing is usually documented or scripted Sanity testing is usually not documented and is
unscripted
Smoke testing is a subset of Acceptance testing Sanity testing is a subset of Regression Testing
Smoke testing exercises the entire system from Sanity testing exercises only the particular
end to end component of the entire system
Smoke testing is like General Health Check Up Sanity Testing is like specialized health check up
Testing the fully integrated applications including external peripherals in order to check how
components interact with one another and with the system as a whole. This is also called
End to End testing scenario.
Live Classes www.qastack.net
On Weekend +92 300 1404 303
Verify thorough testing of every input in the application to check for desired outputs.
Testing of the user's experience with the application.
The purpose of Regression Testing is that Re-testing is done on the basis of the
new code changes should not have any Defect fixes
side effects to existing functionalities
Defect verification is not the part of Defect verification is the part of re-
Regression Testing testing
You can do automation for regression You cannot automate the test cases for
testing, Manual Testing could be Retesting.
expensive and time-consuming
Regression testing is done for passed test Retesting is done only for failed test
cases cases
Regression testing checks for unexpected Re-testing makes sure that the original
side-effects fault has been corrected
Live Classes www.qastack.net
On Weekend +92 300 1404 303
1.6 Integration testing
Testing of all integrated modules to verify the combined functionality after integration is termed as
Integration Testing. Modules are typically code modules, individual applications, client and server
applications on a network, etc. This type of testing is especially relevant to client/server and
distributed systems. Integration testing is the process of testing the interface between two
software units or module. It‘s focus on determining the correctness of the interface. The purpose
of the integration testing is to expose faults in the interaction between integrated units. Once all
the modules have been unit tested, integration testing is performed.
What is Top-Down Approach?
Testing takes place from top to bottom. High-level modules are tested first and then low-level
modules and finally integrating the low-level modules to a high level to ensure the system is
working as intended. Stubs are used as a temporary module if a module is not ready for
integration testing.
Non-Functional Testing
Non-functional testing is a type of testing to check non-functional aspects (performance, usability,
reliability, etc.) of a software application. It is explicitly designed to test the readiness of a system
as per nonfunctional parameters which are never addressed by functional testing.
A good example of non-functional test would be to check how many people can simultaneously
login into a software.
Non-functional testing is equally important as functional testing and affects client satisfaction.
Functional Vs. Non-Functional Testing
Parameters Functional testing Non-functional testing
Execution It is performed before non- It is performed after the functional
functional testing. testing.
Focus area It is based on customer's It focuses on customer's expectation.
requirements.
Requirement It is easy to define functional It is difficult to define the requirements
requirements. for non-functional testing.
Usage Helps to validate the behavior of Helps to validate the performance of the
the application. application.
Objective Carried out to validate software It is done to validate the performance of
actions. the software.
Requirements Functional testing is carried out This kind of testing is carried out by
using the functional specification. performance specifications
Manual testing Functional testing is easy to It's very hard to perform non-functional
execute by manual testing. testing manually.
Functionality It describes what the product does. It describes how the product works.
Example Test Check login functionality. The dashboard should load in 2 seconds.
Case
Number of concurrent users that an application can support, and scalability to allow more
users to access it.
It is a type of non-functional testing. In Software Engineering, Load testing is commonly used for the
Client/Server, Web-based applications - both Intranet and Internet.
ensures that the software system and application are free from any threats or risks that can cause
a loss. Security testing of any system is focuses on finding all possible loopholes and weaknesses
of the system which might result into the loss of information or repute of the organization.
The goal of security testing is to:
To identify the threats in the system.
To measure the potential vulnerabilities of the system.
To help in detecting every possible security risks in the system.
To help developers in fixing the security problems through coding.
Major Focus Areas in Security Testing:
Network Security
System Software Security
Client-side Application Security
Server-side Application Security
done by the people having enough experience on the system to "guess" the most likely source of
errors.
In Software Engineering, Ad-hoc Testing saves lot of time as it doesn't require elaborate test
planning, documentation and Test Case design.
Alpha testing performed by Testers who are usually internal employees of the Beta testing is performed by Clients or End Users who are not employees of the
organization organization
Alpha Testing performed at developer's site Beta testing is performed at a client location or end user of the product
Reliability and Security Testing are not performed in-depth Alpha Testing Reliability, Security, Robustness are checked during Beta Testing
Alpha testing involves both the white box and black box techniques Beta Testing typically uses Black Box Testing
Alpha testing requires a lab environment or testing environment Beta testing doesn't require any lab environment or testing environment. The software
is made available to the public and is said to be real time environment
Long execution cycle may be required for Alpha testing Only a few weeks of execution are required for Beta testing
Critical issues or fixes can be addressed by developers immediately in Alpha Most of the issues or feedback is collected from Beta testing will be implemented in
testing future versions of the product
Alpha testing is to ensure the quality of the product before moving to Beta testing Beta testing also concentrates on the quality of the product, but gathers users input on
the product and ensures that the product is ready for real time users.
the early stages of the development cycle. This testing is also called a Non-execution technique or
verification testing.
Static testing involves manual or automated reviews of the documents. This review is done during
an initial phase of testing to catch Defect early in STLC. It examines work documents and
provides review comments.
Under Dynamic Testing, the code is executed. It checks for functional behavior of software
system, memory/CPU usage and overall performance of the system. Hence the name "Dynamic"
Live Classes www.qastack.net
On Weekend +92 300 1404 303
The main objective of this testing is to confirm that the software product works in conformance
with the business requirements. This testing is also called an Execution technique or validation
testing.
Static Testing Dynamic Testing
Testing was done without executing the
program Testing is done by executing the program
This testing does the verification process Dynamic testing does the validation process
Dynamic testing is about finding and fixing the
Static testing is about prevention of defects defects
Static testing gives an assessment of code and Dynamic testing gives bugs/bottlenecks in the
documentation software system.
Cost of finding defects and fixing is less Cost of finding and fixing defects is high
Return on investment will be high as this Return on investment will be low as this process
process involved at an early stage involves after the development phase
More reviews comments are highly More defects are highly recommended for good
recommended for good quality quality.
The main focus of black box testing is on White Box Testing (Unit Testing) validates
the validation of your functional internal structure and working of your
requirements. software code
Black box testing gives abstraction from To conduct White Box Testing, knowledge of
code and focuses on testing effort on the underlying programming language is
software system behavior. essential. Current day software systems use a
variety of programming languages and
technologies and it‟s not possible to know all
of them.
Black box testing facilitates testing White box testing does not facilitate testing
communication amongst modules communication amongst modules
3) Test data with values just above the extreme edges of input domain i.e. values 2 and 1001.
Boundary value analysis is often called as a part of stress and negative testing.
Web application testing - Application is loaded on the server and there is no exe installed on the
client machine, you are required to test it on various web browsers. It is probable that web
applications are to be tested on different OS platforms and browsers so, broadly speaking; web
application is tested chiefly for system compatibility and browser compatibility, static pages, load
testing, error handling and backend testing.
It does not involve executing the program It always involves executing a program
In order to meet the customer requirements, QA QC confirms that the standards are followed
defines standards and methodologies while working on the product
Its main motive is to prevent defects in the Its main motive is to identify defects or bugs
system. It is a less time-consuming activity in the system. It is a more time-consuming
activity
QA ensures that everything is executed in the QC ensures that whatever we have done is
right way, and that is why it falls under as per the requirement, and that is why it
verification activity falls under validation activity
It requires the involvement of the whole team It requires the involvement of the Testing
team
Definition The process of evaluating work- The process of evaluating software during
products (not the actual final product) or at the end of the development process to
of a development phase to determine determine whether it satisfies specified
whether they meet the specified business requirements.
requirements for that phase.
Objective To ensure that the product is being built To ensure that the product actually meets
according to the requirements and the user‟s needs and that the specifications
design specifications. In other words, were correct in the first place. In other
to ensure that work products meet their words, to demonstrate that the product
specified requirements. fulfills its intended use when placed in its
intended environment.
Question Are we building the product right? Are we building the right product?
Walkthroughs
Inspections
Verified: The tester re-tests the bug after it got fixed by the developer. If there is no bug
detected in the software, then the bug is fixed and the status assigned is "verified."
Reopen: If the bug persists even after the developer has fixed the bug, the tester changes
the status to "reopened". Once again the bug goes through the life cycle.
Closed: If the bug is no longer exists then tester assigns the status "Closed."
Duplicate: If the defect is repeated twice or the defect corresponds to the same concept of
the bug, the status is changed to "duplicate."
Rejected: If the developer feels the defect is not a genuine defect then it changes the defect
to "rejected."
Deferred: If the present bug is not of a prime priority and if it is expected to get fixed in the
next release, then status "Deferred" is assigned to such bugs
Not a bug: If it does not affect the functionality of the application then the status assigned to
a bug is "Not a bug".
Low: The Defect is an irritant but repair can be done once the more serious Defect has been
fixed
Medium: During the normal course of the development activities defect should be resolved.
It can wait until a new version is created
High: The defect must be resolved as soon as possible as it affects the system severely and
cannot be used until it is fixed
Priority Vs Severity: Key Difference
Priority Severity
Defect Priority has defined the order Defect Severity is defined as the degree
in which the developer should of impact that a defect has on the
resolve a defect operation of the product
Priority is categorized into three types Severity is categorized into five types
o Low o Critical
o Medium o Major
o High o Moderate
o Minor
o Cosmetic
Priority is associated with scheduling Severity is associated with functionality
or standards
Priority indicates how soon the bug Severity indicates the seriousness of the
should be fixed defect on the product functionality
Priority of defects is decided in QA engineer determines the severity
consultation with the manager/client level of the defect
Priority is driven by business value Severity is driven by functionality
Its value is subjective and can change Its value is objective and less likely to
over a period of time depending on change
the change in the project situation
High priority and low severity status High severity and low priority status
indicates, defect have to be fixed on indicates defect have to be fixed but
immediate bases but does not affect not on immediate bases
the application
Priority status is based on customer Severity status is based on the technical
requirements aspect of the product
During UAT the development team fix During SIT, the development team will
defects based on priority fix defects based on the severity and
then priority
2.10 Difference between Test scenario, Test case and a Test script
Test Case VS Test Scenario
A test case is a set of conditions for evaluation a particular feature of a software product to determine its
compliance with the business requirements.
A Test Case is a set of actions executed to verify a particular feature or functionality of your software
application. The Test Case has a set test data, precondition, certain expected and actual results developed for
specific test scenario to verify any requirement.
A test case includes specific variables or conditions, using which a test engineer can determine as to whether a
software product is functioning as per the requirements of the client or the customer.
Whereas, a test scenario is generally a one line statement describing a feature of application to be tested. It is
used for end to end testing of a feature and is generally derived from the use cases.
COMPARISON
PARAMETER USE CASE TEST CASE
A sequential actions which A Group of test inputs,
is use to describe the conditions and variables by
interaction among the role and which the characteristics of
system to maintain a the
Definition specified objective, software is defined.
To reach the last operation
follow all sequential operation Validating the software as it
Goal is working fine or not.
it follows single test case is
Iteration it follows different paths tested at a time
it is dependent on the it is dependent over the use
Dependency requirements case
Test inputs scripts and each
Documents and research is test scripts complete one
Requirement required step
The testing is done again
Completion complete all step once and again then finish.
Interaction User Results
it is working as following the it is working with the help
step by step function ability of of testers to validate the
Working the software. software
Live Classes www.qastack.net
On Weekend +92 300 1404 303
Testing:
Testing starts once the coding is complete and the modules are released for testing. In this phase,
the developed software is tested thoroughly and any defects found are assigned to developers to
get them fixed.
Retesting, regression testing is done until the point at which the software is as per the customer‘s
expectation. Testers refer SRS document to make sure that the software is as per the customer‘s
standard.
Installation/Deployment:
Once the product is tested, it is deployed in the production environment or first UAT (User
Acceptance testing) is done depending on the customer expectation.
In the case of UAT, a replica of the production environment is created and the customer along with
the developers does the testing. If the customer finds the application as expected, then sign off is
provided by the customer to go live.
Maintenance:
After the deployment of a product on the production environment, maintenance of the product i.e.
if any issue comes up and needs to be fixed or any enhancement is to be done is taken care by
the developers.
SDLC models might have a different approach but the basic phases and activity remain the same
for all the models.
Waterfall Model
Waterfall model is the very first model that is used in SDLC. It is also known as the linear
sequential model.
In this model, the outcome of one phase is the input for the next phase. Development of the next
phase starts only when the previous phase is complete.
First, Requirement gathering and analysis is done. Once the requirement is freeze then only
the System Design can start. Herein, the SRS document created is the output for the
Requirement phase and it acts as an input for the System Design.
In System Design Software architecture and Design, documents which act as an input for the
next phase are created i.e. Implementation and coding.
In the Implementation phase, coding is done and the software developed is the input for the
next phase i.e. testing.
In the testing phase, the developed code is tested thoroughly to detect the defects in the
software. Defects are logged into the defect tracking tool and are retested once fixed. Bug
logging, Retest, Regression testing goes on until the time the software is in go-live state.
In the Deployment phase, the developed code is moved into production after the sign off is
given by the customer.
Any issues in the production environment are resolved by the developers which come under
maintenance.
Live Classes www.qastack.net
On Weekend +92 300 1404 303
V- Shaped Model
V- Model is also known as Verification and Validation Model. In this model Verification & Validation
goes hand in hand i.e. development and testing goes parallel. V model and waterfall model are
the same except that the test planning and testing start at an early stage in V-Model.
a) Verification Phase:
(i) Requirement Analysis:
In this phase, all the required information is gathered & analyzed. Verification activities include
reviewing the requirements.
(ii) System Design:
Once the requirement is clear, a system is designed i.e. architecture, components of the product
are created and documented in a design document.
(iii) High-Level Design:
High-level design defines the architecture/design of modules. It defines the functionality between
the two modules.
(iv) Low-Level Design:
Low-level Design defines the architecture/design of individual components.
(v) Coding:
Code development is done in this phase.
Live Classes www.qastack.net
On Weekend +92 300 1404 303
b) Validation Phase:
(i) Unit Testing:
Unit testing is performed using the unit test cases that are designed and is done in the Low-level
design phase. Unit testing is performed by the developer itself. It is performed on individual
components which lead to early defect detection.
(ii) Integration Testing:
Integration testing is performed using integration test cases in High-level Design phase.
Integration testing is the testing that is done on integrated modules. It is performed by testers.
(iii) System Testing:
System testing is performed in the System Design phase. In this phase, the complete system is
tested i.e. the entire system functionality is tested.
(iv) Acceptance Testing:
Acceptance testing is associated with the Requirement Analysis phase and is done in the
customer‘s environment.
Advantages of V – Model:
It is a simple and easily understandable model.
V –model approach is good for smaller projects wherein the requirement is defined and it
freezes in the early stage.
It is a systematic and disciplined model which results in a high-quality product.
Disadvantages of V-Model:
V-shaped model is not good for ongoing projects.
Requirement change at the later stage would cost too high.
Prototype Model
The prototype model is a model in which the prototype is developed prior to the actual software.
Prototype models have limited functional capabilities and inefficient performance when compared
to the actual software. Dummy functions are used to create prototypes. This is a valuable
mechanism for understanding the customers‘ needs.
Software
prototypes are built prior to the actual software to get valuable feedback from the customer.
Feedbacks are implemented and the prototype is again reviewed by the customer for
any change. This process goes on until the model is accepted by the customer.
Once the requirement gathering is done, the quick design is created and the prototype which is
presented to the customer for evaluation is built.
Customer feedback and the refined requirement is used to modify the prototype and is again
presented to the customer for evaluation. Once the customer approves the prototype, it is used as
a requirement for building the actual software. The actual software is build using the Waterfall
model approach.
Advantages of Prototype Model:
Live Classes www.qastack.net
On Weekend +92 300 1404 303
Prototype model reduces the cost and time of development as the defects are found much
earlier.
Missing feature or functionality or a change in requirement can be identified in the evaluation
phase and can be implemented in the refined prototype.
Involvement of a customer from the initial stage reduces any confusion in the requirement or
understanding of any functionality.
Disadvantages of Prototype Model:
Since the customer is involved in every phase, the customer can change the requirement of
the end product which increases the complexity of the scope and may increase the delivery
time of the product.
Spiral Model
The Spiral Model includes iterative and prototype approach.
Spiral model phases are followed in the iterations. The loops in the model represent the phase of
the SDLC process i.e. the innermost loop is of requirement gathering & analysis which follows the
Planning, Risk analysis, development, and evaluation. Next loop is designing followed by
Implementation & then testing.
Spiral Model has four phases:
Planning
Risk Analysis
Engineering
Evaluation
(i) Planning:
The planning phase includes requirement gathering wherein all the required information is
gathered from the customer and is documented. Software requirement specification document is
created for the next phase.
(ii) Risk Analysis:
In this phase, the best solution is selected for the risks involved and analysis is done by building
the prototype.
For Example, the risk involved in accessing the data from a remote database can be that the data
access rate might be too slow. The risk can be resolved by building a prototype of the data access
subsystem.
(iii) Engineering:
Live Classes www.qastack.net
On Weekend +92 300 1404 303
Once the risk analysis is done, coding and testing are done.
(iv) Evaluation:
Customer evaluates the developed system and plans for the next iteration.
Advantages of Spiral Model:
Risk Analysis is done extensively using the prototype models.
Any enhancement or change in the functionality can be done in the next iteration.
Disadvantages of Spiral Model:
Agile Model
Agile Model is a combination of the Iterative and incremental model. This model focuses more on
flexibility while developing a product rather than on the requirement.
In Agile, a product is broken into small incremental builds. It is not developed as a complete
product in one go. Each build increments in terms of features. The next build is built on previous
functionality.
In agile iterations are termed as sprints. Each sprint lasts for2-4 weeks. At the end of each sprint,
the product owner verifies the product and after his approval, it is delivered to the customer.
Customer feedback is taken for improvement and his suggestions and enhancement are worked
on in the next sprint. Testing is done in each sprint to minimize the risk of any failures.
The word scrum also is used in rugby to define a play where players struggle against each to gain
possession of the ball. The goal of a scrum in software development is to perform at a high-
performing level like a rugby team does in a scrum.
How Scrum Works
In a rugby scrum, all the players literally put their heads together. When it comes to software
development, a scrum can be characterized by developers putting their heads together to address
complex problems.
Scrum software development starts with a wish list of features — a.k.a. a product backlog.
The team meets to discuss:
o The backlog.
o What still needs to be completed.
o How long it will take.
Scrum relies on an agile software development concept called sprints:
o Sprints are periods of time when software development is actually done.
o A sprint usually lasts from one week to one month to complete an item from the
backlog.
o The goal of each sprint is to create a saleable product.
o Each sprint ends with a sprint review.
o Then the team chooses another piece of backlog to develop — which starts a new
sprint.
o Sprints continue until the project deadline or the project budget is spent.
In daily scrums, teams meet to discuss their progress since the previous meeting and make
plans for that day.
o The meetings should be brief — no longer than 15 minutes.
o Each team member needs to be present and prepared.
o The Scrum Master keeps the team focused on the goal.
Live Classes www.qastack.net
On Weekend +92 300 1404 303
Agile software development has been Scrum is ideally used in the project where
widely seen as highly suited to the requirement is rapidly changing.
environments which have small but
expert project development team
In the Agile process, the leadership plays Scrum fosters a self-organizing, cross-
a vital role. functional team.
Agile can require lots of up-front Not too many changes needed while
development process and organizational implementing scrum process.
change.
The agile method needs frequent In the scrum, after each sprint, a build is
delivery to the end user for their delivered to the client for their feedback.
feedback.
Project head takes cares of all the tasks There is no team leader, so
in the agile method. the entire team addresses the issues or
problems.
In the Agile method, the priority is always Empirical Process Control is a core
to satisfy the customer by philosophy of Scrum based process.
providing continuous delivery of
valuable software.
6 CONTEXT DIAGRAM
A context diagram, sometimes called a level 0 data-flow diagram, is drawn in order to define and clarify the boundaries
of the software system. It identifies the flows of information between the system and external entities. The entire software
system is shown as a single process.
7 ACTIVITY DIAGRAM
An activity diagram is a behavioral diagram i.e. it depicts the behavior of a system. An activity
diagram portrays the control flow from a start point to a finish point showing the various decision paths that
exist while the activity is being executed.
1. Requirement Analysis
During this phase, test team studies the requirements from a testing point of view to identify the
testable requirements.
The QA team may interact with various stakeholders (Client, Business Analyst, Technical Leads,
and System Architects etc.) to understand the requirements in detail.
Requirements could be either Functional (defining what the software must do) or Non Functional
(defining system performance /security / availability)
Activities
Identify types of tests to be performed.
Gather details about testing priorities and focus.
Prepare Requirement Traceability Matrix (RTM).
Identify test environment details where testing is supposed to be carried out.
Automation feasibility analysis (if required).
Deliverables
RTM
Automation feasibility report. (if applicable)
2. Test Planning
Typically, in this stage, a Senior QA manager will determine effort and cost estimates for the
project and would prepare and finalize the Test Plan. In this phase, Test Strategy is also
determined.
Activities
Preparation of test plan/strategy document for various types of testing
Test tool selection
Test effort estimation
Resource planning and determining roles and responsibilities.
Training requirement
Live Classes www.qastack.net
On Weekend +92 300 1404 303
Deliverables
Test plan /strategy document.
Effort estimation document.
3. Test Case Development
This phase involves the creation, verification and rework of test cases & test scripts. Test data, is
identified/created and is reviewed and then reworked as well.
Activities
Create test cases, automation scripts (if applicable)
Review and baseline test cases and scripts
Create test data (If Test Environment is available)
Deliverables
Test cases/scripts
Test data
5. Test Execution
During this phase, the testers will carry out the testing based on the test plans and the test cases
prepared. Bugs will be reported back to the development team for correction and retesting will be
performed.
Activities
Execute tests as per plan
Document test results, and log defects for failed cases
Map defects to test cases in RTM
Retest the Defect fixes
Track the defects to closure
Deliverables
Completed RTM with the execution status
Test cases updated with results
Defect reports
Live Classes www.qastack.net
On Weekend +92 300 1404 303
6. Test Cycle Closure
Testing team will meet, discuss and analyze testing artifacts to identify strategies that have to be
implemented in the future, taking lessons from the current test cycle. The idea is to remove the
process bottlenecks for future test cycles and share best practices for any similar projects in the
future.
Activities
Evaluate cycle completion criteria based on Time, Test coverage, Cost, Software, Critical
Business Objectives, Quality
Prepare test metrics based on the above parameters.
Document the learning out of the project
Prepare Test closure report
Qualitative and quantitative reporting of quality of the work product to the customer.
Test result analysis to find out the defect distribution by type and severity.
Deliverables
Test Closure report
Test metrics
8.4 Reviews
Reviews are the form of static testing. In software reviews people analyze the work product of
projects such as requirements document, design document, test strategy, test plan in order to find
out any defects in the documents.
Software Reviews, if done properly are the biggest and most cost effective contributor to product
quality.
Review provides a powerful way to improve the quality and productivity of software development
to recognize and fix their own defects early in the software development process.
Advantages of Reviews:-
1. Types of defects that can be found during static testing are: deviations from standards, missing
requirements, design defects, non-maintainable code and inconsistent interface specifications.
2. Since static testing can start early in the life cycle, early feedback on quality issues can be
established, e.g. an early validation of user requirements and not just late in the life cycle during
acceptance testing.
3. By detecting defects at an early stage, rework costs are relatively low and thus a relatively
cheap improvement of the quality of software products can be achieved.
4. The feedback and suggestions document from the static testing process allows for process
improvement, which supports the avoidance of similar errors being made in the future.
Roles and Responsibilities in a Review
There are various roles and responsibilities defined for a review process. Within a review team,
four types of participants can be distinguished: moderator, author, recorder, reviewer and
manager. Let‘s discuss their roles one by one:-
Live Classes www.qastack.net
On Weekend +92 300 1404 303
1. The moderator: - The moderator (or review leader) leads the review process. His role is to
determine the type of review, approach and the composition of the review team. The moderator
also schedules the meeting, disseminates documents before the meeting, coaches other team
members, paces the meeting, leads possible discussions and stores the data that is collected.
2. The author: - As the writer of the ‗document under review‘, the author‘s basic goal should be to
learn as much as possible with regard to improving the quality of the document. The author‘s
task is to illuminate unclear areas and to understand the defects found.
3. The recorder: – The scribe (or recorder) has to record each defect found and any suggestions
or feedback given in the meeting for process improvement.
4. The reviewer: - The role of the reviewers is to check defects and further improvements in
accordance to the business specifications, standards and domain knowledge.
5. The manager :- Manager is involved in the reviews as he or she decides on the execution of
reviews, allocates time in project schedules and determines whether review process objectives
have been met or not.
Phases of a formal Review (Phases of Inspection)
A formal review takes place in a piecemeal approach which consists of 6 main steps. Let‘s discuss
about these phases one by one.
1. Planning
The review process for a particular review begins with a ‗request for review‘ by the author to the
moderator (or inspection leader). A moderator is often assigned to take care of the
scheduling (dates, time, place and invitation) of the review. The project planning needs to allow
time for review and rework activities, thus providing engineers with time to thoroughly participate
in reviews. There is an entry check performed on the documents and it is decided that which
documents are to be considered or not. The document size, pages to be checked, composition
of review team, roles of each participant, strategic approach are decided into planning phase.
2. Kick-Off
The goal of this meeting is to get everybody on the same page regarding the document under
review. Also the result of the entry and exit criteria is discussed. Basically, during the kick-off
meeting, the reviewers receive a short introduction on the objectives of the review and the
documents. Role assignments, checking rate, the pages to be checked, process changes and
possible other questions are also discussed during this meeting. Also, the distribution of the
document under review, source documents and other related documentation, can also be done
during the kick-off.
3. Preparation
In this phase, participants work individually on the document under review using the related
documents, procedures, rules and checklists provided. The individual participants identify
defects, questions and comments, according to their understanding of the document and role.
Spelling mistakes are recorded on the document under review but not mentioned during the
meeting. The annotated document will be given to the author at the end of the logging meeting.
Using checklists during this phase can make reviews more effective and efficient.
4. Review Meeting
This meeting typically consists of the following elements:-
-logging phase
-discussion phase
-decision phase.
During the logging phase the issues, e.g. defects, that have been identified during the preparation
are mentioned page by page, reviewer by reviewer and are logged either by the author or by a
scribe. This phase is for just jot down all the issues not to discuss them in detail. If an issue needs
discussion, the item is logged and then handled in the discussion phase. A detailed discussion on
whether or not an issue is a defect is not very meaningful, as it is much more efficient to simply log
it and proceed to the next one.
The issues classified as discussion items will be handled during discussion phase. Participants
Live Classes www.qastack.net
On Weekend +92 300 1404 303
can take part in the discussion by bringing forward their comments and reasoning. The moderator
also paces this part of the meeting and ensures that all discussed items either have an outcome
by the end of the meeting, or are defined as an action point if a discussion cannot be solved
during the meeting. The outcome of discussions is documented for future reference.
At the end of the meeting, a decision on the document under review has to be made by the
participants, sometimes based on formal exit criteria. The most important exit criterion is the
average number of critical and major defects found per page. If the number of defects found per
page exceeds a certain level, the document must be reviewed again, after it has been reworked. If
the document complies with the exit criteria, the document will be checked during follow-up by the
moderator or one or more participants. Subsequently, the document can leave or exit the review
process.
5. Rework
Based on the defects detected and improvements suggested in the review meeting, the author
improves the document under review. In this phase the author would be doing all the rework to
ensure that defects detected should fixed and corrections should be properly implied. Changes
that are made to the document should be easy to identify during follow-up, therefore the author
has to indicate where changes are made.
6. Follow-Up
After the rework, the moderator should ensure that satisfactory actions have been taken on all
logged defects, improvement suggestions and change requests. If it is decided that all
participants will check the updated document, the moderator takes care of the distribution and
collects the feedback. In order to control and optimize the review process, a number of
measurements are collected by the moderator at each step of the process. Examples of such
measurements include number of defects found, number of defects found per page, time spent
checking per page, total review effort, etc. It is the responsibility of the moderator to ensure that
the information is correct and stored for future analysis.
Selenium can be used to automate functional tests and can be integrated with automation test
tools such as Maven, Jenkins, & Docker to achieve continuous testing. It can also be integrated
with tools such as TestNG, & JUnit for managing test cases and generating reports.
Advantages of Selenium
Selenium is pure open source, freeware and portable tool.
Selenium supports variety of languages that include Java, Perl, Python, C#, Ruby, Groovy, Java Script, and
VB Script. etc.
Selenium supports many operating systems like Windows, Macintosh, Linux, Unix etc.
Selenium supports many browsers like Internet explorer, Chrome, Firefox, Opera and Safari etc.
Selenium can be integrated with TestNG testing framework for testing our applications and generating
reports.
Selenium supports very less CPU and RAM consumption for script execution.
Disadvantages of Selenium
Selenium needs good technical expertise. The resource should have good programming skills.
Live Classes www.qastack.net
On Weekend +92 300 1404 303
Selenium only supports web based application and does not support windows based application.
It is difficult to test Image based application.
Selenium need outside support for report generation activity like TestNG or Jenkins.
Selenium does not provide any built in IDE for script generation and it need other IDE like Eclipse for
writing scripts.
Selenium script creation time is bit high.
Selenium IDE
Selenium IDE (Integrated Development Environment) is an open source web automation testing
tool under the Selenium Suite. It is a Firefox plugin that you can install as easily as you can with
other plugins. Unlike Selenium WebDriver and RC, it does not require any programming logic to
write its test scripts rather you can simply record your interactions with the browser to create test
cases. Subsequently, you can use the playback option to re-run the test cases.
Selenium WebDriver
Selenium WebDriver is the most important component of Selenium Tool's Suite. In WebDriver, test
scripts can be developed using any of the supported programming languages and can be run
directly in most modern web browsers. Languages supported by WebDriver include C#, Java,
Perl, PHP, Python and Ruby.
Before learning the concepts of Selenium WebDriver, you should be well versed with any of the
supported programming languages. Currently, Selenium Web driver is most popular with Java and
C#.
Selenium WebDriver is the most commonly used automation tool within Selenium tool suite, which
automates the web application by speaking directly to the browser using the ‗native‘ method for
the browser and operating system.
Since Selenium WebDriver is the most popular and most used tool in the Selenium suite, it is
referred simply as Selenium. So whenever someone mentions Selenium, it‘s most likely that they
are talking about Selenium WebDriver.
Selenium Grid
Live Classes www.qastack.net
On Weekend +92 300 1404 303
Selenium Grid is a tool that allows you to run your test cases in parallel, that is, you can run
different tests at the same time on different remote machines. This parallel execution would be
especially helpful when you have a large number of test scripts to be executed.
Selenium RC
Selenium RC or Selenium Remote Control uses JavaScript based library to interact with web
pages. While Selenium RC was a tremendous tool, it had its own drawbacks. Selenium RC is no
longer in use now and is not actively supported by the Selenium Developers.
Relational Databases
A relational database at its simplest is a set of tables used for storing data. Each table has a
unique name and may relate to one or more other tables in the database through common values.
Tables
A table in a database is a collection of rows and columns. Tables are also known as entities or
relations.
Rows
A row contains data pertaining to a single item or record in a table. Rows are also known as
records or tuples.
Columns
A column contains data representing a specific characteristic of the records in the table. Columns
are also known as fields or attributes.
Relationships
A relationship is a link between two tables (i.e. relations). Relationships make it possible to find
data in one table that pertains to a specific record in another table.
Datatypes
Each of a table's columns has a defined datatype that specifies the type of data that can exist in
that column. For example, the FirstName column might be defined as varchar (20), indicating that
it can contain a string of up to 20 characters. Unfortunately, datatypes vary widely between
databases.
Candidate Key
A Candidate key is an attribute or set of attributes that uniquely identifies a record. Among the set
of candidate, one candidate key is chosen as Primary Key. So a table can have multiple candidate
key but each table can have maximum one primary key.
Primary Keys
Live Classes www.qastack.net
On Weekend +92 300 1404 303
Most tables have a column or group of columns that can be used to identify records. For example,
an Employees table might have a column called EmployeeID that is unique for every row. This
makes it easy to keep track of a record over time and to associate a record with records in other
tables.
Foreign Keys
Foreign key columns are columns that link to primary key columns in other tables, thereby
creating a relationship. For example, the Customers table might have a foreign key column
called SalesRep that links to EmployeeID, the primary key in the Employees table.
Alternate Key
Alternate keys are candidate keys that are not selected as primary key. Alternate key can also
work as a primary key. Alternate key is also called ―Secondary Key‖.
Unique Key
A unique key is a set of one or more attribute that can be used to uniquely identify the records in
table. Unique key is similar to primary key but unique key field can contain a ―Null‖ value but
primary ke y doesn‘t allow ―Null‖ value. Other difference is that primary key field contain a
clustered index and unique field contain a non-clustered index.
Composite Key
Composite key is a combination of more than one attributes that can be used to uniquely identity
each record. It is also known as ―Compound‖ key. A composite key may be a candidate or primary
key.
Super Key
Super key is a set of on e or more than one keys that can be used to uniquely identify the record
in table. A Super key for an entity is a set of one or more attributes whose combined value
uniquely identifies the entity in the entity set. A super key is a combine form of Primary Key,
Alternate key and Unique key and Primary Key, Unique Key and Alternate Key are subset of super
key.
Surrogate Key
Surrogate key is an artificial key that is used to uniquely identify the record in table. For example,
in SQL Server or Sybase database system contain an artificial key that is known as ―Identity‖.
Surrogate keys are just simple sequential number. Surrogate keys are only used to act as a
primary key.
Difference between primary key and unique constraints?
Primary key cannot have NULL value; the unique constraints can have NULL values. There is only one
primary key in a table, but there can be multiple unique constrains.
Database Normalization
It is a process of analyzing the given relation schemas based on their functional dependencies
and primary keys to achieve the following desirable properties:
1) Minimizing Redundancy
2) Minimizing the Insertion, Deletion, And Update Anomalies
Relation schemas that do not meet the properties are decomposed into smaller relation schemas
that could meet desirable properties.
An update anomaly. Employee 519 is shown as having different addresses on different records.
Live Classes www.qastack.net
On Weekend +92 300 1404 303
An insertion anomaly. Until the new faculty member, Dr. Newsome, is assigned to teach at least one course, his or her
details cannot be recorded.
A deletion anomaly. All information about Dr. Giddens is lost if he or she temporarily ceases to be assigned to any
courses.
When an attempt is made to modify (update, insert into, or delete from) a relation, the following undesirable
side-effects may arise in relations that have not been sufficiently normalized:
Update anomaly. The same information can be expressed on multiple rows; therefore updates to the relation may result
in logical inconsistencies. For example, each record in an "Employees' Skills" relation might contain an Employee ID,
Employee Address, and Skill; thus a change of address for a particular employee may need to be applied to multiple
records (one for each skill). If the update is only partially successful – the employee's address is updated on some
records but not others – then the relation is left in an inconsistent state. Specifically, the relation provides conflicting
answers to the question of what this particular employee's address is. This phenomenon is known as an update
anomaly.
Insertion anomaly. There are circumstances in which certain facts cannot be recorded at all. For example, each record
in a "Faculty and Their Courses" relation might contain a Faculty ID, Faculty Name, Faculty Hire Date, and Course
Code. Therefore, we can record the details of any faculty member who teaches at least one course, but we cannot
record a newly hired faculty member who has not yet been assigned to teach any courses, except by setting the Course
Code to null. This phenomenon is known as an insertion anomaly.
Deletion anomaly. Under certain circumstances, deletion of data representing certain facts necessitates deletion of data
representing completely different facts. The "Faculty and Their Courses" relation described in the previous example
suffers from this type of anomaly, for if a faculty member temporarily ceases to be assigned to any courses, we must
delete the last of the records on which that faculty member appears, effectively also deleting the faculty member,
unless we set the Course Code to null. This phenomenon is known as a deletion anomaly.
Database Normalization
Normalization is a database design technique which organizes tables in a manner that reduces redundancy and
dependency of data.
1st Normal Form
Each table cell should contain a single value.
Each record needs to be unique.
permission to query the view, while denied access to the rest of the base table.
2. Views can join and simplify multiple tables into a single virtual table
3. Views can act as aggregated tables, where the database engine aggregates data (sum,
average etc.) and presents the calculated results as part of the data
Database Trigger
A Trigger is a code that associated with insert, update or delete operations. The code is executed
automatically whenever the associated query is executed on a table. Triggers can be useful to
maintain integrity in database.
Stored Procedure
A stored procedure is like a function that contains a set of operations compiled together. It
contains a set of operations that are commonly used in an application to do some common
database tasks.
Database Indexes
A database index is a data structure that improves the speed of data retrieval operations on a
database table at the cost of additional writes and the use of more storage space to maintain the
extra copy of data.
Relational Database Management System
A Relational Database Management System (RDBMS), commonly (but incorrectly) called a
database, is software for creating, manipulating, and administering a database. For simplicity, we
will often refer to RDBMSs as databases.
Characteristics of Database Management System
A database management system has following characteristics:
Data stored into Tables: Data is never directly stored into the database. Data is stored into
tables, created inside the database. DBMS also allows to have relationships between tables which
makes the data more meaningful and connected. You can easily understand what type of data is
stored where by looking at all the tables created in a database.
Reduced Redundancy: In the modern world hard drives are very cheap, but earlier when hard
drives were too expensive, unnecessary repetition of data in database was a big problem. But
DBMS follows Normalization which divides the data in such a way that repetition is minimum.
Data Consistency: On Live data, i.e. data that is being continuously updated and added,
maintaining the consistency of data can become a challenge. But DBMS handles it all by itself.
Support Multiple user and Concurrent Access: DBMS allows multiple users to work on it(update,
insert, delete data) at the same time and still manages to maintain the data consistency.
Query Language: DBMS provides users with a simple Query language, using which data can be
easily fetched, inserted, deleted and updated in a database.
Security: The DBMS also takes care of the security of data, protecting the data from un-
authorized access. In a typical DBMS, we can create user accounts with different access
permissions, using which we can easily secure our data by restricting user access.
DBMS supports transactions, which allows us to better handle and manage data integrity in real
world applications where multi-threading is extensively used.
DDL statements are used to structure objects in a database. The most common DDL statements
are:
CREATE
ALTER
DROP
The TRUNCATE command is used to delete all the rows from the table and free the space containing the
table.
TRUNCATE TABLE table_name;
The SQL DROP command is used to remove an object from the database. If you drop a table,
all the rows in the table is deleted and the table structure is removed from the database. Once a
table is dropped we cannot get it back, so be careful while using DROP command. When a table
is dropped all the references to the table will not be valid.
DROP TABLE table_name;
If a table is dropped, all the relationships with other tables will no longer be valid, the integrity constraints
will be dropped, grant or access privileges on the table will also be dropped, if you want use the table again
it has to be recreated with the integrity constraints, access privileges and the relationships with other tables
should be established again. But, if a table is truncated, the table structure remains the same, therefore any
of the above problems will not exist.
FROM surveys;
Or we can select all of the columns in a table using the wildcard *
SELECT *
FROM surveys;
Unique values
If we want only the unique values so that we can quickly see what species have
been sampled we use DISTINCT SELECT DISTINCT species_id
FROM surveys;
If we select more than one column, then the distinct pairs of values are returned
SELECT DISTINCT
year, species_id FROM
surveys;
Calculated values
We can also do calculations with the values in a query. For example, if we wanted to
look at the mass of each individual on different dates, but we needed it in kg instead of
g we would use
SELECT year, month,
day, weight /1000.0
FROM surveys;
When we run the query, the expression weight / 1000.0 is evaluated for each row and
appended to that row, in a new column. Expressions can use any fields, any arithmetic
operators (+, -, *, and /) and a variety of built-in functions. For example, we could round
the values to make them easier to read.
SELECT plot_id, species_id, sex, weight,
ROUND (weight / 1000.0, 2) FROM
surveys;
Challenge
Write a query that returns the year, month, day, species_id and weight in mg
SOLUTION
SELECT day, month, year,
species_id, weight * 1000 FROM
surveys;
Live Classes www.qastack.net
On Weekend +92 300 1404 303
Filtering
Databases can also filter data – selecting only the data meeting certain criteria. For example,
let‟s say we only want data for the species Dipodomys merriami, which has a species code of
DM. We need to add a WHERE clause to our query:
SELECT *
FROM surveys
WHERE species_id='DM';
We can do the same thing with numbers. Here, we only want the data since 2000:
SELECT * FROM
surveys WHERE year
>= 2000;
We can use more sophisticated conditions by combining tests with AND and OR. For
example, suppose we want the data on Dipodomys merriami starting in the year 2000:
SELECT *
FROM surveys
WHERE (year >= 2000) AND (species_id = 'DM');
Note that the parentheses are not needed, but again, they help with readability. They
also ensure that the computer combines AND and OR in the way that we intend.
If we wanted to get data for any of the Dipodomys species, which have species codes DM, DO,
and DS, we could combine the tests using OR:
SELECT *
FROM surveys
WHERE (species_id = 'DM') OR (species_id = 'DO') OR (species_id = 'DS');
Challenge
Write a query that returns the day, month, year, species_id, and weight (in kg) for individuals
caught on Plot 1 that weigh more than 75 g
SOLUTION
SELECT day, month, year,
species_id, weight / 1000.0 FROM
surveys
WHERE
plot_id = 1
AND weight >
75;
SELECT *
FROM surveys
WHERE (year >= 2000) AND (species_id IN ('DM', 'DO', 'DS'));
We started with something simple, then added more clauses one by one, testing their effects as we went
along. For complex queries, this is a good strategy, to make sure you are getting what you want.
Sometimes it might help to take a subset of the data that you can easily see in a temporary database to
practice your queries on before working on a larger or more complicated database.
When the queries become more complex, it can be useful to add comments. In SQL, comments are started
by --, and end at the end of the line. For example, a commented version of the above query can be written
as:
-- Get post 2000 data on Dipodomys' species
-- These are in the surveys table, and we are
interested in all columns SELECT * FROM
surveys
-- Sampling year is in the column `year`, and we
want to include 2000 WHERE (year >= 2000)
-- Dipodomys' species have the `species_id`
DM, DO, and DS AND (species_id IN ('DM',
'DO', 'DS'));
Although SQL queries often read like plain English, it is always useful to add comments; this is especially
true of more complex queries.
Sorting
We can also sort the results of our queries by using ORDER BY. For simplicity, let‟s go back to the
species table and alphabetize it by taxa.
First, let‟s look at what‟s in the species table. It‟s a table of the species_id and the full genus, species and
taxa information for each species_id. Having this in a separate table is nice, because we didn‟t need to
include all this information in our main surveys table.
SELECT *
FROM species;
Now let‟s order it by taxa.
SELECT *
FROM species
ORDER BY
taxa ASC;
The keyword ASC tells us to order it in Ascending order. We could alternately use DESC to get descending order.
SELECT *
FROM species
ORDER BY taxa DESC;
ASC is the default.
We can also sort on several fields at once. To truly be alphabetical, we might want to order by genus then species.
SELECT *
Live Classes www.qastack.net
On Weekend +92 300 1404 303
FROM species
ORDER BY genus ASC, species ASC;
Challenge
Write a query that returns year, species_id, and weight in kg from the surveys table, sorted with the largest weights at
the top.
SOLUTION
SELECT year, species_id,
weight / 1000.0 FROM
surveys ORDER BY weight
DESC;
Order of execution
Another note for ordering. We don’t actually have to display a column to sort by it. For example, let‟s
say we want to order the birds by their species ID, but we only want to see genus and species.
SELECT genus,
species FROM
species
WHERE taxa =
'Bird'
ORDER BY species_id ASC;
We can do this because sorting occurs earlier in the computational pipeline
than field selection. The computer is basically doing this:
Challenge
Let‟s try to combine what we‟ve learned so far in a single query. Using the surveys table write a query to display the
three date
fields, species_id, and weight in kilograms (rounded to two decimal places), for individuals captured in
1999, ordered alphabetically by the species_id. Write the query as a single line, then put each clause on its
own line, and see how more legible the query becomes!
SOLUTION
SELECT year, month, day, species_id,
ROUND(weight / 1000.0, 2) FROM surveys
WHERE year = 1999
ORDER BY species_id;
GROUP BY:
The GROUP BY clause is a SQL command that is used to group rows that have the same values. The GROUP
BY clause is used in the SELECT statement . Optionally it is used in conjunction with aggregate functions to
Live Classes www.qastack.net
On Weekend +92 300 1404 303
produce summary reports from the database. That's what it does, summarizing data from the database.
Difference between HAVING and WHERE clauses
HAVING: is used to check conditions after the aggregation
takes place. WHERE: is used to check conditions before the
aggregation takes place. This code:
Select City, count(ContactAdd) as AddressCount from Address where State = „MA‟ group by City having
count(ContactAdd)>5
Gives you a table of cities in MA with more than 5 addresses and the number of addresses in each city.
Inner
Outer
Left
Right
2 adam 2 MUMBAI
4 alex 2 MUMBAI
1 abhi 3 CHENNAI
2 adam 3 CHENNAI
4 alex 3 CHENNAI
As you can see, this join returns the cross product of all the records present in both the tables.
INNER Join or EQUI Join
This is a simple JOIN in which the result is based on matched data as per the equality condition
specified in the SQL query.
Inner Join Syntax is,
SELECT column-name-list FROM
table-name1 INNER JOIN table-name2
WHERE table-name1.column-name = table-name2.column-name;
OUTER JOIN
Outer Join is based on both matched and unmatched data. Outer Joins subdivide further into,
3 CHENNAI
7 NOIDA
8 PANIPAT
Live Classes www.qastack.net
On Weekend +92 300 1404 303
ID NAME ID Address
1 Abhi 1 DELHI
2 Adam 2 MUMBAI
3 Alex 3 CHENNAI
4 Anu null null
5 Ashish null null
null Null 7 NOIDA
null Null 8 PANIPAT
}
Example 2:
Let‘s take another example.
Live Classes www.qastack.net
On Weekend +92 300 1404 303
Object: Car
State: Color, Brand, Weight, Model
Behavior: Break, Accelerate, Slow Down, and Gear change.
Note: As we have seen above, the states and behaviors of an object, can be represented by
variables and methods in the class respectively.
Characteristics of Objects:
If you find it hard to understand Abstraction and Encapsulation, do not worry as I have covered
these topics in detail with examples in the next section of this guide.
1. Abstraction
2. Encapsulation
3. Message passing
Abstraction: Abstraction is a process where you show only ―relevant‖ data and ―hide‖ unnecessary
details of an object from the user.
Message passing
A single object by itself may not be very useful. An application contains many objects. One object
interacts with another object by invoking methods on that object. It is also referred to as Method
Invocation. See the diagram below.
// constructor
Website(String name, int age){
this.webName = name;
this.webAge = age;
Live Classes www.qastack.net
On Weekend +92 300 1404 303
}
public static void main(String args[]){
//Creating objects
Website obj1 = new Website("beginners book", 5);
Website obj2 = new Website("google", 18);
What is a Constructor?
Constructor looks like a method but it is in fact not a method. It‘s name is same as class name and
it does not return any value. You must have seen this statement in almost all the programs I have
shared above:
MyClass obj = new MyClass();
If you look at the right side of this statement, we are calling the default constructor of
class myClass to create a new object (or instance).
We can also have parameters in the constructor, such constructors are known as parameterized
constructors.
Example of constructor
int age;
String name;
//Default constructor
ConstructorExample(){
this.name="Chaitanya";
this.age=30;
}
//Parameterized constructor
ConstructorExample(String n,int a){
this.name=n;
this.age=a;
}
public static void main(String args[]){
ConstructorExample obj1 = new ConstructorExample();
ConstructorExample obj2 =
System.out.println(obj1.name+" "+obj1.age);
System.out.println(obj2.name+" "+obj2.age);
}
}
Output:
Chaitanya 30
Steve 56
These four features are the main OOPs Concepts that you must learn to understand the Object
Oriented Programming in Java
Abstraction
Abstraction is the concept of hiding the internal details and describing things in simple terms. There
are many ways to achieve abstraction in object oriented programming, such as encapsulation and
inheritance.
Abstraction is a process where you show only ―relevant‖ data and ―hide‖ unnecessary details of an
object from the user. For example, when you login to your bank account online, you enter your
user_id and password and press login, what happens when you press login, how the input data sent
to server, how it gets verified is all abstracted away from the you.
Encapsulation
Encapsulation is the technique used to implement abstraction in object oriented programming.
Encapsulation is used for access restriction to a class members and methods.
Access modifier keywords are used for encapsulation in object oriented programming. For example,
encapsulation in java is achieved using private, protected and public keywords.
private hides from other classes within the package. public exposes to classes outside the package. protected is a
version of public restricted only to subclasses
in Java protected makes the method also accessible from the whole package.
Encapsulation simply means binding object state(fields) and behavior(methods) together. If you are
creating class, you are doing encapsulation.
Encapsulation example in Java
How to
1) Make the instance variables private so that they cannot be accessed directly from outside the
class. You can only set and get values of these variables through the methods of the class.
2) Have getter and setter methods in the class to set and get the values of the fields.
class EmployeeCount
{
private int numOfEmployees = 0;
public void setNoOfEmployees (int count)
{
numOfEmployees = count;
}
public double getNoOfEmployees ()
{
return numOfEmployees;
}
}
Live Classes www.qastack.net
On Weekend +92 300 1404 303
public class EncapsulationExample
{
public static void main(String args[])
{
EmployeeCount obj = new EmployeeCount ();
obj.setNoOfEmployees(5613);
System.out.println("No Of Employees: "+(int)obj.getNoOfEmployees());
}
}
Output:
No Of Employees: 5613
The class EncapsulationExample that is using the Object of class EmployeeCount will not able to get the
NoOfEmployees directly. It has to use the setter and getter methods of the same class to set and get
the value.
So what is the benefit of encapsulation in java programming
Well, at some point of time, if you want to change the implementation details of the class
EmployeeCount, you can freely do so without affecting the classes that are using it.
Inheritance
The process by which one class acquires the properties and functionalities of another class is
called inheritance. Inheritance provides the idea of reusability of code and each sub class
defines only those features that are unique to it, rest of the features can be inherited from the
parent class.
1. Inheritance is a process of defining a new class based on an existing class by extending its
common data members and methods.
2. Inheritance allows us to reuse of code, it improves reusability in your java application.
3. The parent class is called the base class or super class. The child class that extends the base class
is called the derived class or sub class or child class.
Note: The biggest advantage of Inheritance is that the code in base class need not be
rewritten in the child class.
The variables and methods of the base class can be used in the child class as well.
Syntax: Inheritance in Java
To inherit a class we use extends keyword. Here class A is child class and class B is parent
class.
class A extends B
{
}
Inheritance Example
In this example, we have a parent class Teacher and a child class MathTeacher. In
the MathTeacher class we need not to write the same code which is already present in the
present class. Here we have college name, designation and does() method that is common
for all the teachers, thus MathTeacher class does not need to write this code, the common
data members and methods can inherited from the Teacher class.
class Teacher {
String designation = "Teacher";
String college = "Beginnersbook";
void does(){
System.out.println("Teaching");
}
}
public class MathTeacher extends Teacher{
String mainSubject = "Maths";
public static void main(String args[]){
MathTeacher obj = new MathTeacher();
System.out.println(obj.college);
System.out.println(obj.designation);
Live Classes www.qastack.net
On Weekend +92 300 1404 303
System.out.println(obj.mainSubject);
obj.does();
}
}
Output:
Beginnersbook
Teacher
Maths
Teaching
Note: Multi-level inheritance is allowed in Java but not multiple inheritance
Types of Inheritance:
Single Inheritance: refers to a child and parent class relationship where a class extends the
another class.
Multilevel inheritance: refers to a child and parent class relationship where a class extends
the child class. For example class A extends class B and class B extends class C.
Hierarchical inheritance: refers to a child and parent class relationship where more than one
classes extends the same class. For example, class B extends class A and class C extends
class A.
Multiple Inheritance: refers to the concept of one class extending more than one classes,
which means a child class has two parent classes. Java doesn‘t support multiple inheritance,
read more about it here.
Most of the new OO languages like Small Talk, Java, C# do not support Multiple inheritance.
Multiple Inheritance is supported in C++.
Polymorphism
Polymorphism is the concept where an object behaves differently in different situations. In java, we
use method overloading and method overriding to achieve polymorphism.
Polymorphism is a object oriented programming feature that allows us to perform a single
action in different ways. For example, lets say we have a class Animal that has a
method animalSound(), here we cannot give implementation to this method as we do not know
which Animal class would extend Animal class. So, we make this method abstract like this:
and
Types of Polymorphism
1) Static Polymorphism
2) Dynamic Polymorphism
Static Polymorphism:
Polymorphism that is resolved during compiler time is known as static polymorphism. Method
overloading can be considered as static polymorphism example.
Method Overloading: This allows us to have more than one methods with same name in a
class that differs in signature.
class DisplayOverloading
{
public void disp( char c)
{
System.out.println(c);
}
public void disp(char c, int num)
{
System.out.println(c + " "+num);
}
}
public class ExampleOverloading
{
public static void main(String args[])
{
DisplayOverloading obj = new DisplayOverloading();
obj.disp('a');
obj.disp('a',10);
}
}
Output:
a
a 10
When I say method signature I am not talking about return type of the method, for example if
two methods have same name, same parameters and have different return type, then this is
not a valid method overloading example. This will throw compilation error.
Dynamic Polymorphism
It is also known as Dynamic Method Dispatch. Dynamic polymorphism is a process in which a
call to an overridden method (Method Overriding means method in the child class having
same name and parameter as in parent class but different implementation) is resolved at
runtime rather, thats why it is called runtime polymorphism.
Example
class Animal{
public void animalSound(){
Live Classes www.qastack.net
On Weekend +92 300 1404 303
System.out.println("Default Sound");
}
}
public class Dog extends Animal{
obj.animalSound();
}
}
Output:
Woof
Since both the classes, child class and parent class have the same method animalSound. Which
of the method will be called is determined at runtime by JVM.
Few more overriding examples:
Animal obj = new Animal();
obj.animalSound();
// This would call the Animal class method