What are Room's three main components and their functions?

Tests whether you know Room's architectural layers. Name the three: Database holds config and is the access point; Entity represents a table schema; DAO defines SQL operations. Red flag: confusing DAOs with Repositories or claiming Room is a full ORM.
WHAT THIS TESTS: Even at a senior level, interviewers use this question to verify you did not just copy-paste Room setup from a template. They want to see that you understand the separation of concerns between the database holder, the schema definition, and the query interface. It also reveals whether you appreciate compile-time safety and how Room abstracts SQLite without hiding it completely.
A GOOD ANSWER COVERS: A good answer hits three things in order: first, the Database class, which is an abstract class annotated with @Database that extends RoomDatabase, holds the singleton reference, serves as the main access point for the underlying SQLite database, and lists the entities and version number; second, the Entity, which is a data class annotated with @Entity that maps to a table where each property corresponds to a column and each instance represents a row; third, the DAO, which is an interface or abstract class annotated with @Dao that defines methods for CRUD operations using annotations like @Query, @Insert, @Update, and @Delete, with SQL validated at compile time. A senior candidate also notes that the DAO abstracts the actual SQL execution so the rest of the app does not touch raw SQLite.
COMMON WRONG ANSWERS: Common wrong answers include omitting the Database class entirely and only mentioning entities and DAOs, conflating the DAO with a Repository pattern layer, describing Room as a full ORM like Hibernate rather than an abstraction layer over SQLite, saying Entities manage queries, or claiming that Room replaces SQLite rather than sitting on top of it. Another red flag is confusing the DAO with the ViewModel or suggesting that SQL runs on the main thread by default.
LIKELY FOLLOW-UPS: Likely follow-ups include asking how Room handles migrations when the schema changes, how you would expose Room data to the UI through Flow or LiveData, why you should use a Repository between the DAO and ViewModel, how to test Room databases using an in-memory database, or what happens if you perform a Room query on the main thread.
ONE CONCRETE EXAMPLE: For a todo app, you might define a TaskEntity with @Entity(tableName = "tasks") and columns for id and title. You would define a TaskDao with @Query("SELECT * FROM tasks") and @Insert. Finally, you would define an abstract AppDatabase class annotated with @Database(entities = [TaskEntity::class], version = 1) that exposes an abstract fun taskDao(): TaskDao. The app then uses Room.databaseBuilder to instantiate AppDatabase and calls taskDao() to get the DAO.
Source: developer.android.com
Read the original → developer.android.com
- #android
- #room
- #sqlite
- #persistence
- #architecture-components
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.