Partner – Microsoft – NPI EA (cat = Baeldung)
announcement - icon

Azure Container Apps is a fully managed serverless container service that enables you to build and deploy modern, cloud-native Java applications and microservices at scale. It offers a simplified developer experience while providing the flexibility and portability of containers.

Of course, Azure Container Apps has really solid support for our ecosystem, from a number of build options, managed Java components, native metrics, dynamic logger, and quite a bit more.

To learn more about Java features on Azure Container Apps, visit the documentation page.

You can also ask questions and leave feedback on the Azure Container Apps GitHub page.

Partner – Microsoft – NPI EA (cat= Spring Boot)
announcement - icon

Azure Container Apps is a fully managed serverless container service that enables you to build and deploy modern, cloud-native Java applications and microservices at scale. It offers a simplified developer experience while providing the flexibility and portability of containers.

Of course, Azure Container Apps has really solid support for our ecosystem, from a number of build options, managed Java components, native metrics, dynamic logger, and quite a bit more.

To learn more about Java features on Azure Container Apps, you can get started over on the documentation page.

And, you can also ask questions and leave feedback on the Azure Container Apps GitHub page.

Partner – Orkes – NPI EA (cat=Spring)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag=Microservices)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – MongoDB – NPI EA (tag=MongoDB)
announcement - icon

Traditional keyword-based search methods rely on exact word matches, often leading to irrelevant results depending on the user's phrasing.

By comparison, using a vector store allows us to represent the data as vector embeddings, based on meaningful relationships. We can then compare the meaning of the user’s query to the stored content, and retrieve more relevant, context-aware results.

Explore how to build an intelligent chatbot using MongoDB Atlas, Langchain4j and Spring Boot:

>> Building an AI Chatbot in Java With Langchain4j and MongoDB Atlas

Partner – LambdaTest – NPI EA (cat=Testing)
announcement - icon

Accessibility testing is a crucial aspect to ensure that your application is usable for everyone and meets accessibility standards that are required in many countries.

By automating these tests, teams can quickly detect issues related to screen reader compatibility, keyboard navigation, color contrast, and other aspects that could pose a barrier to using the software effectively for people with disabilities.

Learn how to automate accessibility testing with Selenium and the LambdaTest cloud-based testing platform that lets developers and testers perform accessibility automation on over 3000+ real environments:

Automated Accessibility Testing With Selenium

1. Overview

Operators are a fundamental building block of any programming language. We use operators to perform operations on values and variables.

Java provides many groups of operators. They are categorized by their functionalities.

In this tutorial, we’ll walk through all Java operators to understand their functionalities and how to use them.

2. Arithmetic Operators

We use arithmetic operators to perform simple mathematical operations. We should note that arithmetic operators only work with primitive number types and their boxed types, such as int and Integer.

Next, let’s see what operators we have in the arithmetic operator group.

2.1. The Addition Operator

The addition operator (+) allows us to add two values or concatenate two strings:

int ten = 5 + 5;
String youAndMe = "You " + "and" + " Me";

2.2. The Subtraction Operator

Usually, we use the subtraction operator (-) to subtract one value from another:

int five = 10 - 5;
int negative80 = 20 - 100;

2.3. The Multiplication Operator

The multiplication operator (*) is used to multiply two values or variables:

int hundred = 20 * 5;
int fifteen = -5 * -3;

2.4. The Division Operator

The division operator (/) allows us to divide the left-hand value by the right-hand one:

int four = 20 / 5;
int seven = 15 / 2;

When we use the division operator on two integer values (byte, short, int, and long), we should note that the result is the quotient value. The remainder is not included.

As the example above shows, if we calculate 15 / 2, the quotient is 7, and the remainder is 1. Therefore, we have 15 / 2 = 7.

2.5. The Modulo Operator

We can get the quotient using the division operator. However, if we just want to get the remainder of a division calculation, we can use the modulo operator (%):

int one = 15 % 2;
int zero = 10 % 5;

3. Unary Operators

As the name implies, unary operators only require one single operand. For example, we usually use unary operators to increment, decrement, or negate a variable or value.

Now, let’s see the details of unary operators in Java.

3.1. The Unary Plus Operator

The unary plus operator (+) indicates a positive value. If the number is positive, we can omit the ‘+’ operator:

int five = +5; // same as: int five = 5

3.2. The Unary Minus Operator

Opposite to the unary plus operator, the unary minus operator (-) negates a value or an expression:

int negativeFive = -5;
int eighty = -(20 - 100);

3.3. The Logical Complement Operator

The logical complement operator (!) is also known as the “NOT” operator. We can use it to invert the value of a boolean variable or value:

boolean aTrue = true;
boolean bFalse = !aTrue;

3.4. The Increment Operator

The increment operator (++) allows us to increase the value of a variable by 1:

int number = 5;
number++; // number = 6

3.5. The Decrement Opeartor

The decrement operator (–) does the opposite of the increment operator. It decreases the value of a variable by 1:

int number = 5;
number--; // number = 4

We should keep in mind that the increment and decrement operators can only be used on a variable. For example, “int a = 5; a++;” is fine. However, the expression “5++” won’t be compiled.

4. Relational Operators

Relational operators can be called “comparison operators” as well. Basically, we use these operators to compare two values or variables.

4.1. The “Equal To” Operator

We use the “equal to” operator (==) to compare the values on both sides. If they’re equal, the operation returns true:

int number1 = 5;
int number2 = 5;
boolean theyAreEqual = number1 == number2;

The “equal to” operator is pretty straightforward. On the other hand, the Object class has provided the equals() method. As the Object class is the superclass of all Java classes, all Java objects can use the equals() method to compare each other.

When we want to compare two objects – for instance, when we compare Long objects or compare Strings – we should choose between the comparison method from the equals() method and that of the “equal to” operator wisely.

4.2. The “Not Equal To” Operator

The “not equal to” operator (!=) does the opposite of the ‘==’ operator. If the values on both sides are not equal, the operation returns true:

int number1 = 5;
int number2 = 7;
boolean notEqual = number1 != number2;

4.3. The “Greater Than” Operator

When we compare two values with the “greater than” operator (>), it returns true if the value on the left-hand side is greater than the value on the right-hand side:

int number1 = 7;
int number2 = 5;
boolean greater = number1 > number2;

4.4. The “Greater Than or Equal To” Operator

The “greater than or equal to” operator (>=) compares the values on both sides and returns true if the left-hand side operand is greater than or equal to the right-hand side operand:

int number1 = 7;
int number2 = 5;
boolean greaterThanOrEqualTo = number1 >= number2;
number1 = 5;
greaterThanOrEqualTo = number1 >= number2;

4.5. The “Less Than” Operator

The “less than” operator (<) compares two values on both sides and returns true if the value on the left-hand side is less than the value on the right-hand side:

int number1 = 4;
int number2 = 5;
boolean lessThan = number1 < number2;

4.6. The “Less Than or Equal To” Operator

Similarly, the “less than or equal to” operator (<=) compares the values on both sides and returns true if the left-hand side operand is less than or equal to the right-hand side:

int number1 = 4;
int number2 = 5;
boolean lessThanOrEqualTo = number1 <= number2;
number1 = 5;
lessThanOrEqualTo = number1 <= number2;

5. Logical Operators

We have two logical operators in Java: the logical AND and OR operators. Basically, their function is pretty similar to the AND gate and the OR gate in digital electronics.

Usually, we use a logical operator with two operands, which are variables or expressions that can be evaluated as boolean.

Next, let’s take a closer look at them.

5.1. The Logical AND Operator

The logical AND operator (&&) returns true only if both operands are true:

int number1 = 7;
int number2 = 5;
boolean resultTrue = (number1 > 0) && (number1 > number2);

5.2. The Logical OR Operator

Unlike the ‘&&‘ operator, the logical OR operator (||) returns true if at least one operand is true:

int number1 = 7;
int number2 = 5;
boolean resultTrue = (number1 > 100) || (number1 > number2);

We should note that the logical OR operator has the short-circuiting effect: It returns true as soon as one of the operands is evaluated as true, without evaluating the remaining operands.

6. Ternary Operator

A ternary operator is a short form of the if-then-else statement. It has the name ternary as it has three operands. First, let’s have a look at the standard if-then-else statement syntax:

if ( condition ) {
    expression1
} else {
    expression2
}

We can convert the above if-then-else statement into a compact version using the ternary operator:

Let’s look at its syntax:

condition ? expression1 : expression2

Next, let’s understand how the ternary operator works through a simple example:

int number = 100;
String greaterThan50 = number > 50 ? "The number is greater than 50" : "The number is NOT greater than 50";

7. Bitwise and Bit Shift Operators

As the article “Java bitwise operators” covers the details of bitwise and bit shift operators, we’ll briefly summarize these operators in this tutorial.

7.1. The Bitwise AND Operator

The bitwise AND operator (&) returns the bit-by-bit AND of input values:

int number1 = 12;
int number2 = 14;
int twelve = number1 & number2; // 00001100 & 00001110 = 00001100 = 12

7.2. The Bitwise OR Operator

The bitwise OR operator (|) returns the bit-by-bit OR of input values:

int number1 = 12;
int number2 = 14;
int fourteen = number1 | number2; // 00001100 | 00001110 = 00001110 = 14

7.3. The Bitwise XOR Operator

The bitwise XOR (exclusive OR) operator (^) returns the bit-by-bit XOR of input values:

int number1 = 12;
int number2 = 14;
int two = number1 ^ number2; // 00001100 ^ 00001110 = 00000010 = 2

7.4. The Bitwise Complement Operator

The bitwise complement operator (~) is a unary operator. It returns the value’s complement representation, which inverts all bits from the input value:

