Java Basic Data Types And Variables

By Kunal Kapoor
19-04-2018
260

Java language has following major data types

  • 1.       Integer

An integer in java can be byte, short, int, and long. All of these are signed, positive and negative values

Eg to declare a integer variable containing value 20 is

 

a.       int variable_name = 20;

b.       short variable_name =30;

c.        long variable_name = 2000000;

d.       byte variable_name = 1;

 

  • 2.       Float / Double

Double variable contain values that have decimal  values.

Eg double variable_name = 2.5;

 

  • 3.       Character

a.       A character is a variable contacting character values.

Eg char character_variable = ‘g’;

 

b.       String is variable type that contains sequence of characters

Eg String variable_name = “ourcoaching.com”;

 

  • 4.       Boolean

A Boolean variable type contains Boolean expression -   true or false

Eg Boolean variable_name = true;


example:



ourcoaching.java:


public class ourcoaching {
	public static void main(String[] args) {
		
		int int_variable = 20;
		boolean boolean_variable = true;
		char char_variable= 'o';
		double double_variable = 32.34;

		System.out.println("int = "+int_variable);
		System.out.println("boolean = "+boolean_variable);
		System.out.println("char = "+char_variable);
		System.out.println("double = "+double_variable);
		
	}

}

output:
int = 20
boolean = true
char = o
double = 32.34



Related Tutorials