0% found this document useful (0 votes)
32 views25 pages

JAVA

The document outlines key features of Java, including its object-oriented nature, platform independence, robustness, and security, which contribute to its popularity. It also discusses the systematic approach to Java program development, emphasizing the phases of planning, analysis, design, implementation, testing, deployment, and maintenance. Additionally, it covers the importance of the main method in Java, the architecture of Android, and best practices for security in Android applications.

Uploaded by

DENNIS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views25 pages

JAVA

The document outlines key features of Java, including its object-oriented nature, platform independence, robustness, and security, which contribute to its popularity. It also discusses the systematic approach to Java program development, emphasizing the phases of planning, analysis, design, implementation, testing, deployment, and maintenance. Additionally, it covers the importance of the main method in Java, the architecture of Android, and best practices for security in Android applications.

Uploaded by

DENNIS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

𝐉𝐀𝐕𝐀

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.

2. How do you convert String to numbers in Java? Give an example.


𝐔𝐬𝐞 𝐈𝐧𝐭𝐞𝐠𝐞𝐫. 𝐩𝐚𝐫𝐬𝐞𝐈𝐧𝐭( )
or
𝐔𝐬𝐞 𝐈𝐧𝐭𝐞𝐠𝐞𝐫. 𝐯𝐚𝐥𝐮𝐞𝐎𝐟( )

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.

4. Explain Architecture of Android with neat diagram.

𝐋𝐢𝐧𝐮𝐱 𝐊𝐞𝐫𝐧𝐞𝐥 : is the foundation and heart of Android architecture that


provides a level of abstraction between device hardware and other
components of Android architecture, allowing different hardware components
to be used without needing to rewrite software. It manages all the drivers
needed during the runtime of an Android device. Such drivers are USB driver,
Bluetooth driver, camera driver, memory driver.
𝐋𝐢𝐛𝐫𝐚𝐫𝐢𝐞𝐬 : is the collection of prewritten code that programmers can use and
optimize tasks. These native libraries including C/C + + core libraries that
facilitate the creation of Android applications, SQLite database for storing and
sharing data, and Secure Socket Layer, SSL libraries for Internet security.
𝐀𝐧𝐝𝐫𝐨𝐢𝐝 𝐑𝐮𝐧𝐭𝐢𝐦𝐞 : It contains key components namely 𝑐𝑜𝑟𝑒 𝑙𝑖𝑏𝑟𝑎𝑟𝑖𝑒𝑠 and
𝐷𝑎𝑙𝑣𝑖𝑘 𝑉𝑖𝑟𝑡𝑢𝑎𝑙 𝑀𝑎𝑐ℎ𝑖𝑛𝑒, DVM that translates bytecode (compiled code) into the
executable machine code that the android processor can understand. The
Android runtime, along with the libraries, powers our applications.

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.

5. Provide a detailed explanation of the systematic approach to developing a Java program,


and discuss the significance of each step in the overall software development life cycle.

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.

6. Certainly! Here's a combined question for you:


𝐎𝐤𝐚𝐲.

7. Provide a comprehensive explanation of how to determine a student's final grade


using an algorithm written in pseudocode. The algorithm should calculate the average of
four marks and indicate whether the grade is passing or failing. Additionally, convert the
pseudocode algorithm into a flowchart representation.

𝐒𝐭𝐞𝐩 𝟏: // 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.

𝐌𝐚𝐜𝐡𝐢𝐧𝐞 𝐥𝐚𝐧𝐠𝐮𝐚𝐠𝐞 𝐀𝐬𝐬𝐞𝐦𝐛𝐥𝐲 𝐥𝐚𝐧𝐠𝐮𝐚𝐠𝐞 𝐇𝐢𝐠𝐡 𝐥𝐞𝐯𝐞𝐥 𝐥𝐚𝐧𝐠𝐮𝐚𝐠𝐞


