Credits

Friday, February 20, 2009

Simple Data Types of Java

Basic data types of Java include:

int for integers
float or double for numbers with decimals only that double has larger range
char for character or string of characters

Mathematical operators of other languages are also employed in Java. Check this sample program:


class Compute{
public static void main (String args [ ] ){
/* This is a comment paragraph
in Java */
// This is a comment line too
int birthyear=1977, currentyear=2009, age;


age=currentyear-birthyear;
System.out.println("You are " +age+" years old.");
}}


This file may be saved as Compute.java or something else since we did not mark it as public. The variables birthyear, currentyear are initialized.

To display a value of a resulting operation, you may do this inside the output command or as a separate variable.

AddThis