
























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A maintainability-focused Java exam that assesses code readability, modularity, refactoring, documentation quality, cyclomatic complexity reduction, testability improvements, and design pattern usage. Candidates analyze Java codebases and apply best practices to improve long-term sustainability, efficiency, and maintainability.
Typology: Exams
1 / 96
This page cannot be seen from the preview
Don't miss anything!

























































































Question 1. Which ISO/IEC 25010 characteristic directly measures the effort required to modify a software component? A) Reliability B) Maintainability C) Portability D) Security Answer: B Explanation: Maintainability is defined as the degree of effectiveness and efficiency with which a product can be modified, covering corrective, adaptive, perfective, and preventive changes. Question 2. In the context of software maintenance, which type focuses on fixing defects discovered after delivery? A) Adaptive maintenance B) Corrective maintenance C) Perfective maintenance D) Preventive maintenance Answer: B Explanation: Corrective maintenance involves locating and fixing faults that cause the software to behave incorrectly. Question 3. Which of the following is not considered a code smell that reduces maintainability? A) Large class B) Feature envy C) Singleton pattern used appropriately
D) Duplicated code Answer: C Explanation: When used correctly, the Singleton pattern is a design choice, not a code smell. The other options are classic smells. Question 4. The Single Responsibility Principle (SRP) states that a class should have: A) One public method only B) One reason to change C) Only static methods D) No inheritance hierarchy Answer: B Explanation: SRP requires that a class encapsulate a single responsibility, meaning only one reason for it to be modified. Question 5. Which design principle encourages extending behavior without modifying existing code? A) Open/Closed Principle (OCP) B) Liskov Substitution Principle (LSP) C) Interface Segregation Principle (ISP) D) Dependency Inversion Principle (DIP) Answer: A Explanation: OCP states that software entities should be open for extension but closed for modification.
D. Few methods in the class Answer: C Explanation: Fan‑out measures the number of classes that a given class directly uses; a high value suggests high coupling. Question 9. Which refactoring technique extracts a block of code into a new method? A) Move Method B) Extract Method C) Inline Method D) Pull Up Method Answer: B Explanation: Extract Method creates a new method containing the selected code, improving readability and reuse. Question 10. In Java, which keyword is used to declare a constant that cannot be reassigned? A) static B) final C) const D) immutable Answer: B Explanation: The final keyword makes a variable immutable after its initial assignment. Question 11. Which of the following statements best describes high cohesion?
A) A class performs many unrelated tasks. B) A module’s responsibilities are closely related. C) Classes have many public fields. D) Methods in a class call each other frequently. Answer: B Explanation: High cohesion means that the responsibilities of a module are narrowly focused and related, enhancing maintainability. Question 12. Which design pattern is primarily used to decouple an abstraction from its implementation? A) Strategy B) Bridge C) Factory Method D) Observer Answer: B Explanation: The Bridge pattern separates abstraction from implementation, allowing them to vary independently. Question 13. What does the Dependency Inversion Principle (DIP) recommend? A) Depend on concrete classes rather than interfaces. B) High‑level modules should depend on low‑level modules. C) Both high‑ and low‑level modules should depend on abstractions. D) Avoid using interfaces altogether. Answer: C
B) Updating the system to run on a newer operating system version. C) Refactoring code to reduce complexity before bugs appear. D) Adding a new feature requested by users. Answer: C Explanation: Preventive maintenance aims to improve the system to avoid future problems, such as refactoring to reduce complexity. Question 17. The metric “Lack of Cohesion in Methods (LCOM)” measures: A) Number of public methods in a class. B) Degree to which methods use the same instance variables. C) Lines of code per method. D) Depth of inheritance hierarchy. Answer: B Explanation: LCOM quantifies how disjoint the methods are concerning shared instance variables; a high LCOM indicates low cohesion. Question 18. Which Java feature promotes composition over inheritance? A. Abstract classes B. Interfaces with default methods C. Delegation through member objects D. Enums Answer: C Explanation: Composition uses member objects to delegate behavior, reducing tight inheritance hierarchies and improving maintainability.
Question 19. When applying the Interface Segregation Principle (ISP), you should: A) Create one large interface for all clients. B) Split interfaces so each client only sees methods it uses. C) Prefer abstract classes over interfaces. D) Avoid using interfaces entirely. Answer: B Explanation: ISP advises designing fine‑grained interfaces tailored to specific client needs, preventing “fat” interfaces. Question 20. Which of the following best describes code churn? A) The number of lines added, modified, or deleted over time. B) The total size of the codebase measured in LOC. C) The frequency of unit test failures. D) The count of open bugs in the issue tracker. Answer: A Explanation: Code churn tracks changes in the source code, often indicating areas of instability or high maintenance activity. Question 21. In a JUnit test, which annotation marks a method that should run before each test case? A) @BeforeAll B) @BeforeEach C) @Test
Question 24. Which metric is most directly affected by extracting a large method into several smaller ones? A) LOC B) Cyclomatic Complexity C) Fan‑out D) LCOM Answer: B Explanation: Splitting a method reduces its cyclomatic complexity because each new method contains fewer decision points. Question 25. In Java, which collection type guarantees insertion order and allows duplicate elements? A) HashSet B) TreeSet C) ArrayList D) LinkedHashMap Answer: C Explanation: ArrayList preserves insertion order and permits duplicates, unlike Set implementations. Question 26. Which of the following is a perfective maintenance activity? A) Fixing a security vulnerability. B) Migrating the application to a new database version. C) Refactoring code to improve performance.
D) Adding a new reporting feature requested by users. Answer: C Explanation: Perfective maintenance enhances existing functionality, such as performance improvements, without fixing defects or adapting to new environments. Question 27. The term “technical debt” most closely refers to: A) Unpaid licensing fees for third‑party libraries. B) The cost of fixing shortcuts taken during development. C) The amount of documentation missing from a project. D) The number of open feature requests. Answer: B Explanation: Technical debt represents the future cost incurred by taking shortcuts or compromising design quality today. Question 28. Which Java language feature helps to enforce immutability of objects? A) static fields B) final class and fields C) synchronized methods D) volatile variables Answer: B Explanation: Declaring a class as final and its fields as final prevents subclassing and reassignment, supporting immutability.
Answer: C Explanation: When code is duplicated, any bug fix or enhancement must be replicated, raising maintenance cost. Question 32. Which Javadoc tag is used to describe a method’s return value? A) @param B) @return C) @throws D) @see Answer: B Explanation: @return documents what a method returns. Question 33. Which design pattern encapsulates a request as an object, thereby allowing parameterization of clients with queues, requests, and operations? A) Command B) Adapter C) Facade D) Mediator Answer: A Explanation: The Command pattern turns a request into a stand‑alone object, supporting queuing, logging, and undo functionality. Question 34. What is the primary benefit of writing unit tests before implementing code (TDD approach)?
A) Guarantees zero bugs in production. B) Forces a design that is more modular and testable. C) Eliminates the need for integration testing. D) Allows developers to skip code reviews. Answer: B Explanation: Test‑Driven Development leads to small, focused units of code that are easier to maintain. Question 35. Which metric would most likely increase after applying the “Extract Interface” refactoring? A) LOC B) Cyclomatic Complexity C) Number of interfaces implemented D) Fan‑out Answer: C Explanation: Extract Interface introduces a new interface that classes implement, raising the count of implemented interfaces. Question 36. In Java, which exception type is unchecked? A) IOException B) SQLException C) NullPointerException D) ClassNotFoundException Answer: C
Answer: B Explanation: RFC measures the set of methods that could be executed in response to a call, indicating potential complexity. Question 40. Which of the following is a recommended practice for writing self‑documenting Java code? A) Use short, cryptic variable names. B) Write extensive inline comments for every line. C) Choose meaningful names that convey intent. D. Rely on IDE code generation for readability. Answer: C Explanation: Meaningful identifiers reduce the need for explanatory comments and improve maintainability. Question 41. In the context of Java, which keyword is used to achieve dependency inversion via interfaces? A) implements B) extends C) import D) static Answer: A Explanation: Classes implement interfaces, allowing code to depend on abstractions rather than concrete classes.
Question 42. Which refactoring technique would you use to move a method that uses data from two classes into the class that owns the majority of that data? A) Move Method B) Extract Method C) Pull Up Method D) Inline Method Answer: A Explanation: Move Method transfers a method to the class where it fits best, reducing coupling. Question 43. Which of the following best describes adaptive maintenance? A) Adding new features requested by stakeholders. B) Modifying the software to run in a new environment. C) Refactoring code to improve readability. D) Fixing bugs found in production. Answer: B Explanation: Adaptive maintenance updates the system to accommodate changes in the environment, such as OS upgrades. Question 44. Which design pattern provides a simplified interface to a complex subsystem? A) Facade B) Bridge C) Composite D) Decorator Answer: A
C) Cyclomatic Complexity per method D) LCOM for the original class Answer: B Explanation: Extract Class creates a new class, increasing the total class count. Question 48. Which of the following statements about unit tests is true? A) They should test multiple components simultaneously. B) They are executed only after integration testing. C) They should be fast and isolated. D) They replace the need for code reviews. Answer: C Explanation: Unit tests focus on a single unit, run quickly, and do not depend on external resources. Question 49. Which of the following Java language features helps limit the visibility of internal implementation details? A) public B) protected C) package‑private (default) D) private Answer: D Explanation: private restricts access to the declaring class, encapsulating implementation.
Question 50. In a large Java project, which practice helps keep the codebase’s cyclomatic complexity low? A) Using nested switch statements heavily. B) Breaking large methods into smaller ones. C) Adding many boolean flags to methods. D) Implementing all logic in a single utility class. Answer: B Explanation: Smaller methods have fewer decision points, reducing cyclomatic complexity. Question 51. Which of the following is a characteristic of a well‑designed API according to SOLID principles? A) It forces clients to implement many unnecessary methods. B) It changes frequently due to added features. C) It provides small, focused interfaces. D) It relies on concrete classes for all operations. Answer: C Explanation: Small, focused interfaces align with ISP and promote maintainability. Question 52. Which design pattern is best suited for adding responsibilities to objects dynamically without affecting other objects? A) Decorator B) Prototype C) Builder D) Adapter