The byte keyword in Java programming language
- Home
- Keyword in Java
- The byte keyword in Java programming language
- On
- By
- 0 Comment
- Categories: Keyword in Java
The byte keyword in Java programming language
The byte keyword in Java programming language
In this tutorial, we will discuss the byte keyword in Java programming language
The “byte” Java keyword is used to declare a variable as a numeric type. A byte value can hold 8 bits (a byte holds eight bits signed integer) an integer number of the primitive data type. This ranges from -128 to 127.
Varaible declaration
The byte keyword can be used to declare a variable in Java
syntax
The syntax of byte keyword for variable declaration
byte <variable_name>=<integer_value>;
Example
This is an example for the variable declaration of byte keyword
byte month=19; //or byte value='c' //The number 99 is the value for 'c'(small) in ASCII
Method declaration
The byte keyword can be used to declare a return type method in Java
public byte getMyAge(){ return 28; }
Here is an Example
Program 1
public class Byte_example{ public static void main(String args[]){ int age=18; System.out.print("my age is :"); System.out.println(age); } }
When the above code is executed, it produces the following results
my age is :18
Program 2
Find ASCII value using byte
public class Byte_example1{ public static void main(String args[]){ int find_ASCII_1='c'; int find_ASCII_2='C'; System.out.println("Find ASCII value of C :"+find_ASCII_2); System.out.print("Find ASCII value of c :"+find_ASCII_1); } }
When the above code is executed, it produces the following results
Find ASCII value of C :67 Find ASCII value of c :99
There are other Java language keywords that are similar to this keyword
Suggested for you
Usage of this statement in the Java language
Constructor overloading in Java