From the course: Java 8+ Essential Training: Syntax and Structure
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Evaluate conditions with if-else - Java Tutorial
From the course: Java 8+ Essential Training: Syntax and Structure
Evaluate conditions with if-else
- [Instructor] Writing conditional code is a common practice in all programming languages. Conditional code is commonly called an if/then or an if/else clause. I've already used if statements previously in this course, it's pretty unavoidable, but now I'll go into the details of the if keyword, and it's associated keyword, else. To demonstrate this, I'll start with an integer variable that I'll name monthNumber, and I'll give it a value of zero. Now, when you're working with date and time values in Java, traditionally monthNumbers are indexed starting at zero. So, zero means January, one is February, and so on. There's a newer package that was introduced in Java 8 that changes this to indexing starting with one, but you can't use it everywhere you're programming Java. For example, if you're coding in Java for Android, you might still have to use the older approach. So, I'm going to assume I'm using the older libraries. MonthNumber zero means it's January. Now I'll write some…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Evaluate conditions with if-else4m 17s
-
Evaluate conditions with switch-case4m 32s
-
(Locked)
Create looping code blocks7m 13s
-
(Locked)
Create reusable code with methods8m 17s
-
(Locked)
Create overloaded methods3m 27s
-
(Locked)
Pass arguments by reference vs. value4m
-
(Locked)
Challenge: A more complex calculator1m 18s
-
(Locked)
Solution: A more complex calculator2m 20s
-
(Locked)
-