Require some insight regarding Objects & Json

Prakhar Makhija matcdac at gmail.com
Sun Nov 12 16:26:34 UTC 2017


Hi,


*Scenario*

Having 1.5 million json files of same structure (same keys).
Each file is of around 64 KB, which makes a total of 1 GB.

Created a class MyDummyJsonClass, having the attribute names same as the
keys in those json files.

Reading the json files, loading them into MyDummyJsonClass, using
ObjectMapper.


*Doubt 1*

Will the objects occupy the same amount of space in Java's Memory, as they
were occupying earlier as flat files?


*Doubt 2*

Does Java convert Objects to Enumerations at Runtime?

What I mean to ask is, does it enumerate the attribute names while creating
objects, in order to save the memory?

Because the Class is just a blueprint, and we create objects out of it over
and over again.


*Example*


class MyDummyJsonClass {

private Object meaningfulNameOfAttributeOne;
private String meaningfulNameOfAttributeTwo;
private Integer meaningfulNameOfAttributeThree;
private Float meaningfulNameOfAttributeFour;
private Double meaningfulNameOfAttributeFive;
private Long meaningfulNameOfAttributeSix;
private Byte meaningfulNameOfAttributeSeven;
private Boolean meaningfulNameOfAttributeEight;
private Character meaningfulNameOfAttributeNine;
private Short meaningfulNameOfAttributeTen;

// Contructors

// Getters & Setters

}


Here the field meaningfulNameOfAttributeOne is of 28 characters, and Java
uses Unicode, so internally just this attribute name will it be occupying
56 bytes of memory in every Object we create?

Or is meaningfulNameOfAttributeOne mapped to enum value 1, and will occupy
maybe just 1 byte, depending upon the number of fields?

If less than or equal to 256 fields in the class, allocate 1 byte enum,
else 2 bytes enum.

And some kind of Interceptor decides, to give it logical attribute name
mapping?


More information about the core-libs-dev mailing list