Sie sind auf Seite 1von 50

More than ever before, the world is mobile.

Of this mobile revolution, Android is one of


the top platforms. Put out by Google to compete with Apple's iOS, Android shows no
signs of slowing down. People are wanting to build the apps that run on Android. You
always hear about the success stories of apps getting bought for millions of dollars such
as Draw Something or Instagram, and now you can start the path to building your
million-dollar idea.

Remove these ads by Signing Up

Step 1: Installing Java

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.

Step 2: Downloading the Development


Environment

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!

Step 3: Installing the ADT Bundle

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!

Step 4: Running the ADT Bundle

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.

Step 5: Building your first App!

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.

Step 6: Programming your App

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.

Step 7: Creating the Device to Test Your App

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.

Step 8: Testing Your App

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!

Step 9: Thank you

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

Compiling and Running Java Programs



, byte code

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

Hello World Program


class Hello {

public static void main(String[] arguments) {


System.out.println("Hello world");
}

:
|
| | |
|

|
| |
| ,
|
public static void main |
|
, ,
( ) [] ,
|
, |
,
|
(println , ) |
|
|

Hello Program Part 2



interactive
:
user ,
user

Packages
user input input output Package
, user
respond
Artificial Intelligence
:

// 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

What are Classes?


object oriented . .
,
, , , |
.
, |
| |
define
integer declare |
, |
| object
, constructor method |
public class Cycle {
//
//

fields
cadence

public int cadence; // declare |



public int gear;
public int speed;
// constructor .
public Cycle(int startCadence, int startSpeed, int startGear) {
gear = startGear;
cadence = startCadence;

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

Why we need classes?


?
(objects ) ,


|
|

|
oriented
Abstraction ,Inheritance Polymorphism ,
, Abstraction or Polymorphism
,
(array) ya Hash

mileage 14 km / :
car[1] = " " , car[2] ="14" car[name] = " " , car[mileage] ="14" |
mileage 21 km / :

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

// enum types declaration


// definition main() routine
enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY,
SATURDAY }
enum Month { JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC }
public static void main(String[] args) {
Day tgif;
Month libra;

// Day variable declaration .


// Month variable declaration .

tgif = Day.FRIDAY;
virgo = Month.AUG;

// tgif value value assign


// month

System.out.print("Meri rashi Virgo hai, kyu ki mera janm");


System.out.println(virgo);
// output AUG
System.out.print("mein hua hai");
System.out.print("Yeh saal ka ");
System.out.print( virgo.ordinal() ); //
System.out.println("-th mahina hai.");
System.out.println("
(0 Say count kiya hai!)");
System.out.print("Isn't it nice to get to ");
System.out.println(tgif);
// Output value will be:

FRIDAY

System.out.println( tgif + " is the " + tgif.ordinal()


+ "-th day of the week.");
// You can concatenate enum values onto Strings!
}
}
output :
Meri rashi Virgo hai, kyu ki mera janm AUG mein hua hai
Yeh saal ka 9-th month of the year.(0 Say count kiya hai!)
Isn't it nice to get to FRIDAY
FRIDAY is the 5-th day of the week.

Integer Multiplication and Division


public class IntOps {

public static void main(String[] args) {


int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
int sum = a + b;
int prod = a * b;
int quot = a / b;
int rem = a % b;
System.out.println(a
System.out.println(a
System.out.println(a
System.out.println(a
System.out.println(a
}

+
+
+
+
+

"
"
"
"
"

+
*
/
%
=

"
"
"
"
"

+
+
+
+
+

b + " = " + sum);


b + " = " + prod);
b + " = " + quot);
b + " = " + rem);
quot + " * " + b + " + " + rem);

|
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

Compute the amount of interest


/**
* ( 17000) . (0.07)
*
* output |
*/
public class Interest {
public static void main(String[] args) {
/* variables declare the
variables */
//
//
//

double principal;
double rate;
double interest;
/*

*/

principal = 17000;
rate = 0.07;
interest = principal * rate;

//

principal = principal + interest;


// .
// (Note: .
// )
/* output */
System.out.print("The interest earned is $");

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
{
}

if-else loop grade


.
if else if grade
:
class IfElseUdharan {
// declaration
public static void main(String[] args) {

//

int testscore = 36; // testscore grade



char grade; // grade char
if (testscore >= 90)
grade = 'A';
} else if (testscore
grade = 'B';
} else if (testscore
grade = 'C';
} else if (testscore

// score 90

integer

A grade

>= 80) { // score 80

B grade

>= 70) { // score 70

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 ?

Using Loops in Java


|
|

|
/*************************************************************************
*
* "Hello, World" |
* .
*************************************************************************/
public class TenHelloWorlds

// (
//

public static void main(String[] args)

// ,

System.out.println("Hello, World");// (System.out)Console


(print)
// (ln)
System.out.println("Hello, World");
System.out.println("Hello, World");
System.out.println("Hello, World");
System.out.println("Hello, World");
System.out.println("Hello, World");
System.out.println("Hello, World");
System.out.println("Hello, World");
System.out.println("Hello, World");
System.out.println("Hello, World");
}
}
|
?? !!
:
public class TenHelloWorlds

// (

//
public static void main(String[] args)
{
// ,

// i 0 ,

for (int i = 0; i < 10; i++) {


// ??
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");
}
}

Introduction of While loop

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

*
*
*
*
*
*
*
*

real numbers , average |


% java Average
10.0 5.0 6.0
3.0 7.0 32.0
<Ctrl-d>
Average is 10.5

* <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

star problem in java





:
*****
****
***
**
*

: , 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");
}
}
}

Calculating time for Mathematical operation



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

System.out.print("A triangle with sides 40 and 15 has


hypotenuse ");
System.out.println(hypotenuse);
System.out.println("\nMathematically, sin(x)*sin(x) + "
+ "cos(x)*cos(x) - 1 should
be 0.");
System.out.println("Let's check this for x = 1:");
System.out.print("
sin(1)*sin(1) + cos(1)*cos(1) - 1 is
");
System.out.println( Math.sin(1)*Math.sin(1)
+ Math.cos(1)*Math.cos(1) 1 );
System.out.println("(There can be round-off errors when"
+ " computing with real
numbers!)");
System.out.print("\nHere is a random number:
System.out.println( Math.random() );

");

endTime = System.currentTimeMillis();
time = (endTime - startTime) / 1000.0;
System.out.print("\nRun time in seconds was:
System.out.println(time);
} //
} //

");

main()

class TimedComputation

What are Constructors ?


constructors
| constructors value return void | Value return
, function
return value |
Constructor :

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

return (length * breadth * height);


}
Constructor1() {
// parameters constructor
length = 10;
breadth = 10;
height = 10;
}
Constructor1(int l, int b, int h) { // parameters int l,int b int h constructor
length = l; //lenght variable mein l store kar
breadth = b;
height = h;
}
public static void main(String[] args) {
Contructor1 contructorObj1, constructorObj2;
constructorObj1 = new Contructor1();
contructorObj2 = new Contructor1(10, 20, 30);
System.out.println("Volume of Constructor1 is : " + constructorObj1.getVolume());
System.out.println("Volume of Constructor1 is : " + constructorObj2.getVolume());
}
}

Array
arrays ,

datatype . int[] c c array


datatype
integer .

:
int[] c, d;
c = new int [ 4 ];

d = new int [ 125 ];

// 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

anArray = new int[10];// integers allote


anArray[0] = 100; // initialize
anArray[1] = 200; //second initialize

anArray[2] = 300; // values


anArray[3] = 400;
anArray[4] = 500;
anArray[5] = 600;
anArray[6] = 700;
anArray[7] = 800;
anArray[8] = 900;
anArray[9] = 1000;
// arrays initialize
System.out.println("Element at index 0: " + anArray[0]);
System.out.println("Element at index 1: " + anArray[1]);
System.out.println("Element at index 2: " + anArray[2]);
System.out.println("Element at index 3: " + anArray[3]);
System.out.println("Element at index 4: " + anArray[4]);
System.out.println("Element at index 5: " + anArray[5]);
System.out.println("Element at index 6: " + anArray[6]);
System.out.println("Element at index 7: " + anArray[7]);
System.out.println("Element at index 8: " + anArray[8]);
System.out.println("Element at index 9: " + anArray[9]);
}
}

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

One Dimensional Array

/*
* =============================================================
* DemoArrays1.java: one-dimentional ays
*
*
* : Array structure datatype value
* *
* =============================================================
*/
import java.text.*;
public class DemoArrays1 {
// Constructor

method.

// declaration ,

public DemoArrays1() {};


// Define NoColums to be a "constant" .... (see use below)
public final static int NoColumns = 10;
// main method : execution .

//
public static void main ( String [] args ) {
int i;
//

// [a] single dimensional array


(5) integers
int [] iA = new int[5];
for ( i = 0; i <= 4; i = i + 1)
iA [i] = i;
// [b] iA
System.out.println("Array: iA");
for ( i = 0; i <= 4; i = i + 1) // 0


// 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"

six columns contents ...

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

System.out.println("Array: fA (formatted output)");


for ( i = 1; i <= fA.length; i = i + 1) {
// array element Format print

....

String output1 = formatOutput.format( fA [i-1] );


System.out.print(" " + output1 );
// end of ....
if (i % NoColumns == 0 || i == fA.length )
System.out.println("");
}
// [g] array
String [] saNames = { "Coronet Peak",
"Heavenly",
"Vail",
"Whistler/Blackcomb" };
System.out.println("");
System.out.println("Length of saNames = " + saNames.length );
System.out.println("");
System.out.println("Array: saNames");
for ( i = 0; i < saNames.length; i = i + 1)
System.out.println( saNames [i] );
}

Two Dimensional Arrays

matrix values array (2 Dimensional


Array) . 2 dimensional array single
dimensional array a[i] i , dimensional array a[i][j] i
j.
2- ?

, |
|
|
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];
}
}
}
|

