0Pricing
Java Academy · Lesson

Operators

Operators

Operators is a free Java Academy lesson on CoddyKit — lesson 1 of 1. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Java Academy learning path, one of 1 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Introduction

Hello,

Java offers us many operators to operate on the data we have. With the help of these operators, we can manipulate the data we have.

They are Arithmetic operators, the type of operator we now know most of from mathematics.

Addition operator

Addition Operator

We do the addition with the + operator.

class Main{

public static void main(String[] args){
   int num1 = 10;
   int num2 = 20;
   int num3 = num1 + num2;
   System.out.println(num3);
 }
}

Subtraction

Subtraction Operator

We do the subtraction with the (-) operator.

Let's look at the example.

class Main{

public static void main(String[] args){
   int num1 = 10;
   int num2 = 20;
   int num3 = num1 - num2;
   System.out.println(num3);
 }
}

Multiplication

Multiplication Operator

We do the multiplication with the (*) operator.

class Main{

public static void main(String[] args){
   int num1 = 10;
   int num2 = 20;
   int num3 = num1 * num2;
   System.out.println(num3);
 }
}

Division Operator

Division Operator

We do the division with the (/) operator.

Let's look at the example.

class Main{

public static void main(String[] args){
   int num1 = 10;
   int num2 = 20;
   int num3 = num1 / num2;
   System.out.println(num3);
 }
}

Modulus Operator

Modulus Operator

We use the (%) operator to get the modulus of a number.

class Main{

public static void main(String[] args){
   int num1 = 20;
   int num2 = 4;
   int num3 = num1 % num2;
   System.out.println(num3);
 }
}

Increment Operator

Increment Operator

We use the (++) operator to increment a number by one.

class Main{

public static void main(String[] args){
   int num1 = 20;
   ++num1;
   // Does the same job as the above line
   num1 = num1 +1; 
   System.out.println(num3);
 }
}

Decrement Operator

Decrement Operator

We use the (-) operator to subtract a number by one.

int num1 = 20;

--num1;

Assignment Operator

Assignment Operator

Now let's look at the most commonly used Assignment operators.

The first operator we will use is =, which is perhaps the most used assignment operator in Java.

In the example below, we assign the value 0 to the variable count with the = operator.

int count = 0;

Additional Assignment

Let's look at the Additional Assignment operator.

This operator provides a shortcut to do the addition.

int count = 0;
count += 10;
// It is an abbreviation of count = count + 10.

Subtraction Operator

Subtraction Operator

The subtraction operator provides a shortcut to perform the extraction.

int count = 20;
count -= 10;
// It is an abbreviation of count = count - 10.

Multiplication operator

Multiplication Operator

The multiplication operator provides a shortcut to do multiplication.

int count = 20;
count *= 10;

// It is an abbreviation of count = count * 10.

Comparison Operators

Apart from the above, we can similarly use syntax to perform many operations such as dividing, modding with assignment operators.

Now let's look at Comparison operators.

Comparison operators are used to comparing values in Java.

equality operator

We use the == operator to compare two objects or primitive values.

class Main{

public static void main(String[] args){
   int x = 5;
    int y = 3;
   boolean result = x == y;
   //false
 }
}

not equal operator

The != Operator is used to check the not equal condition.

int x = 5;
int y = 3;

boolean result = x != y;
//true

greater than && less than operator

The algebraic comparison of two values is done with the (>) and (<) operators, just like in mathematics.

int x = 5;
 int y = 3; 

//is x greater than y x > y 
//is x less than y x > y  
// is greater or equal than y x >= y  
// is less or equal than y x <= y

logical operator

Let's see logical operators now.

Logical operators make logical comparisons between boolean types.

int x = true;
int y = false;
int status;


// The AND (&&) operator returns true if both values are true.
// returns false for all cases other than that 
status = x && y;
// status will be false.

example cont.

Let's continue with our example.


/ *
For the OR (||) operator, one of the two values 
compared to true is sufficient for the result to be true.
* /
status = x || y;
// status will be true.

// In the Logical Not operator, it gets the note equivalent of the logic value we have.
status = !(x || y)

/ *
Although the value inside the parentheses returned true, the not operator made the result false.
* /

status  = !(x && y;);

/ *
Although expression with the AND operator in the parenthesis 
returns false, the not operator ensures that the result is true.
* /

Congratulations

Congratulations 🎉

In this section, we learned about operators in Java. 

See you in the next lesson. 🥳

Operators — illustration 19

Frequently asked questions

Is the “Operators” lesson free?

Yes — the full text of “Operators” is free to read here on the web, and the Java Academy course includes 1 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Java Academy course, upgrade to CoddyKit PRO.

What will I learn in “Operators”?

Operators You practise Java Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Java Academy?

No prior experience is required. Java Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 1, so you can start here or from the beginning and move at your own pace.

How long does the “Operators” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Java Academy lesson?

Yes. Every Java Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

← Back to Java Academy