First thing I want to clarify here, this question is because of curiosity. I am not facing any issue.
There are many primitive types available in Java byte
, short
, int
, etc. Now suppose I want to create a new primitive type (e.g. mediumint
or anything else). Can we do that?
If yes then how?
Since the primitive data types consume less memory and can be accessed faster, they are not objects. The equivalent Wrapper classes are also available in java like "Integer" "Short" etc. They can be used as objects if you want.
Collections are the framework used to store and manipulate a group of objects. Java Collection means a single unit of objects. Since the above two statements are true, generic Java collections can not store primitive types directly.
Primitive types are the ones defined by the language itself. In Java
you can only define new types as Classes
all derived from the common base class called Object
.
You all are wrong. Yes. You can. As a rule, you do not need a completely new primitive type. So, you don't need to rebuild JVM. Usually, you only need to "pack" or "cast" your new primitive type to an existing and define some operations like "+" with its wrapper.
You can do it relatively simply with original JVM, but with your own Java compiler. Good luck!
You could, but then it wouldn't be Java anymore.
You cannot create your own primitive datatype.
As the Java documentation explains: A primitive type is predefined by the language and is named by a reserved keyword.
Simply No, You can not create primitive datatype.
Primitive datatype means which are provided and existed in language feature. Basically Java support this for performance reason and perform arithmetic operation.
You can create a user defined datatype using concept of class
and object
.
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