0% found this document useful (0 votes)
4 views

Android QB

The document covers various concepts in Kotlin and Android development, including data types, null safety, the Android application framework, companion objects, object-oriented programming, and exception handling. It also discusses UI controls, collections, activity lifecycle, menus, layouts, default arguments, for loops, and event handlers. Each topic is explained with definitions, examples, and key features relevant to Kotlin and Android programming.

Uploaded by

casualworkcat
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Android QB

The document covers various concepts in Kotlin and Android development, including data types, null safety, the Android application framework, companion objects, object-oriented programming, and exception handling. It also discusses UI controls, collections, activity lifecycle, menus, layouts, default arguments, for loops, and event handlers. Each topic is explained with definitions, examples, and key features relevant to Kotlin and Android programming.

Uploaded by

casualworkcat
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Q1 .

DataTypes in Kotlin

Q2 . Explain Null Safty


Null safety is a feature in Kotlin that helps developers to avoid the dreaded
NullPointerException (NPE) at runtime, which occurs when you try to access or
call a method on an object that is null.
In Kotlin, null safety is achieved through two types:
• Nullable
• non-null.
1 .Nullable types: In Kotlin, a variable of a nullable type can hold a null value.
Nullable types are declared using the ? operator.
For example, the following code declares a nullable variable of type String:
var str: String? = null
2. Non-null types: In Kotlin, a variable of a non-null type cannot hold a null
value. Non-null types are declared without the ? operator.
For example, the following code declares a non-null variable of type String:
var str: String = "Hello"
To use a nullable variable, you need to first check if it is null or not before
accessing its properties or calling its methods. Kotlin provides a safe call
operator (?.)
Q3 . Andorid Application FrameworK
Android Application Framework is the set of tools and APIs provided by the
Android platform to create and develop Android applications.
The Android Application Framework is designed to help developers create
robust, high-performance applications for mobile devices.
It provides a rich set of features, such as multi-tasking, multi-touch, and support
for various sensors, that make it easy for developers to create compelling
applications
The Android Application Framework provides a number of features that
simplify the development of Android applications:
Activity Manager: It manages the lifecycle of the application and provides an
interface for managing user interaction.
Resource Manager: It provides access to resources, such as strings, images,
and layouts, that are used in an application.
View System: It provides a set of UI elements that developers can use to build
the application's user interface.
Content Providers: They allow applications to share data between each other.
Notification Manager: It provides an interface for displaying notifications to
the user.
Location Manager: It provides access to GPS and other location-based
services.
Package Manager: It manages the installation and uninstallation of
applications.
Q4 . Explain companion object in detail
In Kotlin, a companion object is a special object which is a part of a class
definition.
It can be accessed using the name of the enclosing class.
The companion objects can access private members of the class.
Hence, they can be used to implement the factory method patterns.
Companion objects are routinely presented as an alternative to static , and are
regarded as a very controversial design decision.
class Person {
companion object Test {
fun callMe() = println("I'm called.")
}
}
fun main(args: Array<String>) {
Person.callMe()
}
output
I'm called

Q5 . Explain Concept of OOPS

OOP stands for Object-Oriented Programming.

Object-oriented programming is about creating objects that contain both data


and methods. The object created have two characteristics ie. State and Behavior.

Object-oriented programming has several advantages over procedural


programming:

• OOP is faster and easier to execute


