SlideShare una empresa de Scribd logo
1 de 13
Lecture 3
Concepts of OOP




          Object Oriented Programming
          Eastern University, Dhaka
                  Md. Raihan Kibria
Difference between a Class and an
              Object
   A class
      A class is a template
      Definition of a class is only given during design/coding
       time
      A class can be compared to a struct in c

   An object
      An object is an instance of a class
      An object is made only during run time
      An object is made from the definition of a class
An example
Class definition:

public class A{

    String code;
    String name;

}

Code to make a new instance:
A a = new A();
Object/instance
   So far we have defined a class and written
    code to instantiate it. But we still have not
    created the object.
   Compile: javac A.java
   Run: java A.class
   Only now an object or instance of class A is
    created.
   JVM creates the instance or object based
    on class definition found in the byte-code
Some rules for creating class in
                 java
   A class can be defined in any file. However,
    a public class must be in a file name that
    matches the class name.

   Example of a public class:
public class Student{
  String code;
  String name;
}
file name: Student.java
Some rules for creating class in
             java
  Example of non-public class:
class A{
  String name;
  String code;
}
Class B{
  int age;
  String program;
}
Fliename could be anything, such as
   Example.java
Some rules for creating class in
             java
   Please note that many non-public classes
    may reside in one file.
   But a file can have only one public class.
   A file can have one public class and many
    non-public classes.
Packages
   Packages are folders, roughly speaking.
   Typically, “package” is the first line in any
    java program.
   Many java files can be placed under a
    package.
   Package is a way to organize codes.
Example
package com.abc;
public class A{
  String ...
}

This means the file A.java is under folder
 com/abc
Example
public class B{
  String ...
}

This means the file B.java is not under any
 folder
Compiling packaged classes
Suppoer A.java is under com folder.
The first line of A.java is:
package com;

  To compile issue command
javac com/A.java
 The output A.class file will be produced
   under com folder
 To run issue command:
java com.A
Compiling non-packaged classes
  Suppose B.java has no package definition
  To compile issue command:
javac B.java
To run issue command
java B
Compiling a package
  To compile all files under package issue
   command:
