SlideShare a Scribd company logo
1 of 46
    Module 2   Object-Oriented Programming
  Objectives   •  Define modeling concepts: abstraction, encapsulation. •  Define class, member, attribute, method, constructor  and  package   •  Invoke a method on a particular object. •  In a Java program, identify the following: The package statement.  The import statements.  Classes, methods, and attributes.  Constructors.  •   Use the Java API online documentation
Abstraction An essential element of object oriented language is abstraction. Humans manage the complexity through abstraction. For example People do not think of car as a set of tens of thousand of individual  parts. They think of it as a well defined object with its own unique  behavior. They can ignore the details of how the engine, transmission  and braking systems work. Powerful way to manage the abstraction is through the use of  hierarchical classifications.
From the outside, the car is a single object.  Once inside you see that the car consist of several subsystems:  steering, brakes, sound system, seat belts ,cellular system and so on.  In turn each of these subsystem is made up of more specialized units. For example sound system consist of a radio, a CD player and a tape  player. The point is you manage the complexity of car through the use of  hierarchical abstraction.
Hierarchical abstraction of complex systems can also be  applied to computer programs.  The data from program can be transformed by abstraction into its  component objects.  Each object describe its own unique behavior.We can treat these  objects as concrete entities that respond to message telling them to  do something.
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object]
Creating Objects This statement creates a new Rectangle object from the Rectangle  class. Rectangle rect = new Rectangle();  This single statement performs three actions:  Declaration : Rectangle rect is a variable declaration that declares  to the compiler that the name rect will be used to refer to a Rectangle  object. Instantiation : new is a Java operator that creates the new object  Initialization : Rectangle() is a call to Rectangle's constructor,  which initializes the object.
Using Objects   Once you've created an object, you probably want to use it  for something.  You may need information from it, want to change its state, or have  it perform some action.  Objects give you two ways to do these things:  1.Manipulate or inspect its variables .  area = rect.height * rect.width;  2.Call its methods.   rect.move(15, 37);
Cleaning Up Unused Objects   Java allows you to create as many objects as you want  and you never have to worry about destroying them. The Java runtime  environment deletes objects when it determines that they are no longer  being used. This process is called  garbage collection. An object is eligible for garbage collection when there are no more  references to that object. The Java platform has a garbage collector that periodically frees  the memory used by objects that are no longer needed.   The garbage collector runs in a low-priority thread
Finalization Before an object gets garbage-collected, the garbage collector  gives the object an opportunity to clean up after itself through a call to  the object's finalize method. This process is known as  finalization .   During finalization, an object may wish to free system resources  such as files and sockets or to drop references to other objects so  that they in turn become eligible for garbage collection.
[object Object],[object Object],[object Object],[object Object]
Inheritanc e I nheritance  is a  mechanism  that enables one class to inherit  all of the behaviour and attributes of another class.   For example, mountain bikes, road bikes, are all kinds of bicycles. Mountain bikes, road bikes are all subclasses of the bicycle class.  Similarly, the bicycle class is the superclass of mountain bikes,  road bikes. Each subclass inherits state from the superclass.   Mountain bikes, road bikes share some states: cadence, speed, and  the like. Also, each subclass inherits methods from the superclass.  Example  inheritance.java
[object Object],[object Object],[object Object],[object Object],[object Object]
Encapsulation in Java In Java the basis of encapsulation is the class. Since the purpose of a class is to encapsulate complexity,  there are mechanisms for hiding the complexity of the  implementation inside the class. Each method or variable in a class may be marked private or public.
P olymorphism Polymorphism is something like  one name, many forms .  Polymorphism manifests itself in Java in the form of  multiple methods having the same name.  In some cases, multiple methods have the same name, but  different formal argument lists( overloaded methods) Example overload.java In other cases, multiple methods have the same name, same  return type, and same formal argument list  (overridden methods) .   Example override.java
Interface Interface is a device or a system that unrelated entities use  to interact.  Remote control is an interface between you and a television .   T he English language is an interface between two people.  Use an interface to define a behavior that can be  implemented by any class. So interface is a collection  of methods that indicate a class has some behaviour  in addition to what it inherits from its superclass.
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Interface   •  Variables  declared inside of interface declarations  are implicitly public,  final   and  static   •  They must also   be initialized with a constant value   •  All methods are implicitly  public and abstract.   •  Interface methods cannot be marked final, strictfp or native. •  An interface can extend one or more other interfaces. •  An interface cannot implement another interface or class. Example  Callback.java, Client.java
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The following interface method declarations won't compile: final void bounce(); // final and abstract can never be used   // together, and abstract is implied static void bounce(); // interfaces define instance methods private void bounce(); // interface methods are always public protected void bounce(); // (same as above)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Default Constructor •  There is always at least one constructor in every class •  If the writer does not supply any constructors, the default constructor will be present automatically The default constructor takes no arguments  The default constructor has no body  •  Enables you to create object instances with  new Xxx()without having to write a constructor   
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Packages •  Packages help manage large software systems •  Packages can contain classes and sub-packages •  Basic syntax of the package statement: <package_declaration>  ::= package  <top_pkg_name>[.<sub_pkg_name>].*; Example:  package  shipping.reports.Web; •  Specify the package declaration at the beginning of the  source file
Packages •  Only one package declaration per source file •  If no package is declared, then the class &quot;belongs&quot; to  the default package  •  Package names must be hierarchical and separated by  dot
The import Statement •  Basic syntax of the import statement: <import_declaration> ::= import <pkg_name>[.<sub_pkg_name>]*.<class_name | *>; Examples: import  shipping.domain.*; import  java.util.List; import  java.io.*; •  Precedes all class declarations  •  Tells the compiler where to find classes to use  
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
 

