A demo file to initialize and display different variables:
- Create a new class with name VariablesDemo:
public class VariablesDemo {
public static void main(String[] args) {
/* Declaration of variables */
int Id;
String name;
char gender;
double salary;
/* Initialization of variables*/
Id = 4348;
name = "Employer";
gender ='M';
salary = 25000.0;
/* Display the employee details */
System.out.println("Id : "+ Id);
System.out.println("Name : "+ name);
System.out.println("Gender : "+ gender);
System.out.println("Salary : "+ salary);
}
}
public static void main(String[] args) {
/* Declaration of variables */
int Id;
String name;
char gender;
double salary;
/* Initialization of variables*/
Id = 4348;
name = "Employer";
gender ='M';
salary = 25000.0;
/* Display the employee details */
System.out.println("Id : "+ Id);
System.out.println("Name : "+ name);
System.out.println("Gender : "+ gender);
System.out.println("Salary : "+ salary);
}
}
NOTE:
- The text between "/* " and "*/" will not be executed.They are used to write comments.
- For single line comments use "//"