تعلم جافا بسهولة

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 30

:

www.albasheer.mohamed@yahoo.com


:
:
-1
Java Interpreter
-2 applet
:
:

:

}public class Main
-1
)][public static void main (String args
-2
}
-3
)";System.out.println("hellow in java
-4
{end of main method//
-5
{ end of class Main
-6
:
-1 Main
:

-2 main

-3 main
-4 ""
"" + :
)"System.out.println("hellow "+55+"in java
hellow 55 in java :
-5 main
-6 Main

-2
-3
-4

:
-1
.
;
) (.
)(public , private , product

:

-1
-2 .
): (2
:
-1
-2
-3
-4
-5
-6
-7

}public class wellCome


)][public static void main (String args
}
;)"System.out.println("hellow in java
)";System.out.println("with ATTA
{end of main method//
{ end of class Main

:
Hellow in java
With ATTA
:
-1 class welcome
-2 main
-3 main
-4 hellow in java with
ATTA
-5
-6 main
-7 class welcome






\
"

\n
\t
\r
\\
\"
:
)""\ ;Sustem.out.print("\"well\t come
:
"come

"well


3 :
-1
-2
-3 ) : (
- : :
])"[JOtionPane.showMessageDialg(null,"hellow
swing
JOptionPane
:

;1- import javax.swing.JOptionPane


{ 2- public class Main
)][3- public static void main (String args
{4-
;)"5- JOptionPane.showMessageDialog(null,"well come
};)6- System.exit (0
} 7-
:

:
-1 swing import
JOption Pane
-2
-3
-4
-5 method show MessageDialog
JOptionPane
null center by
defult

-6 import
-7 .
: :
])"[;a=JOptionPane.showInputDialog("inter number one
string
:


;1- package atta1
;2- import javax.swing.JOptionPane
{ 3-public class Main
{)][4-public static void main (String args
;)" 5- String name=JOptionPane .showInputDialog("inter your name
;)6- JOptionPane.showMessageDialog(null,"well come "+name
}} 7-
:

ok

ok
:
-1 package
-2 JOption pane
import
-3 class Main
-4 main
-5 name String

show InputDialog
name
-6 well com name
-7
: :
:

:

INTEGER

; Integer a
float
;Float b
STRING
; String s
:
:
JOption pane\\;*import javax.swing.
\\{ public class Main
\\ { )public static void main(String[] args
a =2 \\ ;Integer a =2
b =5 \\ ;Integer b=5
sum =a+b \\ ;Integer sum =a+b
;)JOptionPane.showMessageDialog(null,"the sum = "+sum
sum
\\}}
:

;import javax.swing.JOptionPane

{ public class Main

{ )public static void main(String[] args


= numb1

;String numb1,numb2
numb1=JOptionPane.showInputDialog("inter
;)" number one

= numb1

numb2=JOptionPane.showInputDialog("inter
;)" number tow

= sum

;Integer sum,n1,n2
;)n1=Integer.parseInt(numb1
;)n2=Integer.parseInt(numb2
;sum=n1+n2
JOptionPane.showMessageDialog(null,"the sum
;)is "+sum
}
}

))a // a-- & --a++ & +


1 1

