Data Types in Java

In our Selenium tutorials series previously we discussed about learning Java for better selenium scripting and How to get a selenium tester job as a fresher.

As it is ultimately clear that using Java Programming language for selenium tool is the best choice.

Here this part of selenium tutorial will explain about the Data Types in Java.

Complete Selenium Training Topics to be a Professional


What is a Data Type?

Data Type is a classification of the type of data that an object or variable can hold in a computer programming.
Here is what Techopedia explains about Data Type.

Data Types in Java

It gets better;

Types of Programming Languages

There are two different types of Programming Languages such as Static and Dynamic.

Data Types in Java

Static Programming Language

In Static type programming language the variable and the expression type is already known at compile time. It consist of Data Types in which the variable is stored, and once it is stored it cannot hold values of other data types.

Ex: C, C++, Java


Dynamic Programming Language

Here in this language, the variable can receive different data types over the time.

Ex: Ruby, Python

What’s the bottom line?

Java is strongly static type programming language in which each type of data is predefined such as integer, character, hexadecimal, packed decimal and so forth.


What is a Data Types in Java?

Java has two categories of data they are as follows,

  • Primitive Data
  • Object Data

Primitive Data Type

Primitive Data Type consists of single values, It consists of 8 types, They are explained as follows

Data Types in Java

Important Data Types in Java – Primitive Data Type are explained with example below,

Boolean Data Type:

Only one bit information can be represented by Boolean Data Type either true or false.

Class credosystemz
public static void main(String args[])
boolean b = true;
if (b == true)
System.out.println(“Hi Credo”);


Hi Credo

Byte Data Type:

It is useful to save memory in large arrays.

class credosystemz
public static void main(String args[])
byte a = 126;

// byte is 8 bit value


// It overflows here because
// byte can hold values from -128 to 127

// Looping back within the range



Short Data Type:

A 16 bit signed two complement integer which is similar to byte where you can able to save memory in large numbers.

  • Size: 16 bit
  • Value: -32,768 to 32,767 (inclusive)

Char Data Type:

A single 16-bit unicode character, Values range from ‘\u0000’ (or 0) to ‘\uffff’ 65535

class credosystemz
public static void main(String args[])
// declaring character
char a = ‘C’;

// Integer data type is generally
// used for numeric values
int i=89;

// use byte and short if memory is a constraint
byte b = 4;

// this will give error as number is
// larger than byte range
// byte b1 = 7888888955;

short s = 56;

// this will give error as number is
// larger than short range
// short s1 = 87878787878;

// by default fraction value is double in java
double d = 1.355453532;

// for float use ‘f’ as suffix
float f = 2.7333434f;

System.out.println(“char: ” + a);
System.out.println(“integer: ” + i);
System.out.println(“byte: ” + b);
System.out.println(“short: ” + s);
System.out.println(“float: ” + f);
System.out.println(“double: ” + d);


char: C
integer: 89
byte: 4
short: 56
float: 2.7333436
double: 1.355453532

Hope this Data Types in Java tutorials gives you clear idea about the different data types used in Java Programming Language.

Follow our Free Selenium Tutorial series for latest updates in Selenium , Selenium tutorials step by step, Selenium Interview Questions and more interesting facts.




Search Tags: selenium tutorials for beginners | selenium tutorials for beginners with examples | selenium tutorials for beginners step by step | selenium tutorials for beginners pdf