Docsity

STARTING OUT WITH JAVA FROM CONTROL STRUCTURES THROUGH DATA STRUCTURES COMPLETE PRACTICE R, Exams of Object Oriented Programming

Toggle sidebar
bg1
STARTING OUT WITH JAVA FROM CONTROL STRUCTURES
THROUGH DATA STRUCTURES COMPLETE PRACTICE REVIEW WITH
CORRECT ANSWERS
Question 1.
Name common primitive data types.
Answer: Integers (byte, short, int, long), floating-point numbers (float, double),
Booleans, and characters (char).
Question 2.
How do primitive data types affect program execution speed?
Answer: They allow operations to run quickly as they correspond to the
machine's data storage methods.
Question 3.
What is type safety?
Answer: The enforcement of strict rules regarding type operations to reduce
errors in programming.
Question 4.
What is structured programming?
Answer: A programming paradigm that promotes clear, maintainable code using
control structures like sequence, selection, and iteration.
Question 5.
Who introduced the concept of structured programming?
Answer: Edsger Dijkstra.
Question 6.
What are the key benefits of structured programming?
Answer: Improved code clarity, maintainability, and reliability by avoiding
unstructured constructs like 'goto'.
Question 7.
What is recursion?
Answer: A programming technique where a function calls itself to solve smaller
instances of the same problem.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download STARTING OUT WITH JAVA FROM CONTROL STRUCTURES THROUGH DATA STRUCTURES COMPLETE PRACTICE R and more Exams Object Oriented Programming in PDF only on Docsity!

STARTING OUT WITH JAVA FROM CONTROL STRUCTURES

THROUGH DATA STRUCTURES COMPLETE PRACTICE REVIEW WITH

CORRECT ANSWERS

Question 1.

Name common primitive data types.

Answer: Integers (byte, short, int, long), floating-point numbers (float, double), Booleans, and characters (char).

Question 2.

How do primitive data types affect program execution speed?

Answer: They allow operations to run quickly as they correspond to the machine's data storage methods.

Question 3.

What is type safety?

Answer: The enforcement of strict rules regarding type operations to reduce errors in programming.

Question 4.

What is structured programming?

Answer: A programming paradigm that promotes clear, maintainable code using control structures like sequence, selection, and iteration.

Question 5.

Who introduced the concept of structured programming?

Answer: Edsger Dijkstra.

Question 6.

What are the key benefits of structured programming?

Answer: Improved code clarity, maintainability, and reliability by avoiding unstructured constructs like 'goto'.

Question 7.

What is recursion?

Answer: A programming technique where a function calls itself to solve smaller instances of the same problem.

Give an example of recursion in Python.

Answer: The factorial function: 'def factorial(n): return 1 if n == 0 else n * factorial(n-1)'.

Question 9.

What is iteration?

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

Question 10.

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 11.

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 12.

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 13.

What is type checking?

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

Question 14.

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 15.

What is the significance of composite data types?

How do modern languages connect recursion and iteration?

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

Question 24.

What is lazy evaluation in functional programming?

Answer: A strategy where expressions are not evaluated until their values are needed, improving efficiency.

Question 25.

What is the difference between a procedure and a function?

Answer: A procedure performs a specific task but does not return a value, while a function computes and returns a value.

Question 26.

What programming paradigm primarily uses recursion for tasks resembling iteration?

Answer: Functional programming languages, such as Haskell.

Question 27.

What is tail call optimization?

Answer: A compiler technique that transforms recursive calls into iterative processes to improve performance.

Question 28.

What are activation records?

Answer: Data structures used by a program's runtime to manage function calls, storing parameters, local variables, and return addresses.

Question 29.

What principle does the call stack operate on?

Answer: Last in, first out (LIFO) principle.

Question 30.

What happens during a stack overflow?

Answer: It occurs when too many activation records are pushed onto the stack, often due to deep recursion.

What is pass-by-value?

Answer: A parameter passing method that copies the argument's value into the function's parameter, creating an independent instance.

Question 32.

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

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

Question 33.

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 34.

