Java - Basic Introduction To Variables

Variables are an integral part of any programming language. They are used to store data. Java, like many programming languages has different data types when defining variables. This code snippet shows two of the most common variable data types.

  1. class SimpleVariables {      
  2.     public static void main(String args[]) {      
  3.         String name = "John";      
  4.         int length = name.length();      
  5.         System.out.println("My name " + name +   " has " + length +   " characters");      
  6.     }      
  7. }  

No comments:

Post a Comment