SlideShare a Scribd company logo
1 of 25
Download to read offline
ANDROID COURSE
WITH JAVA
Developed by Keroles Magdy
keroles.m.yacoub@gmail.com
2019 ©
Session topics :-
• Exception and Try .. Catch ….. finally.
• Classes & Objects.
• Naming conventions.
• Access Modifiers.
• Non-Access Modifiers.
• Encapsulation.
Exception and Try .. Catch ... finally :-
• Exception, events that occur during the execution of programs that
disrupt the normal flow of instruction.
• In Java, it is an object that wraps an error event that occurred within a
method and contains:
➢ Information about the error including its type.
➢ The state of the program when the error occurred.
➢ Optionally, other custom information.
• EX:
throw new NullPointerException("demo");
Exception and Try .. Catch ... finally :-
• Exceptions have many different types of error conditions.
➢ JVM Errors:
▪ OutOfMemoryError
▪ StackOverflowError
▪ LinkageError
➢ System errors:
▪ FileNotFoundException
▪ IOException
▪ SocketTimeoutException
➢ Programming errors:
▪ NullPointerException
▪ ArrayIndexOutOfBoundsException
▪ ArithmeticException
Exception and Try .. Catch ... finally :-
Exception and Try .. Catch ... finally :-
• Try, allow programmer to check error in a block of code.
• Catch, allows programmer to define a block of code to be executed, if an
error occurs.
• Finally, statement lets you execute code, after try...catch, regardless of
the result.
• Syntax :
try { // Block of code to try
} catch(Exception e) { // Block of code to handle errors
} finally { System.out.println("The 'try catch' is finished.");
}
try and catch ….finally :-
• EX :
try {
int[] myNumbers = {1, 2, 3};
System.out.println(myNumbers[10]);
} catch (Exception e) {
System.out.println("Something went wrong.");
} finally {
System.out.println("The 'try catch' is finished.");
}
Classes & Objects :-
• Class, consist of constructor, attribute and methods.
• public class MyClass {
int x = 5;
public static void main(String[] args) {
MyClass myObj = new MyClass();
System.out.println(myObj.x);
}
}
Classes & Objects :-
• Class Attributes :
public class Student {
int age = 5;
String name = 3;
}
• Object, is created from a class.
• EX :
MyClass myObj = new MyClass();
Classes & Objects :-
• Method, is a block of code which only runs when it is called.
• Syntax :
void myMethod() {
System.out.println("I just got executed!");
}
EX :
Calling in main method :
public static void main(String[] args) {
myMethod();
}
Classes & Objects :-
• EX :
static void myMethod(String fname) {
System.out.println(fname + " Refsnes");
}
• EX :
static String myMethod(int age , String name) {
return ((5 + age)+name);
}
Classes & Objects :-
• Constructor, special method that called when an object of a class is
created. It can be used to set initial values for object attributes
• EX:
public class MyClass {
int x;
public MyClass() {
x = 5;
}
}
Classes & Objects :-
• EX:
public class MyClass {
int x;
public MyClass( int y) {
if (x==null)
x=0;
x=x+y;
}
}
Break
Naming conventions :-
• Naming convention, is a rule suggested to follow as you decide what to
name your identifiers such as class, package, variable, constant,
method,.... .
• Naming for class :
➢ The name must not contain any white spaces.
➢ The name should not start with special characters like ( &, $, _ ) .
➢ It should start with the uppercase letter.
➢ It should be a noun such as Color, Button, System, Thread, etc.
➢ Use appropriate words, instead of acronyms.
Naming conventions :-
• Naming for Interface :
➢ It should start with the uppercase letter.
➢ It should be an adjective such as Runnable, Remote, ActionListener.
➢ Use appropriate words, instead of acronyms.
• Naming for Method :
➢ It should start with lowercase letter.
➢ It should be a verb such as main(), print(), println().
➢ If the name contains multiple words, start it with a lowercase letter followed by an
uppercase letter such as actionPerformed().
Naming conventions :-
• Naming for Variable :
➢ It should start with a lowercase letter such as id, name.
➢ It should not start with the special characters like & (ampersand), $ (dollar), _
(underscore).
➢ If the name contains multiple words, start it with the lowercase letter followed by an
uppercase letter such as firstName, lastName.
➢ Avoid using one-character variables such as x, y, z.
• Naming for Package :
➢ It should be a lowercase letter such as java, lang.
➢ If the name contains multiple words, it should be separated by dots (.) such as java.util,
java.lang.
Naming conventions :-
• Naming for Constant :
➢ It should be in uppercase letters such as RED, YELLOW.
➢ If the name contains multiple words, it should be separated by an underscore(_) such
as MAX_PRIORITY.
➢ It may contain digits but not as the first letter.
• Camelcase & Pascalcase:
➢ Classes: PascalCase — class VectorImage {}
➢ Methods: camelCase — drawImage()
➢ Variables: camelCase — string newImageName
Access Modifiers :-
• Access Modifiers, controls the access level.
➢ Public, The class is accessible by any other class.
➢ Private, The code is only accessible within the declared class.
➢ Protected, The code is accessible in the same package and subclasses.
➢ Default, The code is only accessible in the same package.
Non-Access Modifiers :-
• Non-Access Modifiers, do not control access level, but provides other
functionality
➢ Static, attributes and methods belongs to the class, rather than an object.
➢ Final, attributes and methods cannot be overridden/modified.
➢ Abstract, can only be used in an abstract class and methods
➢ Transient, attributes and methods are skipped when serializing the object containing
them.
➢ Synchronized, methods can only be accessed by one thread at a time.
➢ Volatile, the value of an attribute is not cached thread-locally, and is always read from
the "main memory"
Non-Access Modifiers :-
• Final Ex:
public class MyClass {
final double PI = 3.14;
public static void main(String[] args) {
MyClass myObj = new MyClass();
myObj.PI = 25; // error
//Scanner in = new Scanner(System.in);
//myObj.PI = in.nextLine();
}
}
Non-Access Modifiers :-
• Static Ex:
static void myStaticMethod() {
System.out.println("Static methods called without creating objects");
}
public void myPublicMethod() {
System.out.println("Public methods called by creating objects");
}
Encapsulation :-
• Encapsulation, is a programming technique that binds the class members
(variables and methods) together and prevents them from being accessed
by other classes.
Variables
Methods
Class
{
variables
+
Methods
}
class
Encapsulation
Encapsulation
Encapsulation :-
EX :
public class Person {
private String name; // private = restricted access
// Getter
public String getName() {
return name;
}
// Setter
public void setName(String newName) {
this.name = newName;
}
}
the End

More Related Content

What's hot

learn Ruby in AMC Square learning
learn Ruby in AMC Square learninglearn Ruby in AMC Square learning
learn Ruby in AMC Square learning
ASIT Education
 

What's hot (20)

04. Review OOP with Java
04. Review OOP with Java04. Review OOP with Java
04. Review OOP with Java
 
Java- Nested Classes
Java- Nested ClassesJava- Nested Classes
Java- Nested Classes
 
Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2
 
Class
ClassClass
Class
 
Java OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceJava OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - Inheritance
 
Session 18 - Review Session and Attending Java Interviews
Session 18 - Review Session and Attending Java InterviewsSession 18 - Review Session and Attending Java Interviews
Session 18 - Review Session and Attending Java Interviews
 
Session 13 - Exception handling - continued
Session 13 - Exception handling - continuedSession 13 - Exception handling - continued
Session 13 - Exception handling - continued
 
Ruby objects
Ruby objectsRuby objects
Ruby objects
 
Java Programming - Polymorphism
Java Programming - PolymorphismJava Programming - Polymorphism
Java Programming - Polymorphism
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
 
Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Concept of Object-Oriented in C++
Concept of Object-Oriented in C++
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Objected-Oriented Programming with Java
Objected-Oriented Programming with JavaObjected-Oriented Programming with Java
Objected-Oriented Programming with Java
 
Session 07 - Intro to Object Oriented Programming with Java
Session 07 - Intro to Object Oriented Programming with JavaSession 07 - Intro to Object Oriented Programming with Java
Session 07 - Intro to Object Oriented Programming with Java
 
Nested classes in java
Nested classes in javaNested classes in java
Nested classes in java
 
Chap02
Chap02Chap02
Chap02
 
learn Ruby in AMC Square learning
learn Ruby in AMC Square learninglearn Ruby in AMC Square learning
learn Ruby in AMC Square learning
 
Inner class
Inner classInner class
Inner class
 
Learn Ruby 2011 - Session 4 - Objects, Oh My!
Learn Ruby 2011 - Session 4 - Objects, Oh My!Learn Ruby 2011 - Session 4 - Objects, Oh My!
Learn Ruby 2011 - Session 4 - Objects, Oh My!
 

Similar to Android course session 3 ( OOP ) part 1

Md06 advance class features
Md06 advance class featuresMd06 advance class features
Md06 advance class features
Rakesh Madugula
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
Connex
 
cs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptxcs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptx
mshanajoel6
 

Similar to Android course session 3 ( OOP ) part 1 (20)

Md06 advance class features
Md06 advance class featuresMd06 advance class features
Md06 advance class features
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
Java inheritance concept, interface, objects, extends
Java inheritance concept, interface, objects, extendsJava inheritance concept, interface, objects, extends
Java inheritance concept, interface, objects, extends
 
Core Java
Core JavaCore Java
Core Java
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
 
cs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptxcs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptx
 
RIBBUN SOFTWARE
RIBBUN SOFTWARERIBBUN SOFTWARE
RIBBUN SOFTWARE
 
Java01
Java01Java01
Java01
 
Introduction what is java
Introduction what is javaIntroduction what is java
Introduction what is java
 
Java01
Java01Java01
Java01
 
Java01
Java01Java01
Java01
 
Java01
Java01Java01
Java01
 
Pi j3.1 inheritance
Pi j3.1 inheritancePi j3.1 inheritance
Pi j3.1 inheritance
 
inheritance
inheritanceinheritance
inheritance
 
java-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbaijava-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbai
 
java-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbaijava-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbai
 
Java2
Java2Java2
Java2
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 

Recently uploaded

“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
Muhammad Subhan
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
FIDO Alliance
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc
 

Recently uploaded (20)

Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Navigating the Large Language Model choices_Ravi Daparthi
Navigating the Large Language Model choices_Ravi DaparthiNavigating the Large Language Model choices_Ravi Daparthi
Navigating the Large Language Model choices_Ravi Daparthi
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 

Android course session 3 ( OOP ) part 1

  • 1. ANDROID COURSE WITH JAVA Developed by Keroles Magdy keroles.m.yacoub@gmail.com 2019 ©
  • 2. Session topics :- • Exception and Try .. Catch ….. finally. • Classes & Objects. • Naming conventions. • Access Modifiers. • Non-Access Modifiers. • Encapsulation.
  • 3. Exception and Try .. Catch ... finally :- • Exception, events that occur during the execution of programs that disrupt the normal flow of instruction. • In Java, it is an object that wraps an error event that occurred within a method and contains: ➢ Information about the error including its type. ➢ The state of the program when the error occurred. ➢ Optionally, other custom information. • EX: throw new NullPointerException("demo");
  • 4. Exception and Try .. Catch ... finally :- • Exceptions have many different types of error conditions. ➢ JVM Errors: ▪ OutOfMemoryError ▪ StackOverflowError ▪ LinkageError ➢ System errors: ▪ FileNotFoundException ▪ IOException ▪ SocketTimeoutException ➢ Programming errors: ▪ NullPointerException ▪ ArrayIndexOutOfBoundsException ▪ ArithmeticException
  • 5. Exception and Try .. Catch ... finally :-
  • 6. Exception and Try .. Catch ... finally :- • Try, allow programmer to check error in a block of code. • Catch, allows programmer to define a block of code to be executed, if an error occurs. • Finally, statement lets you execute code, after try...catch, regardless of the result. • Syntax : try { // Block of code to try } catch(Exception e) { // Block of code to handle errors } finally { System.out.println("The 'try catch' is finished."); }
  • 7. try and catch ….finally :- • EX : try { int[] myNumbers = {1, 2, 3}; System.out.println(myNumbers[10]); } catch (Exception e) { System.out.println("Something went wrong."); } finally { System.out.println("The 'try catch' is finished."); }
  • 8. Classes & Objects :- • Class, consist of constructor, attribute and methods. • public class MyClass { int x = 5; public static void main(String[] args) { MyClass myObj = new MyClass(); System.out.println(myObj.x); } }
  • 9. Classes & Objects :- • Class Attributes : public class Student { int age = 5; String name = 3; } • Object, is created from a class. • EX : MyClass myObj = new MyClass();
  • 10. Classes & Objects :- • Method, is a block of code which only runs when it is called. • Syntax : void myMethod() { System.out.println("I just got executed!"); } EX : Calling in main method : public static void main(String[] args) { myMethod(); }
  • 11. Classes & Objects :- • EX : static void myMethod(String fname) { System.out.println(fname + " Refsnes"); } • EX : static String myMethod(int age , String name) { return ((5 + age)+name); }
  • 12. Classes & Objects :- • Constructor, special method that called when an object of a class is created. It can be used to set initial values for object attributes • EX: public class MyClass { int x; public MyClass() { x = 5; } }
  • 13. Classes & Objects :- • EX: public class MyClass { int x; public MyClass( int y) { if (x==null) x=0; x=x+y; } }
  • 14. Break
  • 15. Naming conventions :- • Naming convention, is a rule suggested to follow as you decide what to name your identifiers such as class, package, variable, constant, method,.... . • Naming for class : ➢ The name must not contain any white spaces. ➢ The name should not start with special characters like ( &, $, _ ) . ➢ It should start with the uppercase letter. ➢ It should be a noun such as Color, Button, System, Thread, etc. ➢ Use appropriate words, instead of acronyms.
  • 16. Naming conventions :- • Naming for Interface : ➢ It should start with the uppercase letter. ➢ It should be an adjective such as Runnable, Remote, ActionListener. ➢ Use appropriate words, instead of acronyms. • Naming for Method : ➢ It should start with lowercase letter. ➢ It should be a verb such as main(), print(), println(). ➢ If the name contains multiple words, start it with a lowercase letter followed by an uppercase letter such as actionPerformed().
  • 17. Naming conventions :- • Naming for Variable : ➢ It should start with a lowercase letter such as id, name. ➢ It should not start with the special characters like & (ampersand), $ (dollar), _ (underscore). ➢ If the name contains multiple words, start it with the lowercase letter followed by an uppercase letter such as firstName, lastName. ➢ Avoid using one-character variables such as x, y, z. • Naming for Package : ➢ It should be a lowercase letter such as java, lang. ➢ If the name contains multiple words, it should be separated by dots (.) such as java.util, java.lang.
  • 18. Naming conventions :- • Naming for Constant : ➢ It should be in uppercase letters such as RED, YELLOW. ➢ If the name contains multiple words, it should be separated by an underscore(_) such as MAX_PRIORITY. ➢ It may contain digits but not as the first letter. • Camelcase & Pascalcase: ➢ Classes: PascalCase — class VectorImage {} ➢ Methods: camelCase — drawImage() ➢ Variables: camelCase — string newImageName
  • 19. Access Modifiers :- • Access Modifiers, controls the access level. ➢ Public, The class is accessible by any other class. ➢ Private, The code is only accessible within the declared class. ➢ Protected, The code is accessible in the same package and subclasses. ➢ Default, The code is only accessible in the same package.
  • 20. Non-Access Modifiers :- • Non-Access Modifiers, do not control access level, but provides other functionality ➢ Static, attributes and methods belongs to the class, rather than an object. ➢ Final, attributes and methods cannot be overridden/modified. ➢ Abstract, can only be used in an abstract class and methods ➢ Transient, attributes and methods are skipped when serializing the object containing them. ➢ Synchronized, methods can only be accessed by one thread at a time. ➢ Volatile, the value of an attribute is not cached thread-locally, and is always read from the "main memory"
  • 21. Non-Access Modifiers :- • Final Ex: public class MyClass { final double PI = 3.14; public static void main(String[] args) { MyClass myObj = new MyClass(); myObj.PI = 25; // error //Scanner in = new Scanner(System.in); //myObj.PI = in.nextLine(); } }
  • 22. Non-Access Modifiers :- • Static Ex: static void myStaticMethod() { System.out.println("Static methods called without creating objects"); } public void myPublicMethod() { System.out.println("Public methods called by creating objects"); }
  • 23. Encapsulation :- • Encapsulation, is a programming technique that binds the class members (variables and methods) together and prevents them from being accessed by other classes. Variables Methods Class { variables + Methods } class Encapsulation Encapsulation
  • 24. Encapsulation :- EX : public class Person { private String name; // private = restricted access // Getter public String getName() { return name; } // Setter public void setName(String newName) { this.name = newName; } }