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
the syntax of short keyword
short<variable_name>=<short_value>;
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
The short keyword can be used to declare the return type of a method in Java
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
Suggested for you
Python code to Calculate sum of odd and even in a list In this tutorial,…
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…