CodeGym /Java Course /Module 1. Java Syntax /Additional lessons for Level

Additional lessons for Level

Module 1. Java Syntax
Level 4 , Lesson 7
Available

Another level is behind you! In the previous lessons, you learned about the if-else conditional statement and the nuances associated with it. We got acquainted with a special data type: boolean. We examined examples of using comparison operators and boolean variables. Finally, we learned more about comparing references and strings.

If you feel that a little more theory and some visual examples definitely won't hurt you, then carry on: here are links to a couple of useful articles.

Equals and comparing strings

Comparing objects is different from comparing primitive data types. You probably already guessed why this is so. In the case of objects, we pass a reference, but in the case of primitives, a value... There are many more interesting nuances that you will learn about from this article. As usual, we will explore the topic using lively examples.

Ternary operator

To beginners, this is very unusual beast. By and large, you can entirely do without it... but the ternary operator shortens the code so easily and beautifully! And this is exactly what a beginner programmer should strive for. If you have not yet had time to thoroughly familiarize yourself with this replacement for the if-else construct, then we recommend that you get to know it better and slowly weave it into your code.


Comments (18)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Donkasking Level 6, United States
6 August 2024
would LOVE to have the correct answer displayed instead of just getting "WRONG!" and having that knowledge slip into the ether
RdzawyPyton Level 4, Kraków, Poland
9 September 2024
you can always refresh the page and do the quiz again ;)
Luke Level 5, Saint Paul, United States
17 February 2024
A little annoyed there was a question about comparing doubles since none of the lessons thus far have done more than even mention type double.
Aishwarya Level 4, deagu , South Korea
5 May 2023
what is thevuse of ternary operator?
abhishe_kira Level 18, India Expert
26 June 2023
same as if-else but it makes you write less code.
Alexander Atanasov Level 16, Bulgaria
27 March 2023
Suggestion: It will help if there is an explanation of the failed answers.
EXadose Level 4, United States of America, United States
20 February 2023
the second to last question and the third to last question are the same
Anonymous #11225109 Level 5, United States of America, United States
2 February 2023
i got the first two questions wrong, i don't know what should be the answers, the rest was ok.80/100
Jonaskinny Level 25, Redondo Beach, United States
27 January 2022
This quiz is actually correct. double values need to be constrained to a given precision in order to be compared. On item 7, if you review the lesson you will see syntax requires ()
Carlos M Level 8, United States
14 January 2022
Also the last question for comparing string variables is the same as the question before.
Carlos M Level 8, United States
14 January 2022
Q7 the question with the expression to determine the max. I can't find the answer to that question anywhere.
Jonaskinny Level 25, Redondo Beach, United States
27 January 2022
On item 7, if you review the lesson you will see syntax requires ()
mathias Level 5, Switzerland
14 June 2022
Execution code goes from (left to right) or (top to bottom). a > b ? a : b; This represents the if/else statements. So, if "a" is greater than "b" 》get "a" else "b"; When expresion value is true, it will take the first answer after the expresion, which this case would read "a" . In the case of being false, it will skip the first answer(a) to get to the second answer(b), while ":" is acting as the "else" statement. Separating or dividing 2 different answers. So all behind ":" would act as the "If" statement and whats on the right side of ":" as "else" statements.
Maciej Macewicz Level 19, Poland, Poland
22 December 2021
This quiz have to be fixed :)