SlideShare uma empresa 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

Mais conteúdo relacionado

Mais procurados

Unit2 java
Unit2 javaUnit2 java
Unit2 java
mrecedu
 

Mais procurados (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
 

Destaque (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
 

Semelhante a Oop lecture3

Z blue interfaces and packages (37129912)
Z blue   interfaces and  packages (37129912)Z blue   interfaces and  packages (37129912)
Z blue interfaces and packages (37129912)
Narayana Swamy
 

Semelhante 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
 

Mais 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

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 

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