Updated MAD Lab File
Updated MAD Lab File
LAB FILE
1
INDEX
2 Packages in JAVA 11
4 Installation of Eclipse 19
7 Introduction of Android
2
Practical 1 : File Handling in C, C++ & JAVA.
a)File Handling in c.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define N 50
struct Student
{ char name[20];
char rollno[20];
char fathername[20];
char mothername[20];
};
main()
int v,i;
scanf("%d",&v);
FILE *p;
p=fopen("Student.txt","w");
for(i=0;i<v;i++)
scanf(" %s",&s[i].name);
scanf("%s",&s[i].rollno);
3
printf("Enter father's name: ");
scanf(" %s",&s[i].fathername);
scanf(" %s",&s[i].mothername);
scanf("%lld",&s[i].cont);
printf("\n");
fprintf(p,"Name:%s\n",s[i].name);
fprintf(p,"Rollnumber:%s\n",s[i].rollno);
fprintf(p,"father's name':%s\n",s[i].fathername);
fprintf(p,"mother's name':%s\n",s[i].mothername);
fprintf(p,"Contact Number:%lld\n",s[i].cont);
fclose(p);
FILE *p1;
p1=fopen("Student.txt","r");
char c;
while(1)
if(p1==NULL)
else
c=fgetc(p1);
4
if(c==EOF)
break;
printf("%c",c);
fclose(p1);
OUTPUT:
5
#include<fstream>
#define N 50
class Student
{ public:
char name[20];
char rollno[20];
char course[20];
char sec;
};
main()
Student s[N];
int a,i;
cin>>a;
ofstream fout;
fout.open("Student1.txt");
for(i=0;i<a;i++)
cin>>s[i].name;
cin>>s[i].rollno;
6
cin>>s[i].course;
cin>>s[i].sec;
cout<<"\n";
fout<<"Name :"<<s[i].name<<endl;
fout<<"Course :"<<s[i].course<<endl;
fout.close();
ifstream fin;
fin.open("Student1.txt");
string tp;
while(getline(fin,tp))
{ cout<<tp<<endl; }
fin.close();
OUTPUT:
7
8
c)File handling in java.
FILE WRITER
import java.util.*;
import java.io.*;
class Info
{
String name;
int roll;
}
public class A
{
public static void main(String[] args) throws IOException
{
Scanner sc = new Scanner(System.in);
Info obj = new Info();
FileWriter fw= new FileWriter("file.txt");
obj.name=sc.nextLine();
fw.write(obj.name);
fw.close();
}
}
FILE READER
import java.io.*;
import java.util.*;
public class B
{
public static void main(String[] args) throws IOException
{
9
FileReader fr=null;
try
{
fr=new FileReader("file.txt");
}catch(Exception e)
{
System.out.println("File Not Found");
}
int a;
while((a=fr.read())!=-1)
{
System.out.print((char)a);
}
fr.close();
}
}
OUTPUT:
10
11
1) java.lang: Contains language support classes(e.g classed which defines primitive data
types, math operations). This package is automatically imported
2) java.io: Contains classed for supporting input / output operations.
3) java.util: Contains utility classes which implement data structures like Linked List,
Dictionary and support ; for Date / Time operations.
4) java.applet: Contains classes for creating Applets
5) java.awt: Contain classes for implementing the components for graphical user interfaces
(like button, menus etc).
6) java.net: Contain classes for supporting networking operations.
7) java.math: multiprecision arithmetics
8) java.nio: the Non-blocking I/O framework for Java
9) java.security: key generation, encryption and decryption
10) java.sql: Java Database Connectivity (JDBC) to access databases
11) javax.swing: hierarchy of packages for platform-independent rich GUI components
12) java.beans: Contains classes related to developing beans -- components based on the
JavaBean architecture.
13) java.text: Provides classes and interfaces for handling text, dates, numbers, and
messages in a manner independent of natural languages.
14) java.rmi: Java API for remote method invocations.
15) java.time: The main API for dates, times, instants, and durations.
16) java.awt.color: provides classes for color spaces.
17) java.awt.fonts: provides classes and interface relating to fonts.
18) java.awt.image: provides classes for creating and modifiying images.
19) java.awt.datatransfer: provides interfaces and classes for transferring data between and
within applications.
20) javax.imageio: The main package of the java image I/O API.
12
Practical 3 :Case Study of NetBeans
Ubuntu 9.10:
Processor: 800MHz Intel Pentium III or equivalent
Memory: 512 MB
Disk space: 650 MB of free disk space
Installation of NetBeans
Install JDK: To use NetBeans for Java programming, you need to first install Java Development
Kit (JDK). See “JDK - How to Install”.
13
At the Welcome page of the installation wizard, click Next.
At the License agreement page, review the license agreement, click the acceptance check
box, and click Next.
At the NetBeans IDE installation page, do the following:
1. Accept the default installation directory for the NetBeans IDE or specify another
directory.
Note: The installation directory must be empty and the user profile you are using to run
the installer must have read/write permissions for this directory.
2. (Applicable only to All or Java EE bundle.) Accept the default JDK installation
to use with the NetBeans IDE or select a different installation from the drop-down
list. If the installation wizard did not find a compatible JDK installation to use
with the NetBeans IDE, your JDK is not installed in the default location. In this
case, specify the path to an installed JDK and click Next, or cancel the current
installation. After installing the required JDK version you can restart the
installation.
Note: If the JDK version is older than the recommended JDK 8, download and install the
latest JDK update from Java SE Downloads page and restart the NetBeans IDE installer.
Click Next.
If the GlassFish Server Open Source Edition 4.1.1 installation page opens, accept the default
installation directory or specify another installation location and click Next.
If you are installing Apache Tomcat, on its installation page, accept the default installation
directory or specify another installation location. Click Next.
At the Summary page, do the following:
1. Verify that the list of components to be installed is correct.
2. Select the Check for Updates check box if you want to check the Update Center
for possible updates.
3. Verify that you have adequate space on your system for the installation.
Click Install to begin the installation.
At the Setup Complete page, provide anonymous usage data if desired, and click Finish.
Use of NetBeans:
Through the NetBeans IDE build process, which relies on industry standards such as Apache
Ant, make, Maven, and rake - rather than a proprietary build process -you can easily customize
projects and add functionality. You can build, run, and deploy projects to servers outside of the
IDE.
Features of NetBeans:
14
brackets, and highlights source code syntactically and semantically. It lets you easily refactor
code, with a range of handy and powerful tools, while it also provides code templates, coding
tips, and code generators.
Project Views
The Projects window is the main entry point to your project sources. It shows a logical view of
important project Content. In addition to the Projects window, the IDE provides the Files
window, so that you can see all the files that belong to a project, and the Favorites window,
where you can add folders and files so that they can be browsed within the IDE.
15
Basic Project Concepts
Projects
In the IDE, you always work inside of a project. In addition to source files, an IDE project
contains metadata about what belongs on the classpath, how to build and run the project, and so
on. The IDE stores project information in a project folder which includes an Ant build script and
properties file that control the build and run settings, and a project.xml file that maps Ant targets
to IDE commands.
Creating a Project
To create a new project:
Choose File New Project (Ctrl-Shift-N on Windows/Cmd-Shift-N on OS X). When the New
Project wizard appears, select the right template for your project and complete the remaining
wizard steps. The project template icon can be displayed in gray, which means that this project
type has not been activated. Proceed with creating the project and this functionality will be
activated in the IDE.
The IDE contains the following standard project templates for Java and Java Web applications:
The Java and Web project categories also have free-form project templates. The free-form
templates enable you to use an existing Ant script for a project but require manual configuration
When you finish creating a project, it opens in the IDE with its logical structure displayed in the
Projects window and its file structure displayed in the Files window:
6. The Projects window is the main entry point to your project sources. It shows a logical
view of important project
7. contents such as Java packages and Web pages. You can right-click any project node to
access a popup menu of commands for building, running, and debugging the project, as
well as opening the Project Properties dialog box.
16
8. The Projects window can be opened by choosing Window > Projects (Ctrl-1 on
Windows/Cmd-1 on OS X).
9. The Files window shows a directory-based view of your projects, including files and
folders that are not displayed
10. in the Projects window. From the Files window, you can open and edit your project
configuration files, such as the
11. project & build script and properties file. You can also view build output like compiled
classes, JAR files, WAR files, and generated Javadoc documentation. The Files window
can be opened by choosing Window & Files (Ctrl-2 on Windows/Cmd -2 on OS X).
NetBeans Libraries:
NetBeans projects are already generally portable between different users, whether or not they use
the IDE. However, by default, the project build script way of referring to libraries is dependent
on factors specific to each user, particularly in the case of libraries defined in the Library
Manager dialog box.
Supported Technologies, Servers, and Mobile Platforms NetBeans IDE 8.2 supports the
following technologies and has been tested with the following application servers and mobile
platforms. If you plan to use versions other than those explicitly listed, please note that you may
encounter unpredictable IDE behavior.
Supported technologies:
Java EE 7, Java EE 6, and Java EE 5
JavaFX 2.2.x and 8
Java ME SDK 8.0
Java Card 3 SDK
Struts 1.3.10
Spring 4.0.1, 3.2.7, 2.5
Hibernate 4.2.6, 3.6.10
Issue Tracking
Bugzilla 4.4 and earlier
Jira 3.13+ and 5.0+
Node.js 4.0+
PHP 7, 5.6, 5.5, 5.4, 5.3, 5.2, 5.1
Groovy 2.1
Grails 2.3, 2.2
Apache Ant 1.9.7
Apache Maven 3.0.5 and earlier
C/C++/Fortran
17
VCS
Subversion: 1.8, 1.7, 1.6
Mercurial: 2.8.x and later
Git 1.8.х and later
Tested Drivers: NetBeans IDE 8.2 has been tested with the following databases and drivers.
18
Open Source Tools For Java
Eclipse:
Eclipse is an integrated development environment (IDE) which is used for almost every language
using Plugins. Currently, it consists of more than 150 projects covering different aspects of
software development.
Tool Features:
It is an Open source development environment that runs in the cloud.
Apart from Java, it supports other languages using plug-ins like C, C++, Perl, Python,
and JavaScript.
It has SDK for Java development tools, which in turn helps the Java developers and
supports development for Tomcat, GlassFish, and many other servers.
This tool is more popular and is widely used everywhere in organizations. It makes code
simple, easy to understand and debug.
NetBeans:
NetBeans is another IDE which is used for developing java codes. It runs on almost every
platform like Windows, Linux, Solaris, and MacOS. Like Eclipse it is also an open source
environment and can be used to develop other programming languages like C, C++, JavaScript
etc.
Features:
It is a framework that is used for the development of Java Swing desktop application.
Used for saving and loading any type of data.
Supports step by step dialogues for Wizard Framework.
Open source Integrated development tools.
Open Source Tools For Database
PostgreSQL:
PostgreSQL is an open source database that comes with features such as data indexing, user
configuration settings, data import/export, and version control. While PostgreSQL is a relational
database, it also allows creating NoSQL databases with programming languages such as Python
and JSON. Users mention that the tool has a large open source community that has built several
plugins for the tool, improving its functionality.
DBeaver:
DBeaver is an SQL client and a database administration tool. For relational databases it uses the
JDBC API to interact with databases via a JDBC driver. For other databases it uses proprietary
database drivers. It provides an editor that supports code completion and syntax highlighting.
The community edition (CE) of DBeaver is \a free and open source software that is distributed
under the Apache License.
19
Practical 4: Installation of Eclipse
1. Download the Eclipse Installer
Download Eclipse Installer from http://www.eclipse.org/downloads. Eclipse is hosted on many
mirrors around the world. Please select the one closest to you and start to download the Installer
2. Start the Eclipse Installer executable
For Windows users, after the Eclipse Installer executable has finished downloading it should be
available in your download directory. Start the Eclipse Installer executable. You may get a
security warning to run this file. If the Eclipse Foundation is the Publisher, you are good to select
Run.
For Mac and Linux users, you will still need to unzip the download to create the Installer. Start
the Installer once it is available.
3. Select the package to install
The new Eclipse Installer shows the packages available to Eclipse users. You can search for the
package you want to install or scroll through the list. Select and click on the package you want to
install.
4. Select your installation folder
Specify the folder where you want Eclipse to be installed. The default folder will be in your User
directory. Select the ‘Install’ button to begin the installation.
5. Launch Eclipse
Once the installation is complete you can now launch Eclipse. The Eclipse Installer has done it's
work. Happy coding.
20
Practical 5: Case Study on Kotlin
21
Practical 6 : Study Different Open Source Mobile Development
Tools.
1. PhoneGap:-
PhoneGap is a popular open-source mobile app development software that allows you to create
hybrid applications. With PhoneGap, the developer doesn’t necessarily need to know mobile
programming languages. Instead, they can get started with languages like CSS, HTML, and
JavaScript for app creation.
In fact, it allows you to create apps that will work for multiple platforms with a single codebase
to reach the maximum number of audience.
Features
Easily integrates with various libraries for developing the app,
Allows you to view and manage any changes in the app using PhoneGap
Operates on multiple operating systems, including iPhone, Android, and Windows
2. Flutter:
Flutter is a free mobile app development software that is best suited for hybrid apps. It is one of
the newest members in the mobile app development space and is written in C, C++, and Skia
Graphics Engine.
It is Google’s UI toolkit that enables you to create applications for mobile, web, and desktop
from a single codebase. What’s more, you don’t have to restart the application when testing your
project. It offers the Hot Reload functionality, which makes the whole process of development
stress-free and optimized.
Features
Incorporate all critical platform differences such as navigation, scrolling, icons, and fonts
Offers fully-customizable widgets to render fast development of native apps
Creates plugins using channels to be easily used by every developer
3. Ionic:
Ionic is another best free, open source mobile app development software mostly preferred for
creating hybrid apps. The best thing is that it allows you to build applications for various
platforms, including Android, iOS, and web — using a single codebase.
What’s more, it offers intuitive UI components that accelerate the app development process.
Besides, it can be deployed virtually anywhere. Ionic boasts over 120 native device features,
predefined elements, and a large community of developers.
Features
Includes interactive paradigms, mobile components, typography, and an extensible base
theme
Written in JavaScript, the program is covered by the MIT license
Allows for Cordova based app building
22
Popular technologies and ease of learning
4. Xamarin:
Xamarin is a free and open-source mobile app development application founded by Microsoft in
2011. It is a set of tools that enables developers to build apps for various operating systems,
including Windows, Android, and iOS — all in one programming language.
One of the reasons why Xamarin is quite popular is that it uses the C# programming language.
Besides, using the Xamarin Test Cloud, you can automatically test apps on around 2,000 real
mobile devices.
Features
Offers a real-time testing module to monitor and catch app errors as and when they
happen
Easily integrates with modern backend services, components, native APIs, and more
Enables you to build stunning cross-platform user interfaces
5. BuildFire:
Another best in the category of free mobile app development software is Buildfire. It offers a
robust set of tools to build apps for both Android and iOS. It is well-known for its high-end
custom development capabilities as well as an easy, intuitive DIY platform.
What’s more, it currently supports more than 10,000 apps and is flexible enough to scale as your
business starts to grow. You can’t ignore the simple and functional drag-and-drop UI either, as it
makes it easy to build the app quickly.
Features
Allows you to build custom functionality with their developer SDK
Offer an interactive intuitive app builder where no coding is required
Can be combined with any third-party API’s or pre-built integrations
6. Flego:
Felgo is a free mobile app development software that supports apps for various platforms,
including iOS, Android, desktop (Windows and Linux), and counting. Using a single codebase,
you can create an application for different operating systems.
Well, it was ranked first as the most time-saving framework, easiest to learn, and best support
system as compared to other 40 leading tools. Besides, it’s a great system to develop game apps
as it supports 3D objects too.
Features
Uses custom UI rendering to reduce the interaction between the native layer and runtime
environment
Provides a well-designed abstraction of platform-specific concepts
Supports creating both business apps and gaming apps
23
Practical 8: Case Study on Android Studio
Android Studio:
Android Studio is the official integrated development environment (IDE) for Android application
development. It is based on the IntelliJ IDEA, a Java integrated development environment for
software, and incorporates its code editing and developer tools.
Android Studio was announced on May 16, 2013 at the Google I/O conference. It was in early
access preview stage starting from version 0.1 in May 2013, then entered beta stage starting from
version 0.8 which was released in June 2014
MAC
Linux
1. So let's launch Android Studio.exe, Make sure before launch Android Studio, Our
Machine should required installed Java JDK.
2. Once you launched Android Studio, its time to mention JDK7 path or later
version in android studio installer.
24
3. Then you need to check the components, which are required to create
applications, you have to select from options like Android Studio, Android
SDK, Android Virtual Machine and performance (Intel chip) etc.
4. Then you need to specify the location of local machine path for Android studio
and Android SDK.
5. Then need to specify the ram space for Android emulator by default it would take
512MB of local machine RAM.
6. At final stage, it would extract SDK packages into our local machine, it would
take a while time to finish the task and would take 2626MB of Hard disk space.
7. After done all above steps perfectly, you must get finish button and it gonna be
open android studio project with Welcome to android studio message
8. You can start your application development by calling start a new android studio
project. in a new installation frame should ask Application name, package
information and location of the project
25
Language Supported by Android Studio
Android Studio supports all the same programming languages of IntelliJ (and CLion) e.g. Java, C++,
and more with extensions, such as Go; and Android Studio 3.0 or later supports Kotlin and "all Java
7 language features and a subset of Java 8 language features that vary by platform version. External
projects backport some Java 9 features. While IntelliJ that Android Studio is built on supports all
released Java versions, and Java 12, it's not clear to what level Android Studio supports Java
versions up to Java 12 (the documentation mentions partial Java 8 support)
It is purpose built for Android to accelerate your development and help you build the highest-quality
apps for every Android device. It is best platform where you can design and code your android app.
Project Structure
Each project in Android Studio contains one or more modules with source code files and resource
files. Types of modules include:
Android app modules
Library modules
Google App Engine modules
26
Practical 9 : Steps to install Android Studio
27
Practical 10 : Develop an Application that uses GUI Components,
Font and Colors.
<TextView android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:gravity="center"
android:text="Hello World!"
android:textSize="25sp"
android:textStyle="bold" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:gravity="center"
android:text="Change font size"
android:textSize="25sp" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:gravity="center"
android:text="Change color"
android:textSize="25sp" />
</LinearLayout>
28
Code for MainActivity.java:
package com.example.exno1;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity
{
int ch=1; float font=30;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView t= (TextView) findViewById(R.id.textView);
Button b1= (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
29
case 4:
t.setTextColor(Color.CYAN);
break;
case 5:
t.setTextColor(Color.YELLOW);
break;
case 6:
t.setTextColor(Color.MAGENTA); break;
}
ch++;
if (ch == 7)
ch = 1;
}
});
}
}
OUTPUT:
30
Practical 11 : Develop an Android Application for Layout Managers
& Event Listeners
Code for Activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:text="Details Form"
android:textSize="25sp"
android:gravity="center"/>
</LinearLayout>
<GridLayout
android:id="@+id/gridLayout"
android:layout_width="match_parent"
31
android:layout_height="match_parent"
android:layout_marginTop="100dp"
android:layout_marginBottom="200dp"
android:columnCount="2"
android:rowCount="3">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_row="0"
android:layout_column="0"
android:text="Name"
android:textSize="20sp"
android:gravity="center"/>
<Edit Text
andr oid:id="@+
id/editText"
andr oid:layout_
width="wra p_content"
andr oid:layout_
height="wra p_content"
andr oid:layout_
margin="10 dp"
andr oid:layout_r
ow="0"
32
android:layout_column="1"
android:ems="10"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_row="1"
android:layout_column="0"
android:text="Reg.No"
android:textSize="20sp"
android:gravity="center"/>
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_row="1"
android:layout_column="1"
android:inputType="number"
android:ems="10"/>
<TextView
android:id="@+id/textView3"
33
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_row="2"
android:layout_column="0"
android:text="Dept"
android:textSize="20sp"
android:gravity="center"/>
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_row="2"
android:layout_column="1"
android:spinnerMode="dropdown"/>
</GridLayout>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginBottom="150dp"
34
android:text="Submit"/>
</RelativeLayout>
35
Code for Activity_second.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.devang.exno2.SecondActivity"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="New Text"
android:textSize="30sp"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="New Text"
android:textSize="30sp"/>
36
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="New Text"
android:textSize="30sp"/>
</LinearLayout>
37
Code for MainActivity.java:
package com.example.exno2;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
EditText e1,e2;
Button bt;
Spinner s;
String [] dept_array={"CSE","ECE","IT","Mech","Civil"};
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
38
e2= (EditText) findViewById(R.id.editText2);
//Creating Adapter for Spinner for adapting the data from array to Spinner
s.setAdapter(adapter);
bt.setOnClickListener(new View.OnClickListener() {
@Override
name=e1.getText().toString();
reg=e2.getText().toString();
dept=s.getSelectedItem().toString();
i.putExtra("name_key", name);
i.putExtra("reg_key",reg);
i.putExtra("dept_key", dept);
startActivity(i);
}
});
}}
39
Code for SecondActivity.java:
package com.example.exno2;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
TextView t1,t2,t3;
String name,reg,dept;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Intent i = getIntent();
//Getting the Values from First Activity using the Intent received
name=i.getStringExtra("name_key");
reg=i.getStringExtra("reg_key");
dept=i.getStringExtra("dept_key");
t1.setText(name);
t2.setText(reg);
40
t3.setText(dept);
}
OUTPUT:
41
Practical 12 : Develop an Android application for native Calculator
Code for Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp">
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal"
android:textSize="20sp" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
42
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp">
<Button
android:id="@+id/Add"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+"
android:textSize="30sp"/>
<Button
android:id="@+id/Sub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-"
android:textSize="30sp"/>
<Button
android:id="@+id/Mul"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="*"
android:textSize="30sp"/>
<Button
android:id="@+id/Div"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
43
android:text="/"
android:textSize="30sp"/>
</LinearLayout>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Answer is"
android:textSize="30sp"
android:gravity="center"/>
</LinearLayout>
44
Code for MainActivity.java:
package com.example.devang.exno3;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements OnClickListener
{
//Defining the Views
EditText Num1;
EditText Num2;
Button Add;
Button Sub;
Button Mul;
Button Div;
TextView Result;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Referring the Views
Num1 = (EditText) findViewById(R.id.editText1);
Num2 = (EditText) findViewById(R.id.editText2);
Add = (Button) findViewById(R.id.Add);
Sub = (Button) findViewById(R.id.Sub);
45
Mul = (Button) findViewById(R.id.Mul);
Div = (Button) findViewById(R.id.Div);
Result = (TextView) findViewById(R.id.textView);
// set a listener
Add.setOnClickListener(this);
Sub.setOnClickListener(this);
Mul.setOnClickListener(this);
Div.setOnClickListener(this);
}
@Override
public void onClick (View v)
{
float num1 = 0;
float num2 = 0;
float result = 0;
String oper = "";
// check if the fields are empty
if (TextUtils.isEmpty(Num1.getText().toString()) || TextUtils.isEmpty(Num2.getText().toString()))
return;
// read EditText and fill variables with numbers
num1 = Float.parseFloat(Num1.getText().toString());
num2 = Float.parseFloat(Num2.getText().toString());
// defines the button that has been clicked and performs the corresponding operation
// write operation into oper, we will use it later for output
switch (v.getId())
{
case R.id.Add:
oper = "+";
result = num1 + num2;
break;
46
case R.id.Sub:
oper = "-";
result = num1 - num2;
break;
case R.id.Mul:
oper = "*";
result = num1 * num2;
break;
case R.id.Div:
oper = "/";
result = num1 / num2;
break;
default:
break;
}
// form the output line
Result.setText(num1 + " " + oper + " " + num2 + " = " + result);
}
}
OUTPUT:
47
Practical 13 : Develop an Android application that draws basic
Graphical Primitives on the Screen
Code for Activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView" />
</RelativeLayout>
48
Code for MainActivity.java:
package com.example.exno4;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.ImageView;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Creating a Bitmap
i.setBackgroundDrawable(new BitmapDrawable(bg));
//Creating the Paint Object and set its color & TextSize
49
paint.setColor(Color.BLUE);
paint.setTextSize(50);
OUTPUT:
50
Practical 14 : Develop an Android application that makes use of
Database
Code for Activity_main.xml:
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="50dp"
android:layout_y="20dp"
android:text="Student Details"
android:textSize="30sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="110dp"
android:text="Enter Rollno:"
android:textSize="20sp" />
<EditText
android:id="@+id/Rollno"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="175dp"
51
android:layout_y="100dp"
android:inputType="number"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="160dp"
android:text="Enter Name:"
android:textSize="20sp" />
<EditText
android:id="@+id/Name"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="175dp"
android:layout_y="150dp"
android:inputType="text"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="210dp"
android:text="Enter Marks:"
android:textSize="20sp" />
<EditText
52
android:id="@+id/Marks"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="175dp"
android:layout_y="200dp"
android:inputType="number"
android:textSize="20sp" />
<Button
android:id="@+id/Insert"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="25dp"
android:layout_y="300dp"
android:text="Insert"
android:textSize="30dp" />
<Button
android:id="@+id/Delete"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="200dp"
android:layout_y="300dp"
android:text="Delete"
android:textSize="30dp" />
<Button
android:id="@+id/Update"
53
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="25dp"
android:layout_y="400dp"
android:text="Update"
android:textSize="30dp" />
<Button
android:id="@+id/View"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="200dp"
android:layout_y="400dp"
android:text="View"
android:textSize="30dp" />
<Button
android:id="@+id/ViewAll"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_x="100dp"
android:layout_y="500dp"
android:text="View All"
android:textSize="30dp" />
</AbsoluteLayout>
package com.example.exno5;
import android.app.Activity;
54
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
EditText Rollno,Name,Marks;
Button Insert,Delete,Update,View,ViewAll;
SQLiteDatabase db;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Rollno=(EditText)findViewById(R.id.Rollno);
Name=(EditText)findViewById(R.id.Name);
Marks=(EditText)findViewById(R.id.Marks);
Insert=(Button)findViewById(R.id.Insert);
Delete=(Button)findViewById(R.id.Delete);
Update=(Button)findViewById(R.id.Update);
55
View=(Button)findViewById(R.id.View);
ViewAll=(Button)findViewById(R.id.ViewAll);
Insert.setOnClickListener(this);
Delete.setOnClickListener(this);
Update.setOnClickListener(this);
View.setOnClickListener(this);
ViewAll.setOnClickListener(this);
if(view==Insert)
if(Rollno.getText().toString().trim().length()==0||
Name.getText().toString().trim().length()==0||
Marks.getText().toString().trim().length()==0)
return;
"','"+Marks.getText()+"');");
56
showMessage("Success", "Record added");
clearText();
if(view==Delete)
if(Rollno.getText().toString().trim().length()==0)
return;
if(c.moveToFirst())
else
clearText();
if(view==Update)
57
{
if(Rollno.getText().toString().trim().length()==0)
return;
if(c.moveToFirst()) {
else {
clearText();
if(view==View)
if(Rollno.getText().toString().trim().length()==0)
58
return;
if(c.moveToFirst())
Name.setText(c.getString(1));
Marks.setText(c.getString(2));
else
clearText();
if(view==ViewAll)
if(c.getCount()==0)
return;
while(c.moveToNext())
59
buffer.append("Rollno: "+c.getString(0)+"\n");
buffer.append("Name: "+c.getString(1)+"\n");
buffer.append("Marks: "+c.getString(2)+"\n\n");
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(message);
builder.show();
Rollno.setText("");
Name.setText("");
Marks.setText("");
Rollno.requestFocus();
60
OUTPUT:
61
62
Practical 15 : Develop an Android application that creates Alarm
Clock
Code for Activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="20dp"
android:checked="false"
android:onClick="OnToggleClicked" />
</LinearLayout>
63
Code for AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.exno11" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<intent-filter>
</intent-filter>
</activity>
</receiver>
</application>
</manifest>
64
Code for MainActivity.java:
package com.example.exno11;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TimePicker;
import android.widget.Toast;
import android.widget.ToggleButton;
import java.util.Calendar;
TimePicker alarmTimePicker;
PendingIntent pendingIntent;
AlarmManager alarmManager;
@Override
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
65
{
long time;
{
calendar.set(Calendar.HOUR_OF_DAY, alarmTimePicker.getCurrentHour());
calendar.set(Calendar.MINUTE, alarmTimePicker.getCurrentMinute());
time=(calendar.getTimeInMillis()-(calendar.getTimeInMillis()%60000));
if(System.currentTimeMillis()>time)
{
if (calendar.AM_PM == 0)
else
}
}
else
{
alarmManager.cancel(pendingIntent);
}
}}
66
Code for AlarmReceiver.java:
package com.example.exno11;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.widget.Toast;
@Override
{
{
alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
}
ringtone.play();
}
67
OUTPUT:
68