Skip to content

Commit 2600c3d

Browse files
Update dataTypes.md
1 parent cafb8ac commit 2600c3d

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

lessons/dataTypes.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,39 +62,39 @@ These are of `8 types`:
6262
|double |0.0d |8 byte |
6363

6464
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
6666
boolean a = false;
6767
```
6868
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
7070
byte a = 10;
7171
byte b = -20;
7272
```
7373
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
7575
short a = 10000;
7676
short b = -5000;
7777
```
7878
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
8080
int a = 100000;
8181
int b = -200000;
8282
```
8383
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
8585
long a = 100000L;
8686
long b = -200000L;
8787
```
8888
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
9090
float f1 = 234.5f ;
9191
```
9292
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
9494
double d1 = 12.3;
9595
```
9696
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
9898
char letterA = 'A';
9999
```
100100

@@ -106,30 +106,30 @@ Non-Primitive data types are created by instantiation, i.e, an object is created
106106

107107
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.
108108

109-
These are of `five types` :
109+
Let's see some of its types:
110110

111111
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
113113
public class GitHub
114114
{
115115
// class body.
116116
}
117117
```
118118
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
120120
Person p = new Person();
121121
```
122122
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
124124
String str = "India";
125125
```
126126
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
128128
int [] numbers;
129129
Student [] x; // Student is a name of class.
130130
```
131131
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.
132-
```
132+
```java
133133
interface printnum{
134134
void print();
135135
}

0 commit comments

Comments
 (0)