You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lessons/dataTypes.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,39 +62,39 @@ These are of `8 types`:
62
62
|double |0.0d |8 byte |
63
63
64
64
1.**Boolean Data Type** : Variables declared with boolean data type can store only true/false. These are used as flag which checks for a particular conditions. Its size is only 1 bit.
65
-
```
65
+
```java
66
66
boolean a =false;
67
67
```
68
68
2.**Byte Data Type** : It is 8-bit signed 2's complement integer. Its value-range lies between -128 to 127 (inclusive). Its default value is 0. The byte data type is used to save memory in large arrays where the memory savings is most required. It saves space because a byte is 4 times smaller than an integer. It can also be used in place of "int" data type.
69
-
```
69
+
```java
70
70
byte a =10;
71
71
byte b =-20;
72
72
```
73
73
3.**Short Data Type** : It is a 16-bit signed 2's complement integer. Its value-range lies between -32,768 to 32,767 (inclusive). Its default value is 0. A short data type is 2 times smaller than an integer.
74
-
```
74
+
```java
75
75
short a =10000;
76
76
short b =-5000;
77
77
```
78
78
4.**Int Data Type** : It is a 32-bit signed 2's complement integer. Its value-range lies between - 2,147,483,648 (-2^31) to 2,147,483,647 (2^31 -1) (inclusive). Its default value is 0. It is generally used as a default data type for integral values.
79
-
```
79
+
```java
80
80
int a =100000;
81
81
int b =-200000;
82
82
```
83
83
5.**Long Data Type** : It is a 64-bit 2's complement integer. Its value-range lies between -9,223,372,036,854,775,808(-2^63) to 9,223,372,036,854,775,807(2^63 -1)(inclusive). Its default value is 0. The long data type is generally used when the integer that we have to store exceeds the range provided by int data type.
84
-
```
84
+
```java
85
85
long a =100000L;
86
86
long b =-200000L;
87
87
```
88
88
6.**Float Data Type** : It is a single-precision 32-bit IEEE 754 floating point.Its value range is unlimited. It is recommended that we should use float (instead of double) if yweou need to save memory in large arrays of floating point numbers. It should never be used for precise values, such as currency. Its default value is 0.0F.
89
-
```
89
+
```java
90
90
float f1 =234.5f ;
91
91
```
92
92
7.**Double Data Type** : It is a double-precision 64-bit IEEE 754 floating point. Its value range is unlimited. This is also generally used for decimal values just like float. The double data type also should never be used for precise values, such as currency. Its default value is 0.0d.
93
-
```
93
+
```java
94
94
double d1 =12.3;
95
95
```
96
96
8.**Char Data Type** : It is a single 16-bit Unicode character. Its value-range lies between '\u0000' (or 0) to '\uffff' (or 65,535 inclusive). It is used to store characters.
97
-
```
97
+
```java
98
98
char letterA ='A';
99
99
```
100
100
@@ -106,30 +106,30 @@ Non-Primitive data types are created by instantiation, i.e, an object is created
106
106
107
107
This object can have more than one reference variable, and if we make changes on the data of the object through one reference variable the actual object gets changed and this changed objects's data is changed in all the variables that are pointing(or referencing) to this object.
108
108
109
-
These are of `five types`:
109
+
Let's see some of its types:
110
110
111
111
1.**Class** : Every class is considered as user-defined data type as a user creates a class. In Java programming, a class is basically a user-defined data type that act as a template for creating objects of identical type. It represents the common properties and actions (functions) of an object.
112
-
```
112
+
```java
113
113
publicclassGitHub
114
114
{
115
115
// class body.
116
116
}
117
117
```
118
118
2.**Object** : An object is any real-world thing that has some properties and actions. In other words, an entity that has state and behavior is known as an object. An Object has three characterstics - State, Behaviour and Identity.
119
-
```
119
+
```java
120
120
Person p =newPerson();
121
121
```
122
122
3.**String** : A String is also a class. It represents a sequence of characters like Shuaib, A123, etc. The simplest way to create a string object is by storing sequence of characters into string type variable.
123
-
```
123
+
```java
124
124
String str ="India";
125
125
```
126
126
4.**Arrays** : It is an Object which is used to store multiple data of same data type. It can store Primitive as well as Non-Primitive data in it.
127
-
```
127
+
```java
128
128
int [] numbers;
129
129
Student [] x; // Student is a name of class.
130
130
```
131
131
5.**Interface** : An interface is declared like a class but the only difference is that it contains only final variables and method declarations. It is a fully abstract class. It is blue print of a class. It is mechanism in Java to achieve abstraction and multiple inheritance. There can only be abstract methods and variables and no method body.
0 commit comments