Thuta Learning
BasicProgrammingbeginner

Data Types

Relax. We'll talk through this in plain words — no textbook voice.

Java data types can mainly be split into Primitive Types and Reference Types. Primitive types store the value directly, while reference types point to an object/location. The first thing beginners should know is that getting the data type right is what makes the operations on it work correctly. For example, if you're not going to do math with a phone number, storing it as a String makes a lot more sense.

java
public class Main {
  public static void main(String[] args) {
    int quantity = 3;
    double price = 19.99;
    char grade = 'A';
    boolean isAvailable = true;
    String productName = "Keyboard";

    System.out.println(productName + " x " + quantity);
    System.out.println("Total: " + (quantity * price));
    System.out.println("Grade: " + grade);
    System.out.println("Available: " + isAvailable);
  }
}

In this example, data for something like a product order is stored using several different types. quantity * price multiplies two numeric types together to get the total price.

You should see
Keyboard x 3 Total: 59.97 Grade: A Available: true

Real-world use

Choosing the right data type matters a lot in real app data models—e-commerce orders, school grading, booking status, payment amounts, and more.

Easy traps

  • Avoid putting a decimal number into an int, putting multiple characters into a char, or using the wrong kind of quotes.
Data Types | Thuta Learning