Basic Data Types in Java Programming – Example Code

In previous post we learned how to write a very simple hello world Java program. In this simple program we will explain what are some different data types in Java. We use specific data types to define variable depending upon the nature of data we want to store in variable.

[js]

public class DataTypesJava {

public static void main(String[] args) {
//single line comment

boolean isBoolean = true; // boolean data type store either true or false
int isInt = 120; // int data type is used to store integer values
int mult = isInt * 2; // multiplication is basic arithmetic operation
int mod = isInt % 2; // modulus operator is used to find remainder
System.out.println(isBoolean);
System.out.println(‘A’); //characters are enclosed in single quotes
System.out.println("Some String Text"); // strings are enclosed in double quotes
System.out.println(isInt);
System.out.println(mult);
System.out.println(isInt / 2); // division is simple arithmetic operation
System.out.println(mod);
}

}

[/js]

Output:

data types in java

2 thoughts on “Basic Data Types in Java Programming – Example Code

    1. Its the output of ‘mod’ variable (modulus operator). When we divide 120 by 2 then the modulus (remainder is 0). That’s why its output is 0.

Leave a Reply to Junaid Hassan Cancel reply

Your email address will not be published. Required fields are marked *