Académique Documents
Professionnel Documents
Culture Documents
Android apps are written in a programming language called Java. Java is one of the most
popular programming languages in the world and helps run billions of devices. One of
the great things about java is that it is completely free to download. It was originally
created by Sun Microsystems, but was purchased by Oracle in 2010. To download java
onto your computer go to https://www.java.com/en/ and click on the "Free Java
Download" button. This will take you to a page where you can start the download. Once
you click the button "Agree and Start Free Download" a file will be downloaded. Once
the file is download, run the .exe file. When the install file opens up follow the steps to
finish the Java installation.
There are a number of ways to develop Android apps. The easiest way to get started
quickly is to use the ADT Bundle developed by Google. The ADT Bundle provides a
number of tools that are essential to building android apps.
To start go to https://developer.android.com/sdk/index.html. Once on this page click on
the button "Download the SDK ADT Bundle". Once this button is clicked check the box
agreeing to the terms and conditions and select either 32-bit or 64-bit, depending on your
computer. After you have agreed and selected your system type click on the "Download
the SDK ADT Bundle" button and the download will start. The download is a fairly
large .zip file (460 mb) so it may take ahwile. After it has completed downloading you
can move on to learn how to install it!
With the file done downloading, double-click to open it. Extract all the files to a location
on your computer. I left it the default location when I extracted. Once the file is finished
extracting click on the file. You should now see two folders named eclipse and sdk and an
application called SDK Manager. We are going to open up the environment where you
will be developing android apps so click on eclipse. You should now see multiple folders
and multiple files. Here you want to double click eclipse.exe to open the application.
With eclipse open we can now get started building our first app!
When you start up the eclipse you get a screen that asks you wear you want to save your
files. Go ahead and leave this default. It should be \path\to\folder\workspace. This is
wear all of your files and folders that you create within eclipse will be saved.
After selecting your workspace go to File -> New -> Android Application Project. This
brings up a new application window for you to fill out the specs of your app. Type "Hello
Wold" into the Application Name space. This will be the name of your application that
gets shown in the Play Store when people try to download it. When you fill out the name
space all other spaces will automatically fill out with it. When your screen looks like my
new application image click next. On the next screen leave everything how it is and click
next. On the next screen you can select your apps icon. For now, just leave it set as the
default and select next. The next screen has you select an activity. Leave Blank Activity
selected and click next. On the final screen keep everything how it is and select Finish.
After you click finish your app is now created! Next we show you how to add stuff to the
screen.
With your new app open, we now want to see how to change what the user will see. The
ADT Bundle gives us a great tool with a visual editor to create our apps. To get to this
click the activity_main.xml tab that is open. If you do not see it, in the file manager on
the left select res -> layout -> activity_main.xml. This opens the visual editor. From the
visual editor click on the smaller text "Hello world!" located on the screen. When this is
clicked a line to the right under properties highlights. Click on the text
@string/hello_world to change it. Your text has to have the @string/ in front of it though.
This is a part of the xml so that Android knows what type it is. Play around with the
visual editor for a bit. When you finish your app, go on to figure out to test it.
There are two ways that you can test your app. You can either put it on to an android
device and run it, or you can set up an emulator to test on. Since not everyone has a
device to test on we'll set up an emulator. The youtube video created by user Andr.oid
Eric shows how to create an Android Emulator using the Android Virtual Device
Manager.
Now that your have your app and you have your device to test it on it's time to put the
two together! To test your app on the emulated device you first need to start up your
emulated device. My emulated device is a Nexus One so your home screen may look
different. When your device is up and running (give it some time, it takes awhile to get
started) you then go back to eclipse and click the green play button. Once pushed, eclipse
will put your HelloWorld app onto the emulator and run it. Congratulations, you have
now created your first android application!
Thank you for following my tutorial on how to set up your computer to build your first
android application! I hope that the steps were easy to follow and that everything went
smoothly. Now that you know how to start developing apps, go out and build your
million-dollar idea!
(high level) , , , Smalltalk, ,
| | ,
, calculate , ,
, |
, ( C )
|
|
| |
| Applet
|
| .
.
, | . Java
|
|
JVM (
)
,
JVM
.
Java Basics
, 1991
,
1.0 1995
?
, ,
?
, ( )
(Objects) (Class)
Encapsulation ?
encapsulation
?
=> =>
=> JVM( ) =>
?
main()
awt
init => Start => =>Stop => destroy
html
JSP ?
JSP 1999 JSP
PHP ( )
JDK ?
Java Introduction
| |
|
class HelloWorld {
< >
}
| :
class Human {
int age;
}
| |
:
Human lucy = new Human();
|
:
= ( )
|
:
Human cg = new Human();
cg.age = 24;
// '.' declared
|
Human john = new Human();
john.age = 19;
System.out.println(cg.age); //
System.out.println(john.age); //
class Human {
int age;
public static void main(String[] args) {
Human cg = new Human();
cg.age=24;
Human john = new Human();
john.age=34;
System.out.println(cg.age);
System.out.println(john.age);
| (javac) | byte
code (platform independent) |
, , |
?
: (Java Virtual Machine). JVM
|
| byte code
| |
, JVM |
| Xyz.java
( ) |
Windows
c:/> javac Xyz.java
In Linux
% javac Xyz.java
error |
, , |
Xyz.class |
Java source code
byte code |
Windows
c:/> java Xyz.java
In Linux
% java Xyz.java
:
|
| | |
|
|
| |
| ,
|
public static void main |
|
, ,
( ) [] ,
|
, |
,
|
(println , ) |
|
|
// Helloi.java - output
// package
, package
import java.io.*;
public class Helloi { // H
// discuss
public static void main(String[] args) throws IOException {
// name declare variable
// , integer String( S
// )
String name;
// Buffer Reader declaration
BufferedReader kb = new BufferedReader(new
InputStreamReader(System.in));
// user
System.out.print("Please enter your name: ");
// name user
name = kb.readLine();
//
System.out.println("Hello World, dear " + name + "!");
System.exit(0);
}
}
,
user
fields
cadence
speed = startSpeed;
// , field ,
// ,
public void setCadence(int newValue) {
cadence = newValue;
}
public void setGear(int newValue) {
gear = newValue;
}
public void applyBrake(int decrement) {
speed -= decrement;
}
public void speedUp(int increment) {
speed += increment;
}
}
discuss
car1[2] = " ", car1[2] = "21" car1[name] = " ", car1[mileage] ="21" |
mileage 13 km / :
car2[2] = " ", car2[2] = "13" car2[name] = " Laura", car2[mileage] ="13"|
100
mileage
, 100
car2
complicated ( ) structure
attribute name and mileage
What is Enum ?
enum |
enum | enum boolean
values true false
| boolean enum |
|
enum main routine declare |
public class EnumUdaharan
tgif = Day.FRIDAY;
virgo = Month.AUG;
FRIDAY
+
+
+
+
+
"
"
"
"
"
+
*
/
%
=
"
"
"
"
"
+
+
+
+
+
|
main function define ,
|
java |
integer ka input ko a integer
|
execute |
|
program | | sum
| prod |
System.out.println use |
:
*
*
*
*
*
*
*
*
*
*
*
*
*
*
javac compile
java IntOps 1234 99 <----(value )
1234 + 99 = 1333
1234 * 99 = 122166
1234 / 99 = 12
1234 % 99 = 46
1234 = 12 * 99 + 46
% java IntOps 10 -3
10 + -3 = 7
10 * -3 = -30
10 / -3 = -3
10 % -3 = 1
10 = -3 * -3 + 1
double principal;
double rate;
double interest;
/*
*/
principal = 17000;
rate = 0.07;
interest = principal * rate;
//
System.out.println(interest);
System.out.print("The value of the investment after one year is $");
System.out.println(principal);
} // main() function
} //
class
if else loop
.
.
check
if-else loop .
.
If (condition) then
{
}
Else
{
}
if else
If ( ) then
{
}
Else
{
}
. if else if
loop .
,
:
If ( ) then
{
}
Else If ( ) then
{
}
Else
{
}
//
// score 90
integer
A grade
B grade
C grade
>= 60) { //
score 60
C grade
grade = 'D';
} else {
// 60 F grade
grade = 'F';
}
System.out.println("Grade = " + grade); // command output
}
}
output :
Grade = F
, score grade ?
// (
//
// ,
// (
//
public static void main(String[] args)
{
// ,
// i 0 ,
// ??
System.out.println("Hello, World"); // ,
}
}
, |
i
| int i = 0 ( integer value zero |
< ,
condition | i++ , i= i+ 1
,
plus condition( i < 10 ) |
public class HelloWorld {
public static void main(String[] args) {
for(int i=0;i<10;i++) {
System.out.println("Hello,World");
}
}
While .
condition false
i value |
.
While
/*************************************************************************
* Compilation: javac TwoTable.java
* Execution:
java TwoTable
*
* value values i = 1 to
10.
* While repeat
While
*
* % java TwoTable
* 2 * 1 = 2
* 2 * 2 = 4
* 2 * 3 = 6
* 2 * 4 = 8
* 2 * 5 = 10
* 2 * 6 = 12
* 2 * 7 = 14
* 2 * 8 = 16
* 2 * 9 = 18
* 2 * 10 = 20
*
*************************************************************************/
public class TwoTable {
public static void main(String[] args) {
// while
System.out.println("2
System.out.println("2
System.out.println("2
*
*
*
1 = 2");
2 = 4");
3 = 6");
// while
int i = 4;
while (i <= 10) {
System.out.print("2 * " + i + " = ");
System.out.println(2*i);
i = i + 1;
}
}
}
Fibonacci Series
50 fibonacci series |
,
fibonaaci series |
while | declare
| series |
class Fibonacci { //
public static void main (String args[]) { //
// ,
int pehlanumber = 0; // zero
int doosranumber = 1; // 1
50
while (doosranumber < 50) { //
System.out.println(doosranumber); //
int temp = doosranumber; // variable
doosranumber = doosranumber + pehlanumber; //
pehlanumber = temp; //
}
}
}
, }
|
Average
/*************************************************************************
*
* : javac Average.java
* Execution :
java Average < data.txt
*
* : StdIn.java StdOut.java
*
*
*
*
*
*
*
*
* <Ctrl-d> unix |
* <Ctrl-z> |
*
*************************************************************************/
public class Average {
// (public) ,
//
public static void main(String[] args) { // ,
|
int count = 0;
// ,
// |
double sum = 0.0;
// , double int
//
//
//
while (!StdIn.isEmpty()) {
double value = StdIn.readDouble(); //
sum += value; // ,
(instruction)
// sum = sum + value;
count++;
// = + 1 ,
// ,
}
// average
double average = sum / count; // average
// average
StdOut.println("Average is " + average); // Average is 10.5
:
*****
****
***
**
*
: , 5
4 1
: 5 ,
4 , 3
:
c:\javac Star.java
c:\java Star
:
public class Star {
public static void main(String[] args) {
for(int i =1; i<=5; i++) {
for(int j=5; j>=i;j--) {
System.out.print("*");
}
System.out.print("\n");
}
}
}
:
*
**
***
****
*****
, 3 , 4 5.
,
() :
i , j 1 i
, 5
:
c:\javac Star.java
c:\java Star
public class Star {
public static void main(String[] args) {
for(int i =1; i<=5; i++) {
for(int j=1; j<=i;j++) {
System.out.print("*");
}
System.out.print("\n");
}
}
}
hypotenuse sides square .
sin theta cos theta square 1 .
/**
* Mathematical
* .
* .
*/
public class TimedComputation {
public static void main(String[] args) {
long startTime; // , in milliseconds.
long endTime;
// , in
milliseconds.
double time;
// , in seconds.
startTime = System.currentTimeMillis();
double width, height, hypotenuse; // sides
width = 40.0;
height = 15.0;
hypotenuse = Math.sqrt( width*width + height*height ); //
// hypotenuse
");
endTime = System.currentTimeMillis();
time = (endTime - startTime) / 1000.0;
System.out.print("\nRun time in seconds was:
System.out.println(time);
} //
} //
");
main()
class TimedComputation
return
constructor
arguments
Constructor parameter( function bracket ) |
example , constructors |
public class Constructor1 { //public( access ) declaration
Constructor1
int length; // lenght variable integer type
int breadth;
int height;
public int getVolume() {
// volume function
Array
arrays ,
:
int[] c, d;
c = new int [ 4 ];
// c d declare
// c 4 elements
// array d 125 elements
byte[] b = new byte [ 100 ];
// array declare
100 elements |
array .
. integer array declare
values . values .
class ArrayDemo {
public static void main(String[] args) {
int[] anArray;
// integers
Element
Element
Element
Element
Element
Element
Element
Element
Element
Element
at
at
at
at
at
at
at
at
at
at
index
index
index
index
index
index
index
index
index
index
0:
1:
2:
3:
4:
5:
6:
7:
8:
9:
100
200
300
400
500
600
700
800
900
1000
/*
* =============================================================
* DemoArrays1.java: one-dimentional ays
*
*
* : Array structure datatype value
* *
* =============================================================
*/
import java.text.*;
public class DemoArrays1 {
// Constructor
method.
// declaration ,
// 4
System.out.println( iA [i] );
// [c] iA lenght print
System.out.println("");
System.out.println("Length of iA = " + iA.length );
// [d] Create and initialize a one dimensional array of
//
twenty floating point nos ....
float [] fA = new float[ 45 ];
for ( i = 0; i < fA.length; i = i + 1)
fA [i] = (float) i;
// [e] "fA"
System.out.println("");
System.out.println("Array: fA (standard printout)");
for ( i = 1; i <= fA.length; i = i + 1) {
System.out.print(" " + fA[i-1] );
if (i % NoColumns == 0 || i == fA.length )
System.out.println("");
}
// [f] "fA" contents six columns
DecimalFormat formatOutput = new DecimalFormat ("00.00");
System.out.println("");
....
, |
|
|
matrix 9 | value |
|
1 dimensional |
int a[];
a[1] =1;
a [2] =2; a[9]
|
| 2D |
2D , |
double[ ][ ] c = new double[N][N];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
for (int k = 0; k < N; k++) {
c[i][j] += a[i][k]*b[k][j];
}
}
}
|
return -1;
}
Functions in Java
functions |
| function |
| ,
| ,
?
|
| function |
(public) , (private, protected) |
?
|
| function
|
, +ve
prime ?
public class Functions { // Functions ,
// variable absolute value ( integer absolute value +ve )
// , static
// fixed , int return , abs funtion , (int x)
// argument
// x value 0 x minus "-" return
else
// x value return
return x;
// Math.sqrt function
// value square return |
}
// Harmonic series
// funtion
public static void drawTriangle(double x0, double y0, double x1, double y1, double x2,
double y2) {
StdDraw.line(x0, y0, x1, y1);
StdDraw.line(x1, y1, x2, y2);
StdDraw.line(x2, y2, x0, y0);
}
Strings in Java
?
. a , b , c
, abc
, |
| abc def
function |
String str = "abc";
|
char data[] = {'a', 'b', 'c'};
String str = new String(data);
declare allocate
constructor . constructor
|
http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html
|
quotes
| assignment
declare |
declare assign :
:
String str = "abc";
String language = "Java";
:
constructor
// "abc" convert
String Concatenation
concatenation | operators(-, *, /)
+
| |
|
|
|
|
/*************************************************************************
* Compilation: javac Jod.java //
// declare ,
//
public static void main(String[] args) { //
// , ,
//
//
String jod1 = "1";
// jod1 , jod1
String jod2 = jod1 + " 2 " + jod1; // jod2 jod1 concatenate()
// ,
// jod1
String jod3 = jod2 + " 3 " + jod2; // jod3 jod3
String jod4 = jod3 + " 4 " + jod3;
String jod5 = jod4 + " 5 " + jod4;
System.out.println(jod1); // jod1 ,
// ln
System.out.println(jod2);
System.out.println(jod3);
System.out.println(jod4);
System.out.println(jod5);
}
}
?
( ) TCP
TCP
java .
, :
java.lang
standard
java .io .* ( ) ,
?
( import java .io .*) io (*)
io (java /io ) jar
6 :
java.lang ,
java.util
java.io
java.math
java.nio
java.net
java.security , ,
java.sql JDBC
java.awt GUI ( )
javax.swing GUI ( )
java.applet
Java Applets
<html>
<head>
<title>Namaste Bharat</title>
</head>
<body>
<h1>Java applet ka ek example</h1>
applet ko html mein embedded karne ka tarika: <applet
code="NamasteBharat.class" height="40" width="200">
</applet><br />
</body>
</html>
.jar
|
import java.applet.*;
import java.awt.*;
public class Linedrawkaro extends Applet {
//
setBackground( Color.black );
}
// execute |
public void paint( Graphics g ) {
// drawing color green |
g.setColor( Color.green );
// loop
// button . respond
// dialog dialog
// "OK" button user
// dialog
String title = "Greetings"; // dialog title
String message = "Hello from the Swing User Interface Library.";
JOptionPane.showMessageDialog(null, message, title,
JOptionPane.INFORMATION_MESSAGE);
} // actionPerformed()
} // class HelloSwing
compile execute , html HelloSwing.html
embedded |
<html>
<head>
<title>HEllo Swing Program </title>
<body>
<APPLET CODE="HelloSwing.class" WIDTH=500 HEIGHT=80 MAYSCRIPT>
</APPLET>
</body>
</html>
/**
*
html
*
* |
*/
appcal.java
//
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//
public class appcal extends Applet implements ActionListener {
// , button1
JButton button1; // 1 ,
JButton button2; // 2 ,
JTextField text1,text2,text3,text4; // 4
JLabel label1,label2,label3,label4; // 4
JPanel p;
public void init() { //
label1=new JLabel("Principal"); // ,
label2=new JLabel("Time");
label3=new JLabel("Rate");
label4=new JLabel("Result");
button1=new JButton("I+A"); //
button2=new JButton("Interest");
text1=new JTextField(); //
text2=new JTextField();
text3=new JTextField();
text4=new JTextField();
// 0 rows ,2 column
this.setLayout(new GridLayout(0,2));
this.add(label1); // ,
this.add(text1);
this.add(label2);
this.add(text2);
this.add(label3);
this.add(text3);
this.add(label4);
this.add(text4);
this.add(button1);
this.add(button2);
button1.addActionListener(this); // listener
button2.addActionListener(this); //
}
public void actionPerformed(ActionEvent ae) {
float principal,time,rate,interest,iplusp;
principal=Float.valueOf(text1.getText()).floatValue(); //
rate=Float.valueOf(text2.getText()).floatValue(); //
time=Float.valueOf(text3.getText()).floatValue(); //
if (ae.getSource()==button2){ //
interest=principal*time*rate/100;
text4.setText(String.valueOf(interest)); // 4
}
if (ae.getSource()==button1){
iplusp=(principal*time*rate)/100+principal;
text4.setText(String.valueOf(iplusp)); // 4
}
}
} //
// simpleinterest.html
<html>
<head><Title>Simple Interest</Title></head>
<body><p>Simple Interest Calculation from Java Hindi Notes</p>
<applet Code="appinterest.class" width=200 Height=100></applet>
</body>
</html>
}
fields methods ,
SUV |
inheritance ?
Inheritance use :
. define :
,
| Inheritance use |
. , Abstract |
|
|