IDS 201 Final Exam

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/79

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 8:16 PM on 4/19/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

80 Terms

1
New cards

1. What is a GUI in Java and how is it different from console programs?

A GUI (Graphical User Interface) allows users to interact visually using components like buttons, text fields, and menus. Unlike console programs that run top-to-bottom once, GUI programs are event-driven, meaning they wait for user actions (clicks, typing) and respond accordingly.

2
New cards

2. What are the three main packages used in Java GUI programming and what does each do?

  • java.awt.* โ†’ basic graphics, colors, layouts

  • java.awt.event.* โ†’ event handling (clicks, mouse, keyboard)

  • javax.swing.* โ†’ GUI components (JFrame, JButton, etc.)

3
New cards

3. What is the difference between a top-level container and a component?

  • Top-level container (JFrame): the main window provided by the OS

  • Components (JButton, JPanel, etc.): elements inside the window
    ๐Ÿ‘‰ Components must always be placed inside a container.

4
New cards

4. Explain the containment hierarchy in Java GUIs. Why is it important?

GUI elements are arranged in a tree structure:

JFrame โ†’ JPanel โ†’ Components

This matters because:

  • Everything must be inside another object

  • Components wonโ€™t appear unless properly added

  • Layout and rendering depend on this structure

5
New cards

5. What is a JFrame and what are its key responsibilities?

A JFrame is the main application window. It:

  • Holds all components

  • Controls size, title, and visibility

  • Manages closing behavior

6
New cards

6. Why doesnโ€™t a JFrame appear or close properly by default?

  • It is invisible until setVisible(true) is called

  • Closing the window does not stop the program unless:

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

7
New cards

7. Why should setVisible(true) be called last when building a GUI?

Because:

  • The GUI should be fully constructed first

  • Prevents flickering or partial rendering

  • Ensures all components appear correctly

8
New cards

8. What is a JComponent and why is it important?

JComponent is the base class for most Swing components (JPanel, JButton, etc.).
It provides shared functionality like:

  • Rendering

  • Handling events

  • Setting size and colors

9
New cards

9. Compare JLabel, JButton, JTextField, and JTextArea.

  • JLabel โ†’ display text/image (no interaction)

  • JButton โ†’ clickable, triggers actions

  • JTextField โ†’ single-line input

  • JTextArea โ†’ multi-line input/output

10
New cards

10. What is a JPanel and why is it heavily used?

A JPanel is a container used to:

  • Organize components

  • Apply layout managers

  • Serve as a drawing surface for graphics

11
New cards

11. Why are layout managers necessary?

Without them:

  • Components overlap

  • Only the last added may be visible
    Layout managers automatically control positioning and sizing.

12
New cards

12. Explain FlowLayout.

  • Default layout

  • Places components left โ†’ right

  • Wraps to next line when space runs out

  • Similar to text in a paragraph

13
New cards

13. Explain GridLayout.

  • Divides container into rows ร— columns

  • All cells are equal size

  • Components fill their entire cell

14
New cards

14. Explain BoxLayout.

  • Arranges components in one direction

  • X_AXIS โ†’ horizontal

  • Y_AXIS โ†’ vertical

  • Good for stacking components neatly

15
New cards

15. What does event-driven programming mean in GUIs?

The program:

  • Waits for user actions (events)

  • Executes code only when events occur
    ๐Ÿ‘‰ You donโ€™t control flow โ€” the user does

16
New cards

16. What is an ActionListener and when is it used?

An ActionListener listens for actions like:

  • Button clicks

  • Pressing Enter in a text field

17
New cards

17. What are the three steps to implement event handling?

  • Implement interface (implements ActionListener)

  • Attach listener (addActionListener)

  • Override method (actionPerformed)

18
New cards

18. What is the role of actionPerformed(ActionEvent e)?

It is automatically called when an action occurs (e.g., button click).
You define what happens inside it.

19
New cards

19. Why is e.getSource() important?

It identifies which component triggered the event.
Useful when multiple components share the same listener.

20
New cards

20. Why canโ€™t you create a Graphics object directly?

Because Graphics is abstract.
Java automatically provides a concrete Graphics object when drawing.

21
New cards

21. What coordinate system does Java graphics use?

  • (0,0) = top-left corner

  • x increases right

  • y increases downward

22
New cards

22. Difference between draw and fill methods?

  • drawRect() โ†’ outline

  • fillRect() โ†’ solid shape

23
New cards

23. What is paintComponent(Graphics g) and why is it important?

It is the main method used for custom drawing in Swing.
You override it in a JPanel subclass to render graphics.

24
New cards

24. Why must you call super.paintComponent(g)?

It:

  • Clears the screen

  • Prevents overlapping drawings

  • Ensures proper rendering

25
New cards

25. Why should you NOT override paint()?

Because:

  • It handles more complex painting tasks

  • Can break component rendering
    ๐Ÿ‘‰ Always use paintComponent() instead

26
New cards

26. What does repaint() do?

  • Requests the GUI to redraw

  • Calls paintComponent() again
    ๐Ÿ‘‰ Use when visuals change

27
New cards

27. What does validate() do?

  • Updates layout after structural changes

  • Fixes component hierarchy

28
New cards

28. When do you use repaint vs validate?

  • repaint() โ†’ visual changes

  • validate() โ†’ adding/removing components

29
New cards

29. How are colors represented in Java?

Using RGB values (0โ€“255):

new Color(255, 0, 0); // red

30
New cards

30. Difference between foreground and background color?

  • Background โ†’ panel/window color

  • Foreground โ†’ text/shapes drawn

31
New cards

31. How do you set a font?

new Font("Verdana", Font.BOLD, 20);

32
New cards

32. What is panel switching and why is it useful?

Instead of modifying one panel, you:

  • Create multiple panels

  • Swap them using:

remove(oldPanel);
add(newPanel);
validate();
repaint();

๐Ÿ‘‰ Cleaner and easier for complex GUIs

33
New cards

33. Why can events feel โ€œsimultaneousโ€?

Because GUIs use threads โ€” multiple events can be processed at the same time, leading to unexpected behavior if not handled carefully.

34
New cards

34. What are the most common mistakes students make?

  • Forgetting setVisible(true)

  • Forgetting super.paintComponent(g)

  • Confusing repaint() vs validate()

  • Not using getSource() with multiple buttons

  • Not using layout managers

35
New cards

35. If you had to explain the entire GUI system in 3 sentences, what would you say?

A Java GUI is a hierarchy of components inside a JFrame, organized using layout managers. The program is event-driven, meaning it waits for user actions and responds using listeners like ActionListener. Graphics are drawn by overriding paintComponent(), and the display is updated using repaint() and validate() when needed.

36
New cards

Q: What is File I/O in Java?

A: Moving data between files (disk) and RAM (memory).

37
New cards

Q: What are streams?

A: Streams are pathways that transfer data between memory and files.

38
New cards

Q: What is the difference between input and output streams?

  • Input โ†’ file โ†’ RAM

  • Output โ†’ RAM โ†’ file

39
New cards

Q: What is the โ€œwater slideโ€ model?

A mental model where:

  • Data starts at the top (object in memory)

  • Flows through streams

  • Ends at the bottom (file)

40
New cards

Q: Why is the water slide model important?

A: It helps you reconstruct any File I/O problem instead of memorizing code.

41
New cards

Q: What does the File class represent?

A: A file or directory path (not the actual data).

42
New cards

Q: Difference between relative and absolute path?

  • Relative โ†’ "file.txt"

  • Absolute โ†’ "C:/folder/file.txt"

43
New cards

Q: Does creating a File object create the file?

A: Noโ€”it only creates a reference.

44
New cards

Q: Why must File I/O use try/catch?

A: Because file operations can fail (missing file, permissions, etc.).

45
New cards

Q: What is IOException?

A: General error for file operations failing.

46
New cards

Q: What is ClassNotFoundException?

A: Happens when reading an object whose class Java cannot find.

47
New cards

Q: What are FileInputStream and FileOutputStream used for?

A: Reading/writing raw bytes.

48
New cards

Q: What type of data do byte streams handle?

A: Only byte arrays (no structure, no objects).

49
New cards

Q: When should you use byte streams?

A: When working with raw binary data or byte arrays.

50
New cards

Q: What is ObjectOutputStream used for?

A: Writing objects to a file.

51
New cards

Q: What is ObjectInputStream used for?

A: Reading objects from a file.

52
New cards

Q: What is serialization?

A: Converting an object into bytes so it can be stored in a file.

53
New cards

Q: What must a class implement to be serialized?

A: Serializable

54
New cards

Q: Does String need Serializable?

A: Noโ€”it already implements it.

55
New cards

Q: What are the TWO hidden stages of writing an object?

  • Object โ†’ byte array

  • Byte array โ†’ file

56
New cards

Q: What are the TWO stages of reading an object?

  • File โ†’ byte array

  • Byte array โ†’ object

57
New cards

Q: Why does readObject() require casting?

A: It returns a generic Object, not a specific type.

58
New cards

Q: What happens if you donโ€™t cast a readObject() function?

A: Compile-time error.

59
New cards

Q: What happens if you cast incorrectly?

A: Runtime ClassCastException.

60
New cards

Q: What is the object writing pattern?

File โ†’ FileOutputStream โ†’ ObjectOutputStream โ†’ writeObject()

61
New cards

Q: What is the object reading pattern?

File โ†’ FileInputStream โ†’ ObjectInputStream โ†’ readObject()

62
New cards

Q: What are DataOutputStream and DataInputStream used for?

A: Writing/reading primitive types (int, double, etc.).

63
New cards

Q: Why are primitive streams easier than object streams?

  • No casting

  • No ClassNotFoundException

64
New cards

Q: What is the MOST IMPORTANT rule for primitives?

A: Read in the SAME order you write.

65
New cards

Q: What happens if order is wrong?

A: Data becomes corrupted.

66
New cards

Q: How do you write a byte array?

A: FileOutputStream โ†’ write(byte[])

67
New cards

Q: How do you read a byte array?

A: FileInputStream โ†’ readAllBytes()

68
New cards

Q: Why is the byte array the simplest case?

A: No conversion, no casting, no extra streams.

69
New cards

Q: Which streams for objects?

A: ObjectInputStream / ObjectOutputStream

70
New cards

Q: Which streams for primitives?

A: DataInputStream / DataOutputStream

71
New cards

Q: Which streams for byte arrays?

A: FileInputStream / FileOutputStream only

72
New cards

Q: What happens if you forget to close streams?

A: Data may not save + memory leaks.

73
New cards

Q: What happens if Serializable is missing?

A: Program throws exception when writing object.

74
New cards

Q: What happens if you read wrong type?

A: ClassCastException.

75
New cards

Q: Why canโ€™t files store objects directly?

A: Files only store bytes, not Java objects.

76
New cards

Q: Why does Java use layered streams?

Each stream handles one responsibility:

  • File stream โ†’ bytes

  • Object/Data stream โ†’ interpretation

77
New cards

Q: Why is ObjectInputStream more complex?

A: It reconstructs objects using metadata + class info.

78
New cards

Q: If question says โ€œobject,โ€ what do you use?

A: Object streams

79
New cards

Q: If question says โ€œint/doubleโ€?

A: Data streams

80
New cards

Q: If question says โ€œbyte[]โ€?

A: File streams only