0% found this document useful (0 votes)
11 views33 pages

Chapter 1

This document serves as an introduction to object-oriented design and Java programming, covering fundamental concepts such as the differences between procedural and object-oriented programming, the structure of Java, and its key features. It outlines the objectives of learning Java, including understanding the OO paradigm, Java syntax, variable types, and creating applications. Additionally, it discusses Java's characteristics, including its portability, security features, and the development tools required to create Java programs.

Uploaded by

nadia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views33 pages

Chapter 1

This document serves as an introduction to object-oriented design and Java programming, covering fundamental concepts such as the differences between procedural and object-oriented programming, the structure of Java, and its key features. It outlines the objectives of learning Java, including understanding the OO paradigm, Java syntax, variable types, and creating applications. Additionally, it discusses Java's characteristics, including its portability, security features, and the development tools required to create Java programs.

Uploaded by

nadia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

{

Object-oriented
design and Java
Programming
Chapter 1: Introduction

}
1
Module overview

{ ..
PU Java 42H

OODJP
3A, 3B PBA
Project-based approach

} .. 2
Chapter objectives

●Understand the OO paradigm

●Discover Java

●Describe the syntax of the Java


programming language
●Identify variable types

●Create a Java application

3
{ ..
OOP vs PP

} .. 4
Procedural programming

Classical programming, as studied in the C,


Pascal, .. and other languages, defines a program
as follows:

● A set of data on which procedures and functions


act.

● Data is the passive part of the program.


Procedures and functions are the active part.

"What should my program


do?" 5
Procedural programming

Programming in this case consists of :

● Defining a number of variables (structures,


arrays, etc.).

● Writing procedures to manipulate them, without


explicitly associating them with one another.

"What should my program


do?" 6
O.O.P (Object-oriented programming)

Object-oriented programming is based on an


approach to software design and development.

Represent real-world elements by computer entities


called "objects", adopting a high level of
abstraction.

"What should my program


consist of?"
7
O.O.P (Object-oriented programming)

An object is a software entity:

● Has an identity

● Capable of storing a state, i.e. a set of


information in internal variables (attributes*).

● Responds to specific messages by triggering


appropriate internal activations that change the
object's state (behavior**).

"What should my program


consist of?"
8
O.O.P (Object-oriented programming)

*An object's attributes are all the An object can receive a message that
information in the form of variables triggers:
that represent the object's state. • A method that modifies its state or
• A method that sends a msg to
**These operations are called another object
methods. They are functions linked to
objects and specify their behavior.

9
Procedural & Object-oriented languages

{ Procedural languages
Object-oriented
languages

Pascal PHP >= 5

C C++

PHP < 5
Java

}
10
11
{ ..
What is JAVA?

} .. 12
Java the language

Java is an object-oriented programming language, which means it lets you create programs
using objects and classes.

Java is a compiled and interpreted language.

Compilation Interpretation

13
Java the language

● Java is designed to be safe and reliable, with built-in security features to protect against
programming errors and external attacks.

● Java is multidisciplinary:

14
Java the language

● Java is portable and platform-independent(Write Once, Run Anywhere).

15
Java the language
The Java platform is made up of several elements that work together to enable Java
programs to run on different platforms. The main elements of the Java platform are :

● Class libraries (API):


a set of predefined classes that
provide basic functionalities
for Java programs.

● JVM (Java Virtual Machine):


A virtual machine is a fictitious computer
computer running on a real computer
which translates bytecode into the computer's
native language.

16
{ ..
Fundamental concepts

} .. 17
Class and Object

In Java, a class is a model for creating objects with similar properties (attributes) and
behaviors (methods).

A class is the mold that will enable us to create objects in its image, as an object is derived
from a class.

18
Class and Object

ATTRIBUTES
Static part Data (Properties) Attributes represent the data
description specific to each
object class.

Code manipulating them


Dynamic part METHODS:
(Methods)
Methods represent all the
actions, procedures, functions or
operations that can be
associated with a class.

19
Variables
In Java, a variable is a memory space that can store a value or a reference to an object.

To declare a variable in Java, you need to specify its type, followed by its name, like this:

int age; //ici "int" est le type de variable et "age" est son nom
float price;
char grade;
Il est également possible d'initialiser une variable lors de sa déclaration en lui donnant une
valeur:

int age = 25; //ici la variable "age" est de type "int" et crée avec la valeur 25
float price = 19.99;
char grade = 'A’;
String name = "John";

20
Data types in java
In Java, there are 2 categories of data types:

⮚ Primitives: These data types contain the actual value of the variable in memory.

⮚ Reference: Contains the memory address where the object information is actually
stored.

21
Primitive types
● Logical value
boolean (true/false)

● Integers The value is stored


byte (1 byte) directly in the memory
short (2bytes) cell
int (4 bytes)
long (8 bytes)

● Non-integer numbers (floating point)


float (4 bytes)
double (8 bytes)

● Character (single)
char (2 bytes)

22
Primitive types

23
Primitive types

Type Default value


byte 0
short 0
int 0
long 0L
float 0.0f
double 0.0d
char '\u0000'
boolean false

24
Reference types
In Java, a reference is a type of variable that stores the address of an object in memory.

References are used to access objects and perform operations on them.

25
Wrappers
A wrapper class is a class that encapsulates a primitive data type and allows it to be treated
as an object.

Wrappers provide useful methods for working with primitive data types, such as converting
a string to a double or comparing two int values.

Example:

26
Wrappers

27
Conditional/iterative structures
Conditional diagrams: execute a series of instructions if a condition is true, and
execute another series of instructions if it is not.
● if (same syntax as in C/C++)
● switch-case (almost the same syntax as in C/C++)

Iterative schemes : Iterative processing is used to execute one or more instructions


several times.

● for (same syntax as in C/C++)


● while (same syntax as in C/C++)
● do-while (same syntax as in C/C++)

28
{ ..
Development tools

} .. 29
Development tools
To develop a JAVA program, you need a :

● IDE(Integrated Development Environment) : A program grouping together a set of


tools for software development. (IntelliJ, NetBeans, Eclipse)

● JDK(Java Development Kit): a set of development tools for Java that includes a
compiler (javac), debugger (jdb), libraries and other tools needed to create and run
Java applications.

● JRE(Java Runtime Environment): a set of tools needed to run Java applications on a


computer, including the JVM.

30
{ ..
First program

} .. 31
1/Launch a text editor and create
a file entitled
"HelloWorld.java "

2/Copy the attached code

3/Compile with the command:

Javac HelloWorld.java

Note that a "HelloWorld.class" file


is generated

4/Run by launching the java


virtual machine and specifying
the entry point:

Java HelloWorld
32
{ .. Thank you for your attention

} .. 33

You might also like