• OOP provides a clear structure for the programs
• OOP helps to keep the Kotlin code DRY "Don't Repeat Yourself", and
makes the code easier to maintain, modify and debug
• OOP makes it possible to create full reusable applications with less code
and shorter development time
Q6 . Steps to create Android Application
steps to create an Android application:
Install Android Studio:
Download and install Android Studio, which is the official integrated
development environment (IDE) for Android app development.
Create a new project:
Open Android Studio and click "Start a new Android Studio project" from the
welcome screen.
Choose the project template you want to use, such as "Empty Activity" or
"Basic Activity", and click "Next".
Configure the project:
Set the project name, package name, and other settings for your new project.
Design the user interface:
Use Android Studio's layout editor to design the user interface for your app.
Write the code:
Use Java or Kotlin to write the code for your app's functionality.
Test the app:
Use Android Studio's emulator or connect a physical Android device to your
computer to test your app.
Debug and optimize the app:
Use Android Studio's debugging tools to find and fix any errors in your code
Publish the app:
Once you're satisfied with your app, you can publish it to the Google Play Store
or other app marketplaces.
You'll need to create a developer account, prepare your app for release.
Q7 . Concept of casting in Kotlin
Casting in Kotlin is the process of converting one data type to another data type.
In Kotlin, there are two types of casting:
• explicit casting
• safe smart casting.
Explicit Casting Operator:
The explicit casting operator is represented by the keyword.
It is used to explicitly cast one data type to another data type.
If the conversion is not possible, a ClassCastException will be thrown at
runtime.

Syntax:
value as datatype
For example:
val a: Any = "Hello"
val b: String = a as String

Safe Casting Operator:


The safe casting operator is represented by the keyword as?.
It is used to safely cast one data type to another data type.
If the conversion is not possible, it returns null instead of throwing a
ClassCastException.

Syntax:
value as? Datatype
For example:
val a: Any = "Hello"
val b: String? = a as? String
Q8 Explain concept of Exception Handling
Exception handling is an important aspect of any programming language, and
Kotlin provides robust support for handling exceptions.
Exception handling in Kotlin is similar to Java, and it follows the try-catch-
finally block syntax.
In Kotlin, you can throw an exception using the throw keyword, and you can
catch an exception using the try-catch block.
The finally block is optional and is used to specify code that should be executed
regardless of whether an exception was thrown or not.
Exception handling is a very important part of a programming language. This
technique restricts our application from generating the wrong output at runtime.

Q9 . Difference between Val and Var with Example

Attribute var val

Declaration var varName="hello val sName =


World" "tutorialspoint.com"

Immutability Mutable Immutable

No. of times a variable Can be assigned Cannot be assigned


can be assigned multiple times. multiple times.

Reassigned Can be reassigned Cannot be reassigned


Example:
val valName = "a";
var varName = "g"

fun main() {
println("Example of val ="+valName);
println("Example of Var ="+varName);

varName = "new value";


println("New value of the var" +varName);
}
Q10 . List Android UI contols

Android UI Controls

There are number of UI controls provided by Android that allow you to build the
graphical user interface for your app.

UI Control & Description

TextView This control is used to display text to the user.

EditText EditText is a predefined subclass of TextView that includes rich editing capabilities.

AutoCompleteTextView t shows a list of completion suggestions automatically while the user


is typing.

Button A push-button that can be pressed, or clicked, by the user to perform an action.

CheckBox An on/off switch that can be toggled by the user. You should use check box when
presenting users with a group of selectable options that are not mutually exclusive.

ToggleButton An on/off button with a light indicator.

RadioButton The RadioButton has two states: either checked or unchecked.

RadioGroup A RadioGroup is used to group together one or more RadioButtons.

ProgressBar The ProgressBar view provides visual feedback about some ongoing tasks

Spinner A drop-down list that allows users to select one value from a set.

TimePicker The TimePicker view enables users to select a time of the day.