Characteristics low-level language Easier but still easier for programmers
that is difficult to learn technical for to read and use the
and use the code. programmers to read code.
(Not user friendly) and use the code. (user friendly)
(Less user friendly)
Level of Lack of Abstraction as Low level of high level of
abstraction it requires the details of Abstraction abstraction by hiding
CPU the details of processor
Hardware direct interact with direct interact with High-level languages
components hardware components hardware components don't directly interact
such as CPU, RAM, such as CPU, RAM, with hardware
and the storage devices and the storage components
devices
Software uses binary code, a represented by Syntax uses command
components sequence of 1s and 0s, mnemonic code such words similar to
to represent the as 𝐴𝑑𝑑, 𝑆𝑢𝑏, 𝑀𝑜𝑣, natural human
instructions and data 𝐸𝑛𝑑 language
Translation No translation required requires Assembler to Requires a Compiler or
as it present in direct translate code into Interpreter to translate
machine execution executable Machine the code into
code language executable Machine
language

9. State the need of progress bar in android application.


𝐏𝐫𝐨𝐠𝐫𝐞𝐬𝐬 𝐛𝐚𝐫: is a graphical display indicator used to show the status of tasks
like a file uploading or file downloading preventing users from feeling that the
app has frozen or is unresponsive.
Types of Progress Bar:
𝐻𝑜𝑟𝑖𝑧𝑜𝑛𝑡𝑎𝑙 𝑃𝑟𝑜𝑔𝑟𝑒𝑠𝑠 𝐵𝑎𝑟 - a linear progress indicator used when the duration
or progress of a task is known.
Example:
40% completed
𝐶𝑖𝑟𝑐𝑢𝑙𝑎𝑟 𝑃𝑟𝑜𝑔𝑟𝑒𝑠𝑠 𝐵𝑎𝑟 – a spinning circular indicator used when the duration
or progress of a task is unknown.

Example:
please wait !

5
10. Explain RecyclerView with respect to android.

is a UI component which improves the efficiency of ListView and GridView by


create a scrolling list that recycling the views which are out of visibility of the
user thereby reducing the memory consumption. 0696485872
For example, if a user scrolled down to a position where the item 4 and 5 are
visible, items 1, 2 and 3 would be cleared (not appear) to reduce the memory
consumption.

11. As security is important for android devices, what are the best practices to implement
security in an android app?

𝐃𝐢𝐬𝐚𝐥𝐥𝐨𝐰 𝐚𝐜𝐜𝐞𝐬𝐬 𝐭𝐨 𝐲𝐨𝐮𝐫 𝐚𝐩𝐩′𝐬 𝐜𝐨𝐧𝐭𝐞𝐧𝐭 𝐩𝐫𝐨𝐯𝐢𝐝𝐞𝐫


Content provider allows the sharing of data from one application to the
requesting application by default. If you don't intend to provide other
applications with access to your 𝐶𝑜𝑛𝑡𝑒𝑛𝑡𝑃𝑟𝑜𝑣𝑖𝑑𝑒𝑟, mark it as
𝑎𝑛𝑑𝑟𝑜𝑖𝑑: 𝑒𝑥𝑝𝑜𝑟𝑡𝑒𝑑 = 𝑓𝑎𝑙𝑠𝑒 in the application manifest.
𝐒𝐞𝐜𝐮𝐫𝐞 𝐍𝐞𝐭𝐰𝐨𝐫𝐤 𝐂𝐨𝐦𝐦𝐮𝐧𝐢𝐜𝐚𝐭𝐢𝐨𝐧 𝐰𝐢𝐭𝐡 𝐭𝐡𝐞 𝐮𝐬𝐞 𝐨𝐟 𝒉𝒕𝒕𝒑𝒔
Always use ℎ𝑡𝑡𝑝𝑠 communication to encrypt Application Programming
Interface, API requests and protect data transmitted between the app and
server.
𝐈𝐦𝐩𝐥𝐞𝐦𝐞𝐧𝐭 𝐒𝐭𝐫𝐨𝐧𝐠 𝐚𝐧𝐝 𝐒𝐞𝐜𝐮𝐫𝐞 𝐀𝐮𝐭𝐡𝐞𝐧𝐭𝐢𝐜𝐚𝐭𝐢𝐨𝐧
Weak login system can lead to unauthorized access and compromise user and
business data. Modern authentication method such as biometric
authentication can prevent brute-force attack.
𝐑𝐞𝐠𝐮𝐥𝐚𝐫 𝐬𝐞𝐜𝐮𝐫𝐢𝐭𝐲 𝐮𝐩𝐝𝐚𝐭𝐞𝐬
The outdated apps become the prime target for attackers, thereby regular
releasing app updates is a crucial practice to address vulnerability to security
threats and improving functionality.
𝐒𝐭𝐨𝐫𝐞 𝐩𝐫𝐢𝐯𝐚𝐭𝐞 𝐝𝐚𝐭𝐚 𝐰𝐢𝐭𝐡𝐢𝐧 𝐝𝐞𝐯𝐢𝐜𝐞’𝐬 𝐢𝐧𝐭𝐞𝐫𝐧𝐚𝐥 𝐬𝐭𝐨𝐫𝐚𝐠𝐞
By default, data kept on internal storage are accessible only to your app.
Android implements this protection, and it's sufficient for most applications.
Avoid storing critical information, such as passwords and personal data, on
external storage like SD cards, as they can be modified by any application and
be accessible to attackers. Instead, use internal storage.

