Acadezi branded
Acadezi logo

☕ Object Oriented Programming

Unit 1: Introduction to OOP languages and Java Environment

📄 SLIDE 1 – Program
College of IT – AI

💻 What is a Program?

Program – a set of instructions written in a programming language that tells a computer what to do and how to do it.

Key Points:

  • Solves specific problems or automates tasks.
  • Programs take input, process it, and produce output.
  • Executed by the computer's CPU.
  • Programs are written using programming languages.

Program: مجموعة تعليمات تخبر الحاسوب ماذا يفعل وكيف. يحل مشاكل، يقوم بمهام، يأخذ مدخلات ويعطي مخرجات، ينفذه المعالج CPU.

📄 SLIDE 2 – Programming language

📝 Programming Language

Programming language – a formal way of writing instructions that a computer can understand and execute. It is the tool used to create the program. Defines words, symbols, and rules to write valid program statements.

Programming language: طريقة رسمية لكتابة التعليمات يفهمها الحاسوب. تحدد الكلمات والرموز والقواعد لكتابة أوامر صحيحة.

📄 SLIDE 3 – Program Development

🛠️ Program Development Phases

  1. Writing the program in a specific programming language (e.g., Java).
  2. Translating the program into a form the computer can execute (machine language).
  3. Debugging: Finding and fixing different types of errors.

١- كتابة البرنامج بلغة برمجة. ٢- ترجمته إلى لغة الآلة. ٣- تصحيح الأخطاء.

📄 SLIDE 4 – Writing the Program (source code)

📄 Source Code

Source code – a program written in a programming language. It follows the syntax and rules of the language.

  • A program that is syntactically correct is not necessarily logically (semantically) correct.
  • A program will always do what we tell it to do, not what we meant to tell it.
  • Aim for clear, maintainable, and well-structured code.

Source code: الكود المكتوب بلغة برمجة. يجب أن يتبع القواعد النحوية (syntax). الصحة النحوية لا تضمن الصحة المنطقية. البرنامج ينفذ ما نكتبه حرفياً.

📄 SLIDE 5 – Translating the Program

⚙️ Compiler vs Interpreter

Computer cannot understand source code directly. It must be translated into machine language.

CompilerInterpreter
Translates entire source code into machine code (executable file) before the program runs. Directly executes source code line by line without generating a separate machine code file.
The machine code can be saved and executed many times without recompiling. Continues translating until the first error is met.
Examples: C++, C#, Java (compiles to bytecode, then interpreted/JIT). Examples: PHP, Python.

Compiler: يترجم كل الكود إلى لغة آلة دفعة واحدة قبل التنفيذ. ينتج ملفاً تنفيذياً. أمثلة: C++, Java.

Interpreter: ينفذ الكود سطراً سطراً دون إنشاء ملف منفصل. يتوقف عند أول خطأ. أمثلة: Python, PHP.

📄 SLIDE 6 – Debugging: Finding and Fixing Errors

🐞 Types of Errors – Detailed with Examples

SYNTAX ERROR خطأ نحوي

Cause: Violation of language grammar rules. Detected by compiler.

🔹 Most common syntax errors in Java:

  • Missing semicolon at end of statement.
  • Mismatched braces/parentheses { } or ( ).
  • Using undeclared variables or misspelling variable names.
  • Incorrect case (Java is case‑sensitive: main vs Main).
  • Missing quotes around strings.

📌 Examples:

// 1. Missing semicolon System.out.println("Hello") // Error: ';' expected // 2. Mismatched braces public class Test { public static void main(String[] args) { System.out.println("Hi"); } // missing one } ? actually this is correct, but if missing: // } // error: reached end of file while parsing // 3. Undeclared variable x = 5; // Error: cannot find symbol 'x' (if not declared) // 4. Case sensitivity public static void Main(String[] args) { ... } // Error: no 'Main' method, must be 'main' // 5. Missing quotes System.out.println(Hello); // Error: cannot find symbol 'Hello' (should be "Hello")
RUNTIME ERROR خطأ تنفيذي

Cause: Program compiles but crashes during execution.

🔹 Most common runtime errors in Java:

  • ArrayIndexOutOfBoundsException – accessing index outside array length.
  • NullPointerException – calling method on null reference.
  • ArithmeticException – division by zero.
  • NumberFormatException – converting invalid string to number.
  • ClassCastException – invalid casting.

📌 Examples:

// 1. ArrayIndexOutOfBoundsException int[] arr = {1,2,3}; System.out.println(arr[5]); // Runtime error: index 5 out of bounds // 2. NullPointerException String s = null; System.out.println(s.length()); // Runtime error: cannot call length() on null // 3. ArithmeticException: division by zero int a = 10, b = 0; int result = a / b; // Runtime error: / by zero // 4. NumberFormatException String num = "abc"; int n = Integer.parseInt(num); // Runtime error: For input string "abc" // 5. ClassCastException Object obj = "Hello"; Integer num = (Integer) obj; // Runtime error: String cannot be cast to Integer
LOGIC ERROR خطأ منطقي

Cause: Program runs without crashing but produces wrong output. Hardest to detect.

