Chapter 1 Introduction To Java
Chapter 1 Introduction To Java
Widely used:
Imperative: do this and next do that
Examples: Fortran, Algol, Pascal, Basic, C
PROGRAMMING WITH
JAVA
Introduction M. El Dick - I2211
Example: car
MyCar JohnCar We only need its size and color in the problem
Objects brand “honda” brand “kia” We design a class with information only about the size and the
color “blue” color “black” color
speed 65 speed 65
size 100 size 80
M. El Dick - I2211 M. El Dick - I2211
Encapsulation Encapsulation
Hide implementation details Class 1 Class 1
Class2
Group related data and operations in a class/object
Interface
Other classes/objects : public methods
Encapsulation Inheritance
Extend a class and create subclasses
Car
String brand
String color
access A subclass can :
Private fields denied
int speed
Other objects inherit fields and methods of its superclass
and methods int size
can add new fields and methods
change_gear() can redefine (override) methods of its superclass
brake) access
Public methods allowed
accelerate()
play() play()
… Different behaviors …
M. El Dick - I2211 M. El Dick - I2211
Java the Programming Language Java is Portable
Simple and easy to use syntax “Write once and run everywhere”
Secure Regardless of the OS or the hardware
No pointers like in C++ and arbitrary memory access Any platform: Windows, MacOS, Linux, etc.
Portable
Many libraries (in the form of packages) thanks to Java Virtual Machine (JVM)
New libraries are introduced constantly
Environment in which Java programs execute
Object oriented
Software that is implemented on top of hardware
Designed for distributed systems
and OS
Java platform
MyProgram.java
Software-only platform that runs on top of hardware platforms
API
Java
Set of programs to develop and run programs written in Java Java Virtual Machine
Platform
language
Hardware-based Platform
Java SE Java EE
JRE – Java Runtime Environment Java EE – Enterprise Edition
For users For enterprises
JVM + standard library JDK + more libraries for servers (JDBC, RMI,
email)
JDK - Java Development Kit For distributed deployment (Enterprise’s
For developers intranet)
JRE + Java compiler + other programming
tools
Source
code javac Bytecode java Code is executed
Hello.java Hello.class
Hello
library files
M. El Dick - I2211