Program Design and Development - AP Computer Science Principles
- Identify the error: 'while(x > 0); { x--; }'
- Remove ';' after the condition. Semicolon creates empty loop body, preventing intended execution.
- Identify the error: 'if (x = 10)'
- Correct: 'if (x == 10)'. Single '=' assigns value; '==' compares for equality in conditions.
- What is the difference between a class and an object?
- Class is a blueprint; object is an instance. Template defines structure; instance contains actual data values.
- What does 'DRY' stand for in programming?
- Don't Repeat Yourself. Principle promoting code reusability by avoiding duplication.
- Which keyword is used to inherit a class in Java?
- extends. Establishes parent-child relationship between classes for code reuse.
- Which programming construct is used for decision making?
- Conditional statements. if-else and switch statements control program flow based on conditions.
- What is abstraction in programming?
- Hiding complex implementation details behind simple interfaces. Simplifies complexity by exposing only essential features to users.
- What is a function's return type?
- The data type of the value returned by the function. Specifies what kind of value the function sends back.
- Identify the error: 'int x = 10; float y = x / 0;'
- Division by zero error. Mathematical impossibility that causes runtime exception or undefined behavior.
- Find and correct the error: 'int[] arr = new int(5);'
- Correct: 'int[] arr = new int[5];'. Square brackets for arrays, not parentheses like method calls.
- What is an IDE?
- Integrated Development Environment. Software providing comprehensive tools for coding, debugging, and testing.
- Which method is the entry point for a Java application?
- main method. Starting point where JVM begins program execution.
- What is polymorphism in programming?
- Ability of different classes to respond to the same method call. Same interface produces different behaviors in different classes.
- Identify the error: 'switch(x) { case 1: x+=1; break; default: x-=1; }'
- No error. Proper switch syntax with break statements and default case.
- What is the difference between '==' and 'equals()' in Java?
- '==' checks reference equality; 'equals()' checks value equality. Reference vs content comparison for determining object equality.
- What is a software design pattern?
- A reusable solution to a common problem. Template providing proven structure for recurring design challenges.
- What is the role of an algorithm in program design?
- To outline the step-by-step solution to a problem. Provides clear, logical sequence of instructions to solve problems.
- What is the purpose of version control in software development?
- To manage changes to source code over time. Tracks modifications, enables collaboration, and maintains code history.
- What does 'MVC' stand for in software design?
- Model-View-Controller. Architectural pattern separating presentation, logic, and data concerns.
- What is the purpose of a loop in programming?
- To repeat a block of code multiple times. Automates repetitive tasks by controlling iteration and flow.
- Find and correct the error: 'for(int i = 0; i < 10; i+)'
- Correct: 'for(int i = 0; i < 10; i++)'. Missing second '+' in increment operator; should be 'i++'.
- What is inheritance in object-oriented programming?
- Mechanism for one class to inherit attributes and methods from another. Child classes acquire properties and behaviors from parent classes.
- Which loop executes at least once regardless of condition?
- Do-while loop. Condition checked after execution, guaranteeing minimum one iteration.
- Identify the error: 'if (x > y) x = 10; else; y = 10;'
- Remove ';' after else. Semicolon after else creates syntax error in conditional structure.
- Which data structure uses LIFO order?
- Stack. Last In, First Out - elements added/removed from same end.
- Find and correct the error: 'int x = "100";'
- Correct: 'int x = 100;'. String literal assigned to integer variable causes type mismatch.
- What is a syntax error?
- An error in the code's grammar or structure. Violates language rules preventing code from compiling or running.
- Which structure is used to handle exceptions in Java?
- try-catch block. Catches and manages runtime errors gracefully without crashing.
- What is encapsulation in object-oriented programming?
- Bundling data with methods that operate on the data. Data hiding principle combining related data and functions together.
- What is the function of a compiler?
- To convert source code into machine code. Translates high-level code into executable machine instructions.
- What is the purpose of a constructor in a class?
- To initialize new objects. Special method that sets up object state when created.
- What is a recursive function?
- A function that calls itself. Solves problems by breaking them into smaller identical subproblems.
- What is a variable's scope?
- The region of code where the variable is accessible. Determines where variables can be accessed within program structure.
- What is the difference between 'public' and 'private' access modifiers?
- 'public' is accessible everywhere; 'private' is within the same class. Controls visibility and access levels for class members.
- What is an API?
- Application Programming Interface. Interface defining how software components communicate and interact.
- What is the primary purpose of program documentation?
- To explain code logic and facilitate future maintenance. Comments and structure make code understandable for others and future edits.
- Identify the first step in the program development life cycle.
- Problem analysis. Understanding requirements before designing solutions is essential first step.