Java programming
Hoshmand kareem salih
1
An introduction to
Prepared by
contents
Java programming By Hoshmand Kareem 2
Writing first program
using variables
Data types
Using printf
Operators
If-else
Loops
Methods
Switch
Arrays
Writing first program
Public class name {
Public static void main(String args [] ) {
System.out.println(“Welcome to java”);
}
}
Java programming By Hoshmand Kareem 3
using variables
variables are used with names , they represent
data and objects like :
Int a=12;
Scanner input=new Scanner(System.in);
Input and a are variables
Java programming By Hoshmand Kareem 4
Data types
• Data just like the name are memories that holds information as
Strings, integers and floating numbers and declared with a variable
• There are different types of data
Data type declare in java
1) Integer numbers byte, short, int, and long
2) Floating point numbers float and double
3) Strings String
4) Characters char
5) Boolean boolean
Java programming By Hoshmand Kareem 5
Using printf
• The expression of Printf is used for putting data
into a String
• Type into the String %(d , f and s) where you want
to add the data , then when the String finishes
after (”) type (,name of the data)
Int x=14; String v=“java” ; float b=77.99; double n=88.9;
System.out.printf(“%d %s %f %f”,x,v,b,n);
Java programming By Hoshmand Kareem 6
Operators
• Precedence and associativity of operators
• Operators Associativity Type
• * / % left to right multiplicative
• + - left to right additive
• < <= > >= left to right relational
• == != left to right equality
• = right to left assignment
Java programming By Hoshmand Kareem 7
If-else
• conditional statements are used in java like if-else
statement
Ex) if (x>y) {
System.out.println(“x is greater than y”);
}
When the value of x goes bigger than y it prints x is
greater than y
Java programming By Hoshmand Kareem 8
Loops
• Loops are a control statements that perform
specific instructions more than one time as
long as the condition is available(true)
• Loops are so kinds like
For , while , do-while
Java programming By Hoshmand Kareem 9
Methods
• Methods are parts of the program that
includes instructions
• There are different kinds of methods that
some of them just perform instructions and
some are returning a specific data , data are
sends through parameters into a method
Java programming By Hoshmand Kareem 10
Methods
• Methods has security levels , types , names ,
parameters
• Security levels public , protected ,private
• Type void , int , double , String …
• Parameters (int x , String s ,double d)
Java programming By Hoshmand Kareem 11
Methods
• Declaring a method
Public void name (String s){
System.out.println(s);
}
Public int name (int n){
Return n*n+Math.pow(n,10);
}
Java programming By Hoshmand Kareem 12
Methods
• Declaring an object of a class , so it can run
the methods of the class its made of and send
the data through the parameter
classname name=new classname ();
name.methodname(12,”hello”,77.08);
Java programming By Hoshmand Kareem 13
switch
• Switch is used for performing different instructions in
different cases that stands on one variable or situation
Switch(x){
Case 1:
System.out.println(“one”);
Case 2:
System.out.println(“two”);
}
Java programming By Hoshmand Kareem 14
Arrays
• Array is a variable , that could be spitted into a
huge mount of indexes that each index can
hold another data
Int a []=new int [number of indexes];
a[0]=2; a[1]=3 a[2]=6;
Java programming By Hoshmand Kareem 15
THE END
That is all…
Thanks for watching…
Java programming By Hoshmand Kareem
16

An introduction to java programming

  • 1.
    Java programming Hoshmand kareemsalih 1 An introduction to Prepared by
  • 2.
    contents Java programming ByHoshmand Kareem 2 Writing first program using variables Data types Using printf Operators If-else Loops Methods Switch Arrays
  • 3.
    Writing first program Publicclass name { Public static void main(String args [] ) { System.out.println(“Welcome to java”); } } Java programming By Hoshmand Kareem 3
  • 4.
    using variables variables areused with names , they represent data and objects like : Int a=12; Scanner input=new Scanner(System.in); Input and a are variables Java programming By Hoshmand Kareem 4
  • 5.
    Data types • Datajust like the name are memories that holds information as Strings, integers and floating numbers and declared with a variable • There are different types of data Data type declare in java 1) Integer numbers byte, short, int, and long 2) Floating point numbers float and double 3) Strings String 4) Characters char 5) Boolean boolean Java programming By Hoshmand Kareem 5
  • 6.
    Using printf • Theexpression of Printf is used for putting data into a String • Type into the String %(d , f and s) where you want to add the data , then when the String finishes after (”) type (,name of the data) Int x=14; String v=“java” ; float b=77.99; double n=88.9; System.out.printf(“%d %s %f %f”,x,v,b,n); Java programming By Hoshmand Kareem 6
  • 7.
    Operators • Precedence andassociativity of operators • Operators Associativity Type • * / % left to right multiplicative • + - left to right additive • < <= > >= left to right relational • == != left to right equality • = right to left assignment Java programming By Hoshmand Kareem 7
  • 8.
    If-else • conditional statementsare used in java like if-else statement Ex) if (x>y) { System.out.println(“x is greater than y”); } When the value of x goes bigger than y it prints x is greater than y Java programming By Hoshmand Kareem 8
  • 9.
    Loops • Loops area control statements that perform specific instructions more than one time as long as the condition is available(true) • Loops are so kinds like For , while , do-while Java programming By Hoshmand Kareem 9
  • 10.
    Methods • Methods areparts of the program that includes instructions • There are different kinds of methods that some of them just perform instructions and some are returning a specific data , data are sends through parameters into a method Java programming By Hoshmand Kareem 10
  • 11.
    Methods • Methods hassecurity levels , types , names , parameters • Security levels public , protected ,private • Type void , int , double , String … • Parameters (int x , String s ,double d) Java programming By Hoshmand Kareem 11
  • 12.
    Methods • Declaring amethod Public void name (String s){ System.out.println(s); } Public int name (int n){ Return n*n+Math.pow(n,10); } Java programming By Hoshmand Kareem 12
  • 13.
    Methods • Declaring anobject of a class , so it can run the methods of the class its made of and send the data through the parameter classname name=new classname (); name.methodname(12,”hello”,77.08); Java programming By Hoshmand Kareem 13
  • 14.
    switch • Switch isused for performing different instructions in different cases that stands on one variable or situation Switch(x){ Case 1: System.out.println(“one”); Case 2: System.out.println(“two”); } Java programming By Hoshmand Kareem 14
  • 15.
    Arrays • Array isa variable , that could be spitted into a huge mount of indexes that each index can hold another data Int a []=new int [number of indexes]; a[0]=2; a[1]=3 a[2]=6; Java programming By Hoshmand Kareem 15
  • 16.
    THE END That isall… Thanks for watching… Java programming By Hoshmand Kareem 16