int number = 12;
int negative13 = ~number; // ~00001100 = 11110011 = -13

7.5. The Left Shift Operator

Shift operators shift the bits to the left or right by the given number of times.

The left shift operator (<<) shifts the bits to the left by the number of times defined by the right-hand side operand. After the left shift, the empty space in the right is filled with 0.

Next, let’s left shift the number 12 twice:

int fourtyeight = 12 << 2; // 00001100 << 2 = 00110000 = 48

n << x has the same effect of multiplying the number n with x power of two.

7.6. The Signed Right Shift Operator

The signed right shift operator (>>) shifts the bits to the right by the number of times defined by the right-hand side operand and fills 0 on voids left as a result.

We should note that the leftmost position after the shifting depends on the sign extension.

Next, let’s do “signed right shift” twice on the numbers 12 and -12 to see the difference:

int three = 12 >> 2; // 00001100 >> 2 = 00000011 = 3
int negativeThree = -12 >> 2; // 11110100 >> 2 = 11111101 = -3

As the second example above shows, if the number is negative, the leftmost position after each shift will be set by the sign extension.

n >> x has the same effect of dividing the number n by x power of two.

7.7. The Unsigned Right Shift Operator

The unsigned right shift operator (>>>) works in a similar way as the ‘>>’ operator. The only difference is that after a shift, the leftmost bit is set to 0.

Next, let’s unsigned right shift twice on the numbers 12 and -12 to see the difference:

int three = 12 >>> 2; // 00001100 >> 2 = 00000011 = 3
int result = -12 >>> 2; // result = 1073741821 (11111111111111111111111111110100 >>> 2 = 00111111111111111111111111111101)

As we can see in the second example above, the >>> operator fills voids on the left with 0 irrespective of whether the number is positive or negative.

8. The “instanceof” Operator

Sometimes, when we have an object, we would like to test if it’s an instance of a given type. The “instanceof” operator can help us to do it:

boolean resultTrue = Long.valueOf(20) instanceof Number;

9. Assignment Operators

We use assignment operators to assign values to variables. Next, let’s see which assignment operators we can use in Java.

9.1. The Simple Assignment Operator

The simple assignment operator (=) is a straightforward but important operator in Java. Actually, we’ve used it many times in previous examples. It assigns the value on its right to the operand on its left:

int seven = 7;

9.2. Compound Assignments

We’ve learned arithmetic operators. We can combine the arithmetic operators with the simple assignment operator to create compound assignments.

For example, we can write “a = a + 5” in a compound way: “a += 5“.

Finally, let’s walk through all supported compound assignments in Java through examples:

// Assuming all variables (a,b,c,d,e) have the initial value 10
a += 4; // a = 14, same as a = a + 4
b -= 4; // b = 6, same as b = b - 4
c *= 4; // c = 40, same as c = c * 4
d /= 4; // d = 2, same as d = d / 4
e %= 4; // e = 2, same as e = e % 4

10. Conclusion

Java provides many groups of operators for different functionalities. In this article, we’ve passed through the operators in Java.

Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

Partner – Microsoft – NPI EA (cat = Baeldung)
announcement - icon

Azure Container Apps is a fully managed serverless container service that enables you to build and deploy modern, cloud-native Java applications and microservices at scale. It offers a simplified developer experience while providing the flexibility and portability of containers.

Of course, Azure Container Apps has really solid support for our ecosystem, from a number of build options, managed Java components, native metrics, dynamic logger, and quite a bit more.

To learn more about Java features on Azure Container Apps, visit the documentation page.

You can also ask questions and leave feedback on the Azure Container Apps GitHub page.

Partner – Microsoft – NPI EA (cat = Spring Boot)
announcement - icon

Azure Container Apps is a fully managed serverless container service that enables you to build and deploy modern, cloud-native Java applications and microservices at scale. It offers a simplified developer experience while providing the flexibility and portability of containers.

Of course, Azure Container Apps has really solid support for our ecosystem, from a number of build options, managed Java components, native metrics, dynamic logger, and quite a bit more.

To learn more about Java features on Azure Container Apps, visit the documentation page.

You can also ask questions and leave feedback on the Azure Container Apps GitHub page.

Partner – Orkes – NPI EA (cat = Spring)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag = Microservices)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Partner – MongoDB – NPI EA (tag=MongoDB)
announcement - icon

Traditional keyword-based search methods rely on exact word matches, often leading to irrelevant results depending on the user's phrasing.

By comparison, using a vector store allows us to represent the data as vector embeddings, based on meaningful relationships. We can then compare the meaning of the user’s query to the stored content, and retrieve more relevant, context-aware results.

Explore how to build an intelligent chatbot using MongoDB Atlas, Langchain4j and Spring Boot:

>> Building an AI Chatbot in Java With Langchain4j and MongoDB Atlas

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

eBook Jackson – NPI EA – 3 (cat = Jackson)
2 Comments
Oldest
Newest
Inline Feedbacks
View all comments