javac com/*.java

  To compile multiple packages issue
   command:
javac com/*.java com/abc/*.java

Más contenido relacionado

La actualidad más candente

La actualidad más candente (14)

Java principles
Java principlesJava principles
Java principles
 
Class notes(week 7) on packages
Class notes(week 7) on packagesClass notes(week 7) on packages
Class notes(week 7) on packages
 
Sep 15
Sep 15Sep 15
Sep 15
 
Sep 15
Sep 15Sep 15
Sep 15
 
Automation Testing - Part 2 (Things to know in JAVA) - SLT
Automation Testing - Part 2 (Things to know in JAVA) - SLTAutomation Testing - Part 2 (Things to know in JAVA) - SLT
Automation Testing - Part 2 (Things to know in JAVA) - SLT
 
Packages
PackagesPackages
Packages
 
JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O
 
RIBBUN SOFTWARE
RIBBUN SOFTWARERIBBUN SOFTWARE
RIBBUN SOFTWARE
 
Introduction what is java
Introduction what is javaIntroduction what is java
Introduction what is java
 
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class TestingYAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
 
Java packages
Java packagesJava packages
Java packages
 
Unit2 java
Unit2 javaUnit2 java
Unit2 java
 
Java - Interfaces & Packages
Java - Interfaces & PackagesJava - Interfaces & Packages
Java - Interfaces & Packages
 
Java Class Loading
Java Class LoadingJava Class Loading
Java Class Loading
 

Destacado

DCRS September - October 2011 Newsletter
DCRS September - October 2011 NewsletterDCRS September - October 2011 Newsletter
DCRS September - October 2011 NewsletterKanda P.
 
The Voice of PLC Newsletter Oct - Nov 2011
The Voice of PLC Newsletter Oct - Nov 2011The Voice of PLC Newsletter Oct - Nov 2011
The Voice of PLC Newsletter Oct - Nov 2011Kanda P.
 
CLAN September 2011
CLAN September 2011CLAN September 2011
CLAN September 2011Kanda P.
 
DCFA August - September 2011 Newsletter
DCFA August - September 2011 NewsletterDCFA August - September 2011 Newsletter
DCFA August - September 2011 NewsletterKanda P.
 
110614 GEOFF'S LATEST MEDICAL BULLETIN
110614 GEOFF'S LATEST MEDICAL BULLETIN110614 GEOFF'S LATEST MEDICAL BULLETIN
110614 GEOFF'S LATEST MEDICAL BULLETINKanda P.
 
DCFA Nov-Dec 2011 Newsletter
DCFA Nov-Dec 2011 NewsletterDCFA Nov-Dec 2011 Newsletter
DCFA Nov-Dec 2011 NewsletterKanda P.
 

Destacado (9)

DCRS September - October 2011 Newsletter
DCRS September - October 2011 NewsletterDCRS September - October 2011 Newsletter
DCRS September - October 2011 Newsletter
 
The Voice of PLC Newsletter Oct - Nov 2011
The Voice of PLC Newsletter Oct - Nov 2011The Voice of PLC Newsletter Oct - Nov 2011
The Voice of PLC Newsletter Oct - Nov 2011
 
CLAN September 2011
CLAN September 2011CLAN September 2011
CLAN September 2011
 
DCFA August - September 2011 Newsletter
DCFA August - September 2011 NewsletterDCFA August - September 2011 Newsletter
DCFA August - September 2011 Newsletter
 
Oop lecture4
Oop lecture4Oop lecture4
Oop lecture4
 
Oop lecture5
Oop lecture5Oop lecture5
Oop lecture5
 
Oop lecture9
Oop lecture9Oop lecture9
Oop lecture9
 
110614 GEOFF'S LATEST MEDICAL BULLETIN
110614 GEOFF'S LATEST MEDICAL BULLETIN110614 GEOFF'S LATEST MEDICAL BULLETIN
110614 GEOFF'S LATEST MEDICAL BULLETIN
 
DCFA Nov-Dec 2011 Newsletter
DCFA Nov-Dec 2011 NewsletterDCFA Nov-Dec 2011 Newsletter
DCFA Nov-Dec 2011 Newsletter
 

Similar a Oop lecture3

Similar a Oop lecture3 (20)

java01.ppt
java01.pptjava01.ppt
java01.ppt
 
Java PPt.ppt
Java PPt.pptJava PPt.ppt
Java PPt.ppt
 
Object Oriented Programming - Java
Object Oriented Programming -  JavaObject Oriented Programming -  Java
Object Oriented Programming - Java
 
INTRODUCTION TO JAVA
INTRODUCTION TO JAVAINTRODUCTION TO JAVA
INTRODUCTION TO JAVA
 
Core java Basics
Core java BasicsCore java Basics
Core java Basics
 
OOPM Introduction.ppt
OOPM Introduction.pptOOPM Introduction.ppt
OOPM Introduction.ppt
 
Java tutorial for beginners-tibacademy.in
Java tutorial for beginners-tibacademy.inJava tutorial for beginners-tibacademy.in
Java tutorial for beginners-tibacademy.in
 
Core java
Core javaCore java
Core java
 
Javapackages 4th semester
Javapackages 4th semesterJavapackages 4th semester
Javapackages 4th semester
 
Intro To C++ - Class 07 - Headers, Interfaces, & Prototypes
Intro To C++ - Class 07 - Headers, Interfaces, & PrototypesIntro To C++ - Class 07 - Headers, Interfaces, & Prototypes
Intro To C++ - Class 07 - Headers, Interfaces, & Prototypes
 
My Object Oriented.pptx
My Object Oriented.pptxMy Object Oriented.pptx
My Object Oriented.pptx
 
core java for hadoop
core java for hadoopcore java for hadoop
core java for hadoop
 
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building BlocksOCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
 
Packages and interface
Packages and interfacePackages and interface
Packages and interface
 
Packages,interfaces and exceptions
Packages,interfaces and exceptionsPackages,interfaces and exceptions
Packages,interfaces and exceptions
 
core java course online
core java course onlinecore java course online
core java course online
 
Z blue interfaces and packages (37129912)
Z blue   interfaces and  packages (37129912)Z blue   interfaces and  packages (37129912)
Z blue interfaces and packages (37129912)
 
Package in Java
Package in JavaPackage in Java
Package in Java
 
Core_java_ppt.ppt
Core_java_ppt.pptCore_java_ppt.ppt
Core_java_ppt.ppt
 
Structure of java program diff c- cpp and java
Structure of java program  diff c- cpp and javaStructure of java program  diff c- cpp and java
Structure of java program diff c- cpp and java
 

Más de Shahriar Robbani (11)

Group111
Group111Group111
Group111
 
SQL
SQLSQL
SQL
 
Oop lecture9 13
Oop lecture9 13Oop lecture9 13
Oop lecture9 13
 
Oop lecture9 12
Oop lecture9 12Oop lecture9 12
Oop lecture9 12
 
Oop lecture9 10
Oop lecture9 10Oop lecture9 10
Oop lecture9 10
 
Oop lecture8
Oop lecture8Oop lecture8
Oop lecture8
 
Oop lecture9 11
Oop lecture9 11Oop lecture9 11
Oop lecture9 11
 
Oop lecture2
Oop lecture2Oop lecture2
Oop lecture2
 
Oop lecture7
Oop lecture7Oop lecture7
Oop lecture7
 
Oop lecture1
Oop lecture1Oop lecture1
Oop lecture1
 
Oop lecture6
Oop lecture6Oop lecture6
Oop lecture6
 

Último

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Último (20)

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 

Oop lecture3

  • 1. Lecture 3 Concepts of OOP Object Oriented Programming Eastern University, Dhaka Md. Raihan Kibria
  • 2. Difference between a Class and an Object  A class  A class is a template  Definition of a class is only given during design/coding time  A class can be compared to a struct in c  An object  An object is an instance of a class  An object is made only during run time  An object is made from the definition of a class
  • 3. An example Class definition: public class A{ String code; String name; } Code to make a new instance: A a = new A();
  • 4. Object/instance  So far we have defined a class and written code to instantiate it. But we still have not created the object.  Compile: javac A.java  Run: java A.class  Only now an object or instance of class A is created.  JVM creates the instance or object based on class definition found in the byte-code
  • 5. Some rules for creating class in java  A class can be defined in any file. However, a public class must be in a file name that matches the class name.  Example of a public class: public class Student{ String code; String name; } file name: Student.java
  • 6. Some rules for creating class in java  Example of non-public class: class A{ String name; String code; } Class B{ int age; String program; } Fliename could be anything, such as Example.java
  • 7. Some rules for creating class in java  Please note that many non-public classes may reside in one file.  But a file can have only one public class.  A file can have one public class and many non-public classes.
  • 8. Packages  Packages are folders, roughly speaking.  Typically, “package” is the first line in any java program.  Many java files can be placed under a package.  Package is a way to organize codes.
  • 9. Example package com.abc; public class A{ String ... } This means the file A.java is under folder com/abc
  • 10. Example public class B{ String ... } This means the file B.java is not under any folder
  • 11. Compiling packaged classes Suppoer A.java is under com folder. The first line of A.java is: package com;  To compile issue command javac com/A.java  The output A.class file will be produced under com folder  To run issue command: java com.A
  • 12. Compiling non-packaged classes  Suppose B.java has no package definition  To compile issue command: javac B.java To run issue command java B
  • 13. Compiling a package  To compile all files under package issue command: javac com/*.java  To compile multiple packages issue command: javac com/*.java com/abc/*.java