0% found this document useful (0 votes)
25 views

Fundamentals of Programming - Week 3-4-5

The document discusses procedural and object-oriented programming fundamentals. Procedural programming is based on calling procedures or functions, while object-oriented programming uses objects that contain data and code. The document then provides examples of procedural code and defines objects and classes in Java, showing how to create classes and objects that can store information. It also covers basic operators in Java, including arithmetic, relational, assignment, logical, and unary operators. Finally, it discusses using the .format() method to limit the number of decimal places in Java.

Uploaded by

Micaella Shayne
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Fundamentals of Programming - Week 3-4-5

The document discusses procedural and object-oriented programming fundamentals. Procedural programming is based on calling procedures or functions, while object-oriented programming uses objects that contain data and code. The document then provides examples of procedural code and defines objects and classes in Java, showing how to create classes and objects that can store information. It also covers basic operators in Java, including arithmetic, relational, assignment, logical, and unary operators. Finally, it discusses using the .format() method to limit the number of decimal places in Java.

Uploaded by

Micaella Shayne
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

PROCEDURAL

AND OBJECT-
ORIENTED
PROGRAMMIN
FUNDAMENTALS OF PROGRAMMING
College of Computing and Information Technolo
Procedural Programming
Procedural Programming can be defined as a programming model
which is derived from structured programming, based upon the
concept of calling procedure. Procedures, also known as routines,
subroutines or functions, simply consist of a series of computational
steps to be carried out. During a program’s execution, any given
procedure might be called at any point, including by other
procedures or itself.
bject-Oriented Programming
Object-oriented programming can be defined as a programming
model which is based upon the concept of objects. Objects contain
data in the form of attributes and code in the form of methods. In
object-oriented programming, computer programs are designed using
the concept of objects that interact with the real world. Object-
oriented programming languages are various but the most popular
ones are class-based, meaning that objects are instances of classes,
which also determine their types.
cedural & Object-Oriented Programming
ample Procedural Programming
Sample
Object-
Oriented
Programming
OBJECTS AND
CLASSES IN
JAVA

FUNDAMENTALS OF PROGRAMMING
College of Computing and Information Technolo
What is an Object in Java?
An entity that has state and
behavior is known as an object
e.g., chair, bike, marker, pen, table,
car, etc. It can be physical or logical
(tangible and intangible). The
example of an intangible object is
the banking system.
hree characteristics of Objects
Objects in Java
For Example, Pen is an object. Its name is Reynolds; color is white,
known as its state. It is used to write, so writing is its behavior.

An object is an instance of a class. A class is a template or blueprint


from which objects are created. So, an object is the instance(result)
of a class.

Object Definitions:
• An object is a real-world entity.
• An object is a runtime entity.
• The object is an entity which has state and behavior.
• The object is an instance of a class.
What is a Class in Java?
A class is a group of objects which have common properties. It is a
template or blueprint from which objects are created. It is a logical
entity. It can't be physical.

A class in Java can contain:

• Fields
• Methods
• Constructors
• Blocks
• Nested class and interface
mple Code for Class and Object
We can also create multiple objects and
store information in it through reference
variable.
BASIC
OPERATORS IN
JAVA

FUNDAMENTALS OF PROGRAMMING
College of Computing and Information Technolo
ARITHMETIC
OPERATORS
Operator Use Description
+ op1 + op2 Adds op1 and op2; also used to concatenate strings
- op1 - op2 Subtracts op2 from op1
* op1 * op2 Multiplies op1 by op2
/ op1 / op2 Divides op1 by op2
% op1 % op2 Computes the remainder of dividing op1 by op2

The Java programming language supports various arithmetic operators for all
floating-point and integer numbers. These operators are + (addition), -
(subtraction), * (multiplication), / (division), and % (modulo).
RELATIONAL
OPERATORS
Operator Description Example

== Is Equal To 3 == 5 returns false

!= Not Equal To 3 != 5 returns true

> Greater Than 3 > 5 returns false

< Less Than 3 < 5 returns true

>= Greater Than or Equal To 3 >= 5 returns false

<= Less Than or Equal To 3 <= 5 returns true


ASSIGNMENT
OPERATORS
Operator Example Equivalent to
= a = b; a = b;
+= a += b; a = a + b;
-= a -= b; a = a - b;
*= a *= b; a = a * b;
/= a /= b; a = a / b;
%= a %= b; a = a % b;
LOGICAL
OPERATORS
Operator Example Meaning

expression1 && true only if both expression1 and


&& (Logical AND)
expression2 expression2 are true

expression1 || true if either expression1 or expression2


|| (Logical OR) expression2 is true

! (Logical NOT) ! Expression  true if expression is false and vice versa


LOGICAL OPERATORS –
TRUTH TABLE
AND OPERATOR OR OPERATOR
Con1 Con2 Result Con1 Con2 Result
T T T T T T
T F F T F T
F T F F T T
F F F F F F

NOT OPERATOR
Con Result
T F
F T
UNARY
OPERATORS
Operator Meaning
++ Increment operator: increments value by 1
-- Decrement operator: decrements value by 1
LIMIT
DECIMAL
PLACES IN
JAVA
FUNDAMENTALS OF PROGRAMMING
College of Computing and Information Technolo
Using .format()
Using .format()

You might also like