Java supports 8 primitives types
Data Type | Size in byte(s) | Default Value |
byte | 1 | 0 |
short | 2 | 0 |
int | 4 | 0 |
long | 8 | 0L |
float | 4 | 0.0f |
double | 8 | 0.0d |
char | 2 | '\u0000' |
boolean | NA(OS dependent) | false |
Example code
package com.fastlearned; public class PrimitiveType { private byte byteVar = 12; private short shortVar = 23; private int intVar = 10000; private long longVar = 12000000L; private float floatVar = 7829.98f; private double doubleVar = 5235236.987d; private char charVar = 'S'; private boolean booleanVar = true; public PrimitiveType() { System.out.println("byteVar = " + byteVar); System.out.println("shortVar = " + shortVar); System.out.println("intVar = " + intVar); System.out.println("longVar = " + longVar); System.out.println("floatVar = " + floatVar); System.out.println("doubleVar = " + doubleVar); System.out.println("charVar = " + charVar); System.out.println("booleanVar = " + booleanVar); } /** * @param args */ public static void main(String[] args) { new PrimitiveType(); } }Output :
byteVar = 12 shortVar = 23 intVar = 10000 longVar = 12000000 floatVar = 7829.98 doubleVar = 5235236.987 charVar = S booleanVar = true
No comments:
Post a Comment