🔹 Most common logic errors:

  • Wrong formula (e.g., perimeter instead of area).
  • Off-by-one errors in loops (starting from wrong index).
  • Incorrect condition in if statements.
  • Variable initialization mistakes (forgetting to initialize).

📌 Examples:

// 1. Wrong formula: calculating perimeter instead of area int length = 5, width = 3; int area = 2 * (length + width); // Logic error: gives 16, but area should be 15 // 2. Off-by-one: loop starts at 1, skipping first element int[] numbers = {1,2,3,4,5}; int sum = 0; for(int i = 1; i < numbers.length; i++) { // i starts at 1 → skips numbers[0]=1 sum += numbers[i]; } System.out.println(sum); // Output: 14 (should be 15) // 3. Incorrect condition (using > instead of <) int age = 20; if (age > 18) { // correct for adult, but if you needed age < 18 for discount, wrong System.out.println("Adult"); } // 4. Uninitialized variable used (may compile but logic error) int count; // ... some path might not initialize count System.out.println(count); // Logic error if count not properly initialized // 5. Wrong operator: using && instead of || boolean weekend = true; boolean holiday = false; if (weekend && holiday) { // should be || to allow either weekend OR holiday System.out.println("Stay home"); } else { System.out.println("Go to work"); // wrong when weekend true, holiday false }

📊 Error Type Comparison

Error TypeWhen detectedProgram behaviorCommon examples
SyntaxBy compiler (before running)Won't compileMissing semicolon, mismatched braces, undeclared variable
RuntimeDuring executionCrashes/throws exceptionArrayIndexOutOfBounds, NullPointer, division by zero
LogicAfter execution (wrong output)Runs but gives wrong resultWrong formula, off-by-one, incorrect condition

أنواع الأخطاء:

Syntax errors (أخطاء نحوية): يكتشفها المترجم. أمثلة: نسيان الفاصلة المنقوطة ;، عدم تطابق الأقواس {}، استخدام متغير غير مصرح به.

Runtime errors (أخطاء تنفيذية): تحدث أثناء التشغيل. أمثلة: الوصول لمؤشر خارج حدود المصفوفة ArrayIndexOutOfBoundsException، استدعاء دالة على كائن فارغ NullPointerException، القسمة على صفر.

Logic errors (أخطاء منطقية): البرنامج يعمل لكن النتيجة خاطئة. أمثلة: استخدام معادلة خاطئة (محيط بدل المساحة)، بدء حلقة من 1 بدلاً من 0، شرط if خاطئ.

📄 SLIDE 7 – Object-Oriented Programming

🧩 What is OOP?

Object-Oriented Programming (OOP) is a programming paradigm that models a system as a collection of objects, each representing a real-world entity with data (attributes) and behavior (methods).

Classes and objects are the two main aspects of OOP.

OOP: نموذج برمجي يعتمد على الكائنات التي تمثل كيانات حقيقية ببيانات وسلوكيات. الكلاسات والكائنات هما الأساس.

📄 SLIDE 8 – Classes and objects

📦 Class vs Object

  • Class: A template / blueprint / prototype that describes what an object will be. It defines attributes (data/properties) and methods (behaviors).
  • Object: An instance of a class. Represents real-world entities (car, dog, student) with their own attributes and behaviors.

Activity – Student class:

  • Objects (instances): a specific student named "Ahmed", "Sara".
  • Attributes: name, ID, GPA, major.
  • Methods: study(), attendClass(), submitAssignment().

Activity – Bank class:

  • Objects: a specific account (account number 12345).
  • Attributes: accountNumber, balance, ownerName.
  • Methods: deposit(), withdraw(), checkBalance().

Class: مخطط أو نموذج. Object: نسخة من الكلاس. مثال طالب: الكائنات (أحمد، سارة)، الصفات (الاسم، الرقم)، السلوكيات (يدرس، يحضر).

📄 SLIDE 9 – Benefits of OOP

✅ Benefits of OOP

  • Modularity – code organized into self-contained classes/objects.
  • Reusability (DRY – Don't Repeat Yourself) – code can be reused by creating objects from classes and using inheritance (less code, shorter development).
  • Maintainability – clear structure; easier to update, debug, and test.
  • Scalability/Extensibility – add new features/objects with minimal impact.
  • Abstraction – hide complexity; expose essential features.
  • Natural Modeling – maps well to real-world entities and relationships.

Modularity: تقسيم الكود إلى وحدات. Reusability: إعادة استخدام الكود. Maintainability: سهولة الصيانة. Scalability: قابلية التوسع. Abstraction: إخفاء التعقيد. Natural Modeling: محاكاة العالم الحقيقي.

📄 SLIDE 10 – Popular OOP languages & Why Java?

🌍 Popular OOP Languages

Java, C#, Python, C++ (supports both POP and OOP).

☕ Why Java?

  • Created by James Gosling at Sun Microsystems, officially introduced May 20, 1995.
  • Now the world's most widely used OOP language.
  • Java is everywhere: mobile apps, games, web backends, big tech (Google, Amazon, LinkedIn, Netflix, Uber, NASA), trading platforms.

Main features:

  • Simple
  • Pure Object-Oriented (almost)
  • Built-in security
  • Portability & Versatility: “Write once, run anywhere” – code written on one platform can run on any other OS (Windows, Linux, Mac) without recompiling.
  • Networked & Distributed – allows multiple computers to communicate on the same network or over the internet.

جافا لغة كائنية منتشرة. تتميز بالبساطة، الأمان، "اكتب مرة شغل في أي مكان" بفضل JVM. تستخدم في تطبيقات الهاتف، الويب، أنظمة كبرى (جوجل، أمازون، ناسا).

📄 SLIDE 11 – Java Development Phases

⚙️ Java Development – 5 Phases

  1. Edit: write source code (.java file) using an editor or IDE (Eclipse, IntelliJ, NetBeans, VS Code).
  2. Compile: Java compiler (javac) translates source code into bytecode (.class file).
  3. Load: Class loader loads .class files into memory.
  4. Verify: Bytecode verifier checks bytecodes for security and validity.
  5. Execute: JVM executes bytecodes using interpretation and JIT (Just-In-Time compilation).

١- التحرير (كتابة الكود). ٢- الترجمة إلى bytecode. ٣- تحميل الكلاسات. ٤- التحقق من bytecode. ٥- التنفيذ بواسطة JVM.

📄 SLIDE 12 – Bytecode and JVM

🔷 Bytecode & Java Virtual Machine (JVM)

  • Bytecode: platform-independent intermediate code generated by Java compiler. Saved in .class files.
  • JVM (Java Virtual Machine): part of JDK, executes bytecodes. It is a software application that simulates a computer, hiding the underlying OS and hardware.
  • JIT (Just-In-Time) compiler: translates bytecodes into native machine code at runtime for better performance.

Command examples:

javac Welcome.java → produces Welcome.class
java Welcome → runs the program

Bytecode: كود وسيط مستقل عن المنصة. JVM: آلة افتراضية تنفذ bytecode. JIT: يحول bytecode إلى لغة الآلة أثناء التنفيذ لتحسين الأداء.

📄 SLIDE 13 – JDK, JRE, JVM

📦 JDK vs JRE vs JVM

  • JVM (Java Virtual Machine): interprets or compiles bytecode into native machine code for execution.
  • JRE (Java Runtime Environment): allows Java programs to run on any device. JRE = JVM + libraries + classes.
  • JDK (Java Development Kit): used by developers to create and compile Java applications. JDK = JRE + development tools (compiler, debugger, etc.).

JVM: ينفذ bytecode. JRE: بيئة تشغيل = JVM + مكتبات. JDK: أدوات التطوير = JRE + مترجم وأدوات.

📄 SLIDE 14 – Portability in Java

🌍 Write Once, Run Anywhere

While most languages achieve portability by compiling a program for each CPU, Java provides a JVM for each platform so programmers do not have to recompile for different platforms.

Java source code → bytecode (platform independent) → JVM (platform specific) executes it.

جافا توفر JVM لكل منصة، لذا الكود المصدري يُترجم إلى bytecode مستقل، ثم JVM المخصصة للمنصة تنفذه. لا حاجة لإعادة الترجمة.

📋 COMPREHENSIVE SUMMARY

📌 Unit 1 – All key points (complete recap with errors)

  • Program: set of instructions. Programming language: formal rules.
  • Development phases: Write → Translate → Debug.
  • Compiler: whole program at once (Java, C++). Interpreter: line by line (Python).
  • Error types with examples:
    • Syntax – missing semicolon, mismatched braces, undeclared var.
    • Runtime – array index out of bounds, null pointer, division by zero.
    • Logic – wrong formula, off-by-one, incorrect condition.
  • OOP: class (blueprint) vs object (instance). Benefits: modularity, reusability, maintainability, scalability, abstraction, natural modeling.
  • Java: portable via JVM, bytecode, JDK/JRE/JVM, 5-phase execution.
  • Portability: JVM per platform, same bytecode runs everywhere.

ملخص الوحدة الأولى:

  • البرنامج: مجموعة تعليمات. لغة البرمجة: قواعد رسمية.
  • مراحل التطوير: كتابة، ترجمة (compiler/meterجم), تصحيح.
  • الأخطاء النحوية (Syntax): نسيان ;، أقواس غير متطابقة، متغير غير معلن.
  • الأخطاء التنفيذية (Runtime): الوصول لمؤشر خارج المصفوفة، استدعاء دالة على null، قسمة على صفر.
  • الأخطاء المنطقية (Logic): معادلة خاطئة (محيط بدلاً من مساحة)، بدء حلقة من 1 بدلاً من 0، شرط if خاطئ.
  • OOP: كلاس (مخطط) وكائن (نسخة). فوائد: نمطية، إعادة استخدام، سهولة صيانة، تجريد.
  • جافا: محمولة (bytecode + JVM)، JDK (أدوات تطوير)، JRE (بيئة تشغيل)، JVM (آلة افتراضية).

📘 ACADEZI – clear, detailed, bilingual, complete

نتمنى لكم التوفيق والنجاح

جميع الحقوق محفوظة ACADEZI 2026 ©