SlideShare a Scribd company logo
www.webstackacademy.com ‹#›
Java Programming
Language SE – 6
Module 2 : Object-Oriented
Programming
Objectives
● Define object modeling concepts: abstraction,encapsulation and
packages
● Discuss why you can reuse Java technology application code
● Define class, member, attribute, method, constructor, and package
● Use the access modifiers private and public as appropriate for the
guidelines of encapsulation
● Invoke a method on a particular object
● Use the Java technology application programming interface (API)
online documentation
Relevance
● What is your understanding of software analysis and design?
● What is your understanding of design and code reuse?
● What features does the Java programming language possess that
make it an object-oriented language?
● Define the term object-oriented.
Software Engineering
The Analysis and
Design Phase
● Analysis describes what the system needs to do:
Modeling the real-world, including actors and activities, objects,
and behaviors
● Design describes how the system does it:
– Modeling the relationships and interactions between objects and
actors in the system
– Finding useful abstractions to help simplify the problem or
solution
Abstraction
● Functions – Write an algorithm once to be used in many situations
● Objects – Group a related set of attributes and behaviors into a class
● Frameworks and APIs – Large groups of objects that support a
complex activity; Frameworks can be used as is or be modified to
extend the basic behavior
Classes as Blueprints for
Objects
● In manufacturing, a blueprint describes a device from which many
physical devices are constructed.
● In software, a class is a description of an object:
– A class describes the data that each object includes.
– A class describes the behaviors that each object
exhibits.
Classes as Blueprints for
Objects
● In Java technology, classes support three key features of object-
oriented programming (OOP):
– Encapsulation
– Inheritance
– Polymorphism
Declaring Java Technology
Classes
● Basic syntax of a Java class:
<modifier>* class <class_name> {
<attribute_declaration>*
<constructor_declaration>*
<method_declaration>*
}
Declaring Java Technology
Classes
public class Vehicle {
private double maxLoad;
public void setMaxLoad(double value) {
maxLoad = value;
}
}
Declaring Attributes
●
Basic syntax of an attribute:
<modifier>* <type> <name> [ = <initial_value>];
●
Examples:
public class Foo {
private int x;
private float y = 10000.0F;
private String name = "Bates Motel";
}
Declaring Methods
Basic syntax of a method:
<modifier>* <return_type> <name> ( <argument>* ) {
<statement>*
}
Declaring Methods
public class car{
private int modelno;
private String colour;
public void dispInfo(int mno,String col) {
modelno=mno;
colour=col;
}
}
Declaring Methods
Example-2
public class Dog {
private int weight;
public int getWeight() {
return weight;
}
public void setWeight(int newWeight) {
if ( newWeight > 0 ) {
weight = newWeight;
}
}
Accessing Object Members
● The dot notation is: <object>.<member>
● This is used to access object members, including attributes and
methods.
● Examples of dot notation are:
● a.dispInfo(101,”green”);
● a.modelno=”101”;
Example
// create a class car that will display the model number and
colour of car.
class car
{
int modelno;
String colour;
void dispInfo(int mno,String col)
{
modelno = mno;
colour = col;
}
}
Example -2
class carTest
{
car c1=new car();
c1.dispInfo(101,”green”);
}
}
Encapsulation
● Hides the implementation details of a class
● Forces the user to use an interface to access data
● Makes the code more maintainable
CarCar
colour String
model_no int
disp_info() void
Move() void
Declaring Constructors
●
Basic syntax of a constructor:
[<modifier>] <class_name> ( <argument>* ) {
<statement>*
}
●
Example:
public class Car {
private int speed;
public Car() {
speed = 50;
}
}
The Default Constructor
● There is always at least one constructor in every class.
● If the writer does not supply any constructors, the default
constructor is present automatically:
– The default constructor takes no arguments
– The default constructor body is empty
● The default enables you to create object instances with new
Xxx()without having to write a constructor.
Source File Layout
● Basic syntax of a Java source file is:
[<package_declaration>]
<import_declaration>*
<class_declaration>+
Source File Layout
package shipping.reports;
import shipping.domain.*;
import java.util.List;
import java.io.*;
public class VehicleCapacityReport {
private List vehicles;
public void generateReport(Writer output) {...}
}
Software Packages
● Packages help manage large software systems.
● Packages can contain classes and sub-packages.
The package Statement
●
Basic syntax of the package statement is: package
– <top_pkg_name>[.<sub_pkg_name>]*;
●
Examples of the statement are:
– package shipping.gui.reportscreens;
●
Specify the package declaration at the beginning of the source file.
●
Only one package declaration per source file.
●
If no package is declared, then the class is placed into the default
package.
●
Package names must be hierarchical and separated by dots.
The import Statement
● Basic syntax of the import statement is:
Import<pkg_name>[.<sub_pkg_name>]*.<class_name>;
OR
import<pkg_name>[.<sub_pkg_name>]*.*;
● Examples of the statement are:
import java.util.List;
import java.io.*;
import shipping.gui.reportscreens.*;
The import Statement
The import statement does the following:
● Precedes all class declarations
● Tells the compiler where to find classes
Compiling Using the -d
Option
cd JavaProjects/ShippingPrj/src
javac -d ../classes shipping/domain/*.java
Recap
● Class – The source-code blueprint for a run-time object
● Object – An instance of a class;
also known as instance
● Attribute – A data element of an object;
also known as data member, instance variable, and data field
● Method – A behavioral element of an object;
also known as algorithm, function, and procedure
Recap
● Constructor – A method-like construct used to initialize a new object
● Package – A grouping of classes and sub-packages
Java Technology API
Documentation
● A set of Hypertext Markup Language (HTML) files provides
information about the API.
● A frame describes a package and contains hyperlinks to information
describing each class in that package.
● A class document includes the class hierarchy, a description of the
class, a list of member variables, a list of constructors, and so on.
Java Technology API
Documentation
Thank You

More Related Content

PDF
Java - Interfaces & Packages
PPTX
Object Oriented Javascript part2
PPT
PHP - Introduction to Object Oriented Programming with PHP
PPT
object oriented programming language by c++
PPTX
Object oreinted php | OOPs
PDF
09 Object Oriented Programming in PHP #burningkeyboards
PDF
Core Java Introduction | Basics
PPT
Oops concepts in php
Java - Interfaces & Packages
Object Oriented Javascript part2
PHP - Introduction to Object Oriented Programming with PHP
object oriented programming language by c++
Object oreinted php | OOPs
09 Object Oriented Programming in PHP #burningkeyboards
Core Java Introduction | Basics
Oops concepts in php

What's hot (19)

PDF
Java Presentation For Syntax
PPTX
Framework prototype
PPTX
Presentation on class and object in Object Oriented programming.
PPTX
OOPS Characteristics (With Examples in PHP)
PPT
PHP- Introduction to Object Oriented PHP
PDF
Introduction to Java
PDF
Lec 5 13_aug [compatibility mode]
PDF
Core Java Tutorial
PPTX
Only oop
PDF
Java Programming - 04 object oriented in java
PDF
JAVA PROGRAMMING- Exception handling - Multithreading
PPT
Packages in java
PDF
Class and object in C++ By Pawan Thakur
PDF
javapackage
PDF
CLTL python course: Object Oriented Programming (1/3)
PDF
How to write you first class in c++ object oriented programming
PPTX
OCA JAVA - 1 Packages and Class Structure
PPT
Classes, objects and methods
PPT
Lecture 9
Java Presentation For Syntax
Framework prototype
Presentation on class and object in Object Oriented programming.
OOPS Characteristics (With Examples in PHP)
PHP- Introduction to Object Oriented PHP
Introduction to Java
Lec 5 13_aug [compatibility mode]
Core Java Tutorial
Only oop
Java Programming - 04 object oriented in java
JAVA PROGRAMMING- Exception handling - Multithreading
Packages in java
Class and object in C++ By Pawan Thakur
javapackage
CLTL python course: Object Oriented Programming (1/3)
How to write you first class in c++ object oriented programming
OCA JAVA - 1 Packages and Class Structure
Classes, objects and methods
Lecture 9
Ad

Similar to Core Java Programming Language (JSE) : Chapter II - Object Oriented Programming. (20)

PPT
UML to Object Oriented Mapping java .ppt
PPT
Md02 - Getting Started part-2
PPT
Java Tutorial 1
PDF
Lecture2.pdf
PPTX
The smartpath information systems java
PDF
Lec 4 06_aug [compatibility mode]
PPTX
Android Training (Java Review)
PPTX
Ch-2ppt.pptx
PPTX
java part 1 computer science.pptx
PPTX
classes-objects in oops java-201023154255.pptx
PPTX
10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx
PPT
Unidad o informatica en ingles
PPTX
Object Oriended Programming with Java
PDF
Java chapter 3 - OOPs concepts
DOCX
javaopps concepts
DOCX
Java OOPs Concepts.docx
PPT
Core Java unit no. 1 object and class ppt
PPTX
03 Java Language And OOP Part III
PDF
ITFT-Classes and object in java
PPTX
Classes objects in java
UML to Object Oriented Mapping java .ppt
Md02 - Getting Started part-2
Java Tutorial 1
Lecture2.pdf
The smartpath information systems java
Lec 4 06_aug [compatibility mode]
Android Training (Java Review)
Ch-2ppt.pptx
java part 1 computer science.pptx
classes-objects in oops java-201023154255.pptx
10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx
Unidad o informatica en ingles
Object Oriended Programming with Java
Java chapter 3 - OOPs concepts
javaopps concepts
Java OOPs Concepts.docx
Core Java unit no. 1 object and class ppt
03 Java Language And OOP Part III
ITFT-Classes and object in java
Classes objects in java
Ad

More from WebStackAcademy (20)

PDF
Webstack Academy - Course Demo Webinar and Placement Journey
PDF
WSA: Scaling Web Service to Handle Millions of Requests per Second
PDF
WSA: Course Demo Webinar - Full Stack Developer Course
PDF
Career Building in AI - Technologies, Trends and Opportunities
PDF
Webstack Academy - Internship Kick Off
PDF
Building Your Online Portfolio
PDF
Front-End Developer's Career Roadmap
PDF
Angular - Chapter 9 - Authentication and Authorization
PDF
Angular - Chapter 7 - HTTP Services
PDF
Angular - Chapter 6 - Firebase Integration
PDF
Angular - Chapter 5 - Directives
PDF
Angular - Chapter 4 - Data and Event Handling
PDF
Angular - Chapter 3 - Components
PDF
Angular - Chapter 2 - TypeScript Programming
PDF
Angular - Chapter 1 - Introduction
PDF
JavaScript - Chapter 10 - Strings and Arrays
PDF
JavaScript - Chapter 15 - Debugging Techniques
PDF
JavaScript - Chapter 14 - Form Handling
PDF
JavaScript - Chapter 13 - Browser Object Model(BOM)
PDF
JavaScript - Chapter 12 - Document Object Model
Webstack Academy - Course Demo Webinar and Placement Journey
WSA: Scaling Web Service to Handle Millions of Requests per Second
WSA: Course Demo Webinar - Full Stack Developer Course
Career Building in AI - Technologies, Trends and Opportunities
Webstack Academy - Internship Kick Off
Building Your Online Portfolio
Front-End Developer's Career Roadmap
Angular - Chapter 9 - Authentication and Authorization
Angular - Chapter 7 - HTTP Services
Angular - Chapter 6 - Firebase Integration
Angular - Chapter 5 - Directives
Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 3 - Components
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 1 - Introduction
JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 14 - Form Handling
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 12 - Document Object Model

Recently uploaded (19)

DOCX
World Cup Philly Needs 3000 Volunteers for FIFA 2026 Action Next Summer.docx
PDF
FIFA Club World Cup 2025 - USA Chelsea VS PSG in Finals
DOCX
NFL Dublin Steelers Lesser Shows Depth and Power at Camp.docx
PPTX
Soccer_Basics_Presentation_about_and_info.pptx
DOCX
FIFA World Cup 2026 Las Vegas to Host FIFA 2026 Draw Ceremony.docx
DOCX
NFL Dublin Minnesota’s Offensive Edge, the Josh Oliver Effect.docx
PDF
Famous Cricketers Whose Divorces Shocked Fans.pdf
PDF
PROFESSIONAL GAME MODEL principe et sous principe 📚🧠⚽️.pdf
DOCX
Soccer World Cup Tickets Telemundo’s Big Plans for FIFA World Cup 2026.docx
PDF
Lionel Messi The Unparalleled Legacy of Football's Greatest Player.pdf
PDF
Football World Cup Top 10 Teams Aiming for the FIFA 2026 Trophy.pdf
PDF
2025 AASM Schedule of Oral Presentations
PPTX
Daniel Oordt | Club Colors to National Pride: The World Cup's Role in Unity
DOCX
FIFA World Cup Tickets Rodrigo De Paul’s Inter Miami Move and Its FIFA 2026 I...
DOCX
Furniture Movers in Dubai | Best Mover In Dubai
PPTX
Basketball_Basics_Guide_for_kids_parents.pptx
PDF
Inside the Career of a Sports Business Leader
DOCX
Felix's Al Nassr Move Tied to Soccer World Cup, Ronaldo.docx
DOCX
NFL Dublin Steelers Release Patterson Early in Training Camp.docx
World Cup Philly Needs 3000 Volunteers for FIFA 2026 Action Next Summer.docx
FIFA Club World Cup 2025 - USA Chelsea VS PSG in Finals
NFL Dublin Steelers Lesser Shows Depth and Power at Camp.docx
Soccer_Basics_Presentation_about_and_info.pptx
FIFA World Cup 2026 Las Vegas to Host FIFA 2026 Draw Ceremony.docx
NFL Dublin Minnesota’s Offensive Edge, the Josh Oliver Effect.docx
Famous Cricketers Whose Divorces Shocked Fans.pdf
PROFESSIONAL GAME MODEL principe et sous principe 📚🧠⚽️.pdf
Soccer World Cup Tickets Telemundo’s Big Plans for FIFA World Cup 2026.docx
Lionel Messi The Unparalleled Legacy of Football's Greatest Player.pdf
Football World Cup Top 10 Teams Aiming for the FIFA 2026 Trophy.pdf
2025 AASM Schedule of Oral Presentations
Daniel Oordt | Club Colors to National Pride: The World Cup's Role in Unity
FIFA World Cup Tickets Rodrigo De Paul’s Inter Miami Move and Its FIFA 2026 I...
Furniture Movers in Dubai | Best Mover In Dubai
Basketball_Basics_Guide_for_kids_parents.pptx
Inside the Career of a Sports Business Leader
Felix's Al Nassr Move Tied to Soccer World Cup, Ronaldo.docx
NFL Dublin Steelers Release Patterson Early in Training Camp.docx

Core Java Programming Language (JSE) : Chapter II - Object Oriented Programming.

  • 1. www.webstackacademy.com ‹#› Java Programming Language SE – 6 Module 2 : Object-Oriented Programming
  • 2. Objectives ● Define object modeling concepts: abstraction,encapsulation and packages ● Discuss why you can reuse Java technology application code ● Define class, member, attribute, method, constructor, and package ● Use the access modifiers private and public as appropriate for the guidelines of encapsulation ● Invoke a method on a particular object ● Use the Java technology application programming interface (API) online documentation
  • 3. Relevance ● What is your understanding of software analysis and design? ● What is your understanding of design and code reuse? ● What features does the Java programming language possess that make it an object-oriented language? ● Define the term object-oriented.
  • 5. The Analysis and Design Phase ● Analysis describes what the system needs to do: Modeling the real-world, including actors and activities, objects, and behaviors ● Design describes how the system does it: – Modeling the relationships and interactions between objects and actors in the system – Finding useful abstractions to help simplify the problem or solution
  • 6. Abstraction ● Functions – Write an algorithm once to be used in many situations ● Objects – Group a related set of attributes and behaviors into a class ● Frameworks and APIs – Large groups of objects that support a complex activity; Frameworks can be used as is or be modified to extend the basic behavior
  • 7. Classes as Blueprints for Objects ● In manufacturing, a blueprint describes a device from which many physical devices are constructed. ● In software, a class is a description of an object: – A class describes the data that each object includes. – A class describes the behaviors that each object exhibits.
  • 8. Classes as Blueprints for Objects ● In Java technology, classes support three key features of object- oriented programming (OOP): – Encapsulation – Inheritance – Polymorphism
  • 9. Declaring Java Technology Classes ● Basic syntax of a Java class: <modifier>* class <class_name> { <attribute_declaration>* <constructor_declaration>* <method_declaration>* }
  • 10. Declaring Java Technology Classes public class Vehicle { private double maxLoad; public void setMaxLoad(double value) { maxLoad = value; } }
  • 11. Declaring Attributes ● Basic syntax of an attribute: <modifier>* <type> <name> [ = <initial_value>]; ● Examples: public class Foo { private int x; private float y = 10000.0F; private String name = "Bates Motel"; }
  • 12. Declaring Methods Basic syntax of a method: <modifier>* <return_type> <name> ( <argument>* ) { <statement>* }
  • 13. Declaring Methods public class car{ private int modelno; private String colour; public void dispInfo(int mno,String col) { modelno=mno; colour=col; } }
  • 14. Declaring Methods Example-2 public class Dog { private int weight; public int getWeight() { return weight; } public void setWeight(int newWeight) { if ( newWeight > 0 ) { weight = newWeight; } }
  • 15. Accessing Object Members ● The dot notation is: <object>.<member> ● This is used to access object members, including attributes and methods. ● Examples of dot notation are: ● a.dispInfo(101,”green”); ● a.modelno=”101”;
  • 16. Example // create a class car that will display the model number and colour of car. class car { int modelno; String colour; void dispInfo(int mno,String col) { modelno = mno; colour = col; } }
  • 17. Example -2 class carTest { car c1=new car(); c1.dispInfo(101,”green”); } }
  • 18. Encapsulation ● Hides the implementation details of a class ● Forces the user to use an interface to access data ● Makes the code more maintainable CarCar colour String model_no int disp_info() void Move() void
  • 19. Declaring Constructors ● Basic syntax of a constructor: [<modifier>] <class_name> ( <argument>* ) { <statement>* } ● Example: public class Car { private int speed; public Car() { speed = 50; } }
  • 20. The Default Constructor ● There is always at least one constructor in every class. ● If the writer does not supply any constructors, the default constructor is present automatically: – The default constructor takes no arguments – The default constructor body is empty ● The default enables you to create object instances with new Xxx()without having to write a constructor.
  • 21. Source File Layout ● Basic syntax of a Java source file is: [<package_declaration>] <import_declaration>* <class_declaration>+
  • 22. Source File Layout package shipping.reports; import shipping.domain.*; import java.util.List; import java.io.*; public class VehicleCapacityReport { private List vehicles; public void generateReport(Writer output) {...} }
  • 23. Software Packages ● Packages help manage large software systems. ● Packages can contain classes and sub-packages.
  • 24. The package Statement ● Basic syntax of the package statement is: package – <top_pkg_name>[.<sub_pkg_name>]*; ● Examples of the statement are: – package shipping.gui.reportscreens; ● Specify the package declaration at the beginning of the source file. ● Only one package declaration per source file. ● If no package is declared, then the class is placed into the default package. ● Package names must be hierarchical and separated by dots.
  • 25. The import Statement ● Basic syntax of the import statement is: Import<pkg_name>[.<sub_pkg_name>]*.<class_name>; OR import<pkg_name>[.<sub_pkg_name>]*.*; ● Examples of the statement are: import java.util.List; import java.io.*; import shipping.gui.reportscreens.*;
  • 26. The import Statement The import statement does the following: ● Precedes all class declarations ● Tells the compiler where to find classes
  • 27. Compiling Using the -d Option cd JavaProjects/ShippingPrj/src javac -d ../classes shipping/domain/*.java
  • 28. Recap ● Class – The source-code blueprint for a run-time object ● Object – An instance of a class; also known as instance ● Attribute – A data element of an object; also known as data member, instance variable, and data field ● Method – A behavioral element of an object; also known as algorithm, function, and procedure
  • 29. Recap ● Constructor – A method-like construct used to initialize a new object ● Package – A grouping of classes and sub-packages
  • 30. Java Technology API Documentation ● A set of Hypertext Markup Language (HTML) files provides information about the API. ● A frame describes a package and contains hyperlinks to information describing each class in that package. ● A class document includes the class hierarchy, a description of the class, a list of member variables, a list of constructors, and so on.