Java Guide- Added Examples to Built in funcions (#18797)

Added examples of Java.IO package and Java.lang packages
This commit is contained in:
Isaac
2018-10-14 06:59:43 +08:00
committed by Aditya
parent 78c0135748
commit 070d79b807

View File

@ -10,4 +10,32 @@ import java.lang.*;
import java.io.*;
```
These comprise functions which make an otherwise long and hard task easier to do.
These comprise functions which make an otherwise long and hard task easier to do.
Some examples of ```java.lang.* ``` are:
Generating a random number using Math. In this example a random integer from 1 - 10
```java
int randomNumber = (int) (Math.random() * 10) + 1;
```
Usage of primitive types such as double, float, int boolean
```java
int integerNumber = 1;
double doubleNumber = 0.1d;
float floatNumber = 0.2f;
boolean trueOrFalse = false;
```
Classes in ```java.io.* ``` are mainly used for reading and writing of files with diffrent methods such as Input / output streams and buffered readers/ writers.
And example using a buffered reader is below:
```java
File file = new File("C:\\Users\\Desktop\\test.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
String st;
while ((st = br.readLine()) != null)
System.out.println(st);
```