++A
1
A++
1
:
{ public class Main
{ )public static void main(String[] args
;Integer a=4
a =4
;)System.out.println(a
;)System.out.println(a++

;)System.out.println("a = "+a

;)(System .out.println
;Integer b=4
;)System.out.println("b = "+b
;) System.out.println(++b
;)System.out.println("b = "+b
}}
:
4
4
5
4
5
5

): ( true & false


true || false
and , or , xor
Boolean

;Boolean a :
:
public class Main {
public static void main(String[] args) {
boolean a=true ;

boolean b=false ;

System.out.println(a&&b);
a&b
System.out.println(a||b); a||b
System.out.println(!a);
! a
System.err.println(!b);
! b
}}

:
False
True
False
True

:
(==, => ,=< , < , >)
( )
:

import javax.swing.JOptionPane ;
public class Main {
public static void main(String[] args) {
Integer n1,n2;
String num1,num2,result;
result="";
num1=JOptionPane.showInputDialog("enter number one ");
num2=JOptionPane.showInputDialog("enter number tow ");
n1=Integer.parseInt(num1);
n2=Integer.parseInt(num2);

if (n1>n2)
{
result = "number 1 is beger than number 2";}
if (n1<n2)
{
result = "number 1 is smaller than number 2";
}
if (n1==n2)
{
result = "number 1 is equal number 2";}
JOptionPane.showMessageDialog(null,result);
}}
:

SWITCH

IF
.
:
{) Switch ( vriable
Case 1:

;Statement 1
;Break
Case 2:
;Statement 2
;Break
.
.
n Case n:
n ;Statement n
;Break
Default:

;Statement default
}
switch
:


;package switchpkg
;import javax.swing.JOptionPane
{ public class Main
{ )public static void main(String[] args
;String input
input=JOptionPane.showInputDialog("inter number of
;)"month
;int a
;)a=Integer.parseInt(input

{)switch(a

case 1:
System.out.println("janouary");
break;

case 2:
System.out.println("febrouary");
break;
case 3:
System.out.println("march");
break;
case 4:
System.out.println("epril");
break;
case 5:
System.out.println("may");
break;
case 6:
System.out.println("joune");
break;
case 7:
System.out.println("joulay");
break;
case 8:
System.out.println("aougest");
break;
case 9:
System.out.println("septmber");
break;
case 10 :
System.out.println("october");
break;
case 11:
System.out.println("november");
break;
case 12:
System.out.println("december");

default:
System.out.println("the interned not true");
break;
}
}}
:

March
: (WHILE & DO WHILE)
public class Main{
public static void main (String args[]){
int sum=0 ;int i=1;
while (i<4)
4
{

sum=sum+i; + =
i++;
1
}

System.out.println(sum);
}}
:
6
Do while:

:
Do {

Statement;
}
While(condition);

public class Main {


public static void main(String args[])
{ int g ; String in;
int c=0;
int s=0;int v=0;
do {
in=JOptionPane.showInputDialog("inter gread of
student");
g=Integer.parseInt(in) ;
s=s+g;
c++;
}
while(c<10);
v=s/10;
System.out.println("the sum = "+s);
System.out.println("the average is = "+v);}}
:

run:

the sum = 900


the average is = 90

: ( FOR

WHILE

:
For() ; )( ;
{
;
}
:
4
package javaapplication40;
public class Main {
public static void main(String[] args) {
for(Integer i=1;i>5;i++) 4 1=
1
{

System.out.println("well come in Java Program with Atta");
}

}}
:
Well come in Java Program with Atta
Well come in Java Program with Atta
Well come in Java Program with Atta
Well come in Java Program with Atta

for
:

package dareeb;
public static void main(String[] args) {
for (int i=1;i<=10;i++)
for(int j=1;j<=12;j++){
System.out.println(i+ "*" +j+"= " +i*j );
}}
:
run:
1*1= 1
1*2= 2
1*3= 3
1*4= 4
1*5= 5
1*6= 6
1*7= 7
1*8= 8
1*9= 9
1*10= 10
1*11= 11
1*12= 12
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
2*11= 22
2*12= 24
3*1= 3
3*2= 6
3*3= 9
3*4= 12
3*5= 15
3*6= 18
3*7= 21
3*8= 24
3*9= 27
3*10= 30
3*11= 33
3*12= 36
4*1= 4
4*2= 8
4*3= 12
4*4= 16
4*5= 20
4*6= 24
4*7= 28
4*8= 32
4*9= 36
4*10= 40
4*11= 44
4*12= 48
5*1= 5
5*2= 10
5*3= 15
5*4= 20
5*5= 25
5*6= 30
5*7= 35
5*8= 40

5*9= 45
5*10= 50
5*11= 55
5*12= 60
6*1= 6
6*2= 12
6*3= 18
6*4= 24
6*5= 30
6*6= 36
6*7= 42
6*8= 48
6*9= 54
6*10= 60
6*11= 66
6*12= 72
7*1= 7
7*2= 14
7*3= 21
7*4= 28
7*5= 35
7*6= 42
7*7= 49
7*8= 56
7*9= 63
7*10= 70
7*11= 77
7*12= 84
8*1= 8
8*2= 16
8*3= 24
8*4= 32
8*5= 40
8*6= 48
8*7= 56

8*8= 64
8*9= 72
8*10= 80
8*11= 88
8*12= 96
9*1= 9
9*2= 18
9*3= 27
9*4= 36
9*5= 45
9*6= 54
9*7= 63
9*8= 72
9*9= 81
9*10= 90
9*11= 99
9*12= 108
10*1= 10
10*2= 20
10*3= 30
10*4= 40
10*5= 50
10*6= 60
10*7= 70
10*8= 80
10*9= 90
10*10= 100
10*11= 110
10*12= 120

BREAK

) (

:
{) (For
) ( If
; Break
; Statement

}
:
.
:
1 4
;package javaapplication43
{ public class Main
{ )public static void main(String[] args
1 for (int i=0; i<10;i++) 10
){if (i==5
) = (5
;break

;)System.out.println(i
}
}}
:
1
2
3
4
Continue
break

:
;package javaapplication43
{ public class Main
{ )public static void main(String[] args
1 for (int i=0; i<10;i++) 10
){If (i==5

;Continue
;)System.out.println(i
}}}
:
1
2
3
4
6
7
8
9
) (:
)
(.


) .( INDEX
:
) (.
:
.
:
;Int
array1 []= new int
][10

] [

[] = new

:
];Int a[]=new int [10
};Int b[]={1,6,8,9,10,5
:
for
{ public class Main
{ )public static void main(String[] args
4 ;]int array1[]=new int [4
{)for (int i=0;i<4;i++
;array1[i]=i

};)]System.out.println(array1[i
}
:
1
2
3


Float a[2]=.3


=0
Boolean = false
= 0.0

:
Boolean & double
.

public class Main {


public static void main(String[] args) {
double array2[]=new double [4];
array2[1]=.24;
array2[3]=.6;
for(int i=0;i<4;i++){
System.out.println(array2[i]);}
boolean a[]=new boolean[3];
a[0]=true;
a[2]=false;
for(int i=0;i<3;i++)
System.out.println(a[i]);
}}
:
run:
0.0
0.24
0.0
0.6
true
false
False
:

:
:

public class Main {
public static void main(String[] args) {
int element=6;

boolean a=false; false
int u[]={5,6,8,10};

for(int i=0; i<4;i++)

{
if (u[i]==element)
{
a=true; = true
System.out.println("the element search is found in "+i);

}
}
if (a==false) false =
System.out.println("your element search not found
here");
}}

:
run:
The element search is found in 1

:
;}}Int c [][]=new int {{1,50,3,9},{7,9,5,8
C[1][2] === 5
C[0][0] ===1
C[1][3] ===8

:
1
{ public class Main
{ )public static void main(String[] args
String
a[][]={{"ali","ahmed","atta"},
;}}"{"maneagement","doctor","police
;)]System.out.println(a[1][2
}}
:
RUN:
Police

) (METHOD
) (

.

:
Int NAME_OF_METHOD (argument )
{
STATEMENT ; }

CLASS MATH :
.
; CLASS_NAME . METHOD_NAME(ARGUMENT)

:
math
public class Main {
public static void main(String[] args) {
System.out.println("the squert of 9 = "+Math.sqrt(9.0));
System.out.println("the max of 9 & 10 =
"+Math.max(9,10));
System.out.println("the main of .9 & 10 =
"+Math.min(.9,10));
System.out.println("the abs of 9.6 = "+Math.abs(9.6));
System.out.println("the pow of 9 &5 = "+Math.pow(9,5));
}}
:
run:
the squirt of 9 = 3.0
the max of 9 & 10 = 10
the main of .9 & 10 = 0.9
the abs of 9.6 = 9.6
the pow of 9 &5 = 59049.0
: RANDOM
MATH
0.999 0.0
:

5
{ )public static void main(String[] args
;int face
)for (int i=1;i<6;++i
{
;)face = 1 + (int) (Math.random() * 6
;)System.out.println("the random of "+i+" = "+face
}
}}
:
run:
the random of 1 = 1
the random of 2 = 2
the random of 3 = 6
the random of 4 = 4
the random of 5 = 5
:
:
][RETURN_TYPE] [STATIC] [ACCESS_SPECIFIC
}NAME ([ARGUMENT]){METHOD_BODY
:
: ][ .
ACCESS_SPECIFIC
-1

CLASS 3 :
public-1 classes
private -2
.
product-3
.
STATIC -2
.

RETURN_TYPE-3
RETURN
VOID RETURN_TYPE
INT
NAME -4
ARGUMENT -5
.
METHOD_BODY -6 .

You might also like