Chapter 3:
Introduction to Object-Oriented Concepts & Java
What is Object-Oriented Technology?
Object-oriented methodology models real- world objects
Programs and software are built from these objects
In contrast, structured approach focuses on tasks and procedures
Classes and Objects
Java programs are built using classes and objects.
The JDK itself has a rich set of classes that can be used and re-used.
Class
Is a blueprint or template of an object?
It represents broad groups of objects
It contains elements common to a group of objects
Example:
- Animal
- Vehicle
Object
Is an instance of a class?
It is a specific occurrence of a class
Objects have state and behavior
Example:
- Cat is an instance of the class Animal
- Car is an instance of the class Vehicle
A cat has several states: asleep, alive, lost
Its behavior could be: eating, jumping, etc.
Encapsulation, Inheritance, Polymorphism
Encapsulation
Means that data and instructions are wrapped up together and treated as a unit
Inheritance
Ability to “inherit”, use or modify existing or predefined classes
Polymorphism
The ability of objects to respond or behave
differently
Example: A cat “purrs”, a dog “barks”, and a cow “moos”
What is Java?
Is an object-oriented programming language.
Is both a programming language and a platform.
Java is hardware-independent and can run on various operating systems
As a programming language, it
- Contains specifications for writing or coding programs
- Has a compiler for checking syntax and converting programs to bytecodes
- Has a rich set of APIs (Application Programming Interfaces) that can be
reused and modified?
As a platform, it
- Converts bytecodes into executable code
- Has a JVM (Java Virtual Machine) to run java programs on various
operating systems
History of Java
Java
Was created in 1991 by James Gosling, et al. of Sun Microsystems
It was originally designed for consumer electronic devices and was called Oak
With the advent of the Internet, Sun developed a browser named HotJava using Oak
In 1994, Sun renamed Oak to Java and released a free alpha version of the JDK
(Java Developer’s Kit) composed of Java and HotJava
In 1996, Netscape Communications Corp announced support for Java applets which
was later included in version 2.0 of the Navigator browser
What can Java Technology Do?
Development Tools
- Compiler, launcher and documentation tools are in the JDK
Application Programming Interface
- Contains classes ready to be used in programs
Deployment Technologies
- Contains software for deploying applications to end users
User Interface Tookits
- Swing and Java2D tookits are available for creating Graphical User
Interfaces (GUIs)
Integration Libraries
- A suite of libraries for connecting to databases and manipulating remote
objects
Java Programming Environment
The Java Platform
A platform is the hardware or software environment where a program runs
This usually refers to the operating system and the underlying hardware
The Java platform is different in that it is a software-only platform that runs on top of a
hardware platform
It has 2 components:
- Java Virtual Machine (JVM)
- Java Application Programming Interface (API)
The Java Virtual Machine (JVM)
The Java “interprets” bytecodes, and through its java launcher tool, runs the application
program
It sits on top of the operating system. Each operating system has its own JVM.
Bytecodes is the machine language of the JVM. Source code is written on
a text file with a .java extension. This source code is compiled by the java compiler
and produces bytecodes with a .class extension.
There is a JVM for most operating systems (Windows, Linux, Unix,
MacOS). This makes Java “portable”, e.g., the same program (in bytecodes) can be
“ported” and run on other operating systems without need for recompilation.
Structure of Java Program
Features of Java Program
Object-oriented
Distributed
Interpreted
Robust
Secure
Architecture Neutral
Portable
High Performance
Multi-threaded
Dynamic