Practical File: Submitted By: Yuganter Sharma Submitted To: Mukesh Sir Semester: VI
Practical File: Submitted By: Yuganter Sharma Submitted To: Mukesh Sir Semester: VI
Android Studio is the official Integrated Development Environment (IDE) for Android app
development, based on IntelliJIDEA . On top of IntelliJ's powerful code editor and developer
tools, Android Studio offers even more features that enhance your productivity when building
Android apps, such as:
A unified environment where you can develop for all Android devices
Apply Changes to push code and resource changes to your running app without
restarting your app
Code templates and GitHub integration to help you build common app features and
import sample code
Lint tools to catch performance, usability, version compatibility, and other problems
Built-in support for Google Cloud Platform, making it easy to integrate Google Cloud
Messaging and App Engine
Follow the setup wizard in Android Studio and install any SDK packages that it
recommends.
JDK Alpha and Beta (1995): Sun Microsystem announced Java in September 23, 1995.
JDK 1.0 (January 1996): Originally called Oak (named after the oak tree outside James
Gosling's office). Renamed to Java 1 in JDK 1.0.2.
JDK 1.1 (February 1997): Introduced AWT event model, inner class, JavaBean, JDBC, and
RMI.
J2SE 1.2 (JDK 1.2) (December 1998): Re-branded as "Java 2" and renamed JDK to J2SE (Java
2 Standard Edition). Also released J2EE (Java 2 Enterprise Edition) and J2ME (Java 2 Micro
Edition). Included JFC (Java Foundation Classes - Swing, Accessibility API, Java 2D, Pluggable
Look & Feel, and Drag & Drop). Also introduced Collection Framework and JIT compiler.
J2SE 1.3 (JDK 1.3) (May 2000): Introduced Hotspot JVM.
J2SE 1.4 (JDK 1.4) (February 2002): Introduced assert statement, non-blocking IO (nio),
logging API, image IO, Java webstart, regular expression (regex) support.
J2SE 5.0 (JDK 5) (September 2004): Officially called 5.0 instead of 1.5 (by dropping the 1.).
Introduced generics, autoboxing/unboxing, annotation, enum, varargs, for-each loop, static
import. See "JDK 5 New Features".
Java SE 6 (JDK 6) (December 2006): Renamed J2SE to Java SE (Java Platform Standard
Edition). No new language features. See "JDK 6 New Features".
Java SE 7 (JDK 7) (July 2011): First version after Oracle purchased Sun Microsystem - aslo
called OracleJDK. Introduced Strings in switch statement, Binary integer literals, allowing
underscores in numeric literals, improved type inference for generic instance creation (or
diamond operator <>), Catching multiple exception types and rethrowing exceptions with
improved type checking. See "JDK 7 New Features".
Java SE 8 (JDK 8) (LTS) (March 2014): Included support for Lambda expressions, default
and static methods in interfaces, improved collection, and JavaScript runtime. Also
integrated JavaFX graphics subsystem. See "JDK 8 New Features".
Java SE 9 (JDK 9) (September 21, 2017): Introduced modularization of the JDK (module)
under project Jigsaw, the Java Shell (jshell), and more. See "JDK 9 New Features".
Java SE 10 (18.3) (JDK 10) (March 2018): Introduced var for type inference local variable
(similar to JavaScript). Introduced time-based release versioning with two releases each
year, in March and September, denoted as YY.M. Removed native-header generation
tool javah. See "JDK 10 New Features".
Java SE 11 (18.9) (LTS) (JDK 11) (September 2018): Extended var to lambda expression.
Standardize HTTP client in java.net.http. Support TLS 1.3. Clean up the JDK and the
installation package (removed JavaFX, JavaEE, CORBA modules, deprecated Nashorn
JavaScript engine). OracleJDK is no longer free for commercial use, but OpenJDK is still free.
See "JDK 11 New Features".
Java SE 12 (19.3) (JDK 12) (March 2019): Switch Expression (preview). See "JDK 12 New
Features".
Java SE 13 (19.9) (JDK 13) (September 2019): Switch Expression (preview), Multi-line Text
Block (preview). See "JDK 13 New Features".
Java SE 14 (20.3) (JDK 14) (March 2020): Records (preview)
In the main Welcome to Android Studio window, click "Start a new Android Studio project.
In the New Project window, give your application an Application Name, such as "Hello World".
Verify the Project location, or choose a different directory for storing your project.
Apps published to the Google Play Store must have a unique package name. Since domains are
unique, prepending your app's name with your or your company's domain name is going to
result in a unique package name.
If you are not planning to publish your app, you can accept the default example domain. Be
aware that changing the package name of your app later is extra work.
Verify that the default Project location is where you want to store your Hello World app and
other Android Studio projects, or change it to your preferred directory. Click Next.
On the Target Android Devices screen, "Phone and Tablet" should be selected. And you should
ensure that API 15: Android 4.0.3 IceCreamSandwich is set as the Minimum SDK. (Fix this if
necessary.)
At the writing of this book, choosing this API level makes your "Hello World" app compatible
with 97% of Android devices active on the Google Play Store.
Click Next.
If your project requires additional components for your chosen target SDK, Android Studio will
install them automatically. Click Next.
Customize the Activity window. Every app needs at least one activity. An activity represents a
single screen with a user interface and Android Studio provides templates to help you get
started. For the Hello World project, choose the simplest template (as of this writing, the
"Empty Activity" project template is the simplest template) available.
It is a common practice to call your main activity MainActivity. This is not a requirement.
Make sure the Generate Layout file box is checked (if visible).Make sure the Backwards
Compatibility (App Compat) box is checked.
Leave the Layout Name as activity_main. It is customary to name layouts after the activity they
belong to. Accept the defaults and click Finish.
# activity_main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textColor="#2196F3"
android:textSize="40sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
# MainActivity.java
package com.example.helloworld;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
EXPERIMENT: 2
Aim: To understand activity, intent, create sample
application with login module. (Check username and
password)
# activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://sche mas.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:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/Name"
android:layout_width="369dp"
android:layout_height="62dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="113dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="29dp"
android:hint="Name"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/Password"
android:layout_width="372dp"
android:layout_height="55dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="29dp"
android:hint="Password"
app:layout_constraintTop_toBottomOf="@+id/etName" />
<Button
android:id="@+id/button"
android:layout_width="261dp"
android:layout_height="51dp"
android:layout_marginStart="75dp"
android:layout_marginLeft="75dp"
android:layout_marginEnd="75dp"
android:layout_marginRight="75dp"
android:layout_marginBottom="359dp"
android:text="Submit"
app:layout_constraintStart_toStartOf="parent" />
</LinearLayout>
# MainActivity.java
package com.example.login_page;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.jar.Attributes;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NAME = (EditText) findViewById((R.id.Name));
Password = (EditText) findViewById(R.id.Password);
LogIn = (Button) findViewById(R.id.button);
LogIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
st = NAME.getText().toString();
Intent intent=new Intent(MainActivity.this,Main2Activity.class);
intent.putExtra("Value",st);
startActivity(intent);
finish();
}
});
}
}
# activity_main2.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:id="@+id/ettext3"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Main2Activity">
<TextView
android:id="@+id/textView"
android:layout_width="168dp"
android:layout_height="47dp"
android:layout_marginTop="96dp"
android:text="Welcome"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
# Main2Activity.java
package com.example.login_page;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
String st;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
tv=findViewById(R.id.ettext3);
st=getIntent().getExtras().getString("Value");
tv.setText("Welcome "+st);
}
}
EXPERIMENT: 3
Aim: Design simple GUI application with activity and intents. e.g. Calculator
# activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:background="#ecf0f1"
android:orientation="vertical"
tools:context="com.example.calculator.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:orientation="horizontal">
<TextView
android:id="@+id/display"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:drawable/status_bar_item_app_background"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight="0.2"
android:orientation="horizontal">
<Button
android:id="@+id/buttonDel"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="0.25"
android:text="Del"
android:textSize="20sp" />
<Button
android:id="@+id/buttoneql"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="0.25"
android:text="="
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:orientation="horizontal">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="0.25"
android:text="1"
android:textSize="20sp" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="0.25"
android:text="2"
android:textSize="20sp" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="0.25"
android:text="3"
android:textSize="20sp" />
<Button
android:id="@+id/buttondiv"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="0.25"
android:text="/"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:orientation="horizontal">
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="0.25"
android:text="4"
android:textSize="20sp" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="0.25"
android:text="5"
android:textSize="20sp" />
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="0.25"
android:text="6"
android:textSize="20sp" />
<Button
android:id="@+id/buttonsub"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="0.25"
android:text="-"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:orientation="horizontal">
<Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="0.25"
android:text="7"
android:textSize="20sp" />
<Button
android:id="@+id/button8"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="0.25"
android:text="8"
android:textSize="20sp" />
<Button
android:id="@+id/button9"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="0.25"
android:text="9"
android:textSize="20sp" />
<Button
android:id="@+id/buttonmul"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="0.25"
android:text="x"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:orientation="horizontal">
<Button
android:id="@+id/buttonDot"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="0.25"
android:text="."
android:textSize="20sp" />
<Button
android:id="@+id/button0"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="0.25"
android:text="0"
android:textSize="20sp" />
<Button
android:id="@+id/Remainder"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="0.25"
android:text="%"
android:textSize="30sp" />
<Button
android:id="@+id/buttonadd"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="0.25"
android:text="+"
android:textSize="30sp" />
</LinearLayout>
</LinearLayout>
MainActivity.java
package com.example.calculator;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
<EditText
android:id="@+id/Name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:hint="Enter Name" />
<EditText
android:layout_marginTop="5dp"
android:id="@+id/Surname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:layout_below="@+id/Name"
android:inputType="textPersonName"
android:hint="Enter Surname"/>
<LinearLayout
android:layout_below="@+id/Surname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="vertical">
<Button
android:id="@+id/add"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="ADD" />
<Button
android:id="@+id/display"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Display" />
</LinearLayout>
</RelativeLayout>
# MainActivity.java
package com.example.sqliteapp;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
EditText Name,Surname;
Button Add,Display;
SqliteHelper mydb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Name = findViewById(R.id.Name);
Surname = findViewById(R.id.Surname);
Add = findViewById(R.id.add);
Display = findViewById(R.id.display);
Add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean isInserted=
mydb.insertData(Name.getText().toString(),Surname.getText().toString());
if (isInserted==true){
Toast.makeText(getApplicationContext(),"Data
Inserted",Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(getApplicationContext(),"Data not
Inserted",Toast.LENGTH_LONG).show();
}
}
});
}
showMessage("Error","Nothing Found");
return;
}
StringBuffer buffer = new StringBuffer();
while (res.moveToNext()){
buffer.append("Id:"+res.getString(0)+"\n");
buffer.append("Name:"+res.getString(1)+"\n\n");
buffer.append("Surname:"+res.getString(2)+"\n\n");
}
showMessage("Data",buffer.toString());
}
});
# SqliteHelper
package com.example.sqliteapp;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_NAME +" (ID INTEGER PRIMARY KEY
AUTOINCREMENT,NAME TEXT,SURNAME TEXT,MARKS INTEGER)");
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
EXPERIMENT: 5
Aim: write an application that draws basic graphical primitives in the screen.
# activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
# MainActivity.java
package com.example.graphics;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Test ts=new Test(this);
setContentView(ts);
}
}
# Test.java
package com.example.graphics;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.view.View;
import androidx.annotation.RequiresApi;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint=new Paint();
paint.setColor(Color.RED);
canvas.drawRect(400,400,500,500,paint);
canvas.drawCircle(100,300,50,paint);
canvas.drawLine(200,100,500,400,paint);
}
}