![]() |
| Data Types in Java Programming Language |
Java Data Types: Data Types which is used in the program. There are many predefined data types in java library like integer, floating and character data types. Java data types are divided in two categories Primitive data types it can only single value store. Non-primitive data type it can also store reference data type.
Types of Primitive Data Types in Java
Integer Data Types in Java
| Data Type | Size in bytes | Range |
|---|---|---|
| byte | 1 | -128 to 127 |
| short | 2 | -32,768 to 32,767 |
| int | 4 | 32,768 to 32,767 |
| long | 8 | -2,147,483,648 to 2,147,483,647 |
Byte Data Type: A byte data type can be used large array of memory.
Example of Byte Data Types in Java
byte x = 50; System.out.println("Byte Data Type: " + x); } } ============OUTPUT============ Byte Data Type:50 |
Example of Short Data Types in Java
short x = 2000; System.out.println("Short Data Type: " + x); } } ============OUTPUT============ Short Data Type:2000 |
Integer Data Type: A integer data types can be using without decimal places number. It can be stored whole numbers. It is commonly used in Java programming. Integer can used memory size 4 byte and 32 bit in Java memory.
Example of Integer Data Types in Java
int pin_code = 244002; System.out.println("Integer Data Types: " +pin_code); } } ============OUTPUT============ Integer Data Types:244002 |
Long Data Type: A long data type can be used in 64-bit signed memory. Long dats type to store large whole numbers that exceed the capacity of the int data type. It is one of the 8 bytes primitive data types in Java.
Example of Long Data Types in Java
long mobile_no = 9856254526L; System.out.println("Long Data Types: " + mobile_no); } } ============OUTPUT============ Long Data Types: |
Float Data Types in Java
| Data Type | Size in bytes | Range |
|---|---|---|
| float | 4 | 3.4e-038 to 3.4e+038 |
| double | 8 | 1.7e-308 to 1.7e+038 |
Float Data Types: A float data type can be used in floating-point number. It can be store decimal values. It is one of the two primitive types. Float data types a 4 bytes and 32 bit memory size.
Example of Float Data Types in Java
float marks = 98.5f; System.out.println("Float Data Types: " + marks); } } ============OUTPUT============ Float Data Types: |
Double Data Types: A double are the two primitive data types in Java it can be store decimal point numbers (floating-point numbers) with the primary difference being their storage size and precision. double data type used 16 decimal places value. It can be used 8 bytes and 64 bit memory size.
Example of Double Data Types in Java
double number = 98.56254526; System.out.println("Double Data Types: " +number); } } ============OUTPUT============ Double Data Types: |
Boolean Data Types in Java
| Keyword | boolean |
| Syntax | boolean x; |
| Value | True/False |
| Default | False |
Boolean Data Types: A boolean data type in Java is a primitive data type used to store one of two possible logical values true and false. boolean data types can be using conditional statements.
Example of Boolean Data Types in Java
boolean noida = true; System.out.println("Boolean Data Types: " +noida); } } ============OUTPUT============ Boolean Data Types: true |
Character Data Types in Java
| Keyword | char |
| Syntax | char x; |
| Value | 'J','$','8' |
| Range | 0 to 65536 |
Character Data Type: A character data type can be used only single character value.It can be using single quote(' ').
Example of Character Data Types in Java
char grade = 'A'; char symbol='@'; char number='9'; System.out.println("Character Data Types Grade: " +grade); System.out.println("Character Data Types Symbol: " +symbol); System.out.println("Character Data Types Number: " +number); } } ============OUTPUT============ Character Data Types Grade: A Character Data Types Grade Symbol:@ Character Data Types Grade Number:9 |
Types of Non Primitive(Reference) Data Types in Java
Primitive Data Types: Primitive data is a predefined data types in Java language non primitive data types are a fixed memory size. It can be store the actual value directly it can not be null.
Non-primitive data types are created by the programmer and refer to objects in memory. They have variable sizes and can be assigned the value null.
The data type which is derived from primitive data type is called non-primitive data type. It is also called reference data type. They don't store the value, but store a reference to that value.
Non primitive Data Type in Java
String: A string is a sequence of characters treated as an object. It can be used double quotes("Jiocoding").
Example of String Data Types in Java
String name = "Jiocoding"; String msg = "Welcome To Java Language"; System.out.println("Website Name: " + name); System.out.println("Greeting: " + msg); } } ============OUTPUT============ Website Name: Greeting: Welcome To Java Language |
Arrays: Array is a container object that holds a fixed number of values of a single type. It can be stored in same data types and value.
Example of Array Data Types in Java
int[] num = {10, 20, 30, 40, 50}; String[] names = {"Java", "Python", "Jiocoding"}; System.out.println("Number Data: " + num[0]); System.out.println("String Data: " + names[2]); } } ============OUTPUT============ Number Data: 10 String Data: Jiocoding |
Classes: Class is a user defined data types it is a blueprints from which objects are created.
Example of Class Data Types in Java
String name; student(String name) { this.name = name; } } class Jiocoding { student s = new student("John"); System.out.println("Student Name: " + s.name); } } ============OUTPUT============ Student Name: John |
Interfaces: A interface data types can be used abstract types that define a contract for what a class can do.
Example of Interface Data Types in Java
void website(); } class Welcome implements Coding { public void website() { System.out.println("Welcome To Jiocoding Website"); } } class Jiocoding{ Coding c = new Welcome(); c.website(); } } ============OUTPUT============ Welcome To Jiocoding Website |
Conclusion of Data Type in Java
Conclusion: A Java data types are simple and easy to learn. Data types are important part of Java language. if any query for data types in Java you can contact me. I will solve your problem and better understanding solution provides.

0 Comments