Object:
- An Object is a physical entity meaning that it will physically create a heap memory at runtime.
- An object is a combination of state (data/variables-Color, RAM) and behavior(methods /functions-Call, SMS).
Syntax:
Classname referenceName = new Classname();
- new is a Java keyword.
- If we mention a new keyword in object,JVM will allcated one memory in heap at runtime.
Data Types:
- Data types specify what type of data a variable can store.
- Java has two main types of data types:
- Primitive data types.
- Non-primitive data types.
Primitive data type:
-Primitive data types store simple values.
-Memory management of primitive data type is stack.
-There are 8 primitive data types in java.
1.short
2.byte
3.int
4.long
5.float
6.double
7.char
8.boolean
-These 8 primitive data types are known as Keywords.
Non-Primitive Data Type:
-String is a Non-primitive data type.
Size and Range of data types:
Size of all primitive data types:
1.short = 2 byte.
2.byte = 1 byte.
3.int = 4 byte.
4.long = 8 byte.
5.float = 4 byte.
6.double = 8 byte.
7.char = 2 byte.
8.boolean = 1 bit.
To calulate range:
-1 byte = 8 bit = 2*2*2*2*2*2*2*2.
= 256 (so 256/2=128)
- To store the negative value the range starts from -128 to 127(The range ends at 127 because 0 i included).
Range:
-short = -32,768 to +32,767.
-byte = -128 to 127.
Top comments (0)