MOCKSTACKS
EN
Questions And Answers

More Tutorials









Java Data Types


Data types in Java fall under the following categories :

1. Primitive Data Types (Intrinsic)

2. Non-Primitive Data Types (Derived)

Primitive Data Types


Java is statically typed, i.e., variables must be declared before use. Java supports 8 primitive data types:


Data TypeSizeValue Range
Byte1 byte-128 to 127
short 1 byte -32,768 to 32,767
int 2 byte -2,147,483,648 to 2,147,483,647
float 4 byte 3.40282347 x 1038 to 1.40239846 x 10-45
long 8 byte -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
double 8 byte 1.7976931348623157 x 10308, 4.9406564584124654 x 10-324
char 2 byte 0 to 65,535
boolean Depends on JVM True or False

How to choose data types for our variables


In order to choose the data type, we first need to find the type of data we want to store. After that, we need to analyze the min & max value we might use.

Adding 3 number variables


public class Main {
  public static void main(String[] args) {
    int num1 = 10, num2 = 20, num3 = 30;
    System.out.println("Addition of 3 numbers are :" + (num1+num2+num3));
  }
}

Output

Addition of 3 numbers are : 60


Conclusion

In this page (written and validated by ) you learned about Java Data Types . What's Next? If you are interested in completing Java tutorial, your next topic will be learning about: Java Literals.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.