0% found this document useful (0 votes)
13 views

JAVA

Uploaded by

Israa Al
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

JAVA

Uploaded by

Israa Al
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 75

1

workplan
1. Introduction

2. Java Basics

3. Java Methods

4. Java Files

5. Java Lambda Expressions

2
1. Introduction
- Java is a popular programming language and is used to develop

mobile apps, web apps, desktop apps, games and much more.

3
2. Java Syntax

4
Java Variables
1. String - stores text, such as "Hello"

2. int - stores integers (without decimals ) such as 123 or -123

3. float - stores floating ( with decimals ) such as 19.99 or -19.99

4. char - stores single characters, such as 'a' or 'B'

5. boolean - stores values with two states : true or false

5
Java Variables

6
Java Data types

7
Java types casting
Type casting is when you assign a value of one primitive data type to another

type.

1. Widening Casting (automatically) - converting a smaller type to a larger

type size

2. Narrowing Casting (manually) - converting a larger type to a smaller size

type

8
Java types casting

9
Java types casting
1. Widening Casting (automatically) - converting a smaller type to a larger

10

10
Java types casting
2. Narrowing Casting (manually) - converting a larger type to a smaller size type

11

11
Java Operators
Java divides the operators into the following groups:

1. Arithmetic operators

2. Assignment operators

3. Comparison operators

4. Logical operators

5. Bitwise operators
12

12
Java Operators
1. Arithmetic operators

13

13
Java Operators
2. Assignment operators

14

14
Java Operators
2. Assignment operators

15

15
Java Operators
3. Comparison operators

16

16
Java Operators
4. Logical operators

17

17
Java Operators
5. Bitwise operators

Bitwise operators are used to performing the manipulation of individual

bits of a number

18

18
Java Operators
5. Bitwise operators

19

19
Java Operators
5. Bitwise operators - Examples

20

20
Java Operators
5. Bitwise operators - more Examples

https://www.geeksforgeeks.org/bitwise-operators-in-java/

21

21
Java Strings

22

22
Java Strings

23

23
Java Math functions

24

24
Java Math functions

25

25
Java Math functions

26

26
Java Booleans

27

27
Java Booleans

28

28
Java Conditions (If statement)

29

29
Java Conditions (If statement)

30

30
Java Conditions (If-else statement)

31

31
Java Conditions (If-else statement)

32

32
Java Conditions (If-else statement - shorthand)

33

33
Java Conditions (If-else statement - shorthand)

34

34
Java Conditions (switch statement)

35

35
Java Conditions (switch statement)

36

36
Java Loops - For

37

37
Java Loops - For

38

38
Java Loops - While

39

39
Java Loops - While

40

40
Java Loops - Do-while

41

41
Java Loops - Do-while

42

42
Java Loops - Foreach

43

43
Java Loops - Break statement

44

44
Java Loops - Continue statement

45

45
Java Arrays

46

46
Java Arrays - 1-D

47

47
Java Arrays - 1-D

48

48
Java Arrays 2-D

49

49
Java Arrays 2-D

50

50
Java ArrayList
- The difference between an array and an ArrayList in Java, is that the size

of an array cannot be modified

- While elements can be added and removed from an ArrayList whenever you

want

51

51
Java ArrayList - Add element

52

52
Java ArrayList - Example

53

53
Java ArrayList - Example

54

54
Java ArrayList - Example

55

55
Java ArrayList - Example

56

56
3. Java Methods
- A method is a block of code which only runs when it is called.

- Methods are used to perform certain actions, and they are also known

as functions.

57

57
3. Java Methods

58

58
3. Java Methods

59

59
3. Java Methods

60

60
3. Java Methods - Overloading
With method overloading, multiple methods can have the same name with

different parameters:

61

61
3. Java Methods - Overloading

62

62
3. Java Methods - Recursion

Recursion is the technique of making a function call itself.

63

63
3. Java Methods - Recursion

64

64
3. Java Methods - Recursion

• When running, the program follows these steps:


Iteration 1: 10 + sum(9)
Iteration 2: 10 + ( 9 + sum(8) )
Iteration 3: 10 + ( 9 + ( 8 + sum(7) ) )
Iteration 4: ...
Iteration 10: 10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + sum(0)
Iteration 11: 10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + 0

65

65
4. Java Files
- File handling is an important part of any application.

- Java has several methods for :

1. creating files

2. reading files

3. updating files

4. deleting files
66

66
4. Java Files - Create

67

67
4. Java Files - Write to file

68

68
4. Java Files - Read from file

69

69
4. Java Files - Delete file

70

70
5. Java Lambda Expressions
- Lambda Expressions were added in Java 8.

- A lambda expression is a short block of code which takes in parameters and

returns a value.

- similar to methods, but they do not need a name

71

71
5. Java Lambda Expressions

72

72
6. Java Exceptions
When executing Java code, different errors can occur:

1. Invalid user input

2. Device failure

3. Loss of network connection

4. Physical limitations (out-of-disk memory)

5. Code errors

6. Opening an unavailable file


73

73
6. Java Exceptions

74

74

You might also like