Software Engineering Prep 3 — Questions and Answers
Question 1: Which testing type verifies that individual units of code work correctly in isolation?
- Integration testing
- System testing
- Unit testing (Correct answer)
- Regression testing
Correct answer: Unit testing
Unit testing checks the smallest testable parts of an application independently from other components.
Question 2: What is the difference between a compiler and an interpreter?
- A compiler runs code line by line; an interpreter translates the whole program first
- A compiler translates the whole program before execution; an interpreter executes line by line (Correct answer)
- A compiler only works with object-oriented languages
- An interpreter produces machine code; a compiler does not
Correct answer: A compiler translates the whole program before execution; an interpreter executes line by line
Compilers translate source code entirely into machine code before execution, while interpreters execute it line by line at runtime.
Question 3: Which design pattern ensures only one instance of a class is created throughout the application lifecycle?
- Factory
- Observer
- Singleton (Correct answer)
- Strategy
Correct answer: Singleton
The Singleton pattern restricts a class to a single instance and provides a global access point to it.
Question 4: In a relational database, what does a PRIMARY KEY enforce?
- Referential integrity between tables
- Uniqueness and non-null identity for each row (Correct answer)
- Default values for a column
- Cascading deletes across tables
Correct answer: Uniqueness and non-null identity for each row
A primary key uniquely identifies each row in a table and cannot be NULL.
Question 5: What is the purpose of a REST API?
- To store data in a relational database
- To compile server-side code
- To enable communication between systems over HTTP using standard methods (Correct answer)
- To manage user authentication tokens only
Correct answer: To enable communication between systems over HTTP using standard methods
REST APIs expose resources via HTTP methods (GET, POST, PUT, DELETE) allowing systems to communicate in a stateless, scalable way.
Question 6: Which principle states that software entities should be open for extension but closed for modification?
- Single Responsibility Principle
- Liskov Substitution Principle
- Open/Closed Principle (Correct answer)
- Dependency Inversion Principle
Correct answer: Open/Closed Principle
The Open/Closed Principle (OCP) promotes extending behavior through new code rather than changing existing, tested code.
Question 7: What is the role of a load balancer in a distributed system?
- To encrypt traffic between services
- To distribute incoming requests across multiple servers (Correct answer)
- To cache database query results
- To monitor application logs
Correct answer: To distribute incoming requests across multiple servers
A load balancer routes client requests across a pool of servers to prevent any single server from becoming a bottleneck.
Which testing type verifies that individual units of code work correctly in isolation?