JAVA
JAVA
Features of JAVA
1. Give the key features of the Java programming language. Additionally, elaborate on how
these features contribute to the popularity and versatility of Java as a programming
language.
𝐉𝐚𝐯𝐚 𝐢𝐬 𝐚𝐧 𝐎𝐛𝐣𝐞𝐜𝐭 𝐎𝐫𝐢𝐞𝐧𝐭𝐞𝐝 𝐏𝐫𝐨𝐠𝐫𝐚𝐦𝐦𝐢𝐧𝐠, 𝐎𝐎𝐏: Java programs are written
using classes and objects. It supports every OOP concepts namely
Inheritance, Encapsulation, Polymorphism and Abstraction.
𝐉𝐚𝐯𝐚 𝐢𝐬 𝐢𝐧𝐭𝐞𝐫𝐩𝐫𝐞𝐭𝐞𝐝: Unlike many other programming languages Java source
code is compiled using Java Compiler. The compiler converts the source code
into an intermediate code called the byte code. The JVM is an interpreter,
further converts this code into the machine-dependent form.
𝐉𝐚𝐯𝐚 𝐢𝐬 𝐚 𝐩𝐥𝐚𝐭𝐟𝐨𝐫𝐦 𝐢𝐧𝐝𝐞𝐩𝐞𝐧𝐝𝐞𝐧𝐭 (𝐏𝐨𝐫𝐭𝐚𝐛𝐥𝐞): The JVM can execute byte code on
any platform or operating system on which it is present.
Therefore, Java supports WORA (Write Once, Run Anywhere), meaning
programmers can develop applications in one operating system and run on
any other without any modification.
𝐌𝐮𝐥𝐭𝐢𝐭𝐡𝐫𝐞𝐚𝐝𝐞𝐝: In java we can write programs that can perform many tasks
simultaneously. This design feature allows the developers to construct
interactive applications that can run smoothly.
𝐉𝐚𝐯𝐚 𝐢𝐬 𝐑𝐨𝐛𝐮𝐬𝐭: Java can handle run-time errors by checking the code during
the compilation and runtime. The JVM will not be passed directly to the
underlying system if it identifies any runtime error. Instead, it will
immediately terminate the program and stop it from causing any harm to the
system.
𝐉𝐚𝐯𝐚 𝐢𝐬 𝐒𝐞𝐜𝐮𝐫𝐞: Java ensures that programs cannot gain access to memory
locations without authorization. It has access modifiers to check memory
access. Java also ensures that no viruses enter an applet.
𝐉𝐚𝐯𝐚 𝐢𝐬 𝐒𝐢𝐦𝐩𝐥𝐞: Java syntax is very straight forward and very easy to learn.
Java removes complex features like pointers and multiple inheritance, which
makes it more beginner friendly.
1
3. Explain the importance of Main method in Java and write skeleton code to show its
structure.
The 𝐦𝐚𝐢𝐧 𝐦𝐞𝐭𝐡𝐨𝐝 is an entry point containing code to execute or call other
methods. When a Java program is run, the Java Virtual Machine (JVM) looks
for the main method to begin execution. If the main method is not present or
is not defined correctly, the program will not run.
𝐏𝐮𝐛𝐥𝐢𝐜 𝐬𝐭𝐚𝐭𝐢𝐜 𝐯𝐨𝐢𝐝 𝐦𝐚𝐢𝐧(𝐒𝐭𝐫𝐢𝐧𝐠[ ] 𝐚𝐫𝐠𝐬)
{
// codes to be executed;
}
The parameter args, represents the information provided to the program when
the main( ) method is called by the system.
2
𝐀𝐩𝐩𝐥𝐢𝐜𝐚𝐭𝐢𝐨𝐧 𝐟𝐫𝐚𝐦𝐞𝐰𝐨𝐫𝐤: provides service to the Android operating system, OS
through which we can create the Android application using Java classes.
It also provides an Android Hardware Abstraction Layer (HAL), which allows
the Android application to communicate with hardware drivers of a specific
device.
Some of high-level services that can be beneficial for developing the android
applications
• 𝐶𝑜𝑛𝑡𝑒𝑛𝑡 𝑃𝑟𝑜𝑣𝑖𝑑𝑒𝑟𝑠 – provide the sharing of data in the form of file,
network or database from one application to the requesting application.
Example to share the mobile number from contact book to WhatsApp.
• 𝑁𝑜𝑡𝑖𝑓𝑖𝑐𝑎𝑡𝑖𝑜𝑛𝑠 𝑀𝑎𝑛𝑎𝑔𝑒𝑟 − allows applications to display alerts and
notifications to the user. Example: New message, Tap to read.
• 𝑉𝑖𝑒𝑤 𝑆𝑦𝑠𝑡𝑒𝑚 − displaying data to the user. It handles the application
data on the screen, ensuring that the UI accurately reflects the current
state of the application. You can customize the appearance of the text
by changing its color, size, font, and alignment.
• 𝐴𝑐𝑡𝑖𝑣𝑖𝑡𝑦 𝑀𝑎𝑛𝑎𝑔𝑒𝑟 – manage the application tasks and activity lifecycle
by arranging the creation, execution, and destruction of activities to
ensuring that services are started and stopped as needed and efficient
resource utilization.
• 𝑅𝑒𝑠𝑜𝑢𝑟𝑐𝑒 𝑀𝑎𝑛𝑎𝑔𝑒𝑟 − provides access to non-code resources such as
strings, graphics and layouts files.
𝐀𝐩𝐩𝐥𝐢𝐜𝐚𝐭𝐢𝐨𝐧: is the top layer of the Android architecture contained both native
Android apps including messages, contacts, settings, clock, calculator and
installed apps including Games, WhatsApp and Instagram.
The Program Development Life Cycle, PDLC is a process that allows the
adjustments to be made at each phase of java software development, to ensure
that the final product meets the needs of the stakeholders and is of high
quality.
𝐏𝐡𝐚𝐬𝐞𝐬 𝐨𝐟 𝐏𝐃𝐋𝐂
1) 𝐏𝐥𝐚𝐧𝐧𝐢𝐧𝐠: In this phase, the goals and objectives and the budget of the
program are defined, and a plan is developed to achieve them.
2) 𝐀𝐧𝐚𝐥𝐲𝐬𝐢𝐬: In this phase, the needs, requirements and expectations for the
program are defined.
3
3) 𝐃𝐞𝐬𝐢𝐠𝐧: software designers to come up with the best architecture that
decides on how software application behaves.
4) 𝐈𝐦𝐩𝐥𝐞𝐦𝐞𝐧𝐭𝐚𝐭𝐢𝐨𝐧: the team writes the actual code with the use of a specific
programming language and use a server to share, this helps to ensure that
the code implemented by one developer doesn't cause conflicts with code
written by others.
5) 𝐓𝐞𝐬𝐭𝐢𝐧𝐠: assess how well an application meets the goal in areas such as
usability, performance and security. If an application doesn't pass all tests,
teams may need to fix the issue and then run the tests again.
6) 𝐃𝐞𝐩𝐥𝐨𝐲𝐦𝐞𝐧𝐭: the program is deployed and made available to users through
channels, such as an app store or play store, where they can search for and
download it.
7) 𝐌𝐚𝐢𝐧𝐭𝐞𝐧𝐚𝐧𝐜𝐞: monitor the application to identify errors and issues that
may arise once it is in production and updating the program to meet the
changing requirements.
𝐒𝐭𝐞𝐩 𝟏: // Start by initializing variables and prompt the user to enter the
marks for each subject.
Input M1,M2,M3,M4
𝐒𝐭𝐞𝐩 𝟐: // Calculate average mark
GRADE ¬ (M1+M2+M3+M4)/4
𝐒𝐭𝐞𝐩 𝟑: // Determine the nature of the
final grade
if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
Endif
4
8. Explain the differences between machine language, assembly language, and high-level
language in terms of their characteristics, level of abstraction, and their relationship to
the hardware and software components of a computer system.
Example:
please wait !
5
10. Explain RecyclerView with respect to android.
11. As security is important for android devices, what are the best practices to implement
security in an android app?
6
12. *Explain life cycle of Activity in android.
13. State the purpose of Main Activity file and XML file.
𝐌𝐚𝐢𝐧 𝐀𝐜𝐭𝐢𝐯𝐢𝐭𝐲 𝐟𝐢𝐥𝐞 contains MainActivity.java file, serving as the entry point
and primary screen for the user's interaction with the app in order to handle
all the activities related to the app.
𝐗𝐌𝐋 𝐟𝐢𝐥𝐞 stores data in a way that can be easily read by and shared between
software applications like websites and database.
7
14. Explain the purpose of the following directories in android : color/, drawable/, layout/,
raw/, menu/.
color/ : stores XML files that define the list of color values for your
app.
drawable/ : stores graphics that can be drawn to the screen, including XML
files, Bitmap images (𝑃𝑁𝐺, 𝐽𝑃𝐺, or 𝐺𝐼𝐹) and WebP images i.e. Logo
and Background.
layout/ : is the container for storing XML files that define the UI
components like activity views of your app screen.
Examples: Layout for the main activity, 𝑎𝑐𝑡𝑖𝑣𝑖𝑡𝑦_𝑚𝑎𝑖𝑛. 𝑥𝑚𝑙: and
Layout for list items, 𝑖𝑡𝑒𝑚_𝑙𝑖𝑠𝑡. 𝑥𝑚𝑙:.
raw/ : stores an arbitrary files like audio, video, or data that need to be
accessed in their raw format.
menu/ : stores XML files that define app menus, such as an options menu,
context menu, or submenu.
𝐆𝐫𝐚𝐝𝐥𝐞 is a build tool that we use for Android development to automate the
process of building and publishing apps.
Every time you click the Run button in Android Studio, Gradle compile the
java files into 𝑑𝑒𝑥 𝑓𝑖𝑙𝑒𝑠 and compresses all of them into a single file known as
𝑎𝑝𝑘 𝑓𝑖𝑙𝑒 which is the standard file format used to install apps on Android.
𝐋𝐚𝐲𝐨𝐮𝐭 is the container storing XML files that define the UI components like
activity views of your app screen.
Examples: Layout for the main activity, 𝑎𝑐𝑡𝑖𝑣𝑖𝑡𝑦_𝑚𝑎𝑖𝑛. 𝑥𝑚𝑙: and Layout for list
items, 𝑖𝑡𝑒𝑚_𝑙𝑖𝑠𝑡. 𝑥𝑚𝑙:.
𝐈𝐧𝐭𝐞𝐧𝐭 is messaging object used to request an action from another app
component. Example displaying contact list, display webpage or download a
file.
𝐕𝐢𝐞𝐰 is the UI component that a user can see and interact, example menu,
button and text views of your app screen.
8
𝐂𝐨𝐧𝐭𝐞𝐧𝐭 𝐏𝐫𝐨𝐯𝐢𝐝𝐞𝐫 provide the sharing of data in the form of file, network or
database from one application to the requesting application. Example to share
the mobile number from contact book to WhatsApp.
𝐀𝐜𝐭𝐢𝐯𝐢𝐭𝐲 𝐌𝐚𝐧𝐚𝐠𝐞𝐫 manage the application tasks and activity lifecycle by
arranging the creation, execution, and destruction of activities to ensuring
that services are started and stopped as needed and efficient resource
utilization.
𝐍𝐨𝐭𝐢𝐟𝐢𝐜𝐚𝐭𝐢𝐨𝐧𝐬 𝐌𝐚𝐧𝐚𝐠𝐞𝐫 allows applications to display alerts and notifications to
the user. Example, New message, Tap to read.
𝐂𝐥𝐢𝐜𝐤𝐚𝐛𝐥𝐞 𝐭𝐞𝐱𝐭 is a text that can be clicked, with either the mouse or via a
keyboard command, to produce some result.
Example, a hyperlink is a clickable section of text that takes the user to a
linked website page.: https://www.youtube.com
𝐅𝐨𝐜𝐮𝐬 𝐭𝐞𝐱𝐭 is a text used to determine which element the user is currently
trying to interact with.
For example, when a user types on the keyboard, the input that’s currently
‘in focus’ is where the text will display. The cursor indicate the position for
each character entered.
17. With code snippets, Explain the difference between Implicit and Explicit Intent
Now,when you execute this code the browser app will respond to this intent.
If there are more than one app which can respond to our intent, the Android
system will ask to choose one of them.
9
𝐄𝐱𝐩𝐥𝐢𝐜𝐢𝐭 𝐈𝐧𝐭𝐞𝐧𝐭: enable communication between two activities inside the same
app. In this type of intent, the user knows the target class/activity which
should be responded for our intent.
Example, clicking a button to navigate within your own app
Let us assume that we have two activities and we want to go to second
activity from first. We can write it as:
𝑐𝑜𝑑𝑒 𝑠𝑛𝑖𝑝𝑝𝑒𝑡𝑠
Intent i = new Intent(firstActivity.this, secondActivity2.class);
startActivity(i);
Hint:
An Activity is an application component that provides a screen with which users
can interact in order to do something, such as dial a number, send text or login.
Services that can only be accessed through Context include 𝑳𝒐𝒄𝒂𝒕𝒊𝒐𝒏𝑴𝒂𝒏𝒂𝒈𝒆𝒓
for location information, 𝑵𝒐𝒕𝒊𝒇𝒊𝒄𝒂𝒕𝒊𝒐𝒏𝑴𝒂𝒏𝒂𝒈𝒆𝒓 for sending notifications, and
𝑪𝒐𝒏𝒏𝒆𝒄𝒕𝒊𝒗𝒊𝒕𝒚𝑴𝒂𝒏𝒂𝒈𝒆𝒓 for checking the internet connection.
19. Give the differences between Activity context and Application context.
𝐀𝐜𝐭𝐢𝐯𝐢𝐭𝐲 𝐜𝐨𝐧𝐭𝐞𝐱𝐭: created when the activity starts and remains valid until the
activity closes.
Used for UI-related tasks like start an activity, start a dialog, inflating the
layout and showing Toast messages.
The method of invoking the Activity Context is 𝑔𝑒𝑡𝐶𝑜𝑛𝑡𝑒𝑥𝑡( ).
Hint: A dialog is usually a small window that appears in front of the current
Activity. The underlying Activity loses focus and the dialog accepts all user
interaction. Dialogs are normally used for notifications.
𝐀𝐩𝐩𝐥𝐢𝐜𝐚𝐭𝐢𝐨𝐧 𝐜𝐨𝐧𝐭𝐞𝐱𝐭: created when the application starts and remains valid
until the application closes.
Used for non UI-related tasks like start a service and access the resources
value.
The method of invoking the Activity Context is 𝑔𝑒𝑡𝐴𝑝𝑝𝑙𝑖𝑐𝑎𝑡𝑖𝑜𝑛𝐶𝑜𝑛𝑡𝑒𝑥𝑡( ).
10
20. What is a Toast? Write its syntax.
21. Mention the difference between class, file and activity in Android
Is an entry file that contains the essential Android app informations such as
Package name, Application components, Permissions Linked Libraries and
Minimum API that the Android system must know before it can run any code
of the android mobile app.
Application Programming Interface, 𝑨𝑷𝑰𝑠 are sets of rules and protocols that
allow different software applications to interact with each other. It defines the
requests and responses that are used to exchange data.
Android 𝒍𝒊𝒃𝒓𝒂𝒓𝒊𝒆𝒔 are reusable blocks of code that developers can use to add
functionality to their applications without having to write it from scratch.
11
24. *Explain life cycle of Service in android.
12
25. Briefly explain the components of Android application.
26. What is the importance of having an emulator within the Android environment?
13
29. What is the importance of XML-based layouts?
𝐗𝐌𝐋 − 𝐛𝐚𝐬𝐞𝐝 𝐋𝐚𝐲𝐨𝐮𝐭 is the container storing XML files that define the structure
for UI components like activity views of your app screen.
14
34. What are the different states wherein a process is based?
𝐘𝐞𝐬, 𝐢𝐭 𝐢𝐬 𝐩𝐨𝐬𝐬𝐢𝐛𝐥𝐞.
To use fragments without a UI (a “headless fragment”), they do not inflate any
XML resource or create and return a View. To implement such a fragment,
return null in the onCreateView( ) method of your fragment.
Headless fragments are often used for background processing.
15
37. What are the core components under the Android application architecture?
Qn. 25
38. Do all mobile phones support the latest Android operating system?
𝐍𝐨, not all mobile phones can be upgraded to the latest Android operating
system. This is because software updates may not be compatible for older
versions of OS, this can prevent older devices from running the latest version.
TextView is the user interface that helps to display some text messages on the
application screen.
Attributes associates with TextView
𝐓𝐞𝐱𝐭 : Specifies the text to display in the TextView.
𝐭𝐞𝐱𝐭𝐂𝐨𝐥𝐨𝐫 : Sets the color of the text.
𝐭𝐞𝐱𝐭𝐒𝐢𝐳𝐞 : Determines the size of the text.
𝐭𝐞𝐱𝐭𝐒𝐭𝐲𝐥𝐞 : Allows to apply styles like bold, italic, or bolditalic.
42. What are Broadcast Intents? Explain system broadcast intents and custom broadcast
intents.
16
43. What is the job of scheduler? Explain its components.
The Job Scheduler is a system-level API introduced in Android 5.0 that allows
you to define tasks that need to be executed in the background to ensure that
your app runs efficiently and does not drain the battery unnecessarily.
Components of Job Scheduler.
𝐉𝐨𝐛𝐒𝐜𝐡𝐞𝐝𝐮𝐥𝐞𝐫𝐒𝐞𝐫𝐯𝐢𝐜𝐞: is the core system service that manages and executes
the jobs defined by your application.
𝐉𝐨𝐛𝐈𝐧𝐟𝐨: specifies the conditions under which a job should run.
𝐉𝐨𝐛𝐒𝐞𝐫𝐯𝐢𝐜𝐞: that extend the JobService class and implement the necessary
methods, like onStartJob( ) and onStopJob( ).
𝐈𝐧𝐭𝐞𝐫𝐧𝐚𝐥 𝐬𝐭𝐨𝐫𝐚𝐠𝐞 refers to the memory built into a device, like a phone or
computer, for storing the operating system, apps, and user data.
𝐄𝐱𝐭𝐞𝐫𝐧𝐚𝐥 𝐬𝐭𝐨𝐫𝐚𝐠𝐞 refers to removable storage devices, like SD cards or USB
drives, that can be plugged into the device.
45. What is SQLite? Explain the steps for implementing SQLite database.
17
46. Judge with suitable reasoning why is it important to process some tasks in the
background or off the UI thread.
47. Justify the need of for AndroidManifest.xml and write the basic structure for the same.
Is an entry file that contains the essential Android app informations such as
Package name, Application components, Permissions Linked Libraries and
Minimum API that the Android system must know before it can run any code
of the android mobile app.
Application Programming Interface, 𝑨𝑷𝑰𝑠 are sets of rules and protocols that
allow different software applications to interact with each other. It defines the
requests and responses that are used to exchange data.
Android 𝒍𝒊𝒃𝒓𝒂𝒓𝒊𝒆𝒔 are reusable blocks of code that developers can use to add
functionality to their applications without having to write it from scratch.
18
48. Discuss views in android and list the predefined views in android.
𝐕𝐢𝐞𝐰 is the UI component that a user can see and interact, example menu,
button and text views of your app screen.
View objects are often called 𝑤𝑖𝑑𝑔𝑒𝑡𝑠 and can be one of many subclasses, such
as Button or TextView. The ViewGroup objects are usually called layouts and
can be one of many types that provide a different layout structure, such as
LinearLayout or ConstraintLayout.
The Android system provides many different kinds of views.
𝐁𝐮𝐭𝐭𝐨𝐧: user interface consists of an icon and text, used to perform some
action when clicked
𝐓𝐞𝐱𝐭𝐕𝐢𝐞𝐰: user interface used to display text to the user.
𝐈𝐦𝐚𝐠𝐞𝐕𝐢𝐞𝐰: user interface used to display image to the user.
𝐄𝐝𝐢𝐭𝐓𝐞𝐱𝐭: user interface allows users to input and edit text.
𝑹𝒆𝒔𝒐𝒖𝒓𝒄𝒆 𝒇𝒊𝒍𝒆 is an .xml file format used for storing Android app localized data
(non-code) such as layouts, images, launcher icon, colours and strings.
50. Write Xml program to create activity with Linear Layout and vertical orientation
with the following views/UI elements in it.
i. Two Text views: One to display login username and other to display password.
ii. Two Edit Text: One to accept login username and other to accept password.
iii. Two Buttons: one for login in with OnClick attribute and other to cancel.
<?xmlversion="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:padding="120dp"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/baseline_account_circle_24"/>
19
i. Two Text views: One to display login username and other to display password.
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:hint="Username"
android:layout_marginTop="10dp"
android:textColorHint="@color/black"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:hint="Password"
android:layout_marginTop="30dp"
android:textColorHint="@color/black"/>
ii. Two Edit Text: One to accept login username and other to accept password.
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Enter Username"
android:textColorHint="@color/black"
android:textsize="10dp"
android:padding="10dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Enter Password"
android:textColorHint="@color/black"
android:textsize="20dp"
android:padding="10dp"/>
iii Two Buttons: one for login in with OnClick attribute and other to cancel.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="login"
android:padding="5dp"
android:textColor="@color/white"
android:textSize="20sp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="cancel"
android:padding="5dp"
android:layout_marginTop="10dp"
android:textColor="@color/white"
android:textSize="20sp"/>
20
51. Define intent. Discuss types of intents and explain in detail how to pass data between
activities with intent.
𝐈𝐧𝐭𝐞𝐧𝐭 is messaging object used to request an action from another app
component. Exam displaying contact list, display webpage or download a file.
𝐈𝐦𝐩𝐥𝐢𝐜𝐢𝐭 𝐈𝐧𝐭𝐞𝐧𝐭: enable communication between two activities from different
app.
In implicit intents we do not declare any target class that should be responded
to our intent. We just declare the intent and set the type of action for it and
leave it to the Android platform to identify the app that can respond to our
intent.
𝑐𝑜𝑑𝑒 𝑠𝑛𝑖𝑝𝑝𝑒𝑡𝑠
Intent i=new Intent(Intent.ACTION_VIEW,Uri.parse(“http://www.facebook.com”);
startActivity(i);
Now,when you execute this code the browser app will respond to this intent.
If there are more than one app which can respond to our intent, the Android
system will ask to choose one of them.
𝐄𝐱𝐩𝐥𝐢𝐜𝐢𝐭 𝐈𝐧𝐭𝐞𝐧𝐭: enable communication between two activities inside the same
app. In this type of intent, the user knows the target class/activity which
should be responded for our intent.
Example, clicking a button to navigate within your own app
Let us assume that we have two activities and we want to go to second
activity from first. We can write it as:
𝑐𝑜𝑑𝑒 𝑠𝑛𝑖𝑝𝑝𝑒𝑡𝑠
Intent i = new Intent(firstActivity.this, secondActivity2.class);
startActivity(i);
21
For passing values from one Activity to another activity you can use Intent’s
Extras method.
That data can be in the form of String, Integer. So syntax to pass data along
with your intent object is:
Intent i = new Intent(firstActivity.this, secondActivity2.class);
i.putExtra("name", the name is entered)
startActivity(i);
52. With neat diagram, explain the activity life cycle and life cycle callback methods.
22
53. Demonstrate with an example program how to start an activity for getting results
using intents.
public class MainActivity extends AppCompatActivity
{
private static final int REQUEST_CODE = 1;
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
// where first parameter of Intent constructor is the current Activity and second
parameter is the New Activity which you want to open.
startActivityForResult(intent, REQUEST_CODE);
};
public class SecondActivity extends AppCompatActivity
{
Intent resultIntent = new Intent( );
/Now when you want to send data while switching from one Activity to another,
you can use Extras method of Intent. That data can be in form of String, Integer
resultIntent.putExtra("name", name); // attach data to the intent
setResult (RESULT_OK, resultIntent);
finish( ); // End this activity and return to MainActivity
};
54. What is an Intent object? What information Intent object consists? Explain different
types of intents along with their usage.
55. What are View and View Group classes in android? Why layouts are created using
xml file.
𝐕𝐢𝐞𝐰 is the UI component that a user can see and interact, example menu,
button, image view and text views of your app screen.
𝐕𝐢𝐞𝐰𝐆𝐫𝐨𝐮𝐩𝐬 is a subclass of View that acts as a container to hold and manage
other View objects, which can be basic UI elements like TextView and Button.
The ViewGroup objects are usually called layouts and can be one of many
types that provide a different layout structure, such as LinearLayout,
RelativeLayout or ConstraintLayout.
𝐗𝐌𝐋 allows developers to separate UI design from the app's logic code
(Java/Kotlin). This separation improves code organization so that designers
and developers can preview the UI without running the app.
23
56. When relative layout is used? Explain any six attributes of Relative Layout.
Relative Layout is used to arrange the position of child view in relation to each
other or to the parent view with the use of “above, below, left and right”
position.
𝑎𝑛𝑑𝑟𝑜𝑖𝑑: 𝑙𝑎𝑦𝑜𝑢𝑡_𝑎𝑏𝑜𝑣𝑒
𝑎𝑛𝑑𝑟𝑜𝑖𝑑: 𝑙𝑎𝑦𝑜𝑢𝑡_𝑏𝑒𝑙𝑜𝑤
𝑎𝑛𝑑𝑟𝑜𝑖𝑑: 𝑙𝑎𝑦𝑜𝑢𝑡_𝑡𝑜𝐿𝑒𝑓𝑡𝑂𝑓
𝑎𝑛𝑑𝑟𝑜𝑖𝑑: 𝑙𝑎𝑦𝑜𝑢𝑡_𝑡𝑜𝑅𝑖𝑔ℎ𝑡𝑂𝑓
𝑎𝑛𝑑𝑟𝑜𝑖𝑑: 𝑙𝑎𝑦𝑜𝑢𝑡_𝑎𝑙𝑖𝑔𝑛𝑃𝑎𝑟𝑒𝑛𝑡𝑇𝑜𝑝
𝑎𝑛𝑑𝑟𝑜𝑖𝑑: 𝑙𝑎𝑦𝑜𝑢𝑡_𝑐𝑒𝑛𝑡𝑒𝑟𝐼𝑛𝑃𝑎𝑟𝑒𝑛𝑡
57. List various data storage options. What is SQLite database? Write in brief and
explain code to create a database of your choice in SQLite .
SQLite is a lightweight and serverless database engine used for local data
storage in Android applications.
public void onCreate (SQLiteDatabase db)
{
//This method is called only when you create a database for the first time.
}
58. List different notifications techniques used for notifying the user. Explain any one
techniques using example.
24
59. What is the role of DVM in android? Explain. Also, explain in brief what you mean
by an emulator.
𝐷𝑎𝑙𝑣𝑖𝑘 𝑉𝑖𝑟𝑡𝑢𝑎𝑙 𝑀𝑎𝑐ℎ𝑖𝑛𝑒, DVM translates bytecode (compiled code) into the
executable machine code that the android processor can understand.
60. List out different types of layouts in android. Explain any two layouts.
Android offers several layout types for arranging UI elements. The common:
𝑳𝒊𝒏𝒆𝒂𝒓𝑳𝒂𝒚𝒐𝒖𝒕: arranges its child views in a single direction, either horizontally
or vertically.
𝑹𝒆𝒍𝒂𝒕𝒊𝒗𝒆𝑳𝒂𝒚𝒐𝒖𝒕: allows to position child views relative to each other or to the
parent layout.
𝑪𝒐𝒏𝒔𝒕𝒓𝒂𝒊𝒏𝒕𝑳𝒂𝒚𝒐𝒖𝒕, create flexible and complex layouts with flat structure
reducing nesting.
𝑭𝒓𝒂𝒎𝒆𝑳𝒂𝒚𝒐𝒖𝒕, to specify the position of multiple view on top of each other to
represent a single view screen.
𝑻𝒂𝒃𝒍𝒆𝑳𝒂𝒚𝒐𝒖𝒕, arrange the child view content into rows and columns.
<TextView
android:id="@+id/textView" <Button
android:layout_width="wrap_content" android:id="@+id/button"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="Enter text below" android:layout_height="wrap_content"
android:textSize="18sp" android:text="Display Text"/>
android:layout_marginBottom="16dp"/>
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Type something..."
android:layout_marginBottom="16dp"/>
25