Java, a programming language released in 1995, was developed by James Gosling at Sun Microsystems and later owned by Oracle starting in 2010.
๐๏ธ Key Points:
โญ To use comments in Java:
๐ช `//` is used for inline comments.
๐ช `/* ... */` is used for multi-line comments.
๐ The boilerplate for Java typically starts with:
1. `public class ClassName/FileName {`
(In Java, the file name and class name should be the same.)
2. `public static void main(String args[]) {`
3. `System.out.print("...");` - To print output on the same line.
4. `System.out.println("...");` - Adds a new line after displaying the content.
5. `Scanner scn = new Scanner(System.in);` - To get user input. Java has a special function named `Scanner` found in `java.util.*` package. To use this package, import it at the top of the code using `import java.util.*;`.
6. After the import statement, define the data type of the variable along with its name. Then, use the `=` operator followed by `scn.next()`/`scn.nextLine()`/`scn.nextInt()`/`scn.nextDouble()` depending on the value entered by the user. For example:
๐ If the input is an integer: `int num = scn.nextInt();`
๐ For large integers: `int num = scn.nextLong();`
๐ Java considers all decimal values as `double`. To indicate a floating value, attach `f` along with the decimal digits.
for example - check the above image attached with this article
The above image consist a code which will print the area of circle by taking radius as an input from the user!