🌐
W3Schools
w3schools.com › java › java_operators.asp
Java Operators
Arrays Loop Through an Array Real-Life Examples Multidimensional Arrays Code Challenge · Java Methods Java Method Challenge Java Method Parameters · Parameters Return Values Code Challenge Java Method Overloading Java Scope Java Recursion · Java OOP Java Classes/Objects Java Class Attributes Java Class Methods Java Class Challenge Java Constructors Java this Keyword Java Modifiers · Access Modifiers Non-Access Modifiers Java Encapsulation Java Packages / API Java Inheritance Java Polymorphism Java super Keyword Java Inner Classes Java Abstraction Java Interface Java Anonymous Java Enum
🌐
Tutorialspoint
tutorialspoint.com › java › java_basic_operators.htm
Java Operators
There are few other operators supported by Java Language. Conditional operator is also known as the ternary operator. This operator consists of three operands and is used to evaluate Boolean expressions. The goal of the operator is to decide, which value should be assigned to the variable. The operator is written as − · variable x = (expression) ? value if true : value if false ... In this example, we're creating two variables a and b and using ternary operator we've decided the values of b and printed it.
Discussions

string - What does a[c - 'a' ]++ mean in Java? - Stack Overflow
The goal is to count the common characters in two strings and return an integer. I understand everything except a[c - 'a' ]++; I've tried searching through a few classes's documentation, googling ... More on stackoverflow.com
🌐 stackoverflow.com
syntax - What is the Java ?: operator called and what does it do? - Stack Overflow
Also, it's not exactly syntactically equivalent to the if-else version. For example: String str1,str2,str3,str4; boolean check; //... return str1 + (check ? str2 : str3) + str4; If coded with if-else will always result in more bytecode. ... I believe javac is at liberty to generate the same ... More on stackoverflow.com
🌐 stackoverflow.com
what is the difference between a++ and ++a or a-- and --a in java? - Stack Overflow
Why does the first exercise in The Study of Counterpoint call the notes E and F a fifth? ... Griffiths, Electrodynamics, Example 5.11 (Reverting vector potential to that of natural coordinates) More on stackoverflow.com
🌐 stackoverflow.com
I don’t understand a concept with increments. A++ = A + 1. However in formulas that use A++ + ++A, my answers are always incorrect. Why??? It’s driving me crazy that I cannot get any of these outputs correct
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
29
11
February 23, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › java › operators-in-java
Java Operators - GeeksforGeeks
Logical Operators are used to perform "logical AND" and "logical OR" operations, similar to AND gate and OR gate in digital electronics. They have a short-circuiting effect, meaning the second condition is not evaluated if the first is false. ... import java.io.*; class Geeks { // Main Function public static void main (String[] args) { // Logical operators boolean x = true; boolean y = false; System.out.println("x && y: " + (x && y)); System.out.println("x || y: " + (x || y)); System.out.println("!x: " + (!x)); } }
Published   November 12, 2025
🌐
Programiz
programiz.com › java-programming › operators
Java Operators: Arithmetic, Relational, Logical and more
In the above example, we have used +, -, and * operators to compute addition, subtraction, and multiplication operations. ... Note the operation, a / b in our program. The / operator is the division operator. If we use the division operator with two integers, then the resulting quotient will also be an integer. And, if one of the operands is a floating-point number, we will get the result will also be in floating-point. In Java, (9 / 2) is 4 (9.0 / 2) is 4.5 (9 / 2.0) is 4.5 (9.0 / 2.0) is 4.5
🌐
DigitalOcean
digitalocean.com › community › tutorials › addition-assignment-operator-in-java
What is += Addition Assignment Operator in Java? | DigitalOcean
August 3, 2022 - The first line here gives an error as int can’t be added to a double. ... However, when using the += operator in Java, the addition works fine as Java now converts the double to an integer value and adds it as 1.
🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › operators.html
Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)
As we explore the operators of the Java programming language, it may be helpful for you to know ahead of time which operators have the highest precedence. The operators in the following table are listed according to precedence order. The closer to the top of the table an operator appears, the higher its precedence.
Find elsewhere
🌐
NTU
www3.ntu.edu.sg › home › ehchua › programming › java › J2_Basics.html
Java Basics - Java Programming Tutorial
The type char represents a single ... For example, character '0' is 48 (decimal) or 30H (hexadecimal); character 'A' is 65 (decimal) or 41H (hexadecimal); character 'a' is 97 (decimal) or 61H (hexadecimal)....
🌐
HappyCoders.eu
happycoders.eu › algorithms › a-star-algorithm-java
A* Algorithm (+ Java Code Examples)
June 12, 2025 - In the further course, we need a map that delivers the corresponding wrapper for a graph node. For this, we use a HashMap: Map<N, AStarNodeWrapper<N>> nodeWrappers = new HashMap<>();Code language: Java (java)
Top answer
1 of 16
224

