0% found this document useful (0 votes)
8 views16 pages

Data Types

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

Data Types

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

Java Data Types (Primitive)

Data types specify the different sizes and values that can be stored in
the variable.
Java Literals provide a means of expressing specific values in your
program.
Variables in Java are a memory location that holds a specific value.
Before we use any variable, we need to declare it. Every variable is
identified with a data type.

boolean boolean one = false;


char char A = ‘A’;
int int a = 10;
float float f1 = 234.5f;
double double d1 = 12.3d;
ASSIGNMENT OPERATOR
All variables must be declared before they can be used. you can declare
multiple variables simultaneously by just separating all variables
by comma(,) .
There are different ways to assign value to variables but here we will
see only direct assignment means assigning value to variables at the
time of variable declaration. Variable value assignment at the time
variable declaration is shown in below example1 and example2 shows
declaration multiple variables simultaneously and value assignment.
Using int Data Type
An integer (more commonly called an int) is a number without a decimal point.
Using int Data Type
An integer (more commonly called an int) is a number without a decimal point.
Using int Data Type
Using float Data Type
A float is a floating-point number, which means it is a number that has a decimal place. Floats are used
when more precision is needed.
Using float Data Type
A float is a floating-point number, which means it is a number that has a decimal place. Floats are used
when more precision is needed.

Error because you must use f if your value has decimal


Using double Data Type
Though Float and Double both of them are used for assigning real (or decimal) values in programming
there is a major difference between these two data types. Double is more precise and for storing large
numbers, we prefer double over float
Using String Data Type
String is a sequence of characters, for example. “Hello”
Using char Data Type
The char keyword is a data type that is used to store a single character. A char value must be
surrounded by single quotes, like 'A' or 'c’.

char variable contains int value


Using boolean Data Type
The numerical value cannot be assigned to a boolean variable in Java – only true or
false can be used.
Using Numbers as Variable
Java Arithmetic Operators
Arithmetic operators are used to perform arithmetic
operations on variables and data.
+ operator is
used to add two
variables
Using the + operator is the
most common way to concatenate
two strings in Java. You can provide
either a variable, a number, or a
String literal (which is always
surrounded by double quotes). Be
sure to add a space so that when
the combined string is printed, its
words are separated properly
EXAMPLE OF ARITHMETIC OPERATIONS

You might also like