Sample questions
Kt Android Room PersistenceDifficulty 1
What is the primary purpose of the @Entity annotation in Room?
- aIt marks a class as a network response model parsed directly from JSON.
- bIt marks a class as a UI screen composable.
- cIt marks a class as a table definition for the Room database.✓
- dIt marks a class as a dependency-injection module.
Explanation:@Entity tells Room's annotation processor to generate a table schema from the class's fields; each instance becomes a row.
Kt Android Room PersistenceDifficulty 1
What does a Room @Dao interface typically contain?
- aThe raw SQLite file path configuration used by the underlying platform driver.
- bMethod declarations for database operations (queries, inserts, updates, deletes).✓
- cUI layout definitions for a screen.
- dNetwork retry policy configuration.
Explanation:A DAO (Data Access Object) declares the methods Room implements at compile time to run SQL against the database.
Kt Android Room PersistenceDifficulty 1
What role does the abstract class extending RoomDatabase play?
- aIt is the main access point holding the database and exposing the DAOs.✓
- bIt renders the app's launcher icon.
- cIt defines the app's Gradle build configuration and dependency versions.
- dIt manages the app's push notification tokens.
Explanation:The RoomDatabase subclass, annotated with @Database, is the central holder that Room generates an implementation for, exposing abstract DAO getters.
Kt Android Room PersistenceDifficulty 1
What does @PrimaryKey mark on an @Entity field?
- aThe column Room encrypts by default.
- bThe column used only for sorting UI lists, with no other effect on storage.
- cThe column that uniquely identifies each row.✓
- dThe column that must always be nullable.
Explanation:@PrimaryKey designates the unique row identifier; combined with autoGenerate = true Room can auto-increment it.
Kt Android Room PersistenceDifficulty 1
What is the purpose of the @Query annotation on a DAO method?
- aTo supply the raw SQL statement Room should run for that method.✓
- bTo register the method as a lifecycle callback triggered on Activity restart.
- cTo mark the method as a Compose preview.
- dTo declare the method as a Gradle task.
Explanation:@Query takes a SQL string; Room verifies it at compile time against the entity schema and generates the implementation.
Kt Android Room PersistenceDifficulty 2
What happens by default when an @Insert DAO method inserts a row whose primary key already exists?
- aThe existing row is silently replaced.
- bThe new row is silently ignored.
- cRoom automatically generates a new primary key for it and inserts a duplicate row.
- dThe insert aborts and Room throws a conflict exception.✓
Explanation:The default onConflict strategy for @Insert is OnConflictStrategy.ABORT, which raises a conflict rather than replacing or ignoring.