additional midterm flashcard 2
What is an interface in Java?
A collection of abstract methods and constants that establishes a set of methods that a class must implement
What are the key differences between interfaces and classes?
- Cannot instantiate an interface 2. No constructors 3. All methods are abstract 4. Only static and final fields allowed 5. Classes implement interfaces rather than extend them
What is an Abstract Data Type (ADT)?
A collection of data items together with the operations that can be performed on that data, specifying WHAT operations do but not HOW they do it
When should you use interfaces in Java?
- When you have multiple implementations for the same ADT 2. To expose simple public methods while hiding implementation details 3. To provide a template for classes that must be followed
What is abstraction in programming?
The separation of purpose (what something does) from implementation (how it does it), allowing users to use functionality without knowing internal details
What are generics in Java?
A feature that allows classes, interfaces, and methods to be written as templates that can work with any data type while maintaining type safety at compile time
Why can’t primitive types be used directly with generics?
Primitive types cannot be used directly in angle brackets (like ). Instead, wrapper classes must be used (like )
How do you make a class generic?
Add a type parameter in angle brackets after the class name (e.g., class Name) and use that parameter as a type within the class
What is a data structure?
A particular way of organizing data in a computer so that it can be used efficiently, with different structures suited to different applications
What are the key characteristics of an algorithm?
- Unambiguous description 2. Defined set of inputs and outputs 3. Guaranteed to terminate 4. Produces a defined result
What is a linked structure?
A collection of objects (nodes) storing data and links to other objects, where each node contains both data and references to other nodes
What are the advantages of arrays?
- Random quick access to elements 2. Groups like information together 3. Efficient direct access to elements
What are the disadvantages of arrays?
- Fixed size requiring recreation for resizing 2. Insertion/deletion requires shifting elements 3. Memory must be contiguous
What is the difference between == and .equals() for objects?
== compares if two references point to the same object in memory, while .equals() compares the actual content/values of the objects
What is a node in the context of linked structures?
An object in a linked structure that contains both data and references (links) to other nodes of the same type