6
12. *Explain life cycle of Activity in android.

𝒐𝒏𝑪𝒓𝒆𝒂𝒕𝒆( ) : called when the activity is first created.


𝒐𝒏𝑺𝒕𝒂𝒓𝒕( ) : called when the activity become visible to the user.
followed by 𝑜𝑛𝑅𝑒𝑠𝑢𝑚𝑒( ) if the activity comes to the fore ground
or 𝑜𝑛𝑆𝑡𝑜𝑝( ) if it becomes hidden.
𝒐𝒏𝑹𝒆𝒔𝒖𝒎𝒆( ) : called when the activity will start interacting with the user.
always followed by 𝑜𝑛𝑃𝑎𝑢𝑠𝑒( ).
𝒐𝒏𝑷𝒂𝒖𝒔𝒆( ) : called when the system is about to start resuming the
previous activity.
𝒐𝒏𝑺𝒕𝒐𝒑( ) : called when the activity is no longer visible to the user
followed by 𝑜𝑛𝑆𝑡𝑎𝑟𝑡( ) if the activity is coming back to interact
with the user or 𝑜𝑛𝐷𝑒𝑠𝑡𝑟𝑜𝑦( ) if this activity is going away.
𝒐𝒏𝑫𝒆𝒔𝒕𝒓𝒐𝒚( ) : the final call you receive before the activity is no longer used
and destroyed.

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.

15. Explain the following with respect to android.


1. Gradle 2. Layout 3. Intent
4. View 5. Content Provider 6. Activity Manager
7. Notification Manager

𝐆𝐫𝐚𝐝𝐥𝐞 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.

16. What is clickable and focusable with respect to TextEdit.

𝐂𝐥𝐢𝐜𝐤𝐚𝐛𝐥𝐞 𝐭𝐞𝐱𝐭 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

𝐈𝐦𝐩𝐥𝐢𝐜𝐢𝐭 𝐈𝐧𝐭𝐞𝐧𝐭: 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 will 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.

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);

18. What is context with respect to android?

“𝐂𝐨𝐧𝐭𝐞𝐱𝐭” is a fundamental class that acts as an interface when the android


application components (such as Activity, Service, ContentProvider,
BroadcastReceiver) need to access system resources and interact with each
other.
To use a metaphor, “Context” can be thought of as “a window to the operating
system”.

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.

𝐓𝐨𝐚𝐬𝐭 is a short notification which is displayed for a small period of time to


the user then disappear automatically without disturbing other
functionalities of the application.
𝑆𝑦𝑛𝑡𝑎𝑥
Toast.makeText(Context( ), “This is a Toast”, Toast.LENGTH_SHORT).show( );

21. Mention the difference between class, file and activity in Android

𝐂𝐥𝐚𝐬𝐬 is defined as a blueprint (template) that describes the identity, behaviors


(methods) or state that the object of its type supports. So object is the
instance(result) of a class.
An 𝐀𝐜𝐭𝐢𝐯𝐢𝐭𝐲 is an application component that provides a screen with which
users can interact in order to do something, such as dial the number or login.
In android app every activity have to inherent directly or indirectly from
Activity Class which is predefined in the android system. So activity is also a
class but a special one.
𝐅𝐢𝐥𝐞 is a block of arbitrary information, or resource for managing, storing and
sharing of information.

