0% found this document useful (0 votes)
4 views4 pages

Notes Java

The document explains data types in Java, categorizing them into primitive and non-primitive types. It details primitive types such as boolean, numeric (including byte, short, int, long, float, and double), and char, along with their sizes and ranges. Additionally, it describes arrays as collections of items of the same datatype, including how to declare and access them.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Notes Java

The document explains data types in Java, categorizing them into primitive and non-primitive types. It details primitive types such as boolean, numeric (including byte, short, int, long, float, and double), and char, along with their sizes and ranges. Additionally, it describes arrays as collections of items of the same datatype, including how to declare and access them.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

What are data types?

Java is case sensitive


A data has to be strictly from the respective data type in java
A data can be of diff types be it number, character, string
Data types are two types
1)Primitive and 2) Non-Primitive
Primitive data types need no object creation
Non-Primitive data types need object creation

The primitive data types are as follows


1)Boolean
A value can either be true or false
2)Numeric Type has diff sub categories
1)Integerbyte, short, int, long
2)Floating pointfloat, double
3)Character also comes from Numeric typechar

INTEGER
1)Byte
Size: 1 Byte = 8 bits
Range: -128 to 127 or -2^7 to 2^7-1
ie we can store negative values as well
byte is a keyword
byte b=10;
Java Memory takes space in your RAM
Eg for the data type Age,
2)Short
Size: 2 Bytes = 16 bits
Range: -32768 to 32767 -2^15 to 2^15-1
Short s1= 2000;
3)Int
Size: 4 bytes =32 bits
Range: -2^31 to 2^31-1
Int i=12;
E.g. Bill amount, salary, price etc

4)Long
Size: 8 bytes = 64 bits
Range: -2^63 to 2^63-1
For long type we have to explicitly tell java that we need that number to be of long type
long l=125363233623 //gives error
Now add an l to the end of the number which means java understands that the long data type is
what we want to save the number in
long l=125363233623l;
We can use the long data type for distance between planets,
We cannot use the long for Aadhaar, phone, credit card, account and ssn numbers since we are
not doing any mathematical calculations with those numbers

FLOAT
Size: 4 bytes = 32 bits
Range: after. it can take 7 decimals
float f1= 10.33f(explicitly add f to denote the float numbers)
float f2= (float)30.32 (another way of declaring)
we can also use the integer values in float but during the runtime they will be considered as
float numbers
float f3= 100;

But in integer family we cannot store any float or double numbers

DOUBLE
Size: 8 bytes=64 bits
Range: after . can take up to 15 digits
Double d1= 30.33333333333
E.g. price, temperature, weight, tax etc

Here also we can store an integer in a double


Double d2=30;

CHAR
Char only takes a single digit value
It can take numbers, alphabet, special character
Range: a-z, A-Z,0-9 and all special characters

Char c=’w’;
Char c1=’2’
Char c3=’%’
What is an array?
An array is a collection of items of same datatype

Array is declared as <datatype> variable name []= new <datatype>[size ]

Eg int A[]=new int[5]

Index of the array starts from 0 and ends at size-1

Here index starts at o and ends at size-1 which is 4

So indices are 0,1,2,3,4

Now declaring the values for each index is as follows

A[0]=2;

A[1]=3;

A[2]=4;

A[3]=5;

A[4]=6;

Printin the array values can be done in the following way

[Link](A[0]); //gives the value at the index 0 which is 2

[Link](A); //prints the address of the array –random string

You might also like