This document provides an introduction to Java programming concepts including writing a first program, using variables, data types, operators, conditional statements, loops, methods, switch statements, and arrays. It explains key Java concepts such as declaring variables to represent data, different primitive data types, using printf to output formatted strings, operator precedence and associativity, conditional if/else statements, for/while loops, defining methods with different access levels and return types, passing parameters to methods, using switch statements with cases, and declaring arrays to store multiple values. The document is intended as an overview of fundamental Java programming topics.
2. contents
Java programming By Hoshmand Kareem 2
Writing first program
using variables
Data types
Using printf
Operators
If-else
Loops
Methods
Switch
Arrays
3. Writing first program
Public class name {
Public static void main(String args [] ) {
System.out.println(“Welcome to java”);
}
}
Java programming By Hoshmand Kareem 3
4. 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
5. 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
6. 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
7. 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
8. 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
9. 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
10. 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
11. 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
12. 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
13. 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
14. 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
15. 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
16. THE END
That is all…
Thanks for watching…
Java programming By Hoshmand Kareem
16