Room Database Questions with Answers

13 practice questions on Room Database (Android (Kotlin & Compose)) with answers and step-by-step solutions. Try 10 samples below, then practise all 13 free in the AptiNest app.

Sample questions

Question 1Easy

Room is:

  1. A layer over SQLite
  2. A cloud database service
  3. A network library
  4. A UI toolkit

Answer: A. A layer over SQLite

Explanation

Room adds compile-time SQL checks and maps rows to Kotlin objects.

Step-by-step solution

  1. Room is part of Android Jetpack.
  2. It wraps SQLite with annotations and generated code.
  3. It checks queries at compile time.

Why the other options are wrong

  • B. Room is a local database.
  • C. Networking uses libraries like Retrofit.
  • D. UI toolkits are Compose or Views.

Question 2Easy

Which annotation marks a Room interface that declares database queries?

  1. @Query only
  2. @Entity
  3. @Dao
  4. @Database

Answer: C. @Dao

Explanation

DAOs (Data Access Objects) hold @Query, @Insert, @Update and @Delete methods.

Step-by-step solution

  1. A DAO is an interface (or abstract class) with query methods.
  2. It is annotated with @Dao.
  3. Its methods use @Query, @Insert, @Update and @Delete.

Why the other options are wrong

  • A. @Query marks a method, not the interface.
  • B. @Entity marks a table class.
  • D. @Database marks the database class.

Tip: Room trio: @Entity, @Dao, @Database.

Question 3Easy

The Room database class must extend:

  1. RoomDatabase
  2. SQLiteOpenHelper
  3. Application
  4. ViewModel

Answer: A. RoomDatabase

Explanation

It is abstract and annotated with @Database(entities = [...], version = n).

Step-by-step solution

  1. The database class is abstract and annotated @Database.
  2. It extends RoomDatabase.
  3. It exposes abstract functions that return each DAO.

Why the other options are wrong

  • B. SQLiteOpenHelper is the older, manual approach that Room hides.
  • C. Application is the app-wide class, not a database.
  • D. ViewModel holds UI state, not the database.

Tip: @Database abstract class AppDb: RoomDatabase().

Question 4Easy

Which annotation marks a Kotlin class as a Room table?

  1. @Table
  2. @Model
  3. @Entity
  4. @Dao

Answer: C. @Entity

Explanation

Each @Entity class maps to a table.

Step-by-step solution

  1. A Room table is defined by a data class.
  2. The class is annotated @Entity.
  3. Each property becomes a column; one is marked @PrimaryKey.

Why the other options are wrong

  • A. Room has no @Table annotation.
  • B. @Model is not a Room annotation.
  • D. @Dao is for the query interface.

Tip: Entity = table.

Question 5Medium

What does @PrimaryKey(autoGenerate = true) val id: Long = 0 do?

  1. SQLite assigns the ID
  2. Makes the ID a String
  3. Requires you to set unique IDs
  4. Creates a foreign key

Answer: A. SQLite assigns the ID

Explanation

A value of 0 is treated as unset, so a new ID is generated.

Step-by-step solution

  1. autoGenerate = true lets SQLite assign the next ID.
  2. The default 0 tells Room the ID is unset.
  3. After insert, the new row gets a unique ID.

Why the other options are wrong

  • B. The type stays Long.
  • C. You do not need to supply IDs.
  • D. Foreign keys are declared separately.

Question 6Medium

A DAO method returns Flow<List<Note>>. What happens when a note is inserted?

  1. Nothing until the app restarts
  2. The Flow completes
  3. An exception is thrown
  4. It emits the new list

Answer: D. It emits the new list

Explanation

Room observes table changes and re-runs the query for active collectors.

Step-by-step solution

  1. Room tracks which tables a query reads.
  2. When a write changes those tables, Room reruns the query.
  3. The Flow emits the updated list.

Why the other options are wrong

  • A. Updates arrive immediately.
  • B. Room Flows do not complete on their own.
  • C. Inserts are normal.

Question 7Medium

Marking a DAO method as suspend fun insert(note: Note) means:

  1. It is called from coroutines
  2. It blocks the UI thread
  3. It runs at compile time
  4. It can only be called from Java

Answer: A. It is called from coroutines

Explanation

Room runs suspend DAO methods on a background executor.

Step-by-step solution

  1. suspend functions can only be called from a coroutine or another suspend function.
  2. Room runs suspend DAO methods on a background executor.
  3. So the call does not block the UI thread.

Why the other options are wrong

  • B. suspend functions do not block the thread that calls them.
  • C. They run at runtime, not at compile time.
  • D. suspend functions are awkward to call from Java.

Tip: One-shot DAO call = suspend; live updates = Flow.

Question 8Medium

Room needs TypeConverters to store which kind of field directly?

  1. An Instant
  2. String
  3. Int
  4. ByteArray (BLOB)

Answer: A. An Instant

Explanation

Converters map unsupported types to supported column types like Long or String.

Step-by-step solution

  1. SQLite stores only basic types: integers, reals, text and blobs.
  2. Room maps String, Int and ByteArray directly.
  3. An Instant (date-time) needs a TypeConverter, e.g. to a Long timestamp.

Why the other options are wrong

  • B. String maps to TEXT.
  • C. Int maps to INTEGER.
  • D. ByteArray maps to BLOB.

Question 9Medium

@Insert(onConflict = OnConflictStrategy.REPLACE) means:

  1. The table is cleared first
  2. Duplicates are always ignored
  3. Clashing rows are replaced
  4. An exception is thrown on conflict

Answer: C. Clashing rows are replaced

Explanation

REPLACE deletes the conflicting row and inserts the new one.

Step-by-step solution

  1. A conflict happens when the primary key (or unique index) already exists.
  2. REPLACE deletes the old row and inserts the new one.
  3. The result is an upsert.

Why the other options are wrong

  • A. Only the clashing row is replaced.
  • B. IGNORE skips duplicates.
  • D. ABORT, the default, throws.

Question 10Hard

You add a column to an entity and bump the database version from 1 to 2 without a Migration. On an existing install, what happens (with no destructive fallback)?

  1. Old data is kept and the column ignored
  2. It crashes on startup
  3. Room downgrades to version 1
  4. Room adds the column automatically

Answer: B. It crashes on startup

Explanation

Provide a Migration(1, 2), an auto-migration, or explicitly allow destructive migration.

Step-by-step solution

  1. The schema changed and the version went up.
  2. Room needs a migration path from 1 to 2.
  3. With none and no destructive fallback, it throws IllegalStateException when the database opens, crashing the app.

Why the other options are wrong

  • A. Room refuses to open a database with a mismatched schema.
  • C. Room never downgrades automatically.
  • D. Room does not alter tables without a migration.

Practise all 13 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Android (Kotlin & Compose) topics · All topics