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:
- public void displayDayOfWeek(byte day) {
- if(day == 3){
- System.out.println("Tuesday");
- }
- }
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:
- public byte getDayOfWeek(String day) {
- if(day.equals("Monday")){
- return 2;
- }
- }
public byte getDayOfWeek(String day) { if(day.equals("Monday")){ return 2; } }