22. What is AndroidManifest.xml file and why do you need this?

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.

23. Explain the dialog boxes supported on Android


is a small window displaying a message that prompts the user to enter
additional information or to respond with options such as 𝑦𝑒𝑠 or 𝑛𝑜 with help
of virtual buttons.

11
24. *Explain life cycle of Service in android.

A Service is an application component that runs in the background to perform


long-running operations without need to interact with the user and it works
even if the application is destroyed.
It does not provide a user interface. There are two main types of services:
𝐒𝐭𝐚𝐫𝐭𝐞𝐝 𝐒𝐞𝐫𝐯𝐢𝐜𝐞: a service that is initiated by by calling startService( ) from any
component of your app component, like an Activity and runs indefinitely in
the background.
𝐁𝐨𝐮𝐧𝐝 𝐒𝐞𝐫𝐯𝐢𝐜𝐞: a service that allows components to interact with it and bind
to it for communication and task management.

𝒐𝒏𝑪𝒓𝒆𝒂𝒕𝒆( ) : called automatically by the activity manager when


the activity is first created.
𝒐𝒏𝑺𝒕𝒂𝒓𝒕𝑪𝒐𝒎𝒎𝒂𝒏𝒅( ) : the system calls this method whenever a component,
say an activity requests ‘start’ to a service, using
startService( ).
𝒐𝒏𝑩𝒊𝒏𝒅( ) : this method is called when the service allows binding
with other components (such as activities) using
bindService( ).
𝒐𝒏𝑼𝒏𝑩𝒊𝒏𝒅( ) : this method is called when all clients have
disconnected from a bound service using
unbindService( ).
𝒐𝒏𝑼𝒏𝑩𝒊𝒏𝒅( ) : the service is no longer running and destroyed. This
is the last call that the service receives.

12
25. Briefly explain the components of Android application.

An 𝐀𝐜𝐭𝐢𝐯𝐢𝐭𝐲 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.
A 𝐒𝐞𝐫𝐯𝐢𝐜𝐞 is an application component that runs in the background to perform
long-running operations without need to interact with the user and it works
even if the application is destroyed.
𝐂𝐨𝐧𝐭𝐞𝐧𝐭 𝐏𝐫𝐨𝐯𝐢𝐝𝐞𝐫 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.
𝐁𝐫𝐨𝐚𝐝𝐜𝐚𝐬𝐭𝐑𝐞𝐜𝐞𝐢𝐯𝐞𝐫 Broadcast Receiver is one of the components in Android
that enable apps to listen for and respond to broadcast messages (intents)
from other apps or the system itself. Think of them as listeners waiting for
specific events to occur.

26. What is the importance of having an emulator within the Android environment?

An emulator is a software or hardware tool designed to mimic the functions and


behaviour of another system or device so that one computer system behaves
like another.
𝐀𝐧𝐝𝐫𝐨𝐢𝐝 𝐞𝐦𝐮𝐥𝐚𝐭𝐨𝐫 provides a virtualized platform for developing, testing, and
debugging applications without needing a physical Android device so that
developers can simulate different screen sizes (phones, tablets, foldables),
Android versions, and hardware specifications (RAM, CPU, GPU).

27. Differentiate Activities from Services.


An 𝐀𝐜𝐭𝐢𝐯𝐢𝐭𝐲 is an application component that provides a screen with which
users can interact in order to do something, such as dial the number or login.
A 𝐒𝐞𝐫𝐯𝐢𝐜𝐞 is an application component that runs in the background to perform
long-running operations without need to interact with the user and it works
even if the application is destroyed.

28. What items are important in every Android project?

𝐀𝐧𝐝𝐫𝐨𝐢𝐝𝐌𝐚𝐧𝐢𝐟𝐞𝐬𝐭. 𝐱𝐦𝐥 𝐟𝐢𝐥𝐞, which defines the app's components (Activity,


