Skip to content

Latest commit

 

History

History
31 lines (30 loc) · 1.05 KB

java-basic-syntax.md

File metadata and controls

31 lines (30 loc) · 1.05 KB

Back to Home

The Overview of Java Basic Syntax

Here are some basic Java syntax rules:

List Of Content

1. Java code is case-sensitive.

2. The code is written in classes.

3. Each statement must end with a semicolon ;.

4. Java comments start with // for single-line comments, or /and end with / for multi-line comments.

5. Java uses the curly brace {} to define the scope of methods and classes.

6. The main method is the entry point of a Java program and is defined as follows:

public static void main(String[] args) {
  // code goes here
}

7. To declare a variable, use the data type followed by the variable name, and optionally an initial value:

int num = 10;
String message = "Hello, World!";

8. To output a message to the console, use the System.out.println() method:

System.out.println("Hello, World!");

9. To get input from the user, use the Scanner class:

import java.util.Scanner;
Scanner scanner = new Scanner(System.in);
String name = scanner.nextLine();