byte keyword in java

The byte keyword is used to declare variable as a numeric type.

A byte value can hold an 8-bit integer number which ranges from -128 to 127.

For example:
byte day = 6;

The byte keyword can be used to declare a type of a method parameter as below:

  1. public void displayDayOfWeek(byte day) {
  2.  
  3.     if(day == 3){
  4.  
  5.                    System.out.println("Tuesday");
  6.                 }
  7.  
  8. }
public void displayDayOfWeek(byte day) {

    if(day == 3){

                   System.out.println("Tuesday");
                }

}


The byte keyword can also be used to declare return type of a method as below:

  1. public byte getDayOfWeek(String day) {
  2.  
  3. if(day.equals("Monday")){    
  4.  
  5.                               return 2;
  6.                         }
  7. }
public byte getDayOfWeek(String day) {

if(day.equals("Monday")){    

                              return 2;
                        }
}

About the Author

Founder of javainsimpleway.com
I love Java and open source technologies and very much passionate about software development.
I like to share my knowledge with others especially on technology 🙂
I have given all the examples as simple as possible to understand for the beginners.
All the code posted on my blog is developed,compiled and tested in my development environment.
If you find any mistakes or bugs, Please drop an email to kb.knowledge.sharing@gmail.com

Connect with me on Facebook for more updates

Share this article on