Computer Programming
Computer Programming
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
• The data types that are built upon the primitive data types
to provide additional functionality and features
Enumeratio
Strings Arrays
ns
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
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.