- Java Tutorial
- Java Introduction
- Java Features
- Java Simple Program
- JVM, JDK and JRE
- Java Syntax
- Java Comments
- Java Keywords
- Java Variables
- Java Literals
- Java Separators
- Java Datatypes
- Java Operators
- Java Statements
- Java Strings
- Java Arrays
- Control Statement
- Java If
- Java If-else
- Java If-else-if
- Java Nested If
- Java Switch
- Iteration Statement
- Java For Loop
- Java For Each Loop
- Java While Loop
- Java Do While Loop
- Java Nested Loop
- Java Break/Continue
- Java Methods
- Java Methods
- Java Method Parameters
- Java Method Overloading
- Java Recursion
- Java OOPS
- Java OOPs
- Java Classes/Objects
- Java Inheritance
- Java Polymorphism
- Java Encapsulation
- Java Abstraction
- Java Modifiers
- Java Constructors
- Java Interface
- Java static keyword
- Java this keyword
- Java File Handling
- Java File
- Java Create File
- Java Read/Write File
- Java Delete File
- Java Program To
- Add Two Numbers
- Even or Odd Numbers
- Reverse a String
- Swap Two Numbers
- Prime Number
- Fibonacci Sequence
- Palindrome Strings
- Java Reference
- Java String Methods
- Java Math Methods
Java Data Types
Java data types represent the type of data that variables can store. Here's a summary:
Primitive Data Types:
- Represent basic values and are predefined by the language.
- Include integer types (int, long, short, byte), floating-point types (float, double), characters (char), and boolean (boolean).
Integer Types:
- int: Represents 32-bit signed integers.
- long: Represents 64-bit signed integers.
- short: Represents 16-bit signed integers.
- byte: Represents 8-bit signed integers.
Floating-Point Types:
- float: Represents 32-bit floating-point numbers.
- double: Represents 64-bit floating-point numbers (default for floating-point literals).
Character Type:
- char: Represents a single 16-bit Unicode character.
Boolean Type:
- boolean: Represents a boolean value (true or false).
Reference Data Types:
- Represent references to objects.
- Include classes, interfaces, arrays, and enumerations.
Example
public class DataTypesExample {
public static void main(String[] args) {
// Primitive data types
int age = 25;
long population = 7000000000L;
float pi = 3.14f;
double price = 99.99;
char grade = 'A';
boolean isJavaFun = true;
// Reference data types
String name = "John";
int[] numbers = {1, 2, 3, 4, 5};
Object obj = new Object();
System.out.println("Age: " + age);
System.out.println("Population: " + population);
System.out.println("Pi: " + pi);
System.out.println("Price: " + price);
System.out.println("Grade: " + grade);
System.out.println("Is Java Fun? " + isJavaFun);
System.out.println("Name: " + name);
System.out.println("First Number: " + numbers[0]);
}
}
Summary
Java supports primitive data types (integers, floating-point numbers, characters, booleans) and reference data types (objects, arrays). Understanding data types is essential for defining variables and writing Java programs that manipulate different types of data.