Module 1: AI and building software

Knowledge check: Introduction to AI

Practice Assignment

1. What is the primary difference between Generative AI and Discriminative AI?

  • Discriminative AI is faster than Generative AI in creating content.
  • Generative AI creates new data, while Discriminative AI predicts or classifies existing data. ✅
  • Both Generative and Discriminative AI focus only on data classification.
  • Generative AI predicts outcomes, while Discriminative AI generates new content.

Explanation:

  • Generative AI models, such as GPT, generate new content (e.g., text, images, or music) based on learned patterns.
  • Discriminative AI models classify or predict outcomes by distinguishing between different classes in existing data.

2. True or False: Generating a new piece of music in the style of Beethoven is a task that Generative AI can accomplish.

  • True ✅
  • False

Explanation:
Generative AI can learn patterns from Beethoven’s compositions and use this knowledge to create new music in a similar style. Models like GPT or GANs (Generative Adversarial Networks) specialize in content generation tasks.

3. Why is bias in GenAI a concern?

  • It causes GenAI to prioritize certain types of data over others, such as images.
  • It slows down the AI model’s ability to learn.
  • It prevents the AI from producing any content at all.
  • It can lead to outputs that reinforce harmful societal stereotypes. ✅

Explanation:
Bias in AI models occurs when the training data reflect societal or systemic prejudices, leading to biased outputs. For example, biased AI may produce discriminatory content or perpetuate stereotypes.

4. What is a significant risk associated with deepfake video technology?

  • It can create realistic but false videos, potentially leading to fraud or misinformation. ✅
  • It can corrupt the data integrity in artificial intelligence models.
  • The creation of a deepfake places significant strain on computer hardware, which may pose a risk of system damage.
  • It can crash a financial system.

Explanation:
Deepfake technology can fabricate convincing videos of people saying or doing things they never did, posing risks such as misinformation campaigns, fraud, or identity theft.

5. Which law is designed to regulate the use of high-risk AI applications?

  • China’s AI Regulations (2024)
  • European Union’s AI Act (2024) ✅
  • United States’ AI Bill of Rights (2024)
  • United Nations AI Regulations (2024)

Explanation:
The European Union’s AI Act is one of the most comprehensive laws aimed at regulating high-risk AI applications, ensuring transparency, fairness, and accountability in AI systems.

Knowledge check: Generative AI programming tools

Practice Assignment

6. When using Generative AI tools for coding, few-shot prompting is often employed to achieve better results. What does few-shot prompting involve?

  • Asking the AI to perform a task without providing examples.
  • Encouraging the AI to think step-by-step through a problem.
  • Providing a few examples to guide the AI’s response. ✅
  • Providing direct instructions without examples.

Explanation:
Few-shot prompting refers to providing the AI model with a small number of examples within the prompt to help it better understand and perform the task. It contrasts with zero-shot prompting, where no examples are provided.

7. True or False: Chain-of-thought prompting encourages AI to break down problems step-by-step to generate better results.

  • True ✅
  • False

Explanation:
Chain-of-thought prompting involves guiding the AI to solve problems step-by-step by explicitly breaking them into smaller, logical subproblems. This approach often leads to more accurate and logical outputs.

8. Which features are available in GitHub Copilot for Java developers? Select all that apply.

  • Built-in IDE debugging tools.
  • Code generation for entire blocks. ✅
  • Autocompletion of functions and methods. ✅
  • Conversational support for debugging.

Explanation:
GitHub Copilot assists Java developers by:

  • Code generation: Suggesting and completing entire blocks of code based on the context.
  • Autocompletion: Predicting and autocompleting functions, methods, and snippets to enhance coding efficiency.
    It does not provide built-in IDE debugging tools or conversational support for debugging.

9. A developer is debugging a large Java application with syntax errors and code optimization needs. They want a tool that provides real-time fixes and suggestions directly within their IDE. Which Generative AI tools should they consider? Select all that apply.

  • Amazon Q Developer ✅
  • ChatGPT
  • IntelliJ IDEA
  • GitHub Copilot ✅

