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

What's hot (19)

Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For Syntax
PravinYalameli
 
Framework prototype
Framework prototypeFramework prototype
Framework prototype
DevMix
 
Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.
Enam Khan
 
OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)
baabtra.com - No. 1 supplier of quality freshers
 
PHP- Introduction to Object Oriented PHP
PHP-  Introduction to Object Oriented PHPPHP-  Introduction to Object Oriented PHP
PHP- Introduction to Object Oriented PHP
Vibrant Technologies & Computers
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
Professional Guru
 
Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]
Palak Sanghani
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
eMexo Technologies
 
Only oop
Only oopOnly oop
Only oop
anitarooge
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
Danairat Thanabodithammachari
 
JAVA PROGRAMMING- Exception handling - Multithreading
JAVA PROGRAMMING- Exception handling - MultithreadingJAVA PROGRAMMING- Exception handling - Multithreading
JAVA PROGRAMMING- Exception handling - Multithreading
Jyothishmathi Institute of Technology and Science Karimnagar
 
Packages in java
Packages in javaPackages in java
Packages in java
Jancypriya M
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
Govt. P.G. College Dharamshala
 
javapackage
javapackagejavapackage
javapackage
Arjun Shanka
 
CLTL python course: Object Oriented Programming (1/3)
CLTL python course: Object Oriented Programming (1/3)CLTL python course: Object Oriented Programming (1/3)
CLTL python course: Object Oriented Programming (1/3)
Rubén Izquierdo Beviá
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
Syed Faizan Hassan
 
OCA JAVA - 1 Packages and Class Structure
 OCA JAVA - 1 Packages and Class Structure OCA JAVA - 1 Packages and Class Structure
OCA JAVA - 1 Packages and Class Structure
Fernando Gil
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
farhan amjad
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
Mohammed Saleh
 
Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For Syntax
PravinYalameli
 
Framework prototype
Framework prototypeFramework prototype
Framework prototype
DevMix
 
Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.
Enam Khan
 
Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]
Palak Sanghani
 
CLTL python course: Object Oriented Programming (1/3)
CLTL python course: Object Oriented Programming (1/3)CLTL python course: Object Oriented Programming (1/3)
CLTL python course: Object Oriented Programming (1/3)
Rubén Izquierdo Beviá
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
Syed Faizan Hassan
 
OCA JAVA - 1 Packages and Class Structure
 OCA JAVA - 1 Packages and Class Structure OCA JAVA - 1 Packages and Class Structure
OCA JAVA - 1 Packages and Class Structure
Fernando Gil
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
farhan amjad
 

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

UML to Object Oriented Mapping java .ppt
UML to Object Oriented Mapping java .pptUML to Object Oriented Mapping java .ppt
UML to Object Oriented Mapping java .ppt
JyothiAmpally
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
Rakesh Madugula
 
Java Tutorial 1
Java Tutorial 1Java Tutorial 1
Java Tutorial 1
Tushar Desarda
 
Lecture2.pdf
Lecture2.pdfLecture2.pdf
Lecture2.pdf
SakhilejasonMsibi
 
The smartpath information systems java
The smartpath information systems javaThe smartpath information systems java
The smartpath information systems java
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
Lec 4 06_aug [compatibility mode]
Lec 4 06_aug [compatibility mode]Lec 4 06_aug [compatibility mode]
Lec 4 06_aug [compatibility mode]
Palak Sanghani
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
Khaled Anaqwa
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
ssuser8347a1
 
java part 1 computer science.pptx
java part 1 computer science.pptxjava part 1 computer science.pptx
java part 1 computer science.pptx
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
classes-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptxclasses-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptx
janetvidyaanancys
 
10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx
10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx
10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx
ssuser7fe189
 
Unidad o informatica en ingles
Unidad o informatica en inglesUnidad o informatica en ingles
Unidad o informatica en ingles
Marisa Torrecillas
 
Object Oriended Programming with Java
Object Oriended Programming with JavaObject Oriended Programming with Java
Object Oriended Programming with Java
Jakir Hossain
 
Java chapter 3 - OOPs concepts
Java chapter 3 - OOPs conceptsJava chapter 3 - OOPs concepts
Java chapter 3 - OOPs concepts
Mukesh Tekwani
 
javaopps concepts
javaopps conceptsjavaopps concepts
javaopps concepts
Nikhil Agrawal
 
Java OOPs Concepts.docx
Java OOPs Concepts.docxJava OOPs Concepts.docx
Java OOPs Concepts.docx
FredWauyo
 
Core Java unit no. 1 object and class ppt
Core Java unit no. 1 object and class pptCore Java unit no. 1 object and class ppt
Core Java unit no. 1 object and class ppt
Mochi263119
 
03 Java Language And OOP Part III
03 Java Language And OOP Part III03 Java Language And OOP Part III
03 Java Language And OOP Part III
Hari Christian
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
Atul Sehdev
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
Madishetty Prathibha
 
