Why java has fixed data type size unlike C

In C as we know the size of data types (ex. int) can vary depending on compiler / hardware.

But why the size of data types is constant in java language? Why don’t we have the flexibility for different data type size in java depending on compiler?

Answer

The JVM (Java Virtual Machine) is designed to be platform independent. If data type sizes were different across platforms, then cross-platform consistency is sacrificed.

The JVM isolates the program from the underlying OS and platform. This can make life difficult for performing system-specific work, but the benefits are that you can write-once, run-anywhere (this is largely true, with some unfortunate issues. Write-once, test-everywhere is a much more practical approach).

Leave a Reply

Your email address will not be published. Required fields are marked *