Skip to content
Learn Netverks

Lesson

Step 18/36 50% through track

arrays

Arrays

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Arrays: the syntax, APIs, and habits you need before advancing in Java.

Teams ship Arrays on every Java codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Arrays in contexts like: Spring Boot APIs, banking systems, Android (with Kotlin), and batch/data pipelines on the JVM.

Write Java with a public class (lessons use Main), click Run on server—the dev runner runs javac then java; fix compile errors from stderr (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Java arrays are fixed-length, indexed collections with a component type: int[] scores = new int[3];. Length is immutable after creation—use ArrayList when you need growth.

Declaration and initialization

int[] nums = {10, 20, 30};
String[] names = new String[2];
names[0] = "Ada";

Default values: 0 for numeric types, false for boolean, null for references.

Length and iteration

for (int i = 0; i < nums.length; i++) { }
for (int n : nums) { }

length is a field, not a method—contrast with ArrayList.size().

Important interview questions and answers

  1. Q: Array vs ArrayList?
    A: Array fixed size, primitives allowed; ArrayList resizable, holds objects (with autoboxing).
  2. Q: What happens on out-of-bounds access?
    A: ArrayIndexOutOfBoundsException at runtime.

Self-check

  1. How do you get an array's length?
  2. When must you prefer ArrayList over array?

Pitfall: length is a field on arrays but size() is a method on ArrayList—do not mix them up in interviews.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Length fixed why?
  • Array copy pitfall?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump