For what is Java byte type

3

For what is the byte type of java? ex:

byte[] dados = ... ;

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

    
asked by anonymous 30.04.2014 / 00:47

3 answers

4

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.

        
    30.04.2014 / 01:01
    1

    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.

        
    30.04.2014 / 00:57
    1

    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.

        
    30.04.2014 / 00:57