More Related Content

What's hot

Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP conceptsAhmed Farag
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteTushar B Kute
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and objectFajar Baskoro
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introductionSohanur63
 
Classes and objects
Classes and objectsClasses and objects
Classes and objectsAnil Kumar
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaCPD INDIA
 
Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaObject Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaGlenn Guden
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programmingNeelesh Shukla
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examplesbindur87
 
Oop concepts classes_objects
Oop concepts classes_objectsOop concepts classes_objects
Oop concepts classes_objectsWilliam Olivier
 

What's hot (20)

Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP concepts
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B Kute
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and object
 
Oops Concept Java
Oops Concept JavaOops Concept Java
Oops Concept Java
 
Java Notes
Java NotesJava Notes
Java Notes
 
CLASS & OBJECT IN JAVA
CLASS & OBJECT  IN JAVACLASS & OBJECT  IN JAVA
CLASS & OBJECT IN JAVA
 
java tr.docx
java tr.docxjava tr.docx
java tr.docx
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introduction
 
Oops in java
Oops in javaOops in java
Oops in java
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Java basics
Java basicsJava basics
Java basics
 
OOPS in Java
OOPS in JavaOOPS in Java
OOPS in Java
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674
 
Classes and objects in java
Classes and objects in javaClasses and objects in java
Classes and objects in java
 
Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaObject Oriented Programming Concepts using Java
Object Oriented Programming Concepts using Java
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examples
 
Oop concepts classes_objects
Oop concepts classes_objectsOop concepts classes_objects
Oop concepts classes_objects
 

Viewers also liked

Viewers also liked (8)

Md11 gui event handling
Md11 gui event handlingMd11 gui event handling
Md11 gui event handling
 
Md121 streams
Md121 streamsMd121 streams
Md121 streams
 
A begineers guide of JAVA - Getting Started
 A begineers guide of JAVA - Getting Started A begineers guide of JAVA - Getting Started
A begineers guide of JAVA - Getting Started
 
New features and enhancement
New features and enhancementNew features and enhancement
New features and enhancement
 
Md08 collection api
Md08 collection apiMd08 collection api
Md08 collection api
 
Md13 networking
Md13 networkingMd13 networking
Md13 networking
 