Yes, it is a shorthand form of

int count;
if (isHere)
    count = getHereCount(index);
else
    count = getAwayCount(index);

It's called the conditional operator. Many people (erroneously) call it the ternary operator, because it's the only ternary (three-argument) operator in Java, C, C++, and probably many other languages. But theoretically there could be another ternary operator, whereas there can only be one conditional operator.

The official name is given in the Java Language Specification:

§15.25 Conditional Operator ? :

The conditional operator ? : uses the boolean value of one expression to decide which of two other expressions should be evaluated.

Note that both branches must lead to methods with return values:

It is a compile-time error for either the second or the third operand expression to be an invocation of a void method.

In fact, by the grammar of expression statements (§14.8), it is not permitted for a conditional expression to appear in any context where an invocation of a void method could appear.

So, if doSomething() and doSomethingElse() are void methods, you cannot compress this:

if (someBool)
    doSomething();
else
    doSomethingElse();

into this:

someBool ? doSomething() : doSomethingElse();

Simple words:

booleanCondition ? executeThisPartIfBooleanConditionIsTrue : executeThisPartIfBooleanConditionIsFalse 
2 of 16
34

Others have answered this to reasonable extent, but often with the name "ternary operator".

Being the pedant that I am, I'd like to make it clear that the name of the operator is the conditional operator or "conditional operator ?:". It's a ternary operator (in that it has three operands) and it happens to be the only ternary operator in Java at the moment.

However, the spec is pretty clear that its name is the conditional operator or "conditional operator ?:" to be absolutely unambiguous. I think it's clearer to call it by that name, as it indicates the behaviour of the operator to some extent (evaluating a condition) rather than just how many operands it has.

🌐
ScholarHat
scholarhat.com › home
Operators in Java - Types of Operators in Java ( With Examples )
Full-stack Java jobs pay ₹15–30 LPA in just 2 years. Don’t wait, Enroll now in our Java Full Stack Training to grow fast. Different operations are carried out on variables by Java operators. Examples include adding two integers together, as in 2 + 3.
Published   September 6, 2025
🌐
W3Schools
w3schools.com › java › java_for_loop.asp
Java For Loop
In this example, the loop starts with i = 10. The condition i < 5 is already false, so the loop body is skipped, and nothing is printed. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
Quora
quora.com › What-is-the-value-of-a-a-a-a-How-is-it-done-in-Java
What is the value of a = ++a + ++a + ++a? How is it done in Java? - Quora
Answer (1 of 13): Evaluation order in Java is strictly defined, left to right. See the Java Language Specification, section 15.7. This is a Java translation of a C “riddle”, which is not a “riddle”, it’s a demonstration that C has an undefined expression evaluation order, when the code is lacki...
🌐
GeeksforGeeks
geeksforgeeks.org › java › basic-operators-java
Basic Operators in Java - GeeksforGeeks
September 12, 2023 - For example, x--. Note: The increment and decrement operators are called unary arithmetic operators as they work with a single operand whereas the rest of arithmetic operators are called binary arithmetic operators as they operate on two operands. ... // Java Program to Illustrate Arithmetic Operators import java.util.*; // Class 1 class A { // Main driver method public static void main(String args[]) { int a = 10, b = 4, res; // printing a and b System.out.println("a is " + a + " and b is " + b); res = a + b; // addition System.out.println("a+b is " + res); res = a - b; // subtraction System.out.println("a-b is " + res); res = a * b; // multiplication System.out.println("a*b is " + res); res = a / b; // division System.out.println("a/b is " + res); res = a % b; // modulus System.out.println("a%b is " + res); } }
🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › op1.html
Assignment, Arithmetic, and Unary Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)
You can also combine the arithmetic operators with the simple assignment operator to create compound assignments. For example, x+=1; and x=x+1; both increment the value of x by 1.
🌐
Unstop
unstop.com › home › blog › operators in java | 9 types, precedence & more (+examples)
Operators In Java | 9 Types, Precedence & More (+Examples)
December 9, 2024 - Unary operators are those that operate on a single operand to alter its value or state. For example, the logical complement operator (!) inverts a boolean value, while the unary minus (-) changes the sign of a number. These Java operators are applied directly to the operand, streamlining operations like sign reversal and logical inversion.
🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › opsummary.html
Summary of Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)
+ Unary plus operator; indicates positive value (numbers are positive without this, however) - Unary minus operator; negates an expression ++ Increment operator; increments a value by 1 -- Decrement operator; decrements a value by 1 ! Logical complement operator; inverts the value of a boolean
🌐
Vibrantpublishers
vibrantpublishers.com › blogs › blogs-on-programming › all-about-java-assignment-operators
All About Java Assignment Operators
Similar to the compound statement that we saw above, here also we combine ‘-’ and ‘=’ java operators. So here the value on the right side is subtracted from the initial value of the variable and it is assigned to the variable itself.