Skip to content

Instantly share code, notes, and snippets.

@Audhil
Created July 26, 2020 18:32
Show Gist options
  • Save Audhil/41688ed99714dc37d13218964050173f to your computer and use it in GitHub Desktop.
Save Audhil/41688ed99714dc37d13218964050173f to your computer and use it in GitHub Desktop.
memory required for each data type in Java
// https://blog.udemy.com/java-data-types/?utm_source=adwords&utm_medium=udemyads&utm_campaign=DSA_Catchall_la.EN_cc.INDIA&utm_content=deal4584&utm_term=_._ag_82569850245_._ad_437477497173_._kw__._de_c_._dm__._pl__._ti_dsa-449490803887_._li_9061910_._pd__._&matchtype=b&gclid=CjwKCAjw0_T4BRBlEiwAwoEiAd5tg5iZ8c_k9pQxw5pX5HJoQKHjCc21ylREUKzHurajr3l7v2u5LhoCvKsQAvD_BwE
public static void main(String[] args) {
byte d = 127; // 2^7 = -128 -> 2^7-1 = 127 - 8 bits = 1 byte
short sh = 32767; // 16 bits = 2 bytes
int in = 2147483647; // 32 bits = 4 bytes
long lo = 9223372036854775807L; // 64 bits = 8 bytes
float fl = 23.44f; // 32 bits = 4 bytes
double db = 342.4; // 64 bits = 8 bytes
char ch = 'a'; // 16 bits - 2 byte
boolean bool = false; // 1 bit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment