Java Arrays in Depth: 1D, 2D, 3D & Length Property

🚀 Day 19 – Java Full Stack Journey | Arrays in Depth (1D, 2D, 3D + length Property) Today’s session was a complete deep dive into Arrays in Java — not just creating them, but truly understanding: • Memory behavior • Traversal logic • Why loops are mandatory • How length actually works • Regular vs Jagged arrays 🔹 What is an Array? 👉 Arrays are objects in Java 👉 Stored in the Heap memory 👉 Used to store homogeneous data 👉 Indexed starting from 0 When you print the array reference directly: System.out.println(a); You don’t get elements. You get the address reference — because arrays are objects. To access elements → Traversal using loops is mandatory. 🔹 1️⃣ One-Dimensional Array (1D) int[] a = new int[5]; ✔ Stored in Heap ✔ Default values → 0 ✔ Traversed using single loop Important rule: for(int i = 0; i < a.length; i++) Using a.length makes your code dynamic. Never hardcode size like i < 5. 🔹 2️⃣ Two-Dimensional Array (2D) int[][] a = new int[2][5]; Meaning: 2 rows 5 columns Traversal requires nested loops: for(int i = 0; i < a.length; i++) { for(int j = 0; j < a[i].length; j++) { // Access element } } Important Understanding: a.length → number of rows a[i].length → number of columns in that row This makes the code scalable and flexible. 🔹 3️⃣ Three-Dimensional Array (3D) int[][][] a = new int[2][3][5]; Meaning: 2 blocks 3 rows per block 5 columns per row Traversal requires 3 nested loops: for(int i = 0; i < a.length; i++) { for(int j = 0; j < a[i].length; j++) { for(int k = 0; k < a[i][j].length; k++) { // Access element } } } Understanding flow: Column moves fastest → Then row → Then block That’s how memory gets populated. 🔹 Regular Array vs Jagged Array ✔ Regular Array → All rows have equal number of columns ✔ Looks rectangular Tomorrow’s focus → Jagged Array (Where each row can have different column size) 🔹 Most Important Learning Today Arrays are not about syntax. They are about: • Understanding object behavior • Understanding memory (Heap & Stack) • Writing dynamic loops • Avoiding hardcoded logic • Thinking in dimensions 90% of array problems follow the same pattern: Create → Traverse → Process → Print Once traversal is clear, logic becomes easy. Consistency + Practice + Typing the code yourself = Mastery. Day 19 Complete ✔ #Day19 #Java #CoreJava #Arrays #DataStructures #JVM #FullStackJourney #LearningInPublic #JavaDeveloper #100DaysOfCode TAP Academy

  • text

To view or add a comment, sign in

Explore content categories