ADT's and Exceptions Flashcards

1
Q

What is an Abstract Data Type (ADT)?

A

An Abstract Data Type (ADT) is a high-level description of a data structure that separates the behaviour of the data structure from its implementation details. It describes the type of data stored and the operations that can be performed on it without providing any information about how the module works internally. The purpose of ADT is to provide a clear and concise specification of the module’s functionality, allowing developers to focus on how to use the module, rather than how it is implemented.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the purpose of ADT?

A

The purpose of ADT is to provide a high-level, abstract description of a data structure that separates its behaviour from its implementation. This allows developers to focus on how to use the module and its operations, rather than how it is implemented. It also provides a clear specification of the module’s functionality, which can help to make it easier to understand and maintain.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the main components of an ADT?

A

The main components of an ADT are the type of data that is stored, and the operations that can be performed on it. The type of data stored can be as simple as a single value or as complex as a collection of related data. The operations that can be performed on the data include functions like adding, removing, or retrieving elements from the data structure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why is encapsulation important in ADT?

A

Encapsulation is important in ADT because it helps to ensure that the data structure’s implementation is hidden from the user. By encapsulating the data and its associated operations, developers can protect the module’s internal implementation details from being accessed or modified by outside code. This helps to maintain the integrity and consistency of the data structure, and also helps to prevent errors or unintended consequences that could result from unauthorized access or modification of the module’s data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the types of operations on data in an ADT?

A

The types of operations on data in an ADT typically include adding data to the data structure, removing data from the data structure, and querying the data structure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Why is it important to think about the types of operations before designing the representation of data in an ADT?

A

Thinking about the types of operations before designing the representation of data in an ADT can lead to better data representations. This is because understanding the types of operations that will be performed on the data can help guide the design of the data structure to be more efficient and effective for those operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between an Abstract Data Type (ADT) and a Data Structure?

A

An ADT and a data structure are not the same thing. An ADT is a high-level description of a type of data and the operations that can be performed on it, while a data structure is a specific implementation of an ADT that defines exactly how the data is stored and the implementation of its methods. A data structure is composed of classes, attributes, and methods in Java, and it specifies the exact implementation of the operations described in the ADT. In contrast, an ADT is closer to the design of the data and its operations, while a data structure is closer to its implementation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the attributes of the List ADT?

A

The items in a list have a unique predecessor and a unique successor. The front of the list does not have a predecessor, and the end of the list does not have a successor.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What operations are supported by the List ADT?

A

The List ADT supports the following operations:
Create an empty list
Determine whether a list is empty
Determine the number of items in a list
Add an item at a given position in the list
Remove the item at a given position in the list
Remove all the items from the list
Retrieve the item at a given position in the list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the List ADT specify about the items in the list?

A

The List ADT specifies that the items in a list have a unique predecessor and a unique successor, and that the front of the list does not have a predecessor, and the end of the list does not have a successor.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the List ADT not specify?

A

The List ADT does not specify how the items in the list are stored or how the operations are implemented. It only specifies what operations are supported by the list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the purpose of an interface in Java?

A

An interface in Java specifies a set of methods without implementation, which can be implemented by classes that use the interface.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How does an interface differ from a class in Java?

A

An interface only defines methods and constants, while a class can have attributes, methods, and implementation details.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the benefits of using interfaces in Java?

A

Interfaces allow for more flexible and modular programming, as classes can implement multiple interfaces and be used in different contexts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the List interface in Java specify?

A

The List interface in Java specifies methods for determining if a list is empty, getting the number of elements in a list, adding an item to a list at a specified position, and getting an item from a list at a specified position.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Can an interface have attributes in Java?

A

No, interfaces in Java are not allowed to have attributes or any implementation details.

17
Q

What is the purpose of Exception Handling?

A

The purpose of Exception Handling is to handle errors in a program and build robust and fault-tolerant programs. It is about anticipating common errors and recovering from them before they lead to bigger problems.

18
Q

Why is Exception Handling important in programming?

A

Exception Handling is important in programming because it helps to prevent crashes and errors from causing damage to the program or the system it is running on. It enables the program to detect errors and recover from them gracefully, improving the overall user experience.

19
Q

What are some common examples of exceptions that can occur in a program?

A

Some common examples of exceptions that can occur in a program include out-of-bounds array index, arithmetic overflow, division by zero, null pointer reference, and file I/O errors. These exceptions can cause the program to crash or behave unexpectedly if not handled properly.

20
Q

What is the benefit of anticipating exceptions in a program?

A

Anticipating exceptions in a program can help prevent program crashes and data loss. By identifying and handling exceptions proactively, the program can provide better user experience and improved reliability.

21
Q

How does Exception Handling relate to Input/Output operations in a program?

A

Exception Handling is often associated with Input/Output operations in a program, such as file I/O and user input. This is because input/output operations are often a source of errors in a program, and Exception Handling can help prevent these errors from causing damage to the program or the system.

22
Q

How are errors handled in Java?

A

In Java, errors are thrown and caught using try-catch blocks. When an error occurs, the code that caused the error throws an exception, which causes an immediate return out of the method. The code that called the method then has a catch clause, which receives the error and handles it. The error itself is a class that inherits from the throwable superclass.

23
Q

What is the role of the catch clause in Java exception handling?

A

The catch clause in Java receives the error that is thrown and handles it appropriately based on the type of error. If multiple catch clauses are used, the appropriate catch clause is called depending on the type of error.