2

I have a doubt about why java developers has declared as

public static final int MAX_PRIORITY
public static final int MIN_PRIORITY
public static final int NORMAL_PRIORITY

instead of declaring public static final byte MAX_PRIORITY. Because for these variables highest value is 10 only. So I think byte is sufficient int range is higher than byte.
Any specific reason behind this? Could someone please explain this to me?

3
  • They probably didn't even thought about this. Commented Dec 26, 2013 at 9:30
  • 1
    That wouldn't make difference. Commented Dec 26, 2013 at 9:31
  • 2
    Well, what, in your opinion, would be the benefit of byte? Commented Dec 26, 2013 at 9:31

4 Answers 4

4

Bytes use slightly less space to store but are no faster to use than an integer - since fundamentally all 32 bit processors work in integers anyway.

There is no real reason to use byte over integer unless you are storing an array or similar of them where they can then be packed into a smaller space.

Sign up to request clarification or add additional context in comments.

3 Comments

Well it's not really a fundamental law (and there have been processors with 16 bit integers) but in practice you're absolutely correct. Actually using bytes can worsen performance even on actual hardware out there.
I first started programming on 8 bit computers, I'm not aware of any serious computer using less than 32 for a very long time now though.
There are lots of embedded devices running MIPS and co. That's actually one of the originally intended places for java and I've heard people programming microcontrollers in java to some degree. (Sounds awkward)
0

So that if in future it was desired to introduce another value that wasn't in the range of a byte, the implementors wouldn't find themselves hamstrung by a prior, inappropriate decision such as the one you appear to be favouring.

Comments

0

My guess is that it was a code convention in the project, because in this case due to memory alignment making it byte would save 8 bytes on x64 architecture. The rationale behind this could be that in future versions this field could be used to store other thread state information.

Comments

-1

Behind the scenes, the java int(on most cases) has the same size as of a byte (and short type), so it doesn't really matter.

byte is used when it's logical to use it(when the data itself is represented in bytes, like raw data), or in order to save space when you have an array of small numbers.

int is the default type developers use, unless they have a good reason to use something else.

14 Comments

Can you share some information about what you have specified,please.
Thanks for sharing ! But the statement "byte and int will always be same internally" doesn't hold true always. May vary with CPU architecture.
i am agree with you.int is default type for developers but, being a java developer we won't drop our memory efficiency...(in my point of view)
This answer is simply incorrect. An int is defined as four bytes.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.