Finding a integer in Array


/**
* A N integer , N
* -1 return N index return
* , index i value A[i] == N condition satisfy .
*/

// function ,
// integer .
static int find(int[] A, int N) {
// , values N compare
for (int index = 0; index < A.length; index++) {
if ( A[index] == N )
return index; // N has been found at this index!
}
// N
// -1 Return .

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 )

public static int abs(int x) {

// , static
// fixed , int return , abs funtion , (int x)

if (x < 0) return -x;

// argument
// x value 0 x minus "-" return

else

// x value return

return x;

// double value variable absolute value (overloading)


public static double abs(double x) {
if (x < 0) return -x;
else
return x;
}
// if else value return function

public static boolean isPrime(int N) { // function N Prime

if (N < 2) return false;


// false return x prime

for (int i = 2; i <= N/i; i++) //


if (N % i == 0) return false; // n value
prime
//
return true; //
}

Functions in java Part 2


Functions functions
|
// 90 (hypotenuse) ,
// (sides) square |
// function
public static double hypotenuse(double a, double b) { // public static

// , double datatype

// , a b function

return Math.sqrt(a*a + b*b);

// Math.sqrt function
// value square return |

}
// Harmonic series

// series function function :


public static double H(int N) {
double sum = 0.0;
for (int i = 1; i <= N; i++)
sum += 1.0 / i;
return sum;
}
// random
public static int uniform(int N) {
return (int) (Math.random() * N);
}

// 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

public String() // character |


// value NULL
public String( String value ) // bracket
public String( char[] value ) // char array
:
String s1 = new String();
String s2 = new String( "abc" );
:

// "abc" convert

String s3 = new String( s2 ); // use

char data[] = { 'a', 'b', 'c' };


String s4 = new String( data );
:
class LearnString {
public static void main(String[] args) {
String name = "Java ";
String lastname = "Uncle ";
String message = " string ko aise padte hai";
System.out.println(name + lastname + "ji " + message );
}
}

String Concatenation
concatenation | operators(-, *, /)
+
| |
|

|
|
|
/*************************************************************************
* Compilation: javac Jod.java //

* Execution: java Jod


//
*
* output
*
* % java Jod
* 1
* 121
* 1213121
* 121312141213121
* 1213121412131215121312141213121
*
*************************************************************************/
public class Jod {

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

What is package in java?


,


,

?

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

// "int" variables declaration ()



int width, height; //
// execute |
public void init() {
// Store( )
width = getSize().width;
height = getSize().height;

//
setBackground( Color.black );
}
// execute |
public void paint( Graphics g ) {
// drawing color green |
g.setColor( Color.green );
// loop

// temporary variable i declare int type


|
// "++i" ,"i=i+1" |
for ( int i = 0; i < 10; ++i ) {
// The "drawline" function :
// the x and y ,
// x and y ,
// ,
//
// 2D graphics X=0 ,Y=0
// x
// Y
g.drawLine( width, height, i * width / 10, 0 );
}
}
}

Java Swing Hello Program


// button
// "Click me". button
// Hello from Swing.
import javax.swing.*; // Swing GUI ( user interface )classes defined
import java.awt.event.*; // Event handling class define
public class HelloSwing extends JApplet implements ActionListener {
public void init() {
// method
// button
// JApplet .
// button ActionListener register
JButton bttn = new JButton("Click Me!");
bttn.addActionListener(this);
getContentPane().add(bttn);
} // init()
public void actionPerformed(ActionEvent evt) {
// method
// source
// button. method

// 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>

Simple Interest Calculation with Applet



/**
*

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>

Java Class Inheritance


define
|
,

, tyre
| pedal , |
oriented define
| , ,
|
|
|
|
| SUV , , luxury ( , ,
| SUV
)
(Sport Utitility Vehicle)
engine
oriented ( )
() |

syntax :
class Suv extends Cars {
// method SUV

}
fields methods ,
SUV |
inheritance ?
Inheritance use :
. define :
,
| Inheritance use |
. , Abstract |

|

|

Das könnte Ihnen auch gefallen