2. Session Objectives
Discuss the object oriented approach
Discuss the drawbacks of traditional
programming
Discuss object oriented programming
Discuss basic Object-Oriented concepts such as
objects, classes, properties, methods, abstraction,
inheritance, encapsulation, reusability and
polymorphism.
Describe Java Virtual Machine
Write the First Java Program
Jigar Jobanputra(JJ)
3. The Object-Oriented Approach
PersonnelAccounts
Sales
The real world around is full of objects .We can consider both the living
beings as well as non living elements as objects.
For example, the different departments in a company are objects.
Jigar Jobanputra(JJ)
5. Object – Oriented
Programming
Data
Employee details
Salary statements
Bills
Vouchers
Receipts
Functions
Calculate salary
Pay salary
Pay bills
Tally accounts
Transact with banks
Here the application has to implement the entities as they are seen in real life and
associate their actions and attributes with each other.
Accounts
Jigar Jobanputra(JJ)
6. Objects
Some real-life entities :
Physical Objects
Vehicles in a traffic -monitoring application
Electrical components in a circuit design problem
Elements of the computer-user environment
Windows
Menus
An object is an element with defined boundaries that is relevant to the problem we
are dealing with
Jigar Jobanputra(JJ)
7. Objects (contd…)
Collections of data
An inventory of machine parts
A personnel file
User defined data types
Time
Angles
Complex numbers
Jigar Jobanputra(JJ)
8. Objects (contd…)
Model : Ferrari
Color : Red
Year : 1995
Actions
Start
Stop
Accelerate
Jigar Jobanputra(JJ)
9. Classes
A class is a group of objects that have the same properties, common behavior.
Polygon objects Polygon class
Properties
Vertices
Border color
Fill color
Methods
Draw
Erase
Move
Jigar Jobanputra(JJ)
10. Encapsulation
Encapsulation is a process that allows
selective hiding of properties and
methods in a class.
Not accessible from outside
class
Accessible from outside class
Private
Public
Jigar Jobanputra(JJ)
11. Inheritance
Inheritance is the property that allows the reuse of an existing class to build a
new class
Animals
Jigar Jobanputra(JJ)
15. Object – Oriented Languages
C ++
Small Talk
Eiffel
CLOS
Java
Jigar Jobanputra(JJ)
16. The Problem with High Level
Language
P
R
O
B
L
E
M
Program
Applications
written for a
particular
platform will not
work on another
platform
S
O
L
U
T
I
O
N
Interpreter
Interpreter
Interpreter
Program To solve this
problem, we
make use of
interpreters
So the code for any application can be written only once, which can then be
executed with the help of Interpreters created for different platformsJigar Jobanputra(JJ)
17. Java Language
Java is a language from SUN Microsystems.
Java uses an Interpreter to execute code so that it may run on different
computers without any change to the source code.
Java Programs are platform independent. Hence the code written in Java can be
executed on different platforms.
Java is a program mainly used for Web based applications because of its
support to different platforms.
Java is purely an Object Oriented Programming language.
Jigar Jobanputra(JJ)
18. Java Virtual Machine (JVM)
Source Code
Imaginary computer’s
instruction set
Compiler
Target Machine
Java Virtual Machine
For each computer, there is a unique Java Virtual Machine
Machine language code
Byte Code
Jigar Jobanputra(JJ)
19. Life Cycle of a Java Program
Compiler Filename.class
Byte Code
Filename.java
Source Code
User
Code
Java Virtual Machine
Jigar Jobanputra(JJ)
20. Execution procedure by the JVM
The Java Virtual Machine creates a runtime system
internally that helps the execution of code by :
Loading the “ . class ” files.
Managing the memory.
Performing Garbage collection.
Jigar Jobanputra(JJ)
21. Java code and JVM
All java programs are written keeping in mind the
Java VM.
The Java source code and the byte code is machine
independent while JVM is machine dependant.
Different machines with different Operating system
will require a JVM developed for that machine.
Jigar Jobanputra(JJ)
23. First Program [Contd…]
• Save the file as HelloJava.java
• Use the javac command to compile the
file HelloJava.java
• Execute the bytecodes of
HelloJava.class using the java
command
Jigar Jobanputra(JJ)