# Quick Java Tutorial

## Overview

On this page we will cover

* [Variables](#variables)
* [Conditionals](#conditionals)
* [Loops](#loops)
* [Methods](#class-methods)
* [Classes](#classes)
* [Objects](#using-objects)

## Variables

```
/* Syntax: Type variableName = VALUE; */

int wholeNumber = 93;
double numberWithDigits = 46.85;

String text = "words and stuff";

boolean isValid = true;
boolean isNegative = -3 < 0;

MyObject obj = new MyObject();
```

## Conditionals

```
if (boolean1) {
    // if boolean1 is true
} else if (boolean2) {
    // if boolean1 is false but boolean2 is true
} else {
    // if boolean1 and boolean2 were both false
}
```

## Loops

```
while (isLoopActive) {
    // keep doing something
}
// isLoopActive became false
```

```
for (int i = 0; i < 5; i++) { // start with i=0, increment i each time, continue while i < 5
    // do something 5 times
}
```

## Class Methods

```
/* Syntax: keywords returnType methodName(ParameterType parameterName, ...) { */

public static final double divide(int dividend, double divisor) {
    double quotient = dividend / divisor;
    return quotient;
}

private void moveForward(double inches) {
    // code to move forward [inches] inches
    // don't need to return, as returnType is 'void'
}

public abstract void overrideMeLater;
```

Keywords:

| Access Modifier keyword | Description                                               |
| ----------------------- | --------------------------------------------------------- |
| public                  | Method is accessible by any class                         |
| private                 | Method is accessible by the same class                    |
| protected               | Method is accessible by the same class and any subclasses |
| \[leave blank]          | Method is accessible only by the class's object           |

| Non-Access Modifier keyword | Description                                                              |
| --------------------------- | ------------------------------------------------------------------------ |
| static                      | Method belongs to class \[Class.call()], not the object \[object.call()] |
| abstract                    | Method must be overridden and does not have a body                       |
| final                       | Method cannot be overridden                                              |

## Classes

```
public class ClassName {
    // class variables here
    String name;
    
    // constructor
    public ClassName() {
        this("default name");
    }
    public ClassName(String name) {
        this.name = name;
    }
    
    // class methods here
    public String getName() {
        return name;
    }
}
```

## Using Objects

```
// Creating objects
MyObject objName1 = new MyObject();
MyObject objName2 = new MyObject("Second try");

// Calling methods
MyObject.staticMethod();
objName1.method();
objName2.method();

// Using return values
String output = objName1.toString() + " | " + objName2.toString();


// Note: objects are just unique instances of a class; 
//       you can have multiple of the same class
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.ftctutorial.com/programming/basics/quick-java-tutorial.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