What is the impact of overusing global variables in procedures?

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

Question 35.

How do modern languages like Rust improve reliability in procedures?

Answer: By imposing strict scoping and ownership rules.

Question 36.

What is the role of profilers in programming?

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

Question 37.

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

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

Question 38.

What is the significance of parameter passing techniques?

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

What is the effect of inlining on function performance?

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

Question 48.

What is the significance of return semantics in procedures?

Answer: They define how and what value a procedure or function returns to the caller.

Question 49.

How do modern languages handle stack management?

Answer: They often use virtual machines to manage stack memory, allowing programs to run on different systems.

Question 50.

What is the role of a frame pointer in an activation record?

Answer: It connects to the caller's record, facilitating the return to the correct execution point after a function call.

Question 51.

What is the purpose of closures in functional programming?

Answer: To allow functions to maintain access to their lexical scope even when executed outside that scope.

Question 52.

What is pass-by-reference?

Answer: A method that passes the address of the argument's storage area, allowing a function to modify the original data.

Question 53.

How does pass-by-reference work in C++?

Answer: It allows a function to alter the caller's variable directly, as shown in the example void increment(int& x) { x++; }.

Question 54.

What is a potential risk of using pass-by-reference?

Answer: It can lead to unwanted side effects if the function modifies data unexpectedly.

How does Java handle parameter passing for objects and primitives?

Answer: Java uses pass-by-reference for objects and pass-by-value for primitive types.

Question 56.

What is pass-by-name?

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

Question 57.

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 58.

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 59.

What are closures in programming?

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

Question 60.

How are closures useful in JavaScript?

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

Question 61.

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 62.

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.*

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

Question 71.

What is the role of closures in state management?

Answer: Closures help maintain state in applications, particularly in event-driven programming.

Question 72.

What is the impact of compiler optimizations on closures?

Answer: They can reduce performance costs associated with allocating closures and function calls.

Question 73.

What is the relationship between closures and higher-order functions?

Answer: Closures are often the functions that higher-order functions accept or return.

Question 74.

What is the significance of lambda calculus in functional programming?

Answer: It serves as a foundational concept for understanding functional programming principles.

Question 75.

How do modern languages implement functional programming features?

Answer: Languages like Python and JavaScript incorporate functional methods such as lambda expressions and higher-order functions.

Question 76.

What is the purpose of using lazy evaluation in programming?

Answer: It allows for deferred computation until necessary, which can improve efficiency.

Question 77.

What are some common languages that support functional programming?

Answer: Lisp, Scala, Haskell, Python, and JavaScript.

Question 78.

What is the importance of understanding parameter passing in programming?

Answer: It helps developers avoid errors and write code that behaves as intended.

Question 79.

What programming paradigm uses immutability and pure components?

Answer: Functional Programming (FP)

Question 80.

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

Answer: Clojure

Question 81.

What is the primary focus of Functional Programming?

Answer: Simplicity, correctness, and scalability

Question 82.

Who developed lambda calculus?

Answer: Alonzo Church

Question 83.

What are the three main parts of lambda calculus?

Answer: Variables, lambda abstractions, and applications

Question 84.

What does beta reduction refer to in lambda calculus?

Answer: The process of simplifying function applications

Question 85.

What is a pure function?

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

Question 86.

Give an example of a pure function in OCaml.

Answer: let square x = x * x

What is the SOLID principle in OOP?

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

Question 97.

What is the difference between static and dynamic dispatch?

Answer: Static dispatch resolves method calls at compile time, while dynamic dispatch resolves them at runtime

Question 98.

What programming language treats everything as objects?

Answer: Smalltalk

Question 99.

What is the role of integrated development environments (IDEs) in OOP?

Answer: To provide tools like autocompletion for object methods, streamlining development

Question 100.

What is the significance of lambda calculus in programming languages?

Answer: It provides a foundation for understanding computation and influences functional programming design

Question 101.

What does the term 'higher-order functions' refer to?

Answer: Functions that can take other functions as arguments or return them as results

Question 102.

What is the impact of pure functions on testing?

