0% found this document useful (0 votes)
2 views15 pages

Computer Programming

The document outlines key concepts in computer programming, focusing on functional and object-oriented programming. It covers topics such as data types, variables, operators, control structures, and data structures, emphasizing their roles in algorithmic problem solving and program organization. Additionally, it discusses object-oriented features like abstraction, encapsulation, inheritance, and polymorphism.
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)
2 views15 pages

Computer Programming

The document outlines key concepts in computer programming, focusing on functional and object-oriented programming. It covers topics such as data types, variables, operators, control structures, and data structures, emphasizing their roles in algorithmic problem solving and program organization. Additionally, it discusses object-oriented features like abstraction, encapsulation, inheritance, and polymorphism.
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/ 15

Computer Programming

Functional & Object Oriented Programming


Topics to be Included

1. The binary nature of computer storage


2. Data storage strategies using primitive & derivative data types
3. Data transformations using operators
4. Relational and logical operators
5. Algorithmic problem solving using sequence, selection and
repetition
6. Algorithmic and operating capabilities of a program using
functions, methods and sub-routines
7. Linear and non-linear data structures
8. Object oriented concepts in the organization and structuring of
programs
Binary Nature of Storage

• Computer programs are collections of instructions and data


• Instructions are used to transform data from one to other
form
• There are different forms of data called data types
Data
Types

Numeric Textual .Others

Fractiona
Complete Characte
l Text
Numbers rs
Numbers
Numeric Data Types – Complete
Numbers
• Bit – A basic unit of storage 1.2 voltage = 0
1.5 voltage = 1
• Nibble – set of 4 bits, Byte-set of 8
bits
•Quantit
StorageNibbl
using 1’s
Bytes 2’s Comp +/- Rep. Characte
y e Comp r
0 0000 1111 1 0000 0 A
1 0001 1110 1111 -1 B
2 0010 1101 1110 -2 C
3 0011 1100 1101 -3 D
4 0100 1011 1100 -4 E
5 0101 1010 1011 -5 F
6 0110 1001 1010 -6 G
7 0111 1000 1001 -7 H
8 1000 0111 1000 -8 I
Primitive Data Types

• A data type is a set of values and operations defined on it


• There are number of data types in each programming
language
• For a set of numeric data types
• There is a maximum value (positive) and minimum value (negative)
• Maximum number of bits required to represent either min or max
value determines the size of data type
• Primitive
Data Data
Mintypes
value in Java Max value Size
type
Byte -128 127 8-bit
Char
Short -32768 32767 16-bit
Int -2,147,483,648 -2,147,483,647 32-bit
long - 9,223,372,036,854,775,8 64-bit
Extended Data Types

• The data types that are built upon the primitive data types
to provide additional functionality and features

Enumeratio
Strings Arrays
ns

Wrapper Classes &


Collections
Classes Objects
Variables & Expressions

• A variable is defined over a set of values which can take any


one value at a time
• Mathematics: where v is variable, and N is set of values
• Programming: where a is variable, and int is data type (set of
values)
• Operators: These defines the methods to transform values
• There are different types of operators i.e. arithmetic operators,
logical operators, bitwise operators
Arithmetic Operators on Arithmetic Operators on A=19
constants Variables B=5
Operato Expressio Result Operato Expressio Result
r n r n
+ 5+6 11
- 12-4 8
* 4*3 12
/ 20/5 4
Relational Operators

• These operators are used to compare two Operator Example Result


quantities
• Languages use “if” statement
public to makeargs)
static void main(String[]
< 5<8
9<3
True
False

decision {
int a=13, b=12;
<= 7<=8
8<=8
True
True
9<=8 false
• Examples if(a>b) {
System.out.println("A is greater than
B");
> 8>5
8>9
True
false

}
public static void main(String[] args)
}
>= 7>=8
7>=7
False
True
{ 7>=8 False
int a=13,b=11;
if(a<b) { == 5==5
6==5
True
False
System.out.println("A is greater than
B"); != 6!=9
6!=6
True
False
}
else {
System.out.println("A is not greater than
B");
}
Selection Statements
public static void main(String[] args)
• These are three types of {
int day = 4;
statements switch (day) {
• If statement case 1:
System.out.println("Monday");
• If-else statement break;
• Switch statement: case 2:
System.out.println("Tuesday");
• A switch statement is used to break;
execute different blocks of case 3:
code depending on the value System.out.println("Wednesday");
of a variable break;
case 4:
• Break: this statement is used System.out.println("Thursday");
to come out of switch block break;
case 5:
System.out.println("Friday");
break;
default:
System.out.println("Invalid day");
}
}
Repetitions in Java

• Repetition statements are used to repeat a


statement or a group of statements
• There are three repetition statements int i = 1;
(loops) normally used in languages while (i <= 5) {
System.out.println(i);
• While loop
i++;
• Do-while loop }
• For loop
public static void main(String[] public static void main(String[]
args) { args) {
int[] numbers = {1, 2, 3, 4, 5}; int x = 10;
int sum = 0; do {
for (int i = 0; i < numbers.length; System.out.print("value of
i++) { x : " + x);
sum += numbers[i]; x++;
} System.out.print("\n");
System.out.println("The sum is: " } while (x < 20);
+ sum); }
Functions and Methods

• A function or a method is a block of code


that performs a specific task or set of
tasks
• They are a way to organize and modularize public static double calculateArea(double
code, making it easier to read, understand, radius) {
and maintain double area = Math.PI * radius *
• Function: is a standalone block of code radius;
that can be called from anywhere in a return area;
}
public void setName(String name) {
program.
• It takes some input, performs a set of this.name = name;
operations, and returns some output }
• Method: It is a function that is
associated with an object or a class.
• It performs a specific task or set of tasks on
the object or class, and can modify the
object's state or return some output
Linear Data Structures

• A type of data structure in which the data


elements are organized in a sequential
manner
• Examples
• Arrays
• Linked Lists
• Stacks
• Queues
Non-linear data structures

• Data structures in which data elements are


not organized in a sequential manner.
• Data elements are connected to one or
more other elements in a way that forms a
more complex structure
• Examples
• Trees
• Graphs
• Heaps
• Hash Tables
Modeling of Real
Life Scenarios

• In real life, there exists objects


grouped into classes which interact
with each other
• A class in a program is an
abstraction of real world concept
and objects are materialization of
that concept
• A class consists of two things
• Member variables
• Member functions

• An object in Java is a reference


variable
• Object contains the address where data of
object is stored on heap
Object Orientation Features
Abstraction Modularity
It is the process of defining a It refers to the ability to break down
simplified view of a complex a system into smaller, self-contained
system, focusing on the units (modules) that can be
essential features and hiding developed and tested
independently.
the details

Encapsulation
Inheritance
It means that data and behavior are
bundled together in a class, and It is a way to create a new class
access to the data is controlled by based on an existing one, inheriting
methods or functions defined in the the properties and behavior of the
class. parent class.

Polymorphism
It refers to the ability of
objects of different classes to
be used interchangeably.

You might also like