0% found this document useful (0 votes)
47 views21 pages

Ap File

The document is a practical file for a Programming in Android course, detailing various practical exercises and their implementation. It covers topics such as installation of Java and Android Studio, Android SDK components, Java programming concepts, and the structure of Android projects. Each practical includes code examples and explanations for building Android applications using different UI components like buttons and checkboxes.

Uploaded by

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

Ap File

The document is a practical file for a Programming in Android course, detailing various practical exercises and their implementation. It covers topics such as installation of Java and Android Studio, Android SDK components, Java programming concepts, and the structure of Android projects. Each practical includes code examples and explanations for building Android applications using different UI components like buttons and checkboxes.

Uploaded by

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

LudhianaChaukimann

Group of College

Practical File

Subject: Programming in Android


Programming Laboratory
Subject Code: UGCA1944

Submitted By: Submitted to:


Inderpreet Kaur Ms.Sangita
2219027 Sharma
Index
Sr.
Practical Date Signature
No.

1 Installation of java, android framework

2 Android SDK Manager and its all components

Programs based on the overriding, constructor,


3
classes in Java

Directory Structure of an Android Project, Common


4 Default Resources Folders, The Values Folder,
Leveraging Android XML.

5 Applications based on Text Boxes and Button

6 Applications based on Check Boxes and button

7 Applications based on Radio Buttons


