SlideShare a Scribd company logo
Introduction
Elizabeth MacDonald
The State University of New York at Albany
What we will cover
tonight
• History of Java
• Benefits of Java
• Java Environment
• Types of Java programs
• The Java Platforms
• UML
• Structured vs. Object Oriented Programming
• Basics of a Java application
The History of Java
Code-Name Green
• The name for Sun’s internal corporate
research project aimed at providing
intelligent consumer-electronic devices.
• Result was Oak
– C++ based language
– Created by James Gosling
– Named after an Oak tree outside his office
– Name of new language changed to Java
Green in the red?
• Green project didn’t go far
– Marketplace for intelligent consumer-
electronic devices was slow to rise
– Sun didn’t win certain contracts
– Was on the verge of being cancelled
Saved by the Web!
• World Wide Web popularity explosion in
1993 saved project Green
• Sun saw the potential for Java providing
dynamic content to web pages
• Java was formally announced in 1995
• Java is now used for large-scale
enterprise applications, applications for
consumer devices, and many other
purposes.
Benefits of Java
“Write once run
anywhere”
• Platform independent and architecturally
neutral
• As opposed to C++, you do not need to
recompile
• This is due to the Java Virtual Machine
(we will discuss that in a moment)
• Bytecode can be ported across platforms
with compatible versions of the JVM
Rich libraries
• The term Java refers to both the language
you can use to develop your own libraries,
as well as the numerous existing classes
that have already been developed.
– Simplifies programming
– Includes classes for building Graphical User
Interfaces, file I/O, networking, web
applications, etc.
Internationalization
• Unlike most other languages, Java uses
16 bit Unicode characters
– Can represent the phonetic and ideographic
character sets of the entire world
– C++ uses 8 bits ~ 256 different characters
– 16 bit Java char ~ 65,535 different characters
Distributed
• Java classes can execute remotely
• Has full support for serialization into
bytecode
• Has networking capabilities built in
– ADTs for distributed message passing
Security
• Java has customizable Security settings
• Java applets
– Users would be afraid to run applets that
could damage their machines
– Prevent applets from doing any local file I/O
or killing other running processes…
Threading
• Java simplifies multithreading
• A thread is a lightweight process
• Multiple processes run through the same
set of instructions in memory, as opposed
to loading the application code into
different memory locations
• Java has encapsulated threads as an
Abstract Data Type
Object Oriented
• Java is a truly Object Oriented
programming language
• Everything has to reside in a class
– Main method and all other methods have to
be in a class
• Has support for inheritance,
polymorphism, message passing, …
The Java Environment
To run a Java
Program
– Java instructions need to be translated
into an intermediate language called
bytecode
– Then the bytecode is interpreted into a
particular machine language
What is needed…
• Compiler: A program that translates a
program written in a high-level language into
the equivalent machine language.
– In the case of Java, this machine language is the
bytecode.
• Java Virtual Machine (JVM) - hypothetical
computer developed to make Java programs
machine independent
Java Virtual Machine
• Java programs execute on the JVM.
• The JVM is a virtual rather than a physical
machine (although the JVM has been
implemented in silicon.)
• The JVM is typically implemented as a
run-time interpreter
• Translates Java bytecode instructions 
native instruction codes
Processing a Java
Program
• Source program: Written in a high-level
language
• Linker: Combines bytecode with other programs
provided by the SDK and creates executable
code
• Loader: transfers executable code into main
memory
• Interpreter: reads and translates each bytecode
instruction into machine language and then
executes it
Processing a Java
Program
Java Runtime
Environment
• The java utility in the SDK provides the JVM as a
run-time interpreter.
• The JVM provides a run-time environment (JRE)
• Enables programs to execute on a host platform.
• The Java runtime can work with a security
manager to determine which operations a
program can perform on the host platform.
Types of Java Programs
Program types
• Java has four program types, although the
differences among them are shallow.
• The two most commonly used types are:
– Application
– Applet
Java Application
• Standalone program in the sense of
requiring only the JVM to execute.
• Does not require a host program such as a
browser.
• It’s main method is used as its entry point
• Has to have a method with the following
signature…
public static void main(String args[ ])
Java Applet
• Small program typically downloaded from a
server to a client machine.
• JVM is built into the web browser
• A Web browser acts as the host program for an
applet.
• An applet is typically launched through an HTML
or equivalent document.
• They are imbedded into HTML with the <applet>
tag
Java Applet (cont’d)
• An applet typically operates under a strict
security manager, which imposes sandbox
security.
• This prevents an applet from performing
potentially dangerous operations such as
reading from or writing to the local disk.
• An applet’s class descends from the standard
Applet or JApplet class.
Unified Modeling Language
UML (part 1)
• Unified Modeling Language
– Meant to facilitate the design, development,
deployment and maintenance of software
systems.
– Standardized in 1997 by the Object
Management Group.
– Combines methods from Object Modeling
Technique (OMT) and Object-Oriented Software
Engineering (OOSE).
• UML diagrams can serve as high-level design
specifications for software systems and, in this role,
can guide code development.
UML (part 2)
• Basic UML vocabulary consists of
– Things: Entities to be modeled, whether
concrete or abstract.
– Relationships: Connections among things.
– Diagrams: graphical depictions of things and
their relationships
• We will discuss the types of UML
diagrams as they come up.
Object Oriented vs.
Structured Programming
Structured Approach
• Subset of procedural programming
• Enforces a logical structure on the program being written
to make it more efficient and easier to understand and
modify.
• Frequently employs a top-down design model
– Developers map out the overall program structure into separate
subsections.
– A defined function or set of similar functions is coded in a
separate module or submodule, which means that code can be
loaded into memory more efficiently and that modules can be
reused in other programs.
– After a module has been tested individually, it is then integrated
with other modules into the overall program structure.
Object Oriented
Approach
• Provides a more natural and intuitive way
to view the design process
• Modeling software components just as we
describe real-world objects
– By their attributes, behaviors, and the
messages they pass between each other
• Objects
– Reusable software components
– Building blocks
Benefits of OO
• Quality
– Small, small-contained manageable objects reduces
the complexity of the system development
– Less error prone
• Productivity
– More reuse
• Flexibility
– Can add or modify objects while minimizing the
impact on the rest of the system
– This is achieved via encapsulation
Java and OO
• Just because it’s written in Java, does not
mean it is object-oriented
• The standard Java libraries are not always
good examples of OO programming.
• Compromise between practical and
efficiency considerations and truly good
OO design
What is an object-
oriented system?
• Has the following 6 properties:
– Abstraction with objects
– Encapsulated classes
– Communication via messages
– Object lifetime
– Class hierarchies
– Polymorphism
Abstraction
• A model of a real-world object or concept
• Usually a simplified representation of a
complex situation
• Designing objects can be difficult
• Have to decide on what attributes and
behaviors are necessary
• Address book example
Encapsulated Classes
• Remember abstract data types?
• The process of hiding all the internal
details of an object from the outside
world.
• In Java, this is having definitions for
attributes and methods inside a class
definition.
• State is changed using methods in the
class.
Communication via
Messages
• Messages are how objects communicate with
each other.
• Follows client/server model.
• Objects can send and receive messages.
• Send = invoke a class method
• Receive = have your method called by another
object
• Can also be invoked by the language runtime
system or the operating system.
Class Hierarchies
• An ordering of classes.
• This includes:
– Association
– Aggregation
– Composition
– Inheritance
Association
• A relationship between two classes.
• Indicates how the objects of the classes relate
to each other.
• The relationship has some sort of name (verb).
• Multiplicity specifies the number of objects that
can participate in the association.
Teacher Student
teaches
learns from
*
*
Aggregation
• has-a relationship
• The aggregate object includes other
objects
• The included objects are considered to be
a part-of the aggregate
Car Dealership Car
*
Composition
• Special case of aggregation
• The whole cannot exist without the
aggregate object(s)
Car Engine
1
Inheritance
• is-a relationship
• A mechanism that allows one class (the
subclass) to share the attributes and
behaviors of another class (the superclass).
• A subclass is a specialization of the
generalized superclass.
• The derived class may override or provide
an alternate definition for an attribute or
method of the superclass, or use the default
behaviors of the superclass.
Inheritance Example
Animal
Warm Blooded Cold Blooded
Mammal
Bird
Flying Non-Flying
Parrot Penguin
More on Inheritance
• In Java, all classes are implicitly derived from
the Object class, making Object the root
class.
• Single inheritance is when a class is directly
derived from only 1 parent class.
• Multiple inheritance is when a class is derived
from more than one parent classes.
• Unlike other languages, Java does not support
multiple inheritance.
Multiple Inheritance is
BAD
• Repeated Inheritance – a base can
occur more than once in the parents list.
• Ambiguity – a feature or method occurs
more than once among the parents…
which one is called?
• This brings us to interfaces, the
alternative to multiple inheritance.
Interfaces
• In psychology, a “mask” that allows a person to
behave in a manner appropriate to a particular
role.
• In Java, the specification of methods that a
class using the interface must implement, or
provide code for.
• Defines the is-a relationship between classes.
• You will NOT find code in an interface.
Polymorphism
• Dynamic binding of an object to the
appropriate method. (The actual binding of a
call to a specific method is delayed until
runtime.)
GoodStudent BadStudent
Student
+takeExam() : int
+takeExam() : int
+takeExam() : int
Basics of a Java Application
Jumping into Java
Programming
• To create and run a Java program
– Create a text file with a .java extension for
the source code. For instance, source code
for a first program might reside in the file
Hi.java.
– Write the source code.
– Compile the source code into binary code.
– Execute the binary code.
Compiling
• Suppose that the Java source code
resides in the plain text file Hi.java. Using
the $ as the system prompt, the source
code is compiled with the command
$ javac Hi.java
The javac utility comes with the Java SDK.
Compiling
• Compiling a source file such as Hi.java
generates one or more binary files with a
.class extension, e.g., Hi.class.
– If fatal errors occur during compilation, the
process ends with appropriate error
messages.
– If nonfatal errors occur during compilation,
the process continues with appropriate
warnings.
Executing
• Once the program has been compiled, it
can executed with the java utility. For
instance, if the file Hi.class contains a
compiled standalone program, the
command
$ java Hi
executes the program.
Compiling versus
executing
• Note that the .java extension is included
in the compilation but that the .class
extension is not included in the execution.
Note the contrast:
$ javac Hi.java
$ java Hi
A first program (part 1)
// This program prints
// Hello, world!
// to the standard output.
class Hi {
public static void main( String[ ] a ){
System.out.println( “Hello, world!” );
}
}
A first program (part 2)
• The source code for the Hi program resides in a
text file with a .java extension, Hi.java.
• Every Java program requires at least one
source code class, as the Hi example
illustrates.
• A public class must reside in a .java file of the
same name.
• There can be at most one public class definition
in a file.
A first program (part 3)
• The Hi program is a Java application rather
than, for instance, an applet, or a servlet,
which are other program types.
• A Java application is the most general and
basic program type.
• An application must have a public static method
called main, that takes in an array of Strings:
public static void main(String args[]) {}
A first program (part 4)
• The syntax
String[] a
indicates that a (for “array”) refers to an
array. In general, the square brackets
indicate an array. In this case, the array
can hold references to Strings, which
are any command-line arguments passed
to the program.
A first program (part 5)
• In the print statement
System.out.println( “Hello, world!” );
– System is a standard Java class that
represents the system on which the program
executes.
– out is a static field in the System class
and its type is PrintStream, another
standard Java class.
– println is a PrintStream method.
A first program (part 6)
• In the Hi program’s print statement, the
parts System, out, and println are
separated by the member operator, the
period.
• The print statement is terminated by a
semicolon.
– In Java, the semicolon terminates
statements.

More Related Content

Similar to JAVA object oriented programming (oop).ppt (20)

JavaClassPresentation
JavaClassPresentationJavaClassPresentation
JavaClassPresentation
juliasceasor
 
Java Programming - UNIT - 1, Basics OOPS, Differences
Java Programming - UNIT - 1, Basics OOPS, DifferencesJava Programming - UNIT - 1, Basics OOPS, Differences
Java Programming - UNIT - 1, Basics OOPS, Differences
PradeepT42
 
Core Java Slides
Core Java SlidesCore Java Slides
Core Java Slides
Vinit Vyas
 
Java presentation
Java presentationJava presentation
Java presentation
Karan Sareen
 
Chapter 1 java
Chapter 1 javaChapter 1 java
Chapter 1 java
ahmed abugharsa
 
00 intro to java
00 intro to java00 intro to java
00 intro to java
Deia Abdullah
 
introduction to object orinted programming through java
introduction to object orinted programming through javaintroduction to object orinted programming through java
introduction to object orinted programming through java
Parameshwar Maddela
 
Java
JavaJava
Java
seenak
 
Java1
Java1Java1
Java1
computertuitions
 
Java
Java Java
Java
computertuitions
 
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
10322210023
 
Chapter 1 introduction to java technology
Chapter 1 introduction to java technologyChapter 1 introduction to java technology
Chapter 1 introduction to java technology
sshhzap
 
