Lecture 1
Lecture 1
Prepared by:
Mohamed Mabrouk
3
Grading Policy
Semester Work 15
Midterm Exam 15
Practical Exam 20
Final Exam 50
Total 100
4
Course Format
• One lecture/week
• One lab/week
• Programming Language is Java
• Mid term exam
• Project/Practical exam or both
• Final exam
5
Course Outline
Week Topics
4 1. Inheritance
2. Polymorphism
6
Course Outline
Week Topics
5 1. Exception Handling
2. Collections (Generics)
6 1. Graphical User Interface (GUI 1)
7 1. Interfaces
2. Event Handling (GUI 2)
8 Midterm exam
9 1. Design Patterns (Part 1)
10 1. Design Patterns (Part 2)
7
Lecture Outline
8
Introduction to Java Language
9
Java Language History
• 1991 - Green Project for consumer electronics market (Oak
language → Java)
• 1995 – Sun announces Java
• 1996 – JDK 1.0
• 1997 – JDK 1.1 RMI, AWT, Servlets
• 1998 – Java 1.2 Reflection, Swing, Collections
• 2004 – J2SE 1.5 (Java 5) Generics, enums
• 2014 – Java 8 Lambdas
• 2018 – Java 11 var keyword, improved garbage collection
10
Java Technology
JVM
11
Java Virtual Machine (JVM)
12
Java Runtime Environment (JRE)
• According to Oracle:
“JRE provides the libraries, the Java Virtual Machine,
and other components to run applets and
applications written in the Java programming
language.”
• JRE does not contain tools and utilities such as
compilers or debuggers for developing applets and
applications.
13
Java Development Kit(JDK)
• According to Oracle:
“The JDK is a superset of the JRE, and contains
everything that is in the JRE, plus tools such as the
compilers and debuggers necessary for
developing applets and applications.”
14
Properties of Java
• Object-oriented
• Interpreted
• Portable
• Secure and robust
• Multi-threaded
• Garbage collected
• No support for multiple inheritance
15
Hello World Application
• Write the following source code and name the file
MyClass.java
public class MyClass {
public static void main(String[] args){
System.out.println("Hello World");
}
}
javac MyClass.java
Bytecode
MyClass.class
java MyClass
JVM
17
Garbage Collection
• Memory is dynamically allocated in Java
• Deallocation is removing the objects that are no
longer referenced from memory
• Programmer responsibility à C, C++
• Might lead to memory leaks
• Garbage collector responsibility à Java, C#
• Theoretically no memory leaks
18
Introduction to Object Oriented
Programming
19
Object Oriented Thinking
20
Object Oriented Thinking
21
Class Hierarchy Example
Vehicle
22
Class Hierarchy Example
Vehicle
23
Class Hierarchy Example
Vehicle
24
Name Some Classes of Objects
25
Principles of Object Oriented Programming
26
Principles of Object Oriented Programming
• Encapsulation
27
Principles of Object Oriented Programming
• Encapsulation
• Abstraction
28
Principles of Object Oriented Programming
• Encapsulation
• Abstraction
• Inheritance
29
Principles of Object Oriented Programming
• Encapsulation
• Abstraction
• Inheritance
• Polymorphism
30
Principles of Object Oriented Programming
• Encapsulation
Never forget
• Abstraction
• Inheritance
• Polymorphism
31
Encapsulation
32
Abstraction
33
Inheritance
34
Inheritance
Vehicle
Land
Bus Car
35
Polymorphism
• Means many forms
• Same concept can have different meanings in
different contexts
• Has two forms, overloading and overriding
• Overloading is same method name with different
parameters, e.g.
int add(int num1, int num2){}
and
float add(float num1, float num2){} 36
Polymorphism
37
First Program in Java
38
Hello World Application
public class MyClass {
public static void main(String[] args){
System.out.println("Hello World");
}
}
41
Simple Calculator Application
43