Skip to content
Learn Netverks

Lesson

Step 7/36 19% through track

variables-types

Variables and types

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

This lesson

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

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

You will apply Variables and types 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 variables have an explicit type declared before the name: int count = 0;. Unlike JavaScript or PHP, you cannot silently change a variable from int to String without a compile error.

Primitive types (common)

  • int, long — integers
  • double, float — floating point (prefer double)
  • booleantrue or false only
  • char — single Unicode character in single quotes

Reference types

Objects and arrays are references: String name = "Ada";, int[] scores = {90, 85};. Primitives hold values directly; references point to heap objects.

final and var

final int MAX = 100; cannot be reassigned. Java 10+ var infers type locally: var list = new ArrayList<String>();

Important interview questions and answers

  1. Q: Primitive vs wrapper?
    A: int is a primitive; Integer is an object wrapper used in generics and nullable contexts.
  2. Q: Is String a primitive?
    A: No—String is an immutable reference type.
  3. Q: What is autoboxing?
    A: Automatic conversion between primitives and wrappers, e.g. Integer n = 5;

Self-check

  1. Name two primitive numeric types.
  2. What type does "hello" have?

Pitfall: Use equals for String content—== compares references and breaks comparisons of separate String objects.

Interview prep

Primitive vs wrapper?

Primitives (int) hold values directly; wrappers (Integer) are objects used in generics and nullable contexts—with autoboxing between them.

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

  • int vs Integer?
  • final local when?

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