JAVA_VR23_OOPS THROUGH JAVA PPT UNIT-1.pptx
JAVA_VR23_OOPS THROUGH JAVA PPT UNIT-1.pptxJAVA_VR23_OOPS THROUGH JAVA PPT UNIT-1.pptx
JAVA_VR23_OOPS THROUGH JAVA PPT UNIT-1.pptx
netaji10700
 
object oriented programming unit one ppt
object oriented programming unit one pptobject oriented programming unit one ppt
object oriented programming unit one ppt
isiagnel2
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.ppt
CDSukte
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.ppt
RajeshSukte1
 
Unit 2 Java
Unit 2 JavaUnit 2 Java
Unit 2 Java
arnold 7490
 
PJ_M01_C01_PPT_Introduction to Object Oriented Programming Using Java.pdf
PJ_M01_C01_PPT_Introduction to Object Oriented Programming Using Java.pdfPJ_M01_C01_PPT_Introduction to Object Oriented Programming Using Java.pdf
PJ_M01_C01_PPT_Introduction to Object Oriented Programming Using Java.pdf
projectfora2
 
PROGRAMMING IN JAVA unit 1.pptx
PROGRAMMING IN JAVA unit 1.pptxPROGRAMMING IN JAVA unit 1.pptx
PROGRAMMING IN JAVA unit 1.pptx
SeethaDinesh
 