Answer: They simplify testing because the output is determined solely by the input

Question 103.

What challenges do impure functions present in programming?

Answer: They complicate debugging and testing due to their dependence on external state

What is the relationship between classes and objects in OOP?

Answer: Classes act as factories for creating objects, which are instances of those classes

Question 105.

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

Answer: To hold data concisely.

Question 106.

What performance consideration is important in Java regarding object creation?

Answer: Object creation overhead requires optimization.

Question 107.

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

Answer: Inheritance and composition.

Question 108.

What type of connection does inheritance create between classes?

Answer: An 'is-a' connection.

Question 109.

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

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

Question 110.

What does composition create between classes?

Answer: A 'has-a' connection.

Question 111.

Give an example of composition in programming.

Answer: A Car class having an Engine object.

Question 112.

What is a fragile base class problem?

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

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

Question 122.

What are common access modifiers in programming?

Answer: Public, private, and protected.

Question 123.

What does encapsulation help prevent?

Answer: Unwanted interference and errors in complex systems.

Question 124.

What is a potential downside of too strict access control?

Answer: It complicates proper use and may require workarounds like getters and setters.

Question 125.

How does encapsulation contribute to security in programming?

Answer: It limits access to important states, preventing bad code from making changes.

Question 126.

What is the role of static analyzers in relation to encapsulation?

Answer: They uphold access rules and identify access problems.

Question 127.

What is the balance developers need to strike with encapsulation?

Answer: Balancing safety with ease of use.

Question 128.

What is the significance of using interfaces in TypeScript?

Answer: They uphold polymorphic agreements.

Question 129.

What does the @Override annotation in Java prevent?

Answer: It prevents accidental creation of methods that override superclass methods.

What is the purpose of stack traces in polymorphic code?

Answer: To trace dynamic calls and ensure the correct method is executed.

Question 131.

What advanced feature in Julia enhances polymorphism?

Answer: Multiple dispatch.

Question 132.

What should developers consider when using polymorphism and dynamic binding?

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

Question 133.

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 134.

How does Java manage object memory?

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

Question 135.

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 136.

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.

Question 137.

What is garbage collection?

Answer: It is an automatic memory management process that reclaims memory from objects that are no longer reachable.

What is the significance of using blocks in C#?

Answer: Using blocks ensures that resources are managed and released at the right time.

Question 147.

What is unification in logic programming?

Answer: It is the process of making two logical expressions identical by finding a suitable substitution for variables.

Question 148.

What is backtracking in logic programming?

Answer: It is a method for finding solutions by exploring possible paths and reverting when a path fails.

Question 149.

What is the primary focus of logic programming?

Answer: To specify 'what' a program should achieve rather than 'how' to achieve it.

Question 150.

What is Prolog?

Answer: A logic programming language used for writing facts and rules to infer new information.

Question 151.

What are facts in logic programming?

Answer: Single statements that declare true claims, forming the knowledge base.

Question 152.

What is a rule in logic programming?

Answer: A logical relation between facts that allows for the inference of new facts.

Question 153.

What is a query in logic programming?

Answer: A question posed to the logic program that triggers the inference engine to find solutions.

What is the significance of the operator ':-' in Prolog?

Answer: ':-' means 'if' and is used to define rules in logic programming.

Question 155.

What is the role of an inference engine?

Answer: It assesses logical statements to derive conclusions from the knowledge base.

Question 156.

What are the challenges of logic programming with large datasets?

Answer: Performance issues can arise due to backtracking and unification processes.

Question 157.

What is the relationship between logic programming and SQL?

Answer: SQL queries resemble logic programming as they also involve logical reasoning.

Question 158.

What is the importance of clear facts and rules in logic programming?

Answer: They prevent incorrect conclusions and ensure efficient query processing.

Question 159.

What does the term 'declarative programming' refer to?

Answer: A programming paradigm that expresses the logic of computation without describing its control flow.

Question 160.

What is the impact of unclear rules in logic programming?

Answer: They can lead to endless loops or excessive backtracking, slowing down performance.