Skip to content

Latest commit

 

History

History
81 lines (56 loc) · 1.41 KB

File metadata and controls

81 lines (56 loc) · 1.41 KB

Java Data Types

In Java, data types specify the type of data that a variable can hold. Java has two categories of data types: primitive data types and reference data types.

Primitive Data Types

1. Numeric Types:

  • int: Used for storing integer values.

    int age = 25;
  • double: Used for storing floating-point numbers.

    double salary = 1200.50;
  • float: Similar to double but with less precision.

    float weight = 68.5f;
  • short: Used for small integers.

    short temperature = -10;
  • long: Used for large integers.

    long population = 7000000000L;

2. Boolean Type:

  • boolean: Used for storing true or false values.
    boolean isJavaFun = true;

3. Character Type:

  • char: Used for storing a single character.
    char grade = 'A';

Reference Data Types

1. Object Types:

  • String: Represents a sequence of characters.
    String greeting = "Hello, World!";

2. Arrays:

  • Used for storing multiple values of the same type.
    int[] numbers = {1, 2, 3, 4, 5};

3. Custom Classes:

  • User-defined classes can be used to create objects with specific data types.

    class Person {
        String name;
        int age;
    }
    
    Person john = new Person();
    john.name = "John";
    john.age = 30;