KEMBAR78
Java- language Lecture 5 | PDF
JAVA
FUNDAMENTALS
Eng : Hatem Abd El-Salam
Lecture 5
Agenda
 Intro to OOP
 Classes
 Constructor
 Inheritance
 Final
 Static
 Inner classes
© 2016 by Eng. Hatem Abd El-Salam
OOP
What is OOP ?
 OOP is mapping the real world to software
 OOP is a community of integrating agents called Objects
 Each Object is perform an action that is used by other objects in the community.
 All Objects are instance of a class
© 2016 by Eng. Hatem Abd El-Salam
OOP
© 2016 by Eng. Hatem Abd El-Salam
OOP
© 2016 by Eng. Hatem Abd El-Salam
OOP
© 2016 by Eng. Hatem Abd El-Salam
OOP
© 2016 by Eng. Hatem Abd El-Salam
OOP
© 2016 by Eng. Hatem Abd El-Salam
Classes
© 2016 by Eng. Hatem Abd El-Salam
Classes (Cont.)
 Think of an appropriate name for your class
• Don’t use XYZ or ant random names
 Class Name start with CAPITAL letter
 No reserved words
 No numbers or special characters
 File.java must has at least one class
 If you create two classes at the same file one of them must be public
 File.java name = public class name
© 2016 by Eng. Hatem Abd El-Salam
Classes (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Classes (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Constructor
 Constructor in java is a special type of method that is used to initialize the object.
 Java constructor : is invoked at the time of object creation.
 It constructs the values i.e. provides data for the object that is why it is known as
constructor.
Rules for creating java constructor:
There are basically two rules defined for the constructor:
• Constructor name must be same as its class name
• Constructor must have no explicit return type
© 2016 by Eng. Hatem Abd El-Salam
Constructor (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Constructor (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Constructor (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Constructor (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Inheritance
© 2016 by Eng. Hatem Abd El-Salam
Inheritance (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Inheritance (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Inheritance (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Inheritance (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Inheritance (Cont.)
Types of inheritance in java
© 2016 by Eng. Hatem Abd El-Salam
Inheritance (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Inheritance (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Final
© 2016 by Eng. Hatem Abd El-Salam
Final (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Final (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Final (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Final (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Final (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Final (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Final (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Final (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Static
 The static keyword
in java is used for memory management mainly.
We can apply java static keyword with variables, methods, blocks and nested class.
The static keyword belongs to the class than instance of the class.
 The static can be:
 variable (also known as class variable)
 method (also known as class method)
 block
 nested class
© 2016 by Eng. Hatem Abd El-Salam
Static (Cont.)
 Java static variable
 If you declare any variable as static, it is known static variable.
 The static variable can be used to refer the common property of all objects (that is
not unique for each object)
 The static variable gets memory only once in class area at the time of class loading.
Advantage of static variable
 It makes your program memory efficient (it saves memory)
© 2016 by Eng. Hatem Abd El-Salam
Static (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Static (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Static (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Static (Cont.)
 Counter without static variable
© 2016 by Eng. Hatem Abd El-Salam
Static (Cont.)
 Counter by static variable
© 2016 by Eng. Hatem Abd El-Salam
Static (Cont.)
 If you apply static keyword with any method, it is known as static method.
 A static method belongs to the class rather than object of a class.
 A static method can be invoked without the need for creating an instance of a class.
 Static method can access static data member and can change the value of it.
© 2016 by Eng. Hatem Abd El-Salam
Static (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Static (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Inner classes
© 2016 by Eng. Hatem Abd El-Salam
Inner classes (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Inner classes (Cont.)
 Types of Nested classes
 There are two types of nested classes non-static and static nested classes.
The non-static nested classes are also known as inner classes.
 Non-static nested class (inner class)
a) Member inner class
b) Annomynous inner class
c) Local inner class
 Static nested class
© 2016 by Eng. Hatem Abd El-Salam
© 2016 by Eng. Hatem Abd El-Salam
Name : Eng. Hatem Abd El-Salam
Email : Hatemabdelsalam@Hotmail.com
LinkedIn : linkedin.com/in/hatemabdelsalam
SlideShare : slideshare.net/HatemAbdElSalam
Contact Details
© 2016 by Eng. Hatem Abd El-Salam

Java- language Lecture 5