Advanced Computer Programming
Introduction
Deepen programming practice through language libraries, concurrency, interfaces and network-enabled applications.
Topic-Wise Overview
Advanced Language Features
Abstract classes, interfaces, packages and exception handling
User Interfaces
GUI programming, event handling and desktop components
Database Access
Database connectivity and application integration
Concurrency and Networking
Multithreading and client-server programming
Secure Communications
Sockets, SSL, HTTPS and network authentication
Study Guidance
Start with the core definitions, follow practical examples and check your understanding with independent exercises. Topic-wise MCQs, short questions and step-by-step solutions are planned for this subject.
Explore Other Subjects
Browse Computer Science subjects
Practice MCQs — Set 1 (Questions 1–10)
Choose the best answer, then open the explanation to check your reasoning.
Question 1. What is the main benefit of generic programming?
- It avoids type checking
- It allows reusable algorithms and structures across types
- It requires copying the algorithm for each type
- It disables compilation
Show correct answer and explanation
Correct answer: B. It allows reusable algorithms and structures across types
Generic programming parameterizes code over types or operations. A single algorithm can be reused while preserving the language’s type rules.
Question 2. What is a race condition in multithreaded code?
- A variable with a short name
- A result that depends on uncontrolled timing of concurrent operations
- A compilation error in a loop
- A guaranteed deadlock
Show correct answer and explanation
Correct answer: B. A result that depends on uncontrolled timing of concurrent operations
Concurrent operations may interleave differently from run to run. Without appropriate synchronization, shared state can produce timing-dependent results.
Question 3. What is an invariant in algorithm design?
- A condition that remains true at specified program points
- A value that must always be zero
- A function that never returns
- A type of computer network
Show correct answer and explanation
Correct answer: A. A condition that remains true at specified program points
An invariant is a property maintained through the relevant steps of an algorithm. Loop invariants are useful for explaining and proving correctness.
Question 4. When is recursion especially natural?
- When a problem has smaller subproblems of the same structure
- Only when input is already sorted
- Only when the CPU has one core
- When no base case exists
Show correct answer and explanation
Correct answer: A. When a problem has smaller subproblems of the same structure
Recursive algorithms solve a problem using smaller instances of the same form. A valid base case and progress toward it are needed for termination.
Question 5. What is the purpose of unit testing?
- To replace all integration testing
- To check small units of behavior against expected results
- To remove all runtime exceptions
- To compile code into assembly
Show correct answer and explanation
Correct answer: B. To check small units of behavior against expected results
Unit tests exercise individual functions or components in controlled conditions. They complement, rather than replace, broader integration and system tests.
Question 6. What does time complexity describe?
- The total number of source code lines
- How computational work grows with input size
- The monitor refresh rate
- The network’s physical length
Show correct answer and explanation
Correct answer: B. How computational work grows with input size
Time complexity describes asymptotic growth of operation count or runtime with input size. It helps compare algorithms independently of a particular machine.
Question 7. Why should exceptions be handled at an appropriate abstraction boundary?
- To silently ignore all errors
- To preserve error context and allow meaningful recovery
- To eliminate logging
- To guarantee the error never recurs
Show correct answer and explanation
Correct answer: B. To preserve error context and allow meaningful recovery
An error should be caught where the program can react constructively. Blindly swallowing exceptions hides failures and complicates debugging.
Question 8. What is dependency injection?
- Providing a component with required dependencies from outside
- Storing all dependencies as global variables
- Installing missing operating-system packages
- Making every method static
Show correct answer and explanation
Correct answer: A. Providing a component with required dependencies from outside
Dependency injection supplies services or collaborators to a component rather than constructing them internally. This improves flexibility and supports testing with substitutes.
Question 9. What is memoization?
- Persisting a program as machine code
- Caching results of function calls for reuse
- Duplicating a database table every minute
- Sorting inputs before every call
Show correct answer and explanation
Correct answer: B. Caching results of function calls for reuse
Memoization stores results for previously solved inputs. It can save repeated computation when the same subproblems recur.
Question 10. What is a key risk of sharing mutable global state?
- It always improves concurrency
- Unexpected coupling and difficult-to-reason-about updates
- It makes code compile twice
- It prevents any memory allocation
Show correct answer and explanation
Correct answer: B. Unexpected coupling and difficult-to-reason-about updates
Mutable global data can be changed by distant parts of a program. Hidden dependencies make testing and concurrent execution more error-prone.
