java variable to variables code example

Example 1: variable name in java

Java variable names are case sensitive. ...
Java variable names must start with a letter, or the $ or _ character.
After the first character in a Java variable name, the name can also contain numbers (in addition to letters, the $, and the _ character).

Example 2: Variables in java

// local variable in java example
public class LocalVariableExample
{
   public void employeeDetails()
   {
      // local variable empAge and name
      int empAge = 22;
      String name = "Sachin";
   }
   public static void main(String[] args)
   {
      LocalVariableExample obj = new LocalVariableExample();
      // name and empAge cannot 
      // be resolved to a variable
      System.out.println("Employee name is : " + name + ", and age : " + empAge);
   }
}

Tags:

Java Example