Java Variables & Data Types: Understanding Memory Storage

Day 2/100 — Variables & Data Types in Java 🧱 Before you can write any meaningful Java program, you must understand one fundamental concept — how Java stores data in memory. That’s where variables and data types come in. A variable is simply a named container in memory. When you write int age = 25, you’re telling Java to reserve a space in memory, label it age, and store the value 25 inside it. A data type tells Java two things: • What type of value will be stored • How much memory should be allocated Java has 8 primitive data types: int → whole numbers double → decimal numbers char → a single character (always use single quotes) boolean → true or false long → large whole numbers float → decimal numbers with less precision byte → very small integers short → small integers ⚠️ One important thing beginners often miss: String is NOT a primitive data type. It’s a class, which is why it starts with a capital S. 3 rules you should always remember: ✔ Use single quotes (' ') for char ✔ Use double quotes (" ") for String ✔ long values should end with L → 123456789L ✔ float values should end with f → 3.14f 💻 Today's Challenge Declare 5 variables about yourself: • Name • Age • Height • City • Whether you are a student Use the correct data types for each one. Drop your code in the comments — I’ll check if the types are correct. 👇 #Java #100DaysOfJava #100DaysOfCode #CoreJava #LearnJava #JavaDeveloper #Programming

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories