0
0
Android Kotlinmobile~5 mins

Entity, DAO, Database classes in Android Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an <strong>Entity</strong> class in Android Room?
An Entity class represents a table in the database. Each instance of the class is a row in that table. It uses annotations like @Entity and @PrimaryKey to define the table and its primary key.
Click to reveal answer
beginner
What does a DAO (Data Access Object) do in Room?
A DAO defines methods to access the database, like inserting, updating, deleting, and querying data. It uses annotations like @Insert, @Update, @Delete, and @Query to specify SQL operations.
Click to reveal answer
beginner
What is the role of the <strong>Database</strong> class in Room?
The Database class holds the database and serves as the main access point. It is an abstract class annotated with @Database and lists the entities and version. It provides abstract methods to get DAOs.
Click to reveal answer
intermediate
Why do we use annotations like @Entity, @Dao, and @Database in Room?
Annotations tell Room how to generate the necessary code. @Entity marks a data class as a table, @Dao marks an interface or abstract class for database operations, and @Database defines the database configuration.
Click to reveal answer
intermediate
How does Room help with database operations compared to raw SQLite?
Room provides a simple, type-safe way to work with SQLite databases. It reduces boilerplate code, handles SQL queries with annotations, and integrates with Kotlin coroutines and LiveData for reactive apps.
Click to reveal answer
Which annotation marks a Kotlin data class as a database table in Room?
A@Entity
B@Dao
C@Database
D@Table
What does the @Dao annotation indicate?
ADefines a database table
BDefines a primary key
CDefines the database version
DDefines database access methods
Which class holds the database and provides DAOs in Room?
AEntity class
BDatabase class
CDAO class
DRepository class
Which annotation specifies the database version in Room?
A@Entity(version = 1)
B@Dao(version = 1)
C@Database(version = 1)
D@Version(1)
What is the purpose of the @PrimaryKey annotation in an Entity?
AMarks a field as the unique identifier
BMarks a method as primary
CMarks a class as primary
DMarks a query as primary
Explain the roles of Entity, DAO, and Database classes in Android Room.
Think about how data is stored, accessed, and managed.
You got /3 concepts.
    Describe how annotations help Room generate database code.
    Annotations are like labels telling Room what to do.
    You got /4 concepts.