Service, ContentProvider, ContentReceiver), 𝐁𝐮𝐢𝐥𝐝 𝐒𝐲𝐬𝐭𝐞𝐦 (𝑮𝒓𝒂𝒅𝒍𝒆) to build
configurations, Project structure (a source code directory, 𝑠𝑟𝑐 containing
Java or Kotlin code, a resource directory, res) and Android Development
Tools (Emulator, SDK).

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.

30. What is Orientation?

refers to screen orientation, which dictates whether the screen is displayed in


portrait (tall) or landscape (wide) mode.

31. What are the four essential states of an activity?


𝐀𝐜𝐭𝐢𝐯𝐞/𝐑𝐮𝐧𝐧𝐢𝐧𝐠: the activity is in the foreground, has focus, and is interacting
with the user.
𝐏𝐚𝐮𝐬𝐞𝐝: The activity is no longer in the foreground, but it is still visible and
partially covered by another activity.
𝐒𝐭𝐨𝐩𝐩𝐞𝐝: the activity is completely covered by another activity, it's no longer
visible, but it still exists in memory.
𝐃𝐞𝐬𝐭𝐫𝐨𝐲𝐞𝐝: the activity is no longer in memory and has been completely
removed.

32. What is the function of an intent filter?

is a specification within an app's manifest file that declares what types of


intents (messages) a component (activity, service, or broadcast receiver) can
respond to.

33. When is the onStop( ) method invoked?

𝒐𝒏𝑺𝒕𝒐𝒑( ) method invoked when the activity is completely covered by another


activity, it's no longer visible, but it still exists in memory.

14
34. What are the different states wherein a process is based?

A process is a program in execution example run a code however, it goes


through different phases or states before completion.
Here’s what happens step by step of Two-State Model
𝐍𝐨𝐭 𝐑𝐮𝐧𝐧𝐢𝐧𝐠 𝐒𝐭𝐚𝐭𝐞: When the process is first created, it is not using the CPU.
𝐃𝐢𝐬𝐩𝐚𝐭𝐜𝐡𝐞𝐫 𝐑𝐨𝐥𝐞: The dispatcher checks if the CPU is free (available for use).
𝐑𝐮𝐧𝐧𝐢𝐧𝐠 𝐒𝐭𝐚𝐭𝐞: If the CPU is free, the dispatcher lets the process use the CPU,
and it moves into the running state.
𝐂𝐏𝐔 𝐒𝐜𝐡𝐞𝐝𝐮𝐥𝐞𝐫 𝐑𝐨𝐥𝐞: When the CPU is available, the CPU scheduler decides
which process gets to run next. It picks the process based on a set of rules
called the scheduling scheme, which varies from one operating system to
another.

35. What role does Dalvik play in Android development?

𝐃𝐚𝐥𝐯𝐢𝐤 acts as a runtime environment for Android apps, translating Java


bytecode into Dalvik Executable (DEX) format. Android build process, is
responsible for packaging DEX files into an APK file format that can run into
the operating system of android.
These DEX files contain all the necessary components for an Android
application, including code, resources, and a manifest file.

36. Is it possible to use or add a fragment without using a user interface?


Fragment: UI component that can be added or removed from an activity to create
more dynamic and smoother user interface of a portion or a single screen.

𝐘𝐞𝐬, 𝐢𝐭 𝐢𝐬 𝐩𝐨𝐬𝐬𝐢𝐛𝐥𝐞.
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.

39. What is an action?

Action is a feature that allows users to perform a specific task. Example to


answer an incoming call.

40. Explain XML attributes taking TextView as an example.

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.

41. Explain the steps for sending the implicit itents.

Step 1 : In the sendin Activity, create a new Intent object.


Step 2 : Add information about the request to the Intent object, such as
data or extras.
Step3 : To just start the Activity, send the Intent with 𝑠𝑡𝑎𝑟𝑡𝐴𝑐𝑡𝑖𝑣𝑖𝑡𝑦( ) or
𝑠𝑡𝑎𝑟𝑡𝐴𝑐𝑡𝑖𝑣𝑖𝑡𝑦𝑓𝑜𝑟𝑅𝑒𝑠𝑢𝑙𝑡( ) to start the Activity and get a result back.

42. What are Broadcast Intents? Explain system broadcast intents and custom broadcast
intents.

𝐁𝐫𝐨𝐚𝐝𝐜𝐚𝐬𝐭 𝐢𝐧𝐭𝐞𝐧𝐭 is messaging object used to request an action from another


app component. Example displaying contact list, display webpage or
download a file.
𝐒𝐲𝐬𝐭𝐞𝐦 𝐛𝐫𝐨𝐚𝐝𝐜𝐚𝐬𝐭 𝐢𝐧𝐭𝐞𝐧𝐭 is the broadcast intent delivered by the system when
a system event occurs that might interest your app. Example battery-charging
levels, network connections, incoming calls or headphones being connected.
𝐂𝐮𝐬𝐭𝐨𝐦 𝐛𝐫𝐨𝐚𝐝𝐜𝐚𝐬𝐭 𝐢𝐧𝐭𝐞𝐧𝐭𝐬 are broadcast intents that your application sends
out. For example, when you want to let other apps know that data has been
downloaded to the device and is available for them to use.

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( ).

44. Explain about external and internal storage.

𝐈𝐧𝐭𝐞𝐫𝐧𝐚𝐥 𝐬𝐭𝐨𝐫𝐚𝐠𝐞 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.

𝐒𝐐𝐋𝐢𝐭𝐞 is a type of database management system used to store and manage


data such as mobile app and desktop software in a structured format in such
a way that your program can directly read from, and write to, this database
without connected to an external server.

steps for implementing SQLite database in mobile app.

1. 𝐶𝑟𝑒𝑎𝑡𝑒 𝑎 𝑫𝒂𝒕𝒂𝒃𝒂𝒔𝒆𝑯𝒆𝒍𝒑𝒆𝒓 𝐶𝑙𝑎𝑠𝑠 𝑡ℎ𝑎𝑡 𝑒𝑥𝑡𝑒𝑛𝑑𝑠 𝑺𝑸𝑳𝒊𝒕𝒆𝑶𝒑𝒆𝒏𝑯𝒆𝒍𝒑𝒆𝒓.


This helper class handles database creation and provides methods for
interacting with the database.
3. 𝐼𝑚𝑝𝑙𝑒𝑚𝑒𝑛𝑡 𝑡ℎ𝑒 𝒐𝒏𝑪𝒓𝒆𝒂𝒕𝒆() 𝒎𝒆𝒕𝒉𝒐𝒅.
This method define the database schema (tables, columns, data types,
constraints) using SQL CREATE TABLE statements.
4. Implement 𝒐𝒏𝑼𝒑𝒈𝒓𝒂𝒅𝒆() 𝒎𝒆𝒕𝒉𝒐𝒅.
This method is called when you need to upgrade your database schema,
incase the database version changes.
5. 𝑨𝒄𝒄𝒆𝒔𝒔 𝒕𝒉𝒆 𝒅𝒂𝒕𝒂𝒃𝒂𝒔𝒆.
Use method 𝑔𝑒𝑡𝑊𝑟𝑖𝑡𝑎𝑏𝑙𝑒𝐷𝑎𝑡𝑎𝑏𝑎𝑠𝑒( ) or 𝑔𝑒𝑡𝑅𝑒𝑎𝑑𝑎𝑏𝑙𝑒𝐷𝑎𝑡𝑎𝑏𝑎𝑠𝑒( ) on your
SQLiteOpenHelper instance to obtain a SQLite Database object. This object is
used to perform database operations like inserting, updating, deleting, and
querying data using SQL statements.

17
46. Judge with suitable reasoning why is it important to process some tasks in the
background or off the UI thread.

If a task that takes a long time, such as downloading a file or performing


complex calculations, is running on the UI thread, it can block the thread,
preventing it from responding to user input or updating the display.
By offloading tasks to a background thread, the UI thread can continue to
handle user input and updates.

a 𝐭𝐡𝐫𝐞𝐚𝐝 is a sequence of programmed instructions executed by the CPU.


Background processes are run on a separate thread from the user interface
without affecting the performance of the UI.

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.

49. Elaborate on resource file in android system.

𝑹𝒆𝒔𝒐𝒖𝒓𝒄𝒆 𝒇𝒊𝒍𝒆 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.

