Once you click post assignment, learners in the selected class will immediately be able to see and complete this assignment
Back to Classroom
Short
Introduction To Java Course
Engineers From These Top Companies and Universities Trust EXLskills
1M+ Professionals | 100+ Institutions
This is the EXLskills free and open-source Introduction To Java Course. It guides learners via explanation, demonstration, and thorough practice, from no more than a basic understanding of Java, to a moderate level of essential coding proficiency.
Is this course FREE?
Yes, this a 100% free course that you can contribute to on GitHub here!
The short primitive datatype is another less commonly used integer-related datatype due to its limited range of -32,768 to 32,767. Let's glance at the example below showing the declaration and use of short.
ShortDataTypeExample.java
package exlcode;
public class ShortDataTypeExample {
// short can be any integer between -32768 and 32767
public static short exampleVariableOne = 100;
public static short exampleVariableTwo = -100;
public static short exampleVariableThree = 0;
public static void main(String[] args) {
System.out.println(exampleVariableOne);
System.out.println(exampleVariableTwo);
System.out.println(exampleVariableThree);
}
}
short functions similarly to int as it can only hold whole, non-decimal numbers. This datatype was commonly used when 16-bit computers were used, and are rarely used now as int has pretty much taken its place. However, short takes up about half the space of an int, so in a specific case when you are dealing with a large list of whole numbers, you may chose to use short to save space. With that being said, we will just use int for most of our programs.