Docsity

STARTING OUT WITH JAVA FROM CONTROL STRUCTURES THROUGH DATA STRUCTURES EXAM FULL QUESTIONS, Exams of Object Oriented Programming

Toggle sidebar
bg1
STARTING OUT WITH JAVA FROM CONTROL STRUCTURES
THROUGH DATA STRUCTURES EXAM FULL QUESTIONS AND
CORRECT ANSWERS STUDY GUIDE
Question 1.
What is iteration?
Answer: A programming technique that uses loops to repeatedly execute a block
of code while maintaining state through variables.
Question 2.
How does iteration differ from recursion?
Answer: Iteration uses loops and is generally more memory efficient, while
recursion involves function calls and can risk stack overflow.
Question 3.
What is a tail recursion?
Answer: A specific form of recursion where the recursive call is the last
operation in the function, allowing for optimization by reusing the stack frame.
Question 4.
What are the trade-offs between recursion and iteration?
Answer: Recursion is often clearer for problems with natural order but risks
stack overflow, while iteration is more memory-efficient but can be more
complex.
Question 5.
What is type checking?
Answer: The process of verifying that a program adheres to the defined types of
data, ensuring correct operations.
Question 6.
What is polymorphism in programming?
Answer: The ability of different data types to be treated as instances of the
same type through a common interface.
Question 7.
What is the significance of composite data types?
Answer: They are data types that can hold multiple values, such as arrays and
structures, allowing for more complex data manipulation.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download STARTING OUT WITH JAVA FROM CONTROL STRUCTURES THROUGH DATA STRUCTURES EXAM FULL QUESTIONS and more Exams Object Oriented Programming in PDF only on Docsity!

STARTING OUT WITH JAVA FROM CONTROL STRUCTURES

THROUGH DATA STRUCTURES EXAM FULL QUESTIONS AND

CORRECT ANSWERS STUDY GUIDE

Question 1.

What is iteration?

Answer: A programming technique that uses loops to repeatedly execute a block of code while maintaining state through variables.

Question 2.

How does iteration differ from recursion?

Answer: Iteration uses loops and is generally more memory efficient, while recursion involves function calls and can risk stack overflow.

Question 3.

What is a tail recursion?

Answer: A specific form of recursion where the recursive call is the last operation in the function, allowing for optimization by reusing the stack frame.

Question 4.

What are the trade-offs between recursion and iteration?

Answer: Recursion is often clearer for problems with natural order but risks stack overflow, while iteration is more memory-efficient but can be more complex.

Question 5.

What is type checking?

Answer: The process of verifying that a program adheres to the defined types of data, ensuring correct operations.

Question 6.

What is polymorphism in programming?

Answer: The ability of different data types to be treated as instances of the same type through a common interface.

Question 7.

What is the significance of composite data types?

Answer: They are data types that can hold multiple values, such as arrays and structures, allowing for more complex data manipulation.

What is a user-defined data type?

Answer: A data type created by the programmer to encapsulate data and functions that operate on that data.

Question 9.

How do programming languages handle memory for primitive types?

Answer: Some languages, like C, require manual management, while others, like Python, handle it automatically.

Question 10.

What is the impact of hardware on primitive data types?

Answer: The size and representation of primitive types can vary based on the platform, affecting portability and performance.

Question 11.

What is the role of control structures in structured programming?

Answer: They dictate the flow of execution in a program, enhancing clarity and maintainability.

Question 12.

What is the purpose of modular programming?

Answer: To break programs into smaller, reusable, and testable components, improving organization and clarity.

Question 13.

What is the significance of the 'if' and 'while' constructs in structured programming?

Answer: They provide controlled flow of logic, replacing unstructured jumps like 'goto' to enhance code clarity.

Question 14.

What does the term 'spaghetti code' refer to?

Answer: Code that is tangled and difficult to follow, often resulting from excessive use of unstructured programming techniques.

Question 15.

How do modern languages connect recursion and iteration?

Answer: They may optimize recursive calls into iterative forms to improve performance and manage resources effectively.

What is the main advantage of pass-by-value?

Answer: It guards against errors by ensuring the caller's variable remains unchanged.

Question 25.

What is a closure in programming?

