Initializing local Variables - Java Language Basics

Java examples for Language Basics:Variable

Introduction

In Java, local variables are not given initial default values.

The compiler ensures that you have assigned a value before you use a local variable.

For example, the following program won't compile:

Demo Code

public class Main {
  public static void main(String[] args) {
    int i;/*from ww  w  .  j a va  2s .co  m*/
    //System.out.println("The value of i is " + i);
  }
}

Related Tutorials