← Java tutorial

Java

Operators

Arithmetic (+ - * /), comparison (== != > <), and logical (&& || !) operators work much like other C-family languages.

Example: a boolean expression

public class Main {
    public static void main(String[] args) {
        int score = 85;
        boolean passed = score >= 50 && score <= 100;
        System.out.println("Passed: " + passed);
    }
}
Passed: true

One Java-specific trap worth knowing early: == compares object references for non-primitive types like String, not their actual text content, two separately-created strings with identical text can compare as not equal with ==. Strings are almost always compared with .equals() instead: name.equals("Ada"), not name == "Ada".

Example
public class Main {
    public static void main(String[] args) {
        int score = 85;
        boolean passed = score >= 50 && score <= 100;
        System.out.println("Passed: " + passed);
    }
}
Output
Passed: true
Ready to go further?

These free tutorials are a preview, our Backend Development cohort covers it in depth, with a real project and a cohort alongside you. Closes Nov 30

Enroll in Backend Development

Cookie preferences

Choose what you're comfortable with. You can change this any time from the footer.

Don't miss out

Ready to build something real?

Create a free account to enroll in a track, and get notified the moment a cohort opens.

Create free account