Answer: A function that captures the lexical scope in which it was defined, allowing it to access variables from that scope even when called outside of it.

Question 26.

What is the impact of overusing global variables in procedures?

Answer: It can ruin modularity and cause bugs due to unintended side effects.

Question 27.

How do modern languages like Rust improve reliability in procedures?

Answer: By imposing strict scoping and ownership rules.

Question 28.

What is the role of profilers in programming?

Answer: They help identify performance issues related to recursion and state changes in iterative code.

Question 29.

What is the purpose of using procedures and functions in programming?

Answer: To create modular, reusable code that improves readability and maintainability.

Question 30.

What is the significance of parameter passing techniques?

Answer: They define how arguments are transferred to functions, affecting behavior and efficiency.

Question 31.

What is the result of using pass-by-reference?

Answer: It allows the function to modify the caller's variable directly since it passes a reference to the original variable.

What are some common parameter passing methods?

Answer: Pass-by-value, pass-by-reference, pass-by-name, and pass- by-result.

Question 33.

What does lazy evaluation in functional languages do?

Answer: It delays the evaluation of an expression until its value is needed, optimizing resource use.

Question 34.

How does the call stack handle nested function calls?

Answer: Each function call creates a new activation record on the stack, maintaining proper scoping and local variable separation.

Question 35.

What is the purpose of debugging tools like GDB?

Answer: They help programmers follow function calls and variable states to identify issues in the code.

Question 36.

What happens to activation records when a function call is completed?

Answer: The system removes the activation record from the stack, restoring the caller's state.

Question 37.

What is a potential downside of using recursion?

Answer: It can lead to stack overflow if not managed properly, especially in languages that do not optimize tail calls.

Question 38.

What is the relationship between procedures/functions and structured programming?

Answer: They allow for dividing large programs into smaller, manageable units, enhancing code readability and maintainability.

Question 39.

What is the effect of inlining on function performance?

Answer: Inlining can improve performance by eliminating the overhead of function calls.

What is pass-by-name?

Answer: A method that postpones argument evaluation until the parameter is used, allowing for lazy evaluation.

Question 49.

What is pass-by-result?

Answer: A method that copies the final value of a parameter back to the argument after a procedure finishes.

Question 50.

What is the significance of understanding parameter passing methods?

Answer: It helps prevent errors and ensures that code behaves as expected, especially in object-oriented programming.

Question 51.

What are closures in programming?

Answer: Functions that capture their surrounding environment, retaining access to variables from their defining scope.

Question 52.

How are closures useful in JavaScript?

Answer: They allow data privacy and help with callbacks in event- driven programming.

Question 53.

What are higher-order functions?

Answer: Functions that take other functions as arguments or return them as results, treating functions as first-class citizens.

Question 54.

Give an example of a higher-order function in Python.

Answer: map(lambda x: x2, [1, 2, 3]) applies a doubling function to a list.*

Question 55.

What advantages do higher-order functions provide?

Answer: They enable abstraction over common patterns, promote concise code, and enhance reusability.

What is functional programming (FP)?

Answer: A programming paradigm that emphasizes pure functions, immutability, and higher-order functions.

Question 57.

What does immutability mean in functional programming?

Answer: It means that data cannot be changed after its creation, preventing accidental state changes.

Question 58.

What is referential transparency?

Answer: A property where a function's result is consistent for the same input, allowing for easier reasoning about code.

Question 59.

What are first-class functions?

Answer: Functions that can be treated as values, allowing them to be passed as arguments or returned from other functions.

Question 60.

What is the benefit of function composition in FP?

Answer: It allows simple operations to be combined into complex ones, enhancing modular design.

Question 61.

What challenges might developers face when learning functional programming?

Answer: They may struggle with the abstract qualities of FP and the shift from imperative programming paradigms.

Question 62.

How does FP improve code reliability?

Answer: By reducing side effects, making functions easier to test and verify independently.

Question 63.

What is the role of closures in state management?

Answer: Functional Programming (FP)

Question 72.

Which programming language combines functional ideas with practical features for big data?

Answer: Clojure

Question 73.

What is the primary focus of Functional Programming?

Answer: Simplicity, correctness, and scalability

