You are on page 1of 15

Data Types and Operators

Data and Data types


In computer science and computer programming, a data type or
simply type is an attribute of data which tells
the compiler or interpreter how the programmer intends to use
the data. Most programming languages support basic data types
of integer numbers (of varying sizes), floating-point numbers
(which approximate real numbers), characters and Booleans. A
data type constrains the values that an  expression, such as a
variable or a function, might take. This data type defines the
operations that can be done on the data, the meaning of the data,
and the way values of that type can be stored. A data type
provides a set of values from which an expression (i.e. variable,
function, etc.) may take its values.
Data and Data types
Integer type 
Data and Data types
Floating point type 

Character type 
Constants and Variables
A constant is a value that cannot be altered by the program
during normal execution, i.e., the value is constant. When
associated with an identifier, a constant is said to be “named,”
although the terms “constant” and “named constant” are often
used interchangeably. This is contrasted with a variable, which is
an identifier with a value that can be changed during normal
execution, i.e., the value is variable.

A constant is a data item whose value cannot change during the


program’s execution. Thus, as its name implies – the value is
constant.
Constants and Variables

Constants are used in two ways. They are:


• literal constant
- A literal is a value that is expressed as itself. For example,
the number 25 or the string "Hello World" are both literals.
• defined constant
- ex. Pi - 3.1416
Constants and Variables

A variable is a data item whose value can change during the


program’s execution. Thus, as its name implies – the value can
vary.

class Example { public static void main ( String[] args ) { long


payAmount = 123; //the declaration of the variable
System.out.println("The variable contains: " + payAmount ); } }

The example program uses the variable payAmount. The


statement
long payAmount = 123; is a declaration of a
variable. A declaration of a variable is where a program says that
it needs a variable. For our small programs, place declaration
statements between the two braces of the  main  method.
Types of Operators

An operator is a symbol which helps the user to command the


computer to do a certain mathematical or logical manipulation.
Operators are use in programming language program to operate
on data and variables. Programming language has a rich set of
operators which can be classified as;
Types of Operators

Arithmetic Operators
- The basic arithmetic operations are addition, subtraction,
multiplication, and division. Arithmetic is performed according to
an order of operations.
Types of Operators

Integer Arithmetic
- When an arithmetic operation is performed on two whole
numbers or integers than such an operation is called as integer
arithmetic. It always gives an integer as the result. Let x = 2
and y = 2 be two integer numbers.

Then the integer operation leads to the following results:

x + y = 4;
x - y = 0;
x * y = 4;
x % y = 0;
x / y = 1;
Types of Operators

Floating Point Arithmetic


- When an arithmetic operation is performed on two real
numbers or fraction number such an operation is called
floating point arithmetic. The floating-point results can be
truncated according to the properties requirement. The
remainder operator s not applicable for floating point
arithmetic operands.

Let x = 12.0 and y = 2.0


x + y = 14.0;
x - y = 10.0;
x * y = 24.0;
x / y = 06.0;
Types of Operators

Relational Operators
- Often it is required to compare the relationship between
operands and bring out a decision and program accordingly.
This is when the relational operator comes into picture.
Types of Operators

Logical Operators
- A logical operator is a symbol or word used to connect two
or more expressions such that the value of the compound
expression produced depends only on that of the original
expressions and on the meaning of the operator. Common logical
operators include AND, OR, and NOT.
Types of Operators

Assignment Operators
- Assignment operators are used to assign values to variables.

You might also like