DatePicker The DatePicker view enables users to select a date of the day.
Q 11.)Immutable Collection Mutable Collection
collections are used to store and manipulate groups of objects or data.
Types of Collections
In Kotlin collections are categorized into two forms.
1. Immutable Collection
2. Mutable Collection
1. Immutable Collection
It means that it supports only read-only functionalities and can not be modified
its elements. Immutable Collections and their corresponding methods are:
List – listOf() - by using indicies we can access element.
Fun main(args:Array<String>){
val immutable=listof(“kotlin”)
print(immutable)
}
Output: kotlin
Set – setOf() It does not supports duplicate elements and is collection of
unordered elements means it is a collection of unique elements
fun main(args:Array<String>){
val immutable=setof(“kotlin”,44)
print(immutable)
}
Output: kotlin 4 4
Map – mapOf() :these are unique and holds only one value for unique key.each
key maps to exactly one value
fun main(args:Array<String>){
val immutable=listof(1 to “kotlin”)
print(immutable) }
Output: {1=kotlin}
2. Mutable Collection
It supports both read and write functionalities. Mutable collections and their
corresponding methods are:
List – mutableListOf(): Decleared elements in the kist can either be added or
removed
fun main(args:Array<String>){
val mutableList=mutableListof(“kotlin”)
mutableList.add(“web”)
print(mutableList)
}
Output: kotlin web
Set – mutableSetOf() - It will preserve the order of elements
fun main(args:Array<String>){
val mutableset=mutableSetof(“kotlin”)
mutableset.add(“web”)
print(mutableset)
}
Output: kotlin web
Map – mutableMapOf() - it supports functionalities like put ,remove ,clear, etc
fun main(args:Array<String>){
val mutableMap=mutableMapof(1 to “kotlin”)
mutableMap.add(2 to “web”)
print(mutableMap)
}
12 . Activity Life Cycle

13 .what is menu in android and expalin its types


In Android, a menu is a UI component that displays a list of options or actions
that the user can choose from. There are three types of menus in Android:
Options Menu: The options menu is a standard menu that appears when the
user presses the menu button on their device or taps the menu icon in the action
bar
Context Menu: A context menu is a floating menu that appears when the user
performs a long press on a view, such as an image or a piece of text.
Popup Menu: A popup menu is a modal menu that appears when the user
performs a click on a view. It is similar to a context menu, but it does not
require a long press.
14 . What is Layout in android and explain its types
In Android, a layout is used to define the visual structure for a user interface. It
is used to arrange user interface components such as buttons, text fields, images,
etc. There are several types of layouts available in Android, each with its own
characteristics and use cases:
LinearLayout: This layout arranges child views in a single direction, either
vertically or horizontally.
RelativeLayout: This layout positions child views relative to each other or to
the parent view.
FrameLayout: This layout displays a single view at a time and is typically used
for displaying fragments.
ConstraintLayout: This layout provides a flexible way to arrange child views
using constraints to specify their position relative to other views.
TableLayout: This layout arranges child views in a table structure with rows
and columns.
GridLayout: This layout arranges child views in a grid structure with rows and
columns.
CoordinatorLayout: This layout is designed to handle interactions between
child views, such as scrolling or dragging.
15 . concept of default argument and example
In Kotlin, default arguments allow us to provide default values for function
parameters.
This means that if the caller of a function does not specify an argument value
for a parameter with a default value, the default value will be used instead.
fun greet(name: String = "Guest") {
println("Hello, $name!")
}
In the above example, the greet function takes a name parameter with a default
value of "Guest".
If no argument is provided when calling this function, the default value of
"Guest" will be used.
16 .For Loop with example
In Kotlin, the for loop is used to iterate over a range of values or a collection of
elements.
“For" Loop is used to repeat a specific block of code a known number of times.
If the body of for loop contains only one single line of statement, it is not
necessary to enclose within curly braces {}.
fun main(args : Array<String>) {
val marks = arrayOf (80,85,60,90,70)
for(item in marks){
println(item) }}
Output:
80 85 60 90 70

17. Kotlin Coroutines

18. List method involved in android adapter


19 . Different state of Process

20 . Explain Event Handler in detail


An event handler is a piece of code that is executed when an event occurs in an
application.
In Android, events can be generated by user interactions, such as clicking a
button or touching the screen, or by other internal or external factors, such as
changes in system settings or receiving a push notification.
The event handler is responsible for handling the event by performing a specific
action or set of actions, which can include updating the UI, processing data, or
triggering other events.
In Android, event handlers are typically implemented using listeners, which are
interfaces that define callback methods to be invoked when the event occurs.

You might also like