𝒐𝒏𝑪𝒓𝒆𝒂𝒕𝒆( ) : called when the activity is first created.


𝒐𝒏𝑺𝒕𝒂𝒓𝒕( ) : called when the activity become visible to the user.
followed by 𝑜𝑛𝑅𝑒𝑠𝑢𝑚𝑒( ) if the activity comes to the fore ground
or 𝑜𝑛𝑆𝑡𝑜𝑝( ) if it becomes hidden.
𝒐𝒏𝑹𝒆𝒔𝒖𝒎𝒆( ) : called when the activity will start interacting with the user.
always followed by 𝑜𝑛𝑃𝑎𝑢𝑠𝑒( ).
𝒐𝒏𝑷𝒂𝒖𝒔𝒆( ) : called when the system is about to start resuming the
previous activity.
𝒐𝒏𝑺𝒕𝒐𝒑( ) : called when the activity is no longer visible to the user
followed by 𝑜𝑛𝑆𝑡𝑎𝑟𝑡( ) if the activity is coming back to interact
with the user or 𝑜𝑛𝐷𝑒𝑠𝑡𝑟𝑜𝑦( ) if this activity is going away.
𝒐𝒏𝑫𝒆𝒔𝒕𝒓𝒐𝒚( ) : the final call you receive before the activity is no longer used
and destroyed.
If android developer does not use any lifecycle callback methods while
developing app, user will lose data whenever app is closed for any reason.

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.

An Intent object in Android contains information that describes an operation


to be performed. This includes details like the component to start and the
action to be taken.

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 .

𝐒𝐐𝐋𝐢𝐭𝐞 𝐃𝐚𝐭𝐚𝐛𝐚𝐬𝐞: Store structured data.


𝐒𝐡𝐚𝐫𝐞𝐝 𝐬𝐭𝐨𝐫𝐚𝐠𝐞: Store files that your app intends to share with other apps.
𝐏𝐫𝐞𝐟𝐞𝐫𝐞𝐧𝐜𝐞𝐬: Store private, primitive data.
𝐀𝐩𝐩 − 𝐬𝐩𝐞𝐜𝐢𝐟𝐢𝐜 𝐬𝐭𝐨𝐫𝐚𝐠𝐞: Store files that are meant for your app's use only.

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.

𝐓𝐨𝐚𝐬𝐭 𝐍𝐨𝐭𝐢𝐟𝐢𝐜𝐚𝐭𝐢𝐨𝐧s is a short notification which is displayed for a small period


of time to the user then disappear automatically without disturbing other
functionalities of the application.
𝐒𝐭𝐚𝐭𝐮𝐬 𝐁𝐚𝐫 𝐍𝐨𝐭𝐢𝐟𝐢𝐜𝐚𝐭𝐢𝐨𝐧𝐬 : Appear as icons in the status bar and can be pulled
down to show detailed notifications.
Example: New email or message alerts.
𝐷𝑖𝑎𝑙𝑜𝑔 𝐵𝑜𝑥𝑒𝑠 is a small window displaying a message that prompts the user to
enter additional information or to respond with options such as 𝑦𝑒𝑠 or 𝑛𝑜 with
help of virtual buttons.
𝑉𝑖𝑏𝑟𝑎𝑡𝑖𝑜𝑛 𝐴𝑙𝑒𝑟𝑡𝑠: Trigger device vibration when notifying.
𝑆𝑜𝑢𝑛𝑑 𝐴𝑙𝑒𝑟𝑡𝑠: Play notification sounds to alert the user

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.

An emulator is a software or hardware tool designed to mimic the functions and


behaviour of another system or device so that one computer system behaves
like another.
𝐀𝐧𝐝𝐫𝐨𝐢𝐝 𝐞𝐦𝐮𝐥𝐚𝐭𝐨𝐫 provides a virtualized platform for developing, testing, and
debugging applications without needing a physical Android device so that
developers can simulate different screen sizes (phones, tablets, foldables),
Android versions, and hardware specifications (RAM, CPU, GPU).

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.

61. Create an application having TextView , EditText and Button.

<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

You might also like