PRACTICAL – 1
Installation of java, android framework `
Android Studio is the official IDE (Integrated Development Environment)
for Android app development and it is based on JetBrains’ IntelliJ IDEA
software. Android Studio provides many excellent features that enhance
productivity when building Android apps, such as:

 A blended environment where one can develop for all Android


devices
 Apply Changes to push code and resource changes to the running
app without restarting the app
 A flexible Gradle-based build system
 A fast and feature-rich emulator
 GitHub and Code template integration to assist you to develop
common app features and import sample code
 Extensive testing tools and frameworks
 C++ and NDK support
 Built-in support for Google Cloud Platform, making it easy to
integrate Google Cloud Messaging and App Engine, and many
more.
 Provides GUI tools that simplify the less interesting parts of app
development.
 Easy integration with real time database ‘firebase’.

System Requirements
 Microsoft Windows 7/8/10 (32-bit or 64-bit)
 4 GB RAM minimum, 8 GB RAM recommended (plus 1 GB for the
Android Emulator)
 2 GB of available disk space minimum, 4 GB recommended (500
MB for IDE plus 1.5 GB for Android SDK and emulator system
image)
 1280 x 800 minimum screen resolution
Installation Guide
Step 1: Get the Android Studio executable or zip file.

Step 2: Click on the Download Android Studio Button. Click on the “I


have read and agree with the above terms and conditions” checkbox
followed by the download button. Click on the Save file button in the
appeared prompt box and the file will start downloading.

Step 3: After the downloading has finished, open the file from downloads
and run it. It will prompt the following dialog box. Click on next. In the
next prompt, it’ll ask for a path for installation. Choose a path and hit
next.

Step 4: It will start the installation, and once it is completed. Click on


next.

Step 5: Once “Finish” is clicked, it will ask whether the previous settings
need to be imported [if the android studio had been installed earlier], or
not. It is better to choose the ‘Don’t import Settings option’. Click the OK
button.

Step 6: This will start the Android Studio.

Step 7: After it has found the SDK components, it will redirect to the
Welcome dialog box. Click on Next. Choose Standard and click on Next.
Now choose the theme, whether the Light theme or the Dark one. The
light one is called the IntelliJ theme whereas the dark theme is called
Dracula. Choose as required. Click on the Next button.

Step 8: Now it is time to download the SDK components. Click on Finish.


Components begin to download let it complete.

The Android Studio has been successfully configured. Now it’s time to
launch and build apps. Click on the Finish button to launch it.

Step 9: Click on Start a new Android Studio project to build a new app.
PRACTICAL - 2
Android SDK Manager and all its components
Android SDK stands for Android Software Development Kit which is
developed by Google for Android Platform. With the help of Android
SDK, we can create android Apps easily.

About Android SDK


Android SDK is a collection of libraries and Software Development tools
that are essential for Developing Android Applications. Whenever
Google releases a new version or update of Android Software, a
corresponding SDK also releases with it. In the updated or new version
of SDK, some more features are included which are not present in the
previous version. Android SDK consists of some tools which are very
essential for the development of Android Application. These tools
provide a smooth flow of the development process from developing and
debugging. Android SDK is compatible with all operating systems such
as Windows, Linux, macOS, etc.

Components of Android SDK


1. Android SDK Tools

Android SDK tool is an important component of Android SDK. It consists


of a complete set of development and debugging tools. Below are the
SDK developer tools:

• Android SDK Build tool.

• Android Emulator.

• Android SDK Platform-tools.

• Android SDK Tools.

2. Android SDK Build-Tools

Android SDK build tools are used for building actual binaries of Android
App. The main functions of Android SDK Build tools are built, debug, run
and test Android applications. The latest version of the Android SDK
Build tool is 30.0.3. While downloading or updating Android in our
System, one must ensure that its latest version is download in SDK
Components.

3. Android Emulator

An Android Emulator is a device that simulates an Android device on


your system. Suppose we want to run our android application that we
code. One option is that we will run this on our Android Mobile by
Enabling USB Debugging on our mobile. Another option is using Android
Emulator. In Android Emulator the virtual android device is shown on our
system on which we run the Android application that we code.

Thus, it simply means that without needing any physical device Android
SDK component “Android Emulator” provides a virtual device on the
System where we run our application. The emulator’s come with the
configuration for Various android phones, tablets, Wear OS, and Android
TV devices. In Android Virtual Emulator all functions that are feasible on
real Android mobile is works on virtual Device like:

• phone calls, text messages.

• stimulate different network speeds.

• specify the location of a device

• access on google play store and lots more.

4. Android SDK Platform-tools

Android SDK Platform-tools is helpful when we are working on Project


and they will show the error messages at the same time. It is specifically
used for testing. It includes:

• Android Debug Bridge (ADB), is a command-line tool that helps to


communicate with the device. It allows us to perform an action such as
Installing App and Debugging App etc.

• Fastboot allows you to flash a device with a new system image.

• Systrace tools help to collect and inspect timing information. It is very


crucial for App Debugging.
5. Android SDK Tools

Android SDK tool is a component of SDK tool. It consists of a set of tools


which and other Utilities which are crucial for the development of Android
Application. It contains the complete set of Debugging and Development
tools for android.

6. SDK Update Sites

In SDK Update Sites, some sites are embedded in it which will check for
Android SDK Updates Tools. In this, one must ensure we don’t unclick
the button below because these are checked by default which will check
for updates if we will unclick it then it doesn’t check updates for those.
PRACTICAL - 3
Programs based on overriding, constructor, classes in java
Method Overriding in Java
class Vehicle{

void run(){System.out.println("Vehicle is running");}

class Bike extends Vehicle{

public static void main(String args[]){

Bike obj = new Bike();

obj.run();

Output

Vehicle is running

Constructors in Java
class Student4{

int id;

String name;

Student4(int i,String n){

id = i;

name = n;

void display(){System.out.println(id+" "+name);}


public static void main(String args[]){

Student4 s1 = new Student4(111,"Karan");

Student4 s2 = new Student4(222,"Aryan");

s1.display();

s2.display();

Output

111 Karan

222 Aryan

Java Classes
class Student {

int id;

String name;

public static void main(String args[])

Student s1 = new Student();

System.out.println(s1.id);

System.out.println(s1.name);

Output

Null
PRACTICAL - 4
Program based on the final, this and static keyword in java
final keyword in java
class Bike9{

final int speedlimit=90;

void run(){speedlimit=400;

public static void main(String args[]){

Bike9 obj=new Bike9();

obj.run();

Output:

Compile Time Error

class Bike{

final void run(){System.out.println("running");}

class Honda extends Bike{

void run(){System.out.println("running safely with 100kmph");}

public static void main(String args[]){

Honda honda= new Honda();

honda.run();

}
Output

Compile Time Error

this keyword in Java


class Student{

int rollno;

String name;

float fee;

Student(int rollno,String name,float fee){

this.rollno=rollno;

this.name=name;

this.fee=fee;

void display(){System.out.println(rollno+" "+name+" "+fee);}

class TestThis2{

public static void main(String args[]){

Student s1=new Student(111,"ankit",5000f);

Student s2=new Student(112,"sumit",6000f);

s1.display();

s2.display();

}}

Output:

111 ankit 5000.0

112 sumit 6000.0


static Keyword in Java
class Test

static int a = m1();

static {

System.out.println("Inside static block");

static int m1() {

System.out.println("from m1");

return 20;

public static void main(String[] args)

System.out.println("Value of a : "+a);

System.out.println("from main");

Output

from m1

Inside static block

Value of a : 20

from main
PRACTICAL - 5
Directory structure of an Android Project Common default
resources folders, the value folder, leveraging android
XML.
An android project is a combination of required files and folders which
further builds a directory to complete any android application. As android
is a most popular open source mobile platform so the need of the
android applications is growing very rapidly. In this article I explained the
directory structure for any android project. The directory structure is a
foundation of any android project. It acts like a container which holds
necessary logics, images, customization in its real form. During the
generation(compilation) of a project, android looks into these folder to
locate each type of assets it needs.

Android directory structure typically includes XML layouts, Java code,


rich media files and XML animation definitions.

Generally, we have three kinds of android projects such as:

• Android Projects

• Test Projects

• Library Projects

Android Directory Structure

The main objective of an android project is to build an .apk file from it.
And for this when we start with an android project then some directories
create by default and some needs few customization to enhance android
applications. So, let’s understand the directory structure in android
project to develop an android application.

/src – This is the most common folder in any android project. It contains
our java source code for android application. Under this folder we can
see our java source files in which we write logic for android applications.

/gen – In most IDE(such as Eclipse) this folder is created by IDE for


configuration purpose. Under this folder we can find two java files such
as BuildConfig.java and R.java. Both files are auto generated by IDE
which helps android project to work smoothly.

/Android(version name) – Under this folder we can see some android.jar


file which relates to android sdk platform. We should not modify this file
for smooth functioning of our project.

/assets – By default this folder is empty, but we can store raw asset files
such as music file,data file etc in this folder. The files retains its original
name and structure when compiled into an .apk file.

/bin – This is a very important folder in our directory structure as it


contains AndroidManifest.xml file and serve as a output directory for our
project which further build an .apk file.

/libs – This folder contains private libraries.

/res – This folder contains lots of required sub folders for the project.
Let’s understand these folders one by one
PRACTICAL - 6
Applications based on Text Boxes and Button
Android Button represents a push-button. The android.widget.Button is
subclass of TextView class and CompoundButton is the subclass of Button
class. There are different types of buttons in android such as RadioButton,
ToggleButton, CompoundButton etc.

Here, we are going to create two textfields and one button for sum of two
numbers. If user clicks button, sum of two input values is displayed on the
Toast. button.setOnClickListener(new View.OnClickListener() { @Override

public void onClick(View view) {

//code

});

<Button

android:onClick="methodName"

/>

Drag the component or write the code for UI in activity_main.xml

First of all, drag 2 textfields from the Text Fields palette and one button from
the Form Widgets palette as shown in the following figure.

The generated code for the ui components will be like this:

<?xml version="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"

tools:context="example.javatpoint.com.sumoftwonumber.MainActivity">

<EditText android:id="@+id/editText1"
android:layout_width="wrap_content"android:layout_height="wrap_content"

android:layout_alignParentTop="true"android:layout_centerHorizontal="true"

android:layout_marginTop="61dp"

android:ems="10"
android:inputType="nu="number"tools:layout_editor_absoluteX="84dp"

tools:layout_editor_absoluteY="53dp" />

<EditText android:id="@+id/editText2"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_below="@+id/
editText1"android:layout_centerHorizontal="true"android:layout_marginTop="
32dp" android:ems="10" android:inputType="number"

tools:layout_editor_absoluteX="84dp"
tools:layout_editor_absoluteY="127dp" />

<Button android:id="@+id/button"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_below="@+id/editText2"android:layout_centerHorizontal="true"

android:layout_marginTop="109dp" android:text="ADD"

tools:layout_editor_absoluteX="148dp" tools:layout_editor_absoluteY="266dp"
/>

</RelativeLayout>
PRACTICAL - 7
Applications based on Check Boxes and button
Android CheckBox is a type of two state button either checked or
unchecked.

There can be a lot of usage of checkboxes. For example, it can be used


to know the hobby of the user, activate/deactivate the specific action etc.

Android CheckBox class is the subclass of CompoundButton class.

The android.widget.CheckBox class provides the facility of creating the


CheckBoxes.

There are many inherited methods of View, TextView, and Button


classes in the CheckBox class. Some of them are as follows:

Method Description
Returns true if it is checked
public boolean isChecked() otherwise
false
public void setChecked(boolean Changes the state of the
status) CheckBox.

<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLayout

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"

tools:context="example.javatpoint.com.checkbox.MainActivity">
<CheckBox android:id="@+id/checkBox"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_marginLeft="144dp" android:layout_marginTop="68dp"
android:text="Pizza"

app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"

/>

<CheckBox android:id="@+id/checkBox2"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:layout_marginLeft="144dp"

android:layout_marginTop="28dp" android:text="Coffee

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/checkBox" />

<CheckBox

android:id="@+id/checkBox3" android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:layout_marginLeft="144dp"

android:layout_marginTop="28dp" android:text="Burger"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/checkBox2" />

<Button android:id="@+id/button"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_marginLeft="144dp" android:layout_marginTop="184dp"

android:text="Order" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox3" />

</android.support.constraint.ConstraintLayout>

Activity class

package example.javatpoint.com.checkbox;

import android.support.v7.app.AppCompatActivity; import


android.os.Bundle; import android.view.View;

import android.widget.Button; import android.widget.CheckBox; import

android.widget.Toast;

public class MainActivity extends AppCompatActivity { CheckBox


pizza,coffe,burger;

Button buttonOrder; @Override

protected void onCreate(Bundle savedInstanceState)


{ super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main); addListenerOnButtonClick();

public void addListenerOnButtonClick(){

pizza=(CheckBox)findViewById(R.id.checkBox);

coffe=(CheckBox)findViewById(R.id.checkBox2);

burger=(CheckBox)findViewById(R.id.checkBox3);

buttonOrder=(Button)findViewById(R.id.button);

buttonOrder.setOnClickListener(new View.OnClickListener(){

public void onClick(View view) { int totalamount=0;

StringBuilder result=new StringBuilder(); result.append("Selected


Items:");

if(pizza.isChecked()){

result.append("\nPizza 100Rs"); totalamount+=100;


}

if(coffe.isChecked()){ result.append("\nCoffe 50Rs"); totalamount+=50;

if(burger.isChecked()){ result.append("\nBurger 120Rs");


totalamount+=120;

result.append("\nTotal: "+totalamount+"Rs");

//Displaying the message on the toast


Toast.makeText(getApplicationContext(),

result.toString(),

Toast.LENGTH_LONG).show();

});

}}

You might also like