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

abstract keyword in Java

boolean Keyword in Java

break keyword in Java

Byte keyword in Java 

case keyword in Java 

catch keyword in Java 

char keyword in Java 

class keyword in Java 

continue keyword in Java 

default keyword in Java 

do keyword in Java

double keyword in Java

else keyword in Java

enum keyword in Java

extends keyword in Java

final keyword in Java

finally keyword in Java

float keyword in Java

for keyword in Java

if keyword in Java

static keyword in Java

super keyword in Java

transient keyword in Java

public keyword in Java

private keyword in Java

protected keyword in Java

 

Suggested for you

Usage of this statement in the Java language

Keywords in Java language

Keywords in C language

Keywords in Python language

One dimension Array in Java

Two dimension Array in Java

Three dimension Array in Java

Keywords in C language

Keywords in Python language

 

Method in Java

Method Overloading in Java

constructor in Java

Constructor overloading in Java 

 

 

 

The interface keyword in Java language
Usage of this in Java programming language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago