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

Data Type in Java

The document provides an overview of data types in Java, categorizing them into primitive and non-primitive types. It details the eight primitive data types, including Boolean, Byte, Short, Integer, Long, Float, Double, and Char, along with their sizes and syntax. Additionally, it explains non-primitive data types such as Strings and Arrays, highlighting their characteristics and usage in Java programming.

Uploaded by

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

Data Type in Java

The document provides an overview of data types in Java, categorizing them into primitive and non-primitive types. It details the eight primitive data types, including Boolean, Byte, Short, Integer, Long, Float, Double, and Char, along with their sizes and syntax. Additionally, it explains non-primitive data types such as Strings and Arrays, highlighting their characteristics and usage in Java programming.

Uploaded by

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

DATA TYPE IN JAVA

By Kamal
Apr28
INTRODUCTION
Java Data Types

 Javais statically typed and also a strongly typed


language because, in Java, each type of data
(such as integer, character, hexadecimal, packed
decimal, and so forth) is predefined as part of
the programing language and all constants or
variables defined for a given program must be
described with one of the Java data types.
DATA TYPES IN JAVA
 Data types in java are of different sizes and values
that can be stored in the variable that is made as
per convenience and circumstances to cover up all
test cases. Java has two categories in which data
types are segregated
 1.PrimitiveData Type: such as Boolean, char, int,
short, byte, long, float, and double
 2.Non-Primitive Data Type or Object Data Type:
such as string, Array, etc.
Primitive Data Types in Java
Primitive data are only single values and have no special capabilities. There are 8 primitive data
types.

 Lets us discuss and implement each one of the following data types that are as follows:
1.Boolean Data Type
 Boolean data type represents only one bit of information either True or False which is
intended to represent the two truth values of logic and Boolean algebra, but the size of the
Boolean data type is virtual machine-dependent.
Syntax:
Boolean BooleanVar;
222.Byte Data Type. Byte Data Type
The byte data type is an 8-bit signed two’s complement integer. The byte data type is
useful for saving memory in large arrays.
Syntax:
Byte bytevar;
size: 1 byte(8 bits)
PRIMITIVE DATA TYPES
3.Short Data Type
The short data type is a 16-bit signed two’s complement integer. Similar
to byte, use a short to save memory in large arrays, in situations where
the memory saving actually matters.

 Syntax:
 Short shortVar;
 Size:2 bytes(16 bits)
4.Integer Data Type
It is a 32-bit signed two’s complement integer.
Syntax:
Int intVar;
Size:4 bytes(32 bits)
Example: How to Print an
Integer entered by an user

OUTPUT
5.Long Data Type
The range of a long is quite large. The long data types is a 64-bit two’s
complement integer and is useful for those occasions where an int type is not
 Large enough to hold the desired value. The size of the long datatype
is 8 bytes(64 bits).
Syntax:
Long longVar;

6.Float Data Type


The float data type is a single-precision 32-bit IEEE 754 floating-point.
The size of the float data type is 4 bytes (32 bits).
Syntax:
Float floatvar;
Example 5: Java long data type
7.Double Data Type
The double data type is a double-precision 64-bits IEEE 754 floating-
point. The size of double data type is 8 bytes or 64 bits.
 Syntax:
Double doubleVar;

8.Char Data Type


The char data type is a single 16-bit Unicode character with the size of 2
bytes (16 bits).
Syntax:
Char charVar;
Example 6: Java double data type
Non-Primitive Data Type or Reference Data
Types
 The Reference Data Types will contain a contain a memory address of
variable values because the reference type won’t store the variable
value directly in memory. They are strings, objects, arrays, etc.
They are created by the programmer.
The Non-Primitive Data type starts with an uppercase letter.
Non-Primitive Data type to call methods to perform certain operations.
NON-PRIMITIVE DATA TYPES
1. Strings
strings are defined as an array of characters.
The difference between a character array and
a string in java is, that the string is designed
to hold a Sequence of characters in a single
variable whereas, a character array is
collection of separate char-type entities.
Example: Create a String in Java
2. Array
 An Array is a group of like-typed variables that are referred to by a
common name. Array in Java work differently than they do in c/c++.
The Following are some important points about Java arrays.
 In Java, all arrays are dynamically allocated.(discussed below)
 Since arrays are objects in Java,we can find their length using
member length. This is different from c/c++ where we find length
using size
 A Java array variable can also be declared like other variables with[]
after the data type.
 The size of an array must be specified by an int value and not long or
short.
Example: Access Array Elements
OUTPUT:

You might also like