Home » Java Byte Keyword

Java Byte Keyword

by Online Tutorials Library

Java byte keyword

The Java byte keyword is a primitive data type. It is used to declare variables. It can also be used with methods to return byte value. It can hold an 8-bit signed two’s complement integer.

Points to remember

  • The byte range lies between -128 to 127 (inclusive).
  • Its default value is 0.
  • It is useful to handle the st
  • ream of data from a network or file.

  • It is also useful for saving memory in large arrays.
  • It can be used in place of the int data type.

Java byte keyword

Examples of Java byte keyword

Example 1: Using byte with variable

Test it Now

Output:

Example 2: byte lies out of range

Output:

Java byte keyword

Example 3: Using byte with a method

Output:

The age must be: 18  
Next TopicJava Case Keyword

You may also like