object oriented programming examples
object oriented programming examplesobject oriented programming examples
object oriented programming examples
Abdii Rashid
 
JavaClassPresentation
JavaClassPresentationJavaClassPresentation
JavaClassPresentation
juliasceasor
 
Java Programming - UNIT - 1, Basics OOPS, Differences
Java Programming - UNIT - 1, Basics OOPS, DifferencesJava Programming - UNIT - 1, Basics OOPS, Differences
Java Programming - UNIT - 1, Basics OOPS, Differences
PradeepT42
 
Core Java Slides
Core Java SlidesCore Java Slides
Core Java Slides
Vinit Vyas
 
introduction to object orinted programming through java
introduction to object orinted programming through javaintroduction to object orinted programming through java
introduction to object orinted programming through java
Parameshwar Maddela
 
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
10322210023
 
Chapter 1 introduction to java technology
Chapter 1 introduction to java technologyChapter 1 introduction to java technology
Chapter 1 introduction to java technology
sshhzap
 
JAVA_VR23_OOPS THROUGH JAVA PPT UNIT-1.pptx
JAVA_VR23_OOPS THROUGH JAVA PPT UNIT-1.pptxJAVA_VR23_OOPS THROUGH JAVA PPT UNIT-1.pptx
JAVA_VR23_OOPS THROUGH JAVA PPT UNIT-1.pptx
netaji10700
 
object oriented programming unit one ppt
object oriented programming unit one pptobject oriented programming unit one ppt
object oriented programming unit one ppt
isiagnel2
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.ppt
CDSukte
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.ppt
RajeshSukte1
 
PJ_M01_C01_PPT_Introduction to Object Oriented Programming Using Java.pdf
PJ_M01_C01_PPT_Introduction to Object Oriented Programming Using Java.pdfPJ_M01_C01_PPT_Introduction to Object Oriented Programming Using Java.pdf
PJ_M01_C01_PPT_Introduction to Object Oriented Programming Using Java.pdf
projectfora2
 
PROGRAMMING IN JAVA unit 1.pptx
PROGRAMMING IN JAVA unit 1.pptxPROGRAMMING IN JAVA unit 1.pptx
PROGRAMMING IN JAVA unit 1.pptx
SeethaDinesh
 
object oriented programming examples
object oriented programming examplesobject oriented programming examples
object oriented programming examples
Abdii Rashid
 

Recently uploaded (20)

Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
BradBedford3
 
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
Insurance Tech Services
 
Automating Map Production With FME and Python
Automating Map Production With FME and PythonAutomating Map Production With FME and Python
Automating Map Production With FME and Python
Safe Software
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The SequelMarketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
BradBedford3
 
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps CyclesFrom Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
Marjukka Niinioja
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native BarcelonaOpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FMEIntegrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
Revolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management SoftwareRevolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management Software
Insurance Tech Services
 
Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3
Gaurav Sharma
 