UML to Object Oriented Mapping java .ppt
UML to Object Oriented Mapping java .pptUML to Object Oriented Mapping java .ppt
UML to Object Oriented Mapping java .ppt
JyothiAmpally
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
Rakesh Madugula
 
Lec 4 06_aug [compatibility mode]
Lec 4 06_aug [compatibility mode]Lec 4 06_aug [compatibility mode]
Lec 4 06_aug [compatibility mode]
Palak Sanghani
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
Khaled Anaqwa
 
classes-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptxclasses-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptx
janetvidyaanancys
 
10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx
10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx
10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx
ssuser7fe189
 
Unidad o informatica en ingles
Unidad o informatica en inglesUnidad o informatica en ingles
Unidad o informatica en ingles
Marisa Torrecillas
 
Object Oriended Programming with Java
Object Oriended Programming with JavaObject Oriended Programming with Java
Object Oriended Programming with Java
Jakir Hossain
 
Java chapter 3 - OOPs concepts
Java chapter 3 - OOPs conceptsJava chapter 3 - OOPs concepts
Java chapter 3 - OOPs concepts
Mukesh Tekwani
 
Java OOPs Concepts.docx
Java OOPs Concepts.docxJava OOPs Concepts.docx
Java OOPs Concepts.docx
FredWauyo
 
Core Java unit no. 1 object and class ppt
Core Java unit no. 1 object and class pptCore Java unit no. 1 object and class ppt
Core Java unit no. 1 object and class ppt
Mochi263119
 
03 Java Language And OOP Part III
03 Java Language And OOP Part III03 Java Language And OOP Part III
03 Java Language And OOP Part III
Hari Christian
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
Atul Sehdev
 
Ad

More from WebStackAcademy (20)

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

Recently uploaded (7)

Management of sports with types of tournament.pptx
Management of sports with types of tournament.pptxManagement of sports with types of tournament.pptx
Management of sports with types of tournament.pptx
ZeusOp1
 
Team Work Presentation.pptx.pptx.pptx.pptx
Team Work Presentation.pptx.pptx.pptx.pptxTeam Work Presentation.pptx.pptx.pptx.pptx
Team Work Presentation.pptx.pptx.pptx.pptx
kayaniawais280
 
Best Ticket Resale Verification System.pptx
Best Ticket Resale Verification System.pptxBest Ticket Resale Verification System.pptx
Best Ticket Resale Verification System.pptx
counterten
 
Football - IFAB - Laws of the Game 2025_26.pdf
Football - IFAB - Laws of the Game 2025_26.pdfFootball - IFAB - Laws of the Game 2025_26.pdf
Football - IFAB - Laws of the Game 2025_26.pdf
serdaraker1
 
Chess Mastery: The Path to Excellence (presentation)
Chess Mastery: The Path to Excellence (presentation)Chess Mastery: The Path to Excellence (presentation)
Chess Mastery: The Path to Excellence (presentation)
Brian Shechtman
 
Best Ticket Resale Verification System.pdf
Best Ticket Resale Verification System.pdfBest Ticket Resale Verification System.pdf
Best Ticket Resale Verification System.pdf
counterten
 
NCAA Football Betting System That Will Change Your Gambling Life
NCAA Football Betting System That Will Change Your Gambling LifeNCAA Football Betting System That Will Change Your Gambling Life
NCAA Football Betting System That Will Change Your Gambling Life
Joe Duffy
 
Management of sports with types of tournament.pptx
Management of sports with types of tournament.pptxManagement of sports with types of tournament.pptx
Management of sports with types of tournament.pptx
ZeusOp1
 
Team Work Presentation.pptx.pptx.pptx.pptx
Team Work Presentation.pptx.pptx.pptx.pptxTeam Work Presentation.pptx.pptx.pptx.pptx
Team Work Presentation.pptx.pptx.pptx.pptx
kayaniawais280
 
Best Ticket Resale Verification System.pptx
Best Ticket Resale Verification System.pptxBest Ticket Resale Verification System.pptx
Best Ticket Resale Verification System.pptx
counterten
 
Football - IFAB - Laws of the Game 2025_26.pdf
Football - IFAB - Laws of the Game 2025_26.pdfFootball - IFAB - Laws of the Game 2025_26.pdf
Football - IFAB - Laws of the Game 2025_26.pdf
serdaraker1
 
Chess Mastery: The Path to Excellence (presentation)
Chess Mastery: The Path to Excellence (presentation)Chess Mastery: The Path to Excellence (presentation)
Chess Mastery: The Path to Excellence (presentation)
Brian Shechtman
 
Best Ticket Resale Verification System.pdf
Best Ticket Resale Verification System.pdfBest Ticket Resale Verification System.pdf
Best Ticket Resale Verification System.pdf
counterten
 
NCAA Football Betting System That Will Change Your Gambling Life
NCAA Football Betting System That Will Change Your Gambling LifeNCAA Football Betting System That Will Change Your Gambling Life
NCAA Football Betting System That Will Change Your Gambling Life
Joe Duffy
 

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.