Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Data types
1.
2. A data type is used to declare a variable. Every variable
should be declared before initialization.
3. Primitive data type Non Primitive data type
Boolean
Byte
Char
Short
Int
Long
Float
Double
String
Array
Class
4. Byte-(Size is 2 byte)
*Its integer with small range
*Byte data type is an 8-bit signed two's complement integer.
*Minimum value is -128 (-2^7)
*Maximum value is 127 (inclusive)(2^7 -1)
* Default value is 0
* Byte data type is used to save space in large arrays, mainly in place of integers,
since a byte is four times smaller than an integer.
5. Boolean-(T/F)(size is 1 byte)
Its true or false .by default its false
boolean data type represents one bit of information
There are only two possible values: true and false
6. Char –(size is 2 byte)
char data type is a single 16-bit Unicode character
Minimum value is 0
Maximum value is 65,535
Char data type is used to store any character from keyboard(0-
9,A-Z,a-z)
Example: char letterA = 'A‘
7. Short-(size is 2 bytes)
Its also integer type
Short data type is a 16-bit signed two's complement integer
Minimum value is -32,768 (-2^15)
Maximum value is 32,767 (inclusive) (2^15 -1)
Short data type can also be used to save memory as byte data type. A short is 2
times smaller than an integer
Default value is 0.
Example: short s = 10000, short r = -20000
8. Int- (size is 4 bytes)
Its also integer data type with bigger size.
Int data type is a 32-bit signed two's complement integer.
Minimum value is - 2,147,483,648 (-2^31)
Maximum value is 2,147,483,647(inclusive) (2^31 -1)
Integer is generally used as the default data type for integral values unless there
is a concern about memory.
The default value is 0
Example: int a = 100000, int b = -200000
9. Long- (size is 8 bytes)
Its also integer data type with more size
Long data type is a 64-bit signed two's complement integer
Minimum value is -9,223,372,036,854,775,808(-2^63)
Maximum value is 9,223,372,036,854,775,807 (inclusive)(2^63 -1)
This type is used when a wider range than int is needed
Default value is 0L
Example: long a = 100000L, long b = -200000L
10. Float-(size is 4 bytes)
Used for decimal values
Float is mainly used to save memory in large arrays of floating point numbers
Default value is 0.0f
Float data type is never used for precise values such as currency
Example: float f1 = 234.5f
11. Double- (size is 8 bytes)
- double data type is a double-precision 64-bit
- This data type is generally used as the default data type for decimal values,
generally the default choice.
- Double data type should never be used for precise values such as currency.
- Default value is 0.0d
- Example: double d1 = 123.4
12. In computer science, the precision is usually measured in bits, but sometimes in
decimal digits. i.e no of digits after decimal point
Float and double are two of the data types used to represent decimal values or
floating point literals in the Java programming language.
Float is basically single precision and it can represent decimal values up to 7
digits of precision
double can represent decimal values up to 16 digits of precision.
Single Precision is a 32-bit type; Double Precision is a 64-bit type. Accordingly,
Doubles store a much broader range of values, and with much more precision.
13. For example
If 10/3 is
3.3333333 ..its single precision
But if its 3.33333333333333..its double precision
By default java takes double precision.
14. String
In Java, string is basically an object that represents sequence of char values. An
array of characters works same as Java string. For example: char[]
ch={'j','a','v','a','t','p','o','i','n','t'};
a string is used to represent text rather than numbers. ... For example, the word
“java" and the phrase “I study java" are both strings. “34567" can be defined as
string if defined properly.
The length of a string is determined by a termination null character.”0”. So a
string (“java”) has five characters. ‘j’,’a’,’v’,’a’. And null character ‘0’.
15. An array is a container object that holds fixed number of values of a single type.
Length of an array is decided when array is created.after creation its length is
fixed.
16. A class can be defined as a template/blueprint that describes the behavior/state
that the object of its type support.
Public class dog
{
String breed;
Int age;
String color;