
10 Types of Programming Languages Every Coder should Know
Learn about different types of programming languages and how they are implemented in the real world.

Data types in Java are used to indicate what kind of data a variable is able to hold. They tell the compiler or interpreter about how the programmer plans to make use of the data. The types that people use in Java will guide them toward applying variables appropriately and managing memory effectively.
In this blog post, we will focus on learning primitive data types in Java with code examples. Each characteristic of each primitive data type will be studied, and we shall learn how they are applied in Java programming language.
Data types in Java define what kind of data a variable can store. They help the compiler understand how the programmer intends to use the data. Using the correct data type ensures proper memory management and error-free code execution.
1. Primitive Data Types:
2. Non-Primitive Data Types:
Primitive data types are essential for basic operations, while non-primitive data types are used for more complex data handling. In the next section, we will dive deeper into primitive data types and their specific uses in Java programming.

POSTGRADUATE PROGRAM IN
Multi Cloud Architecture & DevOps
Master cloud architecture, DevOps practices, and automation to build scalable, resilient systems.
Primitive data types are the most basic types in Java. They are predefined by the language and named by a keyword. Primitive data types serve as the building blocks for data manipulation in Java programs. Understanding these types is crucial for efficient coding and memory management.
In this section, we will cover below non-primitive data types.
The boolean data type in Java is used to store two possible values: true or false. This data type is often used for simple flags that track true/false conditions, and it is essential for control flow in Java programs, such as in if statements and loops.
Example:
In this example, the boolean variables ‘isJavaFun’ and ‘isFoodTasty’ are used to store true and false values, respectively. These variables are then used in if statements to control the flow of the program based on their values.
public class BooleanExample {
public static void main(String[] args) {
// Declaring and initialising boolean variables
boolean isJavaFun = true;
boolean isFoodTasty = false;
// Using boolean variables in conditional statements
if (isJavaFun) {
System.out.println("Java is fun!"); // This will be printed
} else {
System.out.println("Java is not fun.");
}
if (isFoodTasty) {
System.out.println("Food is tasty.");
} else {
System.out.println("Food is not tasty!"); // This will be printed
}
// Printing the boolean values directly
System.out.println("Is Java fun? " + isJavaFun);
System.out.println("Is food tasty? " + isFoodTasty);
}
}
Output:
Java is fun!
Food is not tasty!
Is Java fun? true
Is food tasty? false
The char data type in Java is used to store a single 16-bit Unicode character. This data type is essential for handling characters and text in Java programs. Each char value represents a single character from the Unicode character set.
Example:
In this example, the char variables ‘letterA’, ‘letterB’, ‘digit1’, and symbol are used to store different types of characters, including letters, digits, and symbols.
public class CharExample {
public static void main(String[] args) {
// Declaring and initialising char variables
char letterA = 'A';
char letterB = 'B';
char digit1 = '1';
char symbol = '@';
// Printing char variables
System.out.println("Letter A: " + letterA); // Prints: Letter A: A
System.out.println("Letter B: " + letterB); // Prints: Letter B: B
System.out.println("Digit 1: " + digit1); // Prints: Digit 1: 1
System.out.println("Symbol @: " + symbol); // Prints: Symbol @: @
}
}
Output:
Letter A: A
Letter B: B
Digit 1: 1
Symbol @: @
The int data type in Java is used to store 32-bit signed integer values. It is one of the most commonly used data types for numeric values. Java also provides other integer data types such as byte, short, and long to handle various ranges and storage needs.
The byte data type is an 8-bit signed integer. It is the smallest integer data type and is often used for saving memory in large arrays where memory savings are most needed.
Example:
In this example, ‘byteVar1’ and ‘byteVar2’ are declared and initialised with values 100 and -50, respectively.
public class ByteExample {
public static void main(String[] args) {
// Declaring and initialising byte variables
byte byteVar1 = 100;
byte byteVar2 = -50;
// Printing byte variables
System.out.println("Byte Variable 1: " + byteVar1); // Prints: Byte Variable 1: 100
System.out.println("Byte Variable 2: " + byteVar2); // Prints: Byte Variable 2: -50
}
}
Output:
Byte Variable 1: 100
Byte Variable 2: -50
The short data type is a 16-bit signed integer. It is used to save memory in large arrays when the range of values is known to be small.
Example:
In this example, ‘shortVar1’ and ‘shortVar2’ are declared and initialised with values 30000 and -15000, respectively.
public class ShortExample {
public static void main(String[] args) {
// Declaring and initialising short variables
short shortVar1 = 30000;
short shortVar2 = -15000;
// Printing short variables
System.out.println("Short Variable 1: " + shortVar1); // Prints: Short Variable 1: 30000
System.out.println("Short Variable 2: " + shortVar2); // Prints: Short Variable 2: -15000
}
}
Output:
Short Variable 1: 30000
Short Variable 2: -15000
The int data type is a 32-bit signed integer. It is the default choice for integer values unless there is a reason to use another type due to memory constraints or specific range requirements.
Example:
In this example, ‘intVar1’ and ‘intVar2’ are declared and initialised with values 100000 and -200000, respectively.
public class IntExample {
public static void main(String[] args) {
// Declaring and initialising int variables
int intVar1 = 100000;
int intVar2 = -200000;
// Printing int variables
System.out.println("Int Variable 1: " + intVar1); // Prints: Int Variable 1: 100000
System.out.println("Int Variable 2: " + intVar2); // Prints: Int Variable 2: -200000
}
}
Output:
Int Variable 1: 100000
Int Variable 2: -200000
The long data type is a 64-bit signed integer. It is used when a wider range than int is needed.
Example:
In this example, ‘longVar1’ and ‘longVar2’ are declared and initialised with values 10000000000L and -20000000000L, respectively. The ‘L’ suffix is used to indicate a long literal.
public class LongExample {
public static void main(String[] args) {
// Declaring and initialising long variables
long longVar1 = 10000000000L;
long longVar2 = -20000000000L;
// Printing long variables
System.out.println("Long Variable 1: " + longVar1); // Prints: Long Variable 1: 10000000000
System.out.println("Long Variable 2: " + longVar2); // Prints: Long Variable 2: -20000000000
}
}
Output:
Long Variable 1: 10000000000
Long Variable 2: -20000000000
These integer data types (byte, short, int, and long) provide flexibility in handling numeric data with varying ranges and storage requirements. Understanding their differences and uses helps in writing efficient Java programs.
The float data type in Java is a single-precision 32-bit IEEE 754 floating point. It is used to save memory in large arrays of floating point numbers. The double data type is a double-precision 64-bit IEEE 754 floating point. It is the default choice for decimal values.
The float data type is used for floating-point numbers that require less precision and consume less memory.
Example:
In this example, floatVar1 and floatVar2 are declared and initialised with values 5.75f and -3.14f, respectively. The ‘f’ suffix is used to indicate a float literal.
public class FloatExample {
public static void main(String[] args) {
// Declaring and initialising float variables
float floatVar1 = 5.75f; // The 'f' suffix indicates a float literal
float floatVar2 = -3.14f;
// Printing float variables
System.out.println("Float Variable 1: " + floatVar1); // Prints: Float Variable 1: 5.75
System.out.println("Float Variable 2: " + floatVar2); // Prints: Float Variable 2: -3.14
}
}
Output:
Float Variable 1: 5.75
Float Variable 2: -3.14
The double data type is used for decimal values with higher precision and is the default choice for floating-point numbers in Java.
Example:
In the example below, ‘doubleVar1’ and ‘doubleVar2’ are declared and initialise with values 19.99 and -123.456, respectively. No suffix is needed for double literals.
public class DoubleExample {
public static void main(String[] args) {
// Declaring and initialising double variables
double doubleVar1 = 19.99;
double doubleVar2 = -123.456;
// Printing double variables
System.out.println("Double Variable 1: " + doubleVar1); // Prints: Double Variable 1: 19.99
System.out.println("Double Variable 2: " + doubleVar2); // Prints: Double Variable 2: -123.456
}
}
Output:
Double Variable 1: 19.99
Double Variable 2: -123.456
Here’s a comprehensive table for all primitive data types in Java:
| Type | Description | Default | Size | Range of Values | Example Literals |
| byte | 8-bit signed integer | 0 | 8-bit | -128 to 127 | 100, -50 |
| short | 16-bit signed integer | 0 | 16-bit | -32,768 to 32,767 | 30000, -15000 |
| int | 32-bit signed integer | 0 | 32-bit | -2^31 to 2^31-1 | 100000, -200000 |
| long | 64-bit signed integer | 0L | 64-bit | -2^63 to 2^63-1 | 10000000000L, -20000000000L |
| float | Single-precision 32-bit IEEE 754 floating point | 0.0f | 32-bit | ±3.40282347E+38F (6-7 significant decimal digits) | 5.75f, -3.14f |
| double | Double-precision 64-bit IEEE 754 floating point | 0.0d | 64-bit | ±1.79769313486231570E+308 (15 significant decimal digits) | 19.99, -123.456 |
| boolean | Represents one bit of information | false | 1-bit | true or false | true, false |
| char | 16-bit Unicode character | ‘\u0000’ | 16-bit | ‘\u0000’ (0) to ‘\uffff’ (65,535) | ‘A’, ‘B’, ‘\u263A’ |
Java has several primitive data types that must be understood by every single programmer. These data types provide building blocks for handling information and preserving it within Java. When you become experienced with them, you can type less buggy codes which perform better.
As a result, this blog post gives an overview of the eight primitive data types in Java like their sizes, ranges, and some examples used. Hence knowing when and how each one is used will enable better memory management and improved optimization of your Java applications.
Updated on July 30, 2024

Learn about different types of programming languages and how they are implemented in the real world.

Explore 10 front-end development, including key languages, its advantages and disadvantages, and how it shapes user experience in web design and functionality.