Rajendra🙏🏼👇🏽
Posted on January 13, 2020
Here is the video tutorial. Please show some love and subscribe to my channel Subscribe.
What is a Datatype?
A data type is an attribute of data that tells the compiler or interpreter how the programmer intends to use the data.
Data types in Java programming language
There are two different sets of data types in Java
- Primitive Datatypes
- Non Primitive Datatypes
The below image depicts different data types in java
The Java programming language is statically-typed, which means that all variables must first be declared before they can be used. This involves stating the variable's type and name.
boolean: is used to store true or false value.
byte, short, int, long: is used to store whole numbers.
float, double: is used to store fractional numbers.
The below table depicts different datatypes and the size of those datatypes.
The below class has all these datatypes defined and declared.
package com.test.java;
public class BasicDataTypes {
static byte i = 127;
static short j = 3456;
static int k = 24233534;
static long l = 34564;
static float fl = 35325432;
static double db = 34523763;
static boolean b = true;
static char c = 'c';
static String testString = "Hello World";
public static void main(String [] args) {
char[] testCharString = new char[11];
testCharString[0] = 'h';
testCharString[1] = 'e';
testCharString[2] = 'l';
testCharString[3] = 'l';
testCharString[4] = 'o';
testCharString[5] = ' ';
testCharString[6] = 'w';
testCharString[7] = 'o';
testCharString[8] = 'r';
testCharString[9] = 'l';
testCharString[10] = 'd';
System.out.println("Default value of byte is ---> "+i);
System.out.println("Default value of short is ---> "+j);
System.out.println("Default value of int is ---> "+k);
System.out.println("Default value of long is ---> "+l);
System.out.println("Default value of float is ---> "+fl);
System.out.println("Default value of double is ---> "+db);
System.out.println("Default value of boolean is ---> "+b);
System.out.println("Default value of char is ---> "+c);
System.out.println("Default value of String is ---> "+testString);
System.out.println("Default value of char is ---> "+String.valueOf(testCharString));
}
}
Here is the video tutorial. Please show some love and subscribe to my channel Subscribe.
Posted on January 13, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
October 21, 2024