FME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable InsightsFME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable Insights
Safe Software
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlowDevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdfThe Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
Varsha Nayak
 
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentricIntegration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Natan Silnitsky
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 
Maximizing Business Value with AWS Consulting Services.pdf
Maximizing Business Value with AWS Consulting Services.pdfMaximizing Business Value with AWS Consulting Services.pdf
Maximizing Business Value with AWS Consulting Services.pdf
Elena Mia
 
Software Testing & it’s types (DevOps)
Software  Testing & it’s  types (DevOps)Software  Testing & it’s  types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
BradBedford3
 
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
Insurance Tech Services
 
Automating Map Production With FME and Python
Automating Map Production With FME and PythonAutomating Map Production With FME and Python
Automating Map Production With FME and Python
Safe Software
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The SequelMarketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
BradBedford3
 
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps CyclesFrom Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
Marjukka Niinioja
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native BarcelonaOpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FMEIntegrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
Revolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management SoftwareRevolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management Software
Insurance Tech Services
 
Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3
Gaurav Sharma
 
FME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable InsightsFME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable Insights
Safe Software
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlowDevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdfThe Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
Varsha Nayak
 
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentricIntegration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Natan Silnitsky
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 
Maximizing Business Value with AWS Consulting Services.pdf
Maximizing Business Value with AWS Consulting Services.pdfMaximizing Business Value with AWS Consulting Services.pdf
Maximizing Business Value with AWS Consulting Services.pdf
Elena Mia
 
Software Testing & it’s types (DevOps)
Software  Testing & it’s  types (DevOps)Software  Testing & it’s  types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Ad