Question 74.

Who developed lambda calculus?

Answer: Alonzo Church

Question 75.

What are the three main parts of lambda calculus?

Answer: Variables, lambda abstractions, and applications

Question 76.

What does beta reduction refer to in lambda calculus?

Answer: The process of simplifying function applications

Question 77.

What is a pure function?

Answer: A function that always produces the same output for the same input without side effects

Question 78.

Give an example of a pure function in OCaml.

Answer: let square x = x * x

Question 79.

What is an impure function?

Answer: A function that causes side effects or relies on outside conditions

Question 80.

What is the significance of monads in functional programming?

Answer: They help maintain purity by managing side effects

Question 81.

What are the core principles of Object-Oriented Programming (OOP)?

Answer: Encapsulation, inheritance, and polymorphism

Question 82.

What is a class in OOP?

Answer: A blueprint that defines attributes and methods for creating objects

Question 83.

What is an object in OOP?

Answer: An instance of a class created during program execution

Question 84.

What does encapsulation achieve in OOP?

Answer: It hides the internal workings of a class behind a public interface

Question 85.

What is inheritance in OOP?

Answer: A mechanism where a new class can inherit attributes and methods from an existing class

Question 86.

What does polymorphism allow in OOP?

Answer: It allows methods to do different things based on the object it is acting upon

Question 87.

What is the purpose of UML diagrams in OOP?

Answer: To visualize class structures and relationships

Question 88.

What is the SOLID principle in OOP?

Answer: A set of design principles aimed at making software designs more understandable, flexible, and maintainable

What is the purpose of data classes in modern programming languages?

Answer: To hold data concisely.

Question 98.

What performance consideration is important in Java regarding object creation?

Answer: Object creation overhead requires optimization.

Question 99.

What are the two main ways to reuse and arrange code in OOP?

Answer: Inheritance and composition.

Question 100.

What type of connection does inheritance create between classes?

Answer: An 'is-a' connection.

Question 101.

In C++, how does a Dog class inherit from an Animal class?

Answer: Using the syntax: class Dog : public Animal.

Question 102.

What does composition create between classes?

Answer: A 'has-a' connection.

Question 103.

Give an example of composition in programming.

Answer: A Car class having an Engine object.

Question 104.

What is a fragile base class problem?

Answer: It occurs when a superclass changes, breaking its subclass.

Question 105.

What is one risk associated with inheritance?

Answer: Overgeneralization, where unrelated behaviors complicate maintenance.

What design principle do the Gang of Four's patterns favor?

Answer: Composition over inheritance.

Question 107.

What does polymorphism allow in object-oriented programming?

Answer: It allows software to treat objects from different classes as instances of a main class.

Question 108.

What is subtype polymorphism?

Answer: It occurs when a subclass replaces a method from its superclass.

Question 109.

What principle does polymorphism adhere to that allows for code growth?

Answer: The Open-Closed Principle.

Question 110.

What is dynamic binding in programming?

Answer: It resolves method calls at runtime using an object's actual type.

Question 111.

How does dynamic binding affect performance compared to static binding?

Answer: Dynamic binding incurs a speed cost compared to static binding.

Question 112.

What is encapsulation in object-oriented programming?

Answer: It combines data and methods into one unit and restricts direct access to internal data.

Question 113.

What is the purpose of access control mechanisms?

Answer: To specify how much a class member is visible to other parts of the program.

Question 114.

What are common access modifiers in programming?

What advanced feature in Julia enhances polymorphism?

Answer: Multiple dispatch.

Question 124.

What should developers consider when using polymorphism and dynamic binding?

Answer: They need to design carefully to prevent mistakes like wrong overrides.

Question 125.

What is the lifespan of an object in programming?

Answer: An object lives from its creation to its deletion, including being put in memory, used, and removed.

Question 126.

How does Java manage object memory?

Answer: Java uses a garbage collector to reclaim memory when no references point to an object.

Question 127.

What happens to an object in C++ when its scope ends?

Answer: The object dies automatically if it is on the stack; if on the heap, it must be deleted manually.

Question 128.

What is a potential risk of manual memory management in C++?

Answer: It can lead to memory leaks or dangling pointers if not handled correctly.