For what is Java byte type

Posted on

Question :

For what is the byte type of java?

byte[] dados = ... ;

What is the real use?
Does anyone have an example?


Answer :

The byte is a base (primitive) data type, which is the basis of programming, is the lowest level data type of Java, with which it is possible to create any other type.

1 (one) byte is composed of 8 (eight) bits ;

In high-level languages like Java, it is not as widely used in some cases. Where there are other derivatives type that best suit the case, such as String .

But if you program something that involves files for example, you will already come across a good utility for it.

I will try to present you with some examples:

  • Read disk file, or download via network (HTTP or FTP);
  • Write file to disk;
  • Traffic raw data over the network;
  • Image manipulation;
  • Traffic from Streams ;
  • These are some examples that I have already used type byte , there is a lot more thing where type byte is used.

    Java documentation says the following about byte :


    The byte data type is an 8-bit signed two’s complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type is useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of where their limits help to clarify your code; the fact that a variable’s range is limited can serve as a form of documentation.


    Well, byte is a data type consisting of 8 bits.
    There are several uses of this type of data, among them, for example:

    • Masks;
    • Images, Strings, Dlls, among many other data types / compiled objects;
    • Streams;
    • etc.

    For example, in the case of streams, each byte received can be a character and at the end of reception it will have its message.


    Several utilities, are at most 255 bits but also how you posted can be an array of bytes. It is widely used when you want to save an entire file within a database. (Byte Array). Depending on the proportion the attribute of your class will require, using byte makes your application relatively lighter, as it is a primitive data type.


    Leave a Reply

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