Explanation:

  1. GitHub Copilot

    • Provides real-time, AI-driven code suggestions.
    • Integrates seamlessly with IDEs, offering syntax fixes, code generation, and optimization.
  2. Amazon Q Developer

    • A generative AI tool that supports debugging and optimization tasks with context-aware capabilities.

10. What are some best practices when interacting with ChatGPT for Java-related queries? Select all that apply.

  • Using clear and specific prompts. ✅
  • Providing context to clarify the problem. ✅
  • Avoiding detailed follow-up questions.
  • Asking for real-time error detection in IDEs.

Explanation:

  • Clear prompts: Help the AI understand the problem quickly and accurately.
  • Providing context: Ensures that the AI has enough information to generate useful responses.
    Avoiding follow-up questions is not recommended, as follow-ups can clarify or refine queries. Similarly, asking for real-time error detection is not applicable since ChatGPT doesn’t work as an IDE plugin.

Knowledge check: AI for automation

Practice Assignment

11. Which of the following is a primary benefit of using AI to automate Java documentation?

  • Completely eliminates the need for code comments.
  • Automatically fixes logical errors in the code.
  • Increases application performance by reducing code size.
  • Reduces manual effort and ensures up-to-date documentation. ✅

Explanation:
AI automates the process of generating and maintaining documentation, minimizing human effort and ensuring consistency.

12. True or False: AI-powered tools like Amazon Q Developer can identify synchronization issues in Java code during automated code reviews.

  • True ✅
  • False

Explanation:
Tools like Amazon Q Developer are capable of identifying complex issues, such as synchronization problems, during automated code reviews.

13. What is the most apparent issue in the following Java code snippet that could be optimized to improve efficiency?

  • Uninitialized variables
  • Incorrect use of the ‘this’ keyword
  • Redundant synchronization blocks ✅
  • Missing exception handling

Explanation:
Using multiple synchronization blocks on the same object (this) is unnecessary and can reduce efficiency. Combining them into one block would optimize the code.

14. What is the best way to refactor the following verbose switch statement to improve code readability and maintainability?

  • Add more case statements for all days of the week.
  • Leave it as is since switch statements are always optimal.
  • Replace the switch statement with an enum and method call. ✅
  • Convert it into nested if-else statements.

Explanation:
Enums provide a more structured approach and improve readability and maintainability by associating behavior directly with constants.

15. Which of the following best describes the role of AI in automating Java code refactoring?

  • Automatically generates test cases for the codebase.
  • Identifies bugs and fixes them in the code.
  • Improves code readability and performance by suggesting cleaner implementations. ✅
  • Rewrite the entire application in a different programming language.

Explanation:
AI tools are designed to refactor code by improving its structure and efficiency, ensuring better readability and maintainability without altering its functionality.

Knowledge check: AI software design

Practice Assignment

16. How should you format a prompt when writing new code using Amazon Q Developer?

  • Write the code manually without involving the tool.
  • Wait for Amazon Q to suggest code without providing input.
  • Copy and paste code from another source into Amazon Q.
  • Describe the code functionality in natural language. ✅

Explanation:
When using Amazon Q Developer, providing clear and natural language descriptions helps the tool generate accurate and functional code.

17. You are working on a Java project where you need to quickly set up boilerplate code for a RESTful API. You decide to use Amazon Q Developer for this task. How can Amazon Q Developer assist in generating the boilerplate code?

  • By guessing what the user might need without input.
  • By auto-generating entire applications without review.
  • By only providing syntax but no context.
  • By analyzing your project structure and generating controller, service, and repository templates. ✅

Explanation:
Amazon Q Developer can streamline boilerplate code generation by understanding the context of your project and creating essential components like controllers, services, and repositories.

18. How does Amazon Q Developer help you refactor code?

  • It ensures all bugs are fixed in the refactored code.
  • It deletes unused code without user approval.
  • It identifies redundant or inefficient sections in the code. ✅
  • It automatically rewrites the entire application.