JAVA object oriented programming (oop).ppt

  • 1. Introduction Elizabeth MacDonald The State University of New York at Albany
  • 2. What we will cover tonight • History of Java • Benefits of Java • Java Environment • Types of Java programs • The Java Platforms • UML • Structured vs. Object Oriented Programming • Basics of a Java application
  • 4. Code-Name Green • The name for Sun’s internal corporate research project aimed at providing intelligent consumer-electronic devices. • Result was Oak – C++ based language – Created by James Gosling – Named after an Oak tree outside his office – Name of new language changed to Java
  • 5. Green in the red? • Green project didn’t go far – Marketplace for intelligent consumer- electronic devices was slow to rise – Sun didn’t win certain contracts – Was on the verge of being cancelled
  • 6. Saved by the Web! • World Wide Web popularity explosion in 1993 saved project Green • Sun saw the potential for Java providing dynamic content to web pages • Java was formally announced in 1995 • Java is now used for large-scale enterprise applications, applications for consumer devices, and many other purposes.
  • 8. “Write once run anywhere” • Platform independent and architecturally neutral • As opposed to C++, you do not need to recompile • This is due to the Java Virtual Machine (we will discuss that in a moment) • Bytecode can be ported across platforms with compatible versions of the JVM
  • 9. Rich libraries • The term Java refers to both the language you can use to develop your own libraries, as well as the numerous existing classes that have already been developed. – Simplifies programming – Includes classes for building Graphical User Interfaces, file I/O, networking, web applications, etc.
  • 10. Internationalization • Unlike most other languages, Java uses 16 bit Unicode characters – Can represent the phonetic and ideographic character sets of the entire world – C++ uses 8 bits ~ 256 different characters – 16 bit Java char ~ 65,535 different characters
  • 11. Distributed • Java classes can execute remotely • Has full support for serialization into bytecode • Has networking capabilities built in – ADTs for distributed message passing
  • 12. Security • Java has customizable Security settings • Java applets – Users would be afraid to run applets that could damage their machines – Prevent applets from doing any local file I/O or killing other running processes…
  • 13. Threading • Java simplifies multithreading • A thread is a lightweight process • Multiple processes run through the same set of instructions in memory, as opposed to loading the application code into different memory locations • Java has encapsulated threads as an Abstract Data Type
  • 14. Object Oriented • Java is a truly Object Oriented programming language • Everything has to reside in a class – Main method and all other methods have to be in a class • Has support for inheritance, polymorphism, message passing, …
  • 16. To run a Java Program – Java instructions need to be translated into an intermediate language called bytecode – Then the bytecode is interpreted into a particular machine language
  • 17. What is needed… • Compiler: A program that translates a program written in a high-level language into the equivalent machine language. – In the case of Java, this machine language is the bytecode. • Java Virtual Machine (JVM) - hypothetical computer developed to make Java programs machine independent
  • 18. Java Virtual Machine • Java programs execute on the JVM. • The JVM is a virtual rather than a physical machine (although the JVM has been implemented in silicon.) • The JVM is typically implemented as a run-time interpreter • Translates Java bytecode instructions  native instruction codes
  • 19. Processing a Java Program • Source program: Written in a high-level language • Linker: Combines bytecode with other programs provided by the SDK and creates executable code • Loader: transfers executable code into main memory • Interpreter: reads and translates each bytecode instruction into machine language and then executes it
  • 21. Java Runtime Environment • The java utility in the SDK provides the JVM as a run-time interpreter. • The JVM provides a run-time environment (JRE) • Enables programs to execute on a host platform. • The Java runtime can work with a security manager to determine which operations a program can perform on the host platform.
  • 22. Types of Java Programs
  • 23. Program types • Java has four program types, although the differences among them are shallow. • The two most commonly used types are: – Application – Applet
  • 24. Java Application • Standalone program in the sense of requiring only the JVM to execute. • Does not require a host program such as a browser. • It’s main method is used as its entry point • Has to have a method with the following signature… public static void main(String args[ ])
  • 25. Java Applet • Small program typically downloaded from a server to a client machine. • JVM is built into the web browser • A Web browser acts as the host program for an applet. • An applet is typically launched through an HTML or equivalent document. • They are imbedded into HTML with the <applet> tag
  • 26. Java Applet (cont’d) • An applet typically operates under a strict security manager, which imposes sandbox security. • This prevents an applet from performing potentially dangerous operations such as reading from or writing to the local disk. • An applet’s class descends from the standard Applet or JApplet class.
  • 28. UML (part 1) • Unified Modeling Language – Meant to facilitate the design, development, deployment and maintenance of software systems. – Standardized in 1997 by the Object Management Group. – Combines methods from Object Modeling Technique (OMT) and Object-Oriented Software Engineering (OOSE). • UML diagrams can serve as high-level design specifications for software systems and, in this role, can guide code development.
  • 29. UML (part 2) • Basic UML vocabulary consists of – Things: Entities to be modeled, whether concrete or abstract. – Relationships: Connections among things. – Diagrams: graphical depictions of things and their relationships • We will discuss the types of UML diagrams as they come up.
  • 31. Structured Approach • Subset of procedural programming • Enforces a logical structure on the program being written to make it more efficient and easier to understand and modify. • Frequently employs a top-down design model – Developers map out the overall program structure into separate subsections. – A defined function or set of similar functions is coded in a separate module or submodule, which means that code can be loaded into memory more efficiently and that modules can be reused in other programs. – After a module has been tested individually, it is then integrated with other modules into the overall program structure.
  • 32. Object Oriented Approach • Provides a more natural and intuitive way to view the design process • Modeling software components just as we describe real-world objects – By their attributes, behaviors, and the messages they pass between each other • Objects – Reusable software components – Building blocks
  • 33. Benefits of OO • Quality – Small, small-contained manageable objects reduces the complexity of the system development – Less error prone • Productivity – More reuse • Flexibility – Can add or modify objects while minimizing the impact on the rest of the system – This is achieved via encapsulation
  • 34. Java and OO • Just because it’s written in Java, does not mean it is object-oriented • The standard Java libraries are not always good examples of OO programming. • Compromise between practical and efficiency considerations and truly good OO design
  • 35. What is an object- oriented system? • Has the following 6 properties: – Abstraction with objects – Encapsulated classes – Communication via messages – Object lifetime – Class hierarchies – Polymorphism
  • 36. Abstraction • A model of a real-world object or concept • Usually a simplified representation of a complex situation • Designing objects can be difficult • Have to decide on what attributes and behaviors are necessary • Address book example
  • 37. Encapsulated Classes • Remember abstract data types? • The process of hiding all the internal details of an object from the outside world. • In Java, this is having definitions for attributes and methods inside a class definition. • State is changed using methods in the class.
  • 38. Communication via Messages • Messages are how objects communicate with each other. • Follows client/server model. • Objects can send and receive messages. • Send = invoke a class method • Receive = have your method called by another object • Can also be invoked by the language runtime system or the operating system.
  • 39. Class Hierarchies • An ordering of classes. • This includes: – Association – Aggregation – Composition – Inheritance
  • 40. Association • A relationship between two classes. • Indicates how the objects of the classes relate to each other. • The relationship has some sort of name (verb). • Multiplicity specifies the number of objects that can participate in the association. Teacher Student teaches learns from * *
  • 41. Aggregation • has-a relationship • The aggregate object includes other objects • The included objects are considered to be a part-of the aggregate Car Dealership Car *
  • 42. Composition • Special case of aggregation • The whole cannot exist without the aggregate object(s) Car Engine 1
  • 43. Inheritance • is-a relationship • A mechanism that allows one class (the subclass) to share the attributes and behaviors of another class (the superclass). • A subclass is a specialization of the generalized superclass. • The derived class may override or provide an alternate definition for an attribute or method of the superclass, or use the default behaviors of the superclass.
  • 44. Inheritance Example Animal Warm Blooded Cold Blooded Mammal Bird Flying Non-Flying Parrot Penguin
  • 45. More on Inheritance • In Java, all classes are implicitly derived from the Object class, making Object the root class. • Single inheritance is when a class is directly derived from only 1 parent class. • Multiple inheritance is when a class is derived from more than one parent classes. • Unlike other languages, Java does not support multiple inheritance.
  • 46. Multiple Inheritance is BAD • Repeated Inheritance – a base can occur more than once in the parents list. • Ambiguity – a feature or method occurs more than once among the parents… which one is called? • This brings us to interfaces, the alternative to multiple inheritance.
  • 47. Interfaces • In psychology, a “mask” that allows a person to behave in a manner appropriate to a particular role. • In Java, the specification of methods that a class using the interface must implement, or provide code for. • Defines the is-a relationship between classes. • You will NOT find code in an interface.
  • 48. Polymorphism • Dynamic binding of an object to the appropriate method. (The actual binding of a call to a specific method is delayed until runtime.) GoodStudent BadStudent Student +takeExam() : int +takeExam() : int +takeExam() : int
  • 49. Basics of a Java Application
  • 50. Jumping into Java Programming • To create and run a Java program – Create a text file with a .java extension for the source code. For instance, source code for a first program might reside in the file Hi.java. – Write the source code. – Compile the source code into binary code. – Execute the binary code.
  • 51. Compiling • Suppose that the Java source code resides in the plain text file Hi.java. Using the $ as the system prompt, the source code is compiled with the command $ javac Hi.java The javac utility comes with the Java SDK.
  • 52. Compiling • Compiling a source file such as Hi.java generates one or more binary files with a .class extension, e.g., Hi.class. – If fatal errors occur during compilation, the process ends with appropriate error messages. – If nonfatal errors occur during compilation, the process continues with appropriate warnings.
  • 53. Executing • Once the program has been compiled, it can executed with the java utility. For instance, if the file Hi.class contains a compiled standalone program, the command $ java Hi executes the program.
  • 54. Compiling versus executing • Note that the .java extension is included in the compilation but that the .class extension is not included in the execution. Note the contrast: $ javac Hi.java $ java Hi
  • 55. A first program (part 1) // This program prints // Hello, world! // to the standard output. class Hi { public static void main( String[ ] a ){ System.out.println( “Hello, world!” ); } }
  • 56. A first program (part 2) • The source code for the Hi program resides in a text file with a .java extension, Hi.java. • Every Java program requires at least one source code class, as the Hi example illustrates. • A public class must reside in a .java file of the same name. • There can be at most one public class definition in a file.
  • 57. A first program (part 3) • The Hi program is a Java application rather than, for instance, an applet, or a servlet, which are other program types. • A Java application is the most general and basic program type. • An application must have a public static method called main, that takes in an array of Strings: public static void main(String args[]) {}
  • 58. A first program (part 4) • The syntax String[] a indicates that a (for “array”) refers to an array. In general, the square brackets indicate an array. In this case, the array can hold references to Strings, which are any command-line arguments passed to the program.
  • 59. A first program (part 5) • In the print statement System.out.println( “Hello, world!” ); – System is a standard Java class that represents the system on which the program executes. – out is a static field in the System class and its type is PrintStream, another standard Java class. – println is a PrintStream method.
  • 60. A first program (part 6) • In the Hi program’s print statement, the parts System, out, and println are separated by the member operator, the period. • The print statement is terminated by a semicolon. – In Java, the semicolon terminates statements.