In this tutorial we will learn about data types in Java programming language.
Constants are the fixed values that never change during execution of a program.
Following are type of constants in Java.
These are the numbers without any decimal part. And they can be in decimal (bas 10), octal (base 8) or hexadecimal (base 16) number system.
Decimal integer constants uses ten digits from 0 to 9.
Example: -99, 0, 100 are decimal integer constants.
Octal integer constants starts with 0 and uses eight digits from 0 to 7.
Example: 01, 010, 011 are octal integer constants.
Hexadecimal integer constants uses ten digits from 0 to 9 and six letters from A to F. We can also use small letter from a to f.
Example: 0xA, 0xff, 0x0b are hexadecimal integer constants.
These are the numbers with decimal part.
Example: -10.12, 0.5, 100.234 are all real constants.
We can represent real constants in exponential a.k.a scientific notation.
mantisa e exponent
Where, mantisa is either a real number or integer.
And exponent is an integer with plus and minus symbol.
In the following example we are expressing 123000 in exponential form.
123000 = 1.23e5
Similarly, we can represent -0.012 in exponential form as follows.
-0.012 = -1.2e-2
Character constants are single character enclosed in single quotes.
Example: 'a', 'b', 'c', '1', '2' etc are character constants.
String constants are sequence of characters enclosed in double quotes.
Example: "Hello World", "A", "B", "1" etc are string constants.
'a' is a character constant as it is using single quotes.
"a" is a string constant as it is using double quotes.
These are special backslash character constants in Java.
Some of the escape sequence is listed below.
A variable is a named memory location to hold some value.
The value stored in a variable can be changed any time we want.
Example of variables: isGameOver, namge, age etc.
To name variables we have to follow the given rules.
Variable names are case-sensitive so, isGameOver and isgameover are treated as two separate variables.
There are two categories of data types in Java.
The first one is Primitive data type. And the second one is Derivesd data type.
Following are the primitive data types available in Java.
Derived types are Class, Interface, Array etc. and we will discuss them in the later part of this tutorial series.
These take 2 bytes of memory space and we use the char keyword to create a character data type variable.
char ch = 'y';
Boolean date type can take only two values true and false and we use the boolean keyword to create a boolean type variable.
boolean isGameOver = true;
Have fun learning :-)
Copyright © 2014 - 2020 DYclassroom. All rights reserved.
rendered in 0.0149 sec