Explanation:
Amazon Q Developer helps refactor code by pinpointing areas for improvement, such as removing redundancies and optimizing inefficiencies.

19. How does Amazon Q explain code to developers?

  • It guarantees a perfect understanding for all developers.
  • It breaks the code into smaller, understandable parts. ✅
  • It ignores the programming language of the code.
  • It focuses only on syntax without context.

Explanation:
Amazon Q explains code by deconstructing it into manageable sections, making it easier for developers to comprehend the functionality and logic.

20. What should you do if an explanation is too complex? Select all that apply.

  • Assume the explanation is wrong.
  • Ignore the AI and find an alternative tool.
  • Ask for examples to clarify the explanation. ✅
  • Request a simpler explanation for beginners. ✅

Explanation:
If an explanation is too complex, asking for examples or requesting simpler language helps make the information more digestible and useful.

Module quiz: AI and building software

Graded Assignment

21. Which prompting techniques are commonly applied in Generative AI tools? Select all that apply

  • Zero-shot prompting ✅
  • Implicit prompting – No input
  • Contextual prompts ✅
  • Role-based prompting ✅

Explanation:
These techniques are widely used in Generative AI to enhance the effectiveness of prompts and guide AI responses effectively.

22. What are the main features of Amazon Q Developer? Select all that apply

  • Debugging runtime errors automatically.
  • Automating production deployment.
  • Code generation. ✅
  • Explaining existing code logic. ✅

Explanation:
Amazon Q Developer focuses on tasks like generating new code and explaining existing logic but does not handle deployment or runtime debugging directly.

23. What is a feature of AI-powered refactoring tools?

  • Automating integration testing.
  • Rewriting business logic without input.
  • Detecting redundant code for removal. ✅
  • Guaranteeing compatibility across systems.

Explanation:
AI-powered refactoring tools specialize in identifying and addressing redundancies to optimize code performance.

24. What is one major benefit of using Generative AI in software development?

  • Writing entire applications without user input.
  • Handling hardware configurations automatically.
  • Guaranteeing bug-free applications.
  • Reducing repetitive coding tasks. ✅

Explanation:
Generative AI significantly reduces the burden of repetitive tasks, freeing developers to focus on more complex aspects of development.

25. How does Generative AI impact the code review process?

  • By reviewing project architecture independently.
  • By automating the detection of code inefficiencies. ✅
  • By completely eliminating the need for manual reviews.
  • By guaranteeing code is free from all bugs.

Explanation:
Generative AI tools help identify inefficiencies and suggest improvements during the code review process.

26. What approach does Generative AI use to develop coding capabilities?

  • By relying on manual instructions for every task.
  • By copying code from online repositories.
  • By guessing the logic for code execution.
  • By analyzing patterns in training data. ✅

Explanation:
Generative AI learns coding capabilities by identifying and leveraging patterns from its training datasets.

27. How does Generative AI contribute to effective code reviews? Select all that apply.

  • By recommending performance optimizations. ✅
  • By identifying potential bugs. ✅
  • Handling hardware configurations automatically.
  • By detecting redundant logic in code. ✅

Explanation:
Generative AI improves code reviews by enhancing performance, identifying bugs, and addressing redundant logic.

28. How does AI assist in improving code reviews?

  • By automated code inspection ✅
  • By eliminating the need for developer oversight
  • By managing all code deployments automatically
  • By ensuring code is always error-free

Explanation:
AI tools assist in code reviews by automatically inspecting the code, identifying errors, and suggesting fixes.

29. What is one key feature of GitHub Copilot that enhances Java development in IntelliJ?

  • Writing comprehensive test cases without developer intervention.
  • Automatically generating production-ready Java applications without any input.
  • Automatically deploying Java applications to production.
  • Managing deployment pipelines directly from IntelliJ.

30. True or false: AI tools guarantee error-free boilerplate code for all projects.

  • True
  • False ✅

Explanation:
AI tools are helpful but cannot guarantee error-free boilerplate code due to the complexity and variability of project requirements.

Leave a Reply