> ## Documentation Index
> Fetch the complete documentation index at: https://v1-learn.neoartd.my.id/llms.txt
> Use this file to discover all available pages before exploring further.

# Variables and Operators

# Variables

## Variables

![Variables](https://i.ibb.co/DzwtZ4n/Screenshot-2024-04-03-135211.png)

## Declarations

![Declarations](https://i.ibb.co/Gnsy6JT/Screenshot-2024-04-03-135220.png)

## Assignments

![Assignments](https://i.ibb.co/qntJkvh/Screenshot-2024-04-03-135231.png)

## Variable Naming

* Begin with a letter (a-z/A-Z)
* After the initial letter, may also contain letters, digits (0-9), underscore (\_), or dollar sign (\$)
* Not a keyword or reserved word [http://docs.oracle.com/javase/tutorial/java/nutsandbolts/\_keywords.html](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html)
* Case sensitive
* Disarankan:

  * Tidak dimulai dengan huruf kapital
  * camelCase
  * Meaningful

    |             |              |
    | :---------- | :----------- |
    | sum         | address2     |
    | first name  | phone        |
    | first\_name | phone number |
    | firstName   | double       |
    | FirstName   | static       |
    | FIRSTNAME   | e-mail       |
    | 1stName     | GradeTest#1  |
    | Address     | homepageURL  |
    | address     | homepageUrl  |
    | address1    | ...          |

## Declaring Variables

![Declaring Variables](https://i.ibb.co/PY9XQPP/Screenshot-2024-04-03-140708.png)

## Data Types

| Type    | Explanation                            |               Min              |               Max              |
| :------ | :------------------------------------- | :----------------------------: | :----------------------------: |
| int     | 32-bit (4-byte) integers               |         -2,147,483,648         |          2,147,483,647         |
| short   | 16-bit (2-byte) integers               |             -32,768            |             32,767             |
| long    | 64-bit (8-byte) integers               |   -9,223,372,036,854,775,808   |    9,223,372,036,854,775,807   |
| byte    | 8-bit (1-byte) integers                |              -128              |               127              |
| float   | 32-bit (4-byte) floating point numbers |  $\pm$1.40129846432481707e-45  |  $\pm$3.40282346638528860e+38  |
| double  | 64-bit (8-byte) floating point numbers | $\pm$4.94065645841246544e-324d | $\pm$1.79769313486231570e+308d |
| char    | Unicode characters                     |                0               |             65,535             |
| boolean | true or false                          |                -               |                -               |
| String  | Text                                   |                -               |                -               |

## Printing Variables

```java theme={null}
System.out.println(variable);
System.out.print(variable);
```

# Operators

```java theme={null}
System.out.println(quantity * price);
sum = sum + 1;
System.out.println(10 - 2);
System.out.println(sum / 5);
System.out.println(-total);
```

## Arithmetic Operators

```java theme={null}
int a = 10, b = 5;
```

<CodeGroup>
  ```java Addition theme={null}
  + (Addition), e.g.: a + b equals 15
  ```

  ```java Subtraction theme={null}
  - (Subtraction), e.g.: a - b equals 5
  ```

  ```java Multiplication theme={null}
  * (Multiplication), e.g.: a * b equals 50
  ```

  ```java Division theme={null}
  / (Division), e.g.: a / b equals 2
  ```

  ```java Modulus theme={null}
  % (Modulus), e.g.: a % b equals 0
  ```

  ```java Increment theme={null}
  ++ (Increment), e.g.: a++ equals 11
  ```

  ```java Decrement theme={null}
  -- (Decrement), e.g.: a-- equals 9
  ```
</CodeGroup>

```java theme={null}
int a = 10; // variable declaration
// addition (+)
System.out.println(a + 1);
System.out.println(a);
// increment
System.out.println(a++);
System.out.println(a);
// another increment
a++;
System.out.println(a);
```

## Operators for Strings

<CodeGroup>
  ```java Opsi 1 theme={null}
  String message = "Welcome";
  System.out.println(message);
  ```

  ```java Opsi 2 theme={null}
  String message = "Welcome ";
  String name = "Arif";
  System.out.println(message + name);
  ```

  ```java Opsi 3 theme={null}
  String message = "Welcome ";
  String name = "Arif";
  message = message + name;
  System.out.println(message);
  ```

  ```java Opsi 4 theme={null}
  String message = "Welcome ";
  String name = "Arif";
  message = message + name + "!";
  System.out.println(message);
  ```

  ```java Opsi 5 theme={null}
  String message = "Welcome ";
  String name = "Arif";
  message = message + name + "!";
  System.out.println(message);
  int date = 15;
  int month = 9;
  int year = 2016;
  String message2 = "Today's date is " + date;
  System.out.println(message2);
  ```
</CodeGroup>
