For example, is there such a thing as a int.java or a double.java?
Since primitive data types are the building blocks of the Java language, I assume they would be written in some lower-level language.
What language are primitive data types in Java written in?
Can one access those files and see how primitive data types such as int are defined?
No, there is no such thing as int.java or double.java These low level types are hard-coded at the JVM level. They are primitive types even at byte-code level (e.g. different bytecodes apply to operands of 4 bytes as opposed to 8 bytes, or to integral types as opposed to floating point types). You may want to study the implementation of one or more open source Java VMs to see how they are handled (https://en.wikipedia.org/wiki/List_of_Java_virtual_machines#Free_and_open_source_implementations). Also, even compilers treat them specially and make certain assumptions about them, e.g. for optimization purposes.
The other reason for them not having equivalent Java classes (unlike the capitalized ones, java.lang.Integer, java.lang.Double etc.) is that they don't have methods of their own, that you can call, for example with the dot notation. When you do use a primitive type as an object, a conversion takes place (known as autoboxing -- https://en.wikipedia.org/wiki/Object_type_(object-oriented_programming)#Autoboxing) where the primitive type is converted to one of the wrapper types, transparently for the programmer. It is worth having a look at the source code of these classes, for some interesting internal functionality.
Also you cannot create instances of them, by using the new
keyword. The compiler or the VM allocate space for them, as necessary, on the stack, as object or class fields, or even directly in the code.
So, int, double are not the class
in java. Those are the keyword
. And the definition of those keyword written in the native language (I believe c,C++).
1) What language are primitive data types in java written in?
-> I believe those are written n C/C++;
2) Can one access those files and see how primitive data types such as int are defined?
-> There is no .java
the file you can find for that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With