Al Qalam Institute Computer Dept.
( Forth Stage )
“ Object Oriented Programming using Java “
Subject lecturer : Aya Hilal .H
[Link]. Computer Technologies 2026 – 2025
What is Java?
Java is a powerful general-purpose programming language. It is used to develop desktop and mobile
applications, big data processing, embedded systems, and so on. According to Oracle, the company
that owns Java, Java runs on 3 billion devices worldwide, which makes Java one of the most popular
programming languages.
Java is a popular programming language, created in 1995.
It is used for:
Mobile applications (specially Android apps)
Desktop applications
Web applications
Web servers and application servers
Games
Database connection
And much, much more!
2
Java JVM, JRE, JDK
What is JVM?
o JVM (Java Virtual Machine) is an abstract machine that enables your computer to run a Java
program.
o When you run the Java program, Java compiler first compiles your Java code to bytecode. Then,
the JVM translates bytecode into native machine code (set of instructions that a computer's CPU
executes directly).
o Java is a platform-independent language. It's because when you write Java code, it's ultimately
written for JVM but not your physical machine (computer). Since JVM executes the Java bytecode
which is platform-independent, Java is platform-independent.
3
Java JVM, JRE, JDK
What is JRE?
o JRE (Java Runtime Environment) is a software package that provides Java class libraries,
Java Virtual Machine (JVM), and other components that are required to run Java applications.
4
Java JVM, JRE, JDK
What is JDK?
o JDK (Java Development Kit) is a software development kit required to develop applications in Java.
When you download JDK, JRE is also downloaded with it.
o In addition to JRE, JDK also contains a number of development tools (compilers, JavaDoc, Java
Debugger, etc ).
5
Java JVM, JRE, JDK
• Relationship between JVM, JRE, and JDK.
6
Java Development Using Text pad
• Visit the following link:
[Link]
Programs that we can run java code :
Eclipse
Net bin
Visual Studio Code
Notepad ++
Text pad
7
Java Introduction
Java Syntax
• In Java, every application begins with a class name, (class name and file name should be same).
• The main method must be inside the class definition.
• The compiler executes the codes starting from the main function.
• Note: Java is case-sensitive: "MyClass" and 'myclass" has different meaning.
8
Java Comments
• Single-line Comments:
- Single-line comments start with two forward slashes (//).
- Any text between // and the end of the line is ignored by Java (will not be executed).
• Java Multi-line Comments:
- Multi-line comments start with /* and ends with */.
- Any text between /* and */ will be ignored by Java.
9
Java Variables
• Variables are containers for storing data values.
• In Java, there are different types of variables,
for example:
- String: stores text, such as "Hello". String values are surrounded by double quotes.
- int: stores integers (whole numbers), without decimals, such as 123 or -123.
- float: stores floating point numbers, with decimals, such as 19.99 or -19.99.
- char: stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes.
- Boolean: stores values with two states: true or false
10
Java Data Types
• Data types are divided into two groups:
- Primitive data types
- A primitive data type specifies the size and type of variable values, and it has no additional
methods.
- It includes byte, short, int, long, float, double, Boolean and char.
• Non-primitive data types
- Non-primitive data types are called reference types because they refer to objects.
- such as String, Arrays and Classes.
11
Primitive data types VS Non-primitive data types
• Primitive types are predefined (already defined) in Java. Nonprimitive types are created by the
programmer and is not defined by Java (except for String).
• Non-primitive types can be used to call methods to perform certain operations, while primitive
types cannot.
• A primitive type has always a value, while non-primitive types can be null.
• A primitive type starts with a lowercase letter, while non-primitive types starts with an uppercase
letter.
• The size of a primitive type depends on the data type, while nonprimitive types have all the same
size.
12
Declaring (Creating) Variables
• To create a variable, you must specify the type and assign it a value:
• Example:
13
The general rules for naming variables
• Names can contain letters, digits, underscores, and dollar signs.
• Names must begin with a letter.
• Names should start with a lowercase letter and it cannot contain whitespace.
• Names can also begin with $ and _ (but we will not use it in this tutorial).
• Names are case sensitive ("myVar" and "myvar" are different variables).
• Reserved words (like Java keywords, such as int or boolean) cannot be used as names.
14
Java Operators
• Operators are used to perform operations on variables and values.
• Java divides the operators into the following groups:
• Arithmetic operators
• Assignment operators
• Comparison operators
• Logical operators
• Java Unary Operators
• Bitwise operators
15
Arithmetic operators
• Arithmetic operators are used to perform common mathematical operations.
Operator Name Description Example
+ Addition Adds together two values x+y
- Subtraction Subtracts one value from another x-y
* Multiplication Multiplies two values x*y
/ Division Divides one value by another x/y
% Modulus Returns the division remainder x%y
++ Increment Increases the value of a variable by 1 ++ x
-- Decrement Decreases the value of a variable by 1 -- x
16
Example: Arithmetic operators
17
Java Assignment operators
• Assignment operators are used to assign values to variables
Operator Example Same As
= x=5 x= 5
+= x+=3 x=x+3
-= x -= 3 x= x – 3
*= x *= 3 x= x * 3
/= x /= 3 x=x/3
%= x% = 3 x=x%3
18
Java Assignment operators
19
Java Comparison Operators
• Comparison operators are used to compare two values.
Operator Name Example
== Equal to X == y
!= Not equal X!=y
> Greater than X>y
< Less than X<y
>= Greater than or equal to X>=y
<= Less than or equal to X<=y
20
Example: Java Comparison Operators
21
Java Logical operators
• Logical operators are used to determine the logic between variables or values:
Operator Name Description Example
Logical and Returns true if both X < 5 && x < 10
&&
statements are true
Logical or Returns true if one of the
|| X < 5 || x < 4
statements is true
Logical not Reverse the result, returns
! !(X < 5 && x < 10)
false if the result is true
22
Example: Java Logical operators
23
Java Unary operators
• Unary used with only one operand. For example, ++ is a unary operator that increases the value of a
variable by 1. That is, ++5 will return 6.
Operator Meaning
Unary plus: not necessary to use since numbers are positive
+ without using it
- Unary minus: inverts the sign of an expression
++ Increment operator: increments value by 1
-- Decrement operator: decrements value by 1
! Logical complement operator: inverts the value of a boolean.
24
Example: Java Unary operators
25
Java switch Statement
• The switch statement allows us to execute
a block of code among many alternatives.
26
Example: Java switch Statement
27
Java Arrays
• Arrays are used to store multiple values in a single variable, instead of declaring separate
variables for each value.
• To declare an array, define the variable type with square brackets:
28
Thank You
Do everything in your power.
29