Local Storage Essentials: SQLite u0026 Shared Preferences Quiz Quiz

Test your knowledge of local storage concepts with this quiz focused on SQLite databases and Shared Preferences. Learn the basics, key differences, and correct usage scenarios to master local data storage methods for applications.

  1. SQLite Data Type Usage

    Which data type is commonly used when storing integer values in an SQLite table?

    1. FLOAT
    2. INTEGER
    3. INTTEXT
    4. STRING

    Explanation: The correct data type for storing whole numbers in SQLite is INTEGER. STRING and INTTEXT are not valid SQLite data types; STRING is usually replaced with TEXT and INTTEXT does not exist. FLOAT is for decimal numbers, not integers.

  2. Purpose of Shared Preferences

    What is the primary use of Shared Preferences in local storage?

    1. To store large files
    2. To store simple key-value pairs
    3. To run background tasks
    4. To manage relational data

    Explanation: Shared Preferences are mainly used to store simple key-value pairs such as user settings or preferences. They are not intended for large files or complex relational data, and have nothing to do with running background tasks. Using them outside their scope can result in inefficient design.

  3. SQLite Table Creation

    Which command is used to create a new table in SQLite?

    1. CREATE TABLE
    2. FORM TABLE
    3. MAKETABLE
    4. INSERT TABLE

    Explanation: The CREATE TABLE command is the standard way to make a new table in SQLite. Options like INSERT TABLE and FORM TABLE are incorrect commands, and MAKETABLE is not recognized. Using the wrong syntax will result in errors.

  4. Data Persistence in Shared Preferences

    How long does data typically persist in Shared Preferences unless it is explicitly removed?

    1. Until the app is updated
    2. Permanently, until deleted
    3. Until the device is restarted
    4. For one day only

    Explanation: Data stored in Shared Preferences remains until it is manually deleted by the application or the user uninstalls the app. App updates or device restarts do not remove this data. There is also no default automatic expiration after a day.

  5. Relational Data Storage

    What is the best storage option for saving complex relational data with multiple related tables?

    1. SQLite
    2. Preferences Table
    3. Shared Preferences
    4. Clipboard

    Explanation: SQLite is designed to handle complex relational data with multiple tables and relationships. Shared Preferences is meant for simple key-value storage and cannot manage relations. The Clipboard and Preferences Table are unrelated to local database storage.

  6. Shared Preferences Data Types

    Which data types can typically be stored using Shared Preferences?

    1. Strings, integers, and booleans
    2. Database tables
    3. Class objects
    4. Images and videos

    Explanation: Shared Preferences support simple data types like strings, integers, booleans, floats, and sometimes longs. They are not intended for storing images, videos, full tables, or custom class objects. Attempting to do so will result in data loss or errors.

  7. SQLite Query for Data Retrieval

    Which command retrieves data rows from a table in SQLite?

    1. PUT
    2. SELECT
    3. GET FROM
    4. SHOW TABLE

    Explanation: The SELECT command is used to query and retrieve rows from a SQLite table. GET FROM and SHOW TABLE are not valid SQL commands, and PUT is used for uploading or updating, not retrieving.

  8. Shared Preferences Storage Location

    Where are Shared Preferences typically stored on a device?

    1. On a memory card only
    2. Locally in app-specific storage
    3. In the cloud
    4. On a remote server

    Explanation: Shared Preferences are saved locally in an app-specific area that other apps cannot access. They are not stored on remote servers or in the cloud by default, and not exclusively on a memory card. This enhances security and privacy for stored data.

  9. SQLite Database Size Limits

    What is a typical characteristic of SQLite regarding data storage limits?

    1. It can store large amounts of structured data
    2. It has no storage limit
    3. It only allows up to 10 records
    4. It is limited to 100 MB total

    Explanation: SQLite can handle considerable databases with many records and complex structures, though practical limits depend on device resources. There is no inherent 10-record or 100 MB file limit, and every system has resource constraints, making 'no limit' inaccurate.

  10. Default Behavior for Shared Preferences Data Overwrite

    What happens if you store a value with an existing key in Shared Preferences?

    1. An error occurs
    2. Both values are kept
    3. The previous value is overwritten
    4. A new entry is created each time

    Explanation: When a value is saved with an existing key, Shared Preferences replace the old value with the new one. It does not keep both, create multiple entries, or produce an error; the key-value pair simply gets updated.

  11. SQLite Data Modification

    Which SQL command updates data in an existing SQLite table row?

    1. REFRESH
    2. MODIFY
    3. CHANGE
    4. UPDATE

    Explanation: The UPDATE command modifies existing data in a SQLite table. CHANGE, REFRESH, and MODIFY are not valid SQL commands; attempting to use them would lead to syntax errors.

  12. Transaction Benefits in SQLite

    Why are transactions used when working with SQLite databases?

    1. To send emails automatically
    2. To play videos
    3. To ensure data consistency
    4. To delete the database

    Explanation: Transactions help maintain data consistency by ensuring a group of operations are completed fully or not at all. They do not relate to playing videos, deleting databases, or sending emails. This mechanism is essential for reliable database operations.

  13. Shared Preferences Data Format

    In what format is Shared Preferences data typically stored locally?

    1. Plain text XML
    2. CSV spreadsheet
    3. JPEG image
    4. Encrypted binary

    Explanation: Shared Preferences are usually stored as plain text XML files, making them easy to read but not highly secure. They are not stored as binary, images, or CSV files. This choice is made for compatibility and simplicity.

  14. Deleting Data from SQLite

    Which SQL command is used to remove records from a table in SQLite?

    1. ERASE
    2. REMOVE
    3. DELETE
    4. DROP DATABASE

    Explanation: The DELETE command removes records from a table according to specified criteria. REMOVE and ERASE are not recognized SQL commands, and DROP DATABASE is used for dropping databases, not records.

  15. Shared Preferences and User Login

    What is one common use case for Shared Preferences with user accounts?

    1. Storing temporary images
    2. Saving the user's login status
    3. Processing complex search queries
    4. Managing product catalogs

    Explanation: A common use for Shared Preferences is saving a user's login state or session details between app launches. It's not ideal for images, cataloging products, or handling complex queries, all of which require more advanced storage or processing solutions.

  16. Data Security in Local Storage

    Which statement best describes the security of data stored in SQLite and Shared Preferences by default?

    1. Both are fully encrypted automatically
    2. Stored data can be accessed by the same app unless further protected
    3. They cannot store any user data
    4. Data is publically readable by all apps

    Explanation: By default, both storage methods restrict access to the application itself but do not encrypt the data automatically. Unless extra measures are taken, the data is not publically available to all apps, nor is it fully encrypted. Both methods can indeed store user data.