Introduction

A variable gives a name to a value. Choose names that describe the information, such as score or learner_name. Assign a value before you read it, and remember that assigning again replaces the previous value.

Syntax & example

public class Main {
  public static void main(String[] args) {
    String name = "Developer";
    System.out.println("Hello " + name);
  }
}

Expected output

Hello Developer

Common mistakes

  • Using a variable before assigning a value to it.
  • Mixing text and numbers without converting deliberately.
  • Skipping an empty input or a boundary value when testing.

Practice

Create a variable for your favorite city and display it.

13px
Main.javaYour ideas, in code.
Loading your editor…
Run your code to see the output here.
Ready to buildUTF-86 lines