Keyword in Java

The short keyword in Java programming language

The short keyword in Java programming language

In this tutorial, we learn about the short keyword in java programming language.

The short keyword is a Java keyword used to declare a type of numeric variable. A short variable can hold a 16-bit integer number which ranges from -32,768 to 32767

Declaration

short – in variable

the syntax of short keyword

short<variable_name>=<short_value>;

Example

Example of short keyword

short length = 2345;

Program 1

//Example for short variable
public class shortEx1{
    public static void main (String args[]){
        short hight=20456;
        System.out.println("mountain ight is :"+hight);
}
}

 

When we execute the above program, it produces the following result

My Total_marks is: 789

 

short – method

The short keyword can be used to declare the return type of a method in Java

Example

Example of short keyword

public short getHeight(){
return 2345;
}

Above method is a short method which returns any value.

Example short method within a class

public class Example _short{  // this is a class in java
public static void main(String args[]){ // this is a main method in java
}
public short add(){  // this is a short method which returns value;
}
}


program 2

public class shortEx2{
    public static void main (String args[]){
        dis_town();
    }
            static short dis_town(){
                //short keyword is used to declare method
                short distance=20000;
        System.out.println("town distance is :"+distance);
        return distance;//return statements
}
}

 

When we execute the above program, it produces the following result

town distance is: 20000

 

There are other Java language keywords that are similar to this keyword

 byte  in Java Language

 int  in Java Language

long  in Java Language

 float  in Java Language

char  in Java Language

 void  in Java Language

try  in Java Language

Catch in Java Language

implements  in java Language

public  in Java Language

static  in Java language

Volatile  in Java Language

Package  in Java Language

class  in Java Language

boolean  in Java Language

break in Java Language

do  in Java Language

double  in Java Language

This  in Java Language

final  in Java Language

switch  in Java Language

interface  in Java Language

extends  in Java language

 

Suggested for you

 Java language Keywords

C language Keywords

 Python language Keywords

keywords in C language

Finally  in Java language

The int keyword in Java programming language
The long keyword 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

Python code to Calculate sum of odd and even in a list

Python code to Calculate sum of odd and even in a list In this tutorial,…

9 hours ago

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

3 days ago

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