Md10 building java gu is
Md10 building java gu isMd10 building java gu is
Md10 building java gu is
 
Md09 multithreading
Md09 multithreadingMd09 multithreading
Md09 multithreading
 

Similar to Md02 - Getting Started part-2

Selenium Training .pptx
Selenium Training .pptxSelenium Training .pptx
Selenium Training .pptxSajidTk2
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1Geophery sanga
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)Khaled Anaqwa
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer ProgrammingInocentshuja Ahmad
 
Object Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionObject Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionSamuelAnsong6
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oopcolleges
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for seleniumapoorvams
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...AnkurSingh340457
 
Introduction to oop and java fundamentals
Introduction to oop and java fundamentalsIntroduction to oop and java fundamentals
Introduction to oop and java fundamentalsAnsgarMary
 
JavaScript OOPS Implimentation
JavaScript OOPS ImplimentationJavaScript OOPS Implimentation
JavaScript OOPS ImplimentationUsman Mehmood
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptxRaazIndia
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxKunalYadav65140
 

Similar to Md02 - Getting Started part-2 (20)

Cs2305 programming paradigms lecturer notes
Cs2305   programming paradigms lecturer notesCs2305   programming paradigms lecturer notes
Cs2305 programming paradigms lecturer notes
 
Selenium Training .pptx
Selenium Training .pptxSelenium Training .pptx
Selenium Training .pptx
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
Lecture 5.pptx
Lecture 5.pptxLecture 5.pptx
Lecture 5.pptx
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
 
Object Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionObject Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) Introduction
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
 
Java unit 7
Java unit 7Java unit 7
Java unit 7
 
My c++
My c++My c++
My c++
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
 
Introduction to oop and java fundamentals
Introduction to oop and java fundamentalsIntroduction to oop and java fundamentals
Introduction to oop and java fundamentals
 
JavaScript OOPS Implimentation
JavaScript OOPS ImplimentationJavaScript OOPS Implimentation
JavaScript OOPS Implimentation
 
Oops
OopsOops
Oops
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptx
 
concept of oops
concept of oopsconcept of oops
concept of oops
 
Java notes
Java notesJava notes
Java notes
 

Recently uploaded

Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxPoojaSen20
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 

Recently uploaded (20)

Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 

Md02 - Getting Started part-2

  • 1. Module 2 Object-Oriented Programming
  • 2. Objectives • Define modeling concepts: abstraction, encapsulation. • Define class, member, attribute, method, constructor and package • Invoke a method on a particular object. • In a Java program, identify the following: The package statement. The import statements. Classes, methods, and attributes. Constructors. • Use the Java API online documentation
  • 3. Abstraction An essential element of object oriented language is abstraction. Humans manage the complexity through abstraction. For example People do not think of car as a set of tens of thousand of individual parts. They think of it as a well defined object with its own unique behavior. They can ignore the details of how the engine, transmission and braking systems work. Powerful way to manage the abstraction is through the use of hierarchical classifications.
  • 4. From the outside, the car is a single object. Once inside you see that the car consist of several subsystems: steering, brakes, sound system, seat belts ,cellular system and so on. In turn each of these subsystem is made up of more specialized units. For example sound system consist of a radio, a CD player and a tape player. The point is you manage the complexity of car through the use of hierarchical abstraction.
  • 5. Hierarchical abstraction of complex systems can also be applied to computer programs. The data from program can be transformed by abstraction into its component objects. Each object describe its own unique behavior.We can treat these objects as concrete entities that respond to message telling them to do something.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. Creating Objects This statement creates a new Rectangle object from the Rectangle class. Rectangle rect = new Rectangle(); This single statement performs three actions: Declaration : Rectangle rect is a variable declaration that declares to the compiler that the name rect will be used to refer to a Rectangle object. Instantiation : new is a Java operator that creates the new object Initialization : Rectangle() is a call to Rectangle's constructor, which initializes the object.
  • 12. Using Objects Once you've created an object, you probably want to use it for something. You may need information from it, want to change its state, or have it perform some action. Objects give you two ways to do these things: 1.Manipulate or inspect its variables . area = rect.height * rect.width; 2.Call its methods. rect.move(15, 37);
  • 13. Cleaning Up Unused Objects Java allows you to create as many objects as you want and you never have to worry about destroying them. The Java runtime environment deletes objects when it determines that they are no longer being used. This process is called garbage collection. An object is eligible for garbage collection when there are no more references to that object. The Java platform has a garbage collector that periodically frees the memory used by objects that are no longer needed. The garbage collector runs in a low-priority thread
  • 14. Finalization Before an object gets garbage-collected, the garbage collector gives the object an opportunity to clean up after itself through a call to the object's finalize method. This process is known as finalization . During finalization, an object may wish to free system resources such as files and sockets or to drop references to other objects so that they in turn become eligible for garbage collection.
  • 15.
  • 16. Inheritanc e I nheritance is a mechanism that enables one class to inherit all of the behaviour and attributes of another class. For example, mountain bikes, road bikes, are all kinds of bicycles. Mountain bikes, road bikes are all subclasses of the bicycle class. Similarly, the bicycle class is the superclass of mountain bikes, road bikes. Each subclass inherits state from the superclass. Mountain bikes, road bikes share some states: cadence, speed, and the like. Also, each subclass inherits methods from the superclass. Example inheritance.java
  • 17.
  • 18. Encapsulation in Java In Java the basis of encapsulation is the class. Since the purpose of a class is to encapsulate complexity, there are mechanisms for hiding the complexity of the implementation inside the class. Each method or variable in a class may be marked private or public.
  • 19. P olymorphism Polymorphism is something like one name, many forms . Polymorphism manifests itself in Java in the form of multiple methods having the same name. In some cases, multiple methods have the same name, but different formal argument lists( overloaded methods) Example overload.java In other cases, multiple methods have the same name, same return type, and same formal argument list (overridden methods) . Example override.java
  • 20. Interface Interface is a device or a system that unrelated entities use to interact. Remote control is an interface between you and a television . T he English language is an interface between two people. Use an interface to define a behavior that can be implemented by any class. So interface is a collection of methods that indicate a class has some behaviour in addition to what it inherits from its superclass.
  • 21.
  • 22. Interface • Variables declared inside of interface declarations are implicitly public, final and static • They must also be initialized with a constant value • All methods are implicitly public and abstract. • Interface methods cannot be marked final, strictfp or native. • An interface can extend one or more other interfaces. • An interface cannot implement another interface or class. Example Callback.java, Client.java
  • 23.
  • 24. The following interface method declarations won't compile: final void bounce(); // final and abstract can never be used // together, and abstract is implied static void bounce(); // interfaces define instance methods private void bounce(); // interface methods are always public protected void bounce(); // (same as above)
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37. The Default Constructor • There is always at least one constructor in every class • If the writer does not supply any constructors, the default constructor will be present automatically The default constructor takes no arguments The default constructor has no body • Enables you to create object instances with new Xxx()without having to write a constructor  
  • 38.
  • 39.
  • 40.
  • 41. Packages • Packages help manage large software systems • Packages can contain classes and sub-packages • Basic syntax of the package statement: <package_declaration> ::= package <top_pkg_name>[.<sub_pkg_name>].*; Example: package shipping.reports.Web; • Specify the package declaration at the beginning of the source file
  • 42. Packages • Only one package declaration per source file • If no package is declared, then the class &quot;belongs&quot; to the default package • Package names must be hierarchical and separated by dot
  • 43. The import Statement • Basic syntax of the import statement: <import_declaration> ::= import <pkg_name>[.<sub_pkg_name>]*.<class_name | *>; Examples: import shipping.domain.*; import java.util.List; import java.io.*; • Precedes all class declarations • Tells the compiler where to find classes to use  
  • 44.
  • 45.
  • 46.