Docsity

STARTING OUT WITH JAVA: FROM CONTROL STRUCTURES THROUGH DATA STRUCTURES EXAM PREP QUESTION, Exams of Java Programming

Toggle sidebar
bg1
STARTING OUT WITH JAVA: FROM CONTROL
STRUCTURES THROUGH DATA STRUCTURES
EXAM PREP QUESTIONS AND ANSWERS FULLY
VERIFIED
◉ What is iteration?
Answer: A programming technique that uses loops to repeatedly
execute a block of code while maintaining state through variables.
◉ 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.
◉ 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.
◉ 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.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

Download STARTING OUT WITH JAVA: FROM CONTROL STRUCTURES THROUGH DATA STRUCTURES EXAM PREP QUESTION and more Exams Java Programming in PDF only on Docsity!

STARTING OUT WITH JAVA: FROM CONTROL

STRUCTURES THROUGH DATA STRUCTURES

EXAM PREP QUESTIONS AND ANSWERS FULLY

VERIFIED

◉ What is iteration? Answer: A programming technique that uses loops to repeatedly execute a block of code while maintaining state through variables. ◉ 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. ◉ 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. ◉ 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.

◉ What is type checking? Answer: The process of verifying that a program adheres to the defined types of data, ensuring correct operations. ◉ 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. ◉ 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. ◉ How do programming languages handle memory for primitive types? Answer: Some languages, like C, require manual management, while others, like Python, handle it automatically. ◉ What is the impact of hardware on primitive data types?

◉ What is lazy evaluation in functional programming? Answer: A strategy where expressions are not evaluated until their values are needed, improving efficiency. ◉ 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. ◉ What programming paradigm primarily uses recursion for tasks resembling iteration? Answer: Functional programming languages, such as Haskell. ◉ What is tail call optimization? Answer: A compiler technique that transforms recursive calls into iterative processes to improve performance. ◉ What are activation records? Answer: Data structures used by a program's runtime to manage function calls, storing parameters, local variables, and return addresses. ◉ What principle does the call stack operate on? Answer: Last in, first out (LIFO) principle.

◉ 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. ◉ What is the main advantage of pass-by-value? Answer: It guards against errors by ensuring the caller's variable remains unchanged. ◉ 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. ◉ What is the impact of overusing global variables in procedures? Answer: It can ruin modularity and cause bugs due to unintended side effects.

◉ What does lazy evaluation in functional languages do? Answer: It delays the evaluation of an expression until its value is needed, optimizing resource use. ◉ 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. ◉ 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. ◉ 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. ◉ 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. ◉ 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. ◉ What is the effect of inlining on function performance? Answer: Inlining can improve performance by eliminating the overhead of function calls. ◉ What is the significance of return semantics in procedures? Answer: They define how and what value a procedure or function returns to the caller. ◉ How do modern languages handle stack management? Answer: They often use virtual machines to manage stack memory, allowing programs to run on different systems. ◉ 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. ◉ 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.

◉ 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. ◉ What are closures in programming? Answer: Functions that capture their surrounding environment, retaining access to variables from their defining scope. ◉ How are closures useful in JavaScript? Answer: They allow data privacy and help with callbacks in event- driven programming. ◉ What are higher-order functions? Answer: Functions that take other functions as arguments or return them as results, treating functions as first-class citizens. ◉ Give an example of a higher-order function in Python. Answer: map(lambda x: x*2, [1, 2, 3]) applies a doubling function to a list. ◉ 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. ◉ What does immutability mean in functional programming? Answer: It means that data cannot be changed after its creation, preventing accidental state changes. ◉ What is referential transparency? Answer: A property where a function's result is consistent for the same input, allowing for easier reasoning about code. ◉ 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. ◉ What is the benefit of function composition in FP? Answer: It allows simple operations to be combined into complex ones, enhancing modular design.

Answer: It serves as a foundational concept for understanding functional programming principles. ◉ 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. ◉ What is the purpose of using lazy evaluation in programming? Answer: It allows for deferred computation until necessary, which can improve efficiency. ◉ What are some common languages that support functional programming? Answer: Lisp, Scala, Haskell, Python, and JavaScript. ◉ What is the importance of understanding parameter passing in programming? Answer: It helps developers avoid errors and write code that behaves as intended. ◉ What programming paradigm uses immutability and pure components?

Answer: Functional Programming (FP) ◉ Which programming language combines functional ideas with practical features for big data? Answer: Clojure ◉ What is the primary focus of Functional Programming? Answer: Simplicity, correctness, and scalability ◉ Who developed lambda calculus? Answer: Alonzo Church ◉ What are the three main parts of lambda calculus? Answer: Variables, lambda abstractions, and applications ◉ What does beta reduction refer to in lambda calculus? Answer: The process of simplifying function applications ◉ What is a pure function? Answer: A function that always produces the same output for the same input without side effects

Answer: It hides the internal workings of a class behind a public interface ◉ What is inheritance in OOP? Answer: A mechanism where a new class can inherit attributes and methods from an existing class ◉ What does polymorphism allow in OOP? Answer: It allows methods to do different things based on the object it is acting upon ◉ What is the purpose of UML diagrams in OOP? Answer: To visualize class structures and relationships ◉ 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 difference between static and dynamic dispatch? Answer: Static dispatch resolves method calls at compile time, while dynamic dispatch resolves them at runtime ◉ What programming language treats everything as objects?

Answer: Smalltalk ◉ What is the role of integrated development environments (IDEs) in OOP? Answer: To provide tools like autocompletion for object methods, streamlining development ◉ What is the significance of lambda calculus in programming languages? Answer: It provides a foundation for understanding computation and influences functional programming design ◉ What does the term 'higher-order functions' refer to? Answer: Functions that can take other functions as arguments or return them as results ◉ What is the impact of pure functions on testing? Answer: They simplify testing because the output is determined solely by the input ◉ What challenges do impure functions present in programming? Answer: They complicate debugging and testing due to their dependence on external state

Answer: A 'has-a' connection. ◉ Give an example of composition in programming. Answer: A Car class having an Engine object. ◉ What is a fragile base class problem? Answer: It occurs when a superclass changes, breaking its subclass. ◉ 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. ◉ What does polymorphism allow in object-oriented programming? Answer: It allows software to treat objects from different classes as instances of a main class. ◉ What is subtype polymorphism? Answer: It occurs when a subclass replaces a method from its superclass.

◉ What principle does polymorphism adhere to that allows for code growth? Answer: The Open-Closed Principle. ◉ What is dynamic binding in programming? Answer: It resolves method calls at runtime using an object's actual type. ◉ How does dynamic binding affect performance compared to static binding? Answer: Dynamic binding incurs a speed cost compared to static binding. ◉ What is encapsulation in object-oriented programming? Answer: It combines data and methods into one unit and restricts direct access to internal data. ◉ What is the purpose of access control mechanisms? Answer: To specify how much a class member is visible to other parts of the program. ◉ What are common access modifiers in programming?