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

Evaluate conditions with if-else - Java Tutorial

From the course: Java 8+ Essential Training: Syntax and Structure

Start my 1-month free trial

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…

Contents