Data types:
Non-Primitive data type:
- Primitive data type
- Non-Primitive data type
Primitive data type:
- Integer type (byte, short, int and long)
- Decimal type (float and double)
- Boolean type (boolean)
- Character type (char)
DataType | Value | Default Value | Size (bits) | Range |
---|---|---|---|---|
boolean | true or false | false | 1 | true and false |
char | Unicode character | \u0000 | 16 | \u0000 to \uFFFF |
byte | Signed Integer | 0 | 8 | -128 to 127 |
short | Signed Integer | 0 | 16 | -32768 to 32767 |
int | Signed Integer | 0 | 32 | -2147483648 to 2147483647 |
long | Signed Integer | 0 | 64 | -9223372036854775808 to 9223372036854775807 |
float | IEEE 754 Floating point | 0.0 | 32 | ±1.4E-45 to ±3.4028235E+38 |
double | IEEE 754 Floating point | 0.0 | 64 | ±4.9E-324 to ±1.7976931348623157E+308 |
Non-Primitive data type:
- String
- Array
- Stack
- Vector
package com.java.basics;
public class Variables {
public static void main(String[] args) {
byte bmin = -0x80, bmax = 0x7f;
System.out.println("Minimum value for byte is " + bmin
+ " and Maximum value for byte is " + bmax);
short smin = -0x8000, smax = 0x7fff;
System.out.println("Minimum value for short is " + smin
+ " and Maximum value for short is " + smax);
int imin = -0x80000000, imax = 0x7fffffff;
System.out.println("Minimum value for int is " + imin
+ " and Maximum value for int is " + imax);
long lmin = -0x8000000000000000L, lmax = 0x7fffffffffffffffL;
System.out.println("Minimum value for long is " + lmin
+ " and Maximum value for long is " + lmax);
float fmin1 = -1.4e-45f, fmin2 = -3.4028235E+38f;
float fmax1 = 1.4e-45f, fmax2 = 3.4028235E+38f;
System.out.println("Minimum value for float is " + fmin1
+ " and Minimum value for float is " + fmin2);
System.out.println("Maximum value for float is " + fmax1
+ " and Maximum value for float is " + fmax2);
System.out.println(0.0f / 0.0f);
System.out.println(1.0f / 0.0f);
System.out.println(-1.0f / 0.0f);
double dmin1 = -4.9E-324, dmin2 = -1.7976931348623157E+308;
double dmax1 = 4.9E-324, dmax2 = 1.7976931348623157E+308;
System.out.println("Minimum value for float is " + dmin1
+ " and Minimum value for float is " + dmin2);
System.out.println("Maximum value for float is " + dmax1
+ " and Maximum value for float is " + dmax2);
int x = 10, y = 20, z;
z = x + y;
System.out.println("Addition of two numbers is " + z);
char ch = 'A';
int unicode = ch;
System.out.println("Unicode value of " + ch + " is " + unicode);
double percentage = 78.56;
System.out.println("In 12th standard got " + percentage + "%");
boolean isEven = (x % 2 == 0);
System.out.println(isEven);
String str = "Hello ";
str = str + "World";
System.out.println(str);
}
}
public class Variables {
public static void main(String[] args) {
byte bmin = -0x80, bmax = 0x7f;
System.out.println("Minimum value for byte is " + bmin
+ " and Maximum value for byte is " + bmax);
short smin = -0x8000, smax = 0x7fff;
System.out.println("Minimum value for short is " + smin
+ " and Maximum value for short is " + smax);
int imin = -0x80000000, imax = 0x7fffffff;
System.out.println("Minimum value for int is " + imin
+ " and Maximum value for int is " + imax);
long lmin = -0x8000000000000000L, lmax = 0x7fffffffffffffffL;
System.out.println("Minimum value for long is " + lmin
+ " and Maximum value for long is " + lmax);
float fmin1 = -1.4e-45f, fmin2 = -3.4028235E+38f;
float fmax1 = 1.4e-45f, fmax2 = 3.4028235E+38f;
System.out.println("Minimum value for float is " + fmin1
+ " and Minimum value for float is " + fmin2);
System.out.println("Maximum value for float is " + fmax1
+ " and Maximum value for float is " + fmax2);
System.out.println(0.0f / 0.0f);
System.out.println(1.0f / 0.0f);
System.out.println(-1.0f / 0.0f);
double dmin1 = -4.9E-324, dmin2 = -1.7976931348623157E+308;
double dmax1 = 4.9E-324, dmax2 = 1.7976931348623157E+308;
System.out.println("Minimum value for float is " + dmin1
+ " and Minimum value for float is " + dmin2);
System.out.println("Maximum value for float is " + dmax1
+ " and Maximum value for float is " + dmax2);
int x = 10, y = 20, z;
z = x + y;
System.out.println("Addition of two numbers is " + z);
char ch = 'A';
int unicode = ch;
System.out.println("Unicode value of " + ch + " is " + unicode);
double percentage = 78.56;
System.out.println("In 12th standard got " + percentage + "%");
boolean isEven = (x % 2 == 0);
System.out.println(isEven);
String str = "Hello ";
str = str + "World";
System.out.println(str);
}
}
No comments:
Post a Comment