Java development for beginners 6. Logic operators. Boolean type.

Logical Operators are operators that operate on Boolean values; that is values that are true of false.

Logical Operator Java symbols
And &&
Or ||

Boolean Expressions:

-Boolean is a primitive java data type

-A Boolean expression is an expression that evaluates to either true of false

- true and false are both reserved words in java

- Boolean expressions are made up of comparison and logical operators

- Boolean expressions can be used in the if statements and conditional loops

- Boolean expressions can also be used is assignment statements

The comparison operators compare two values and will evaluate to either true or false

Comparison Java symbols
less than <
greater than >
equal to==
not equal to!=
less than or equal to<=
greater than or equal to>=

In the class Tutorial6 we have the code of the example of the video tutorial so you can play with it.

    package com.edu4java.tutorial6;

import java.util.Scanner;

public class Tutorial6 {
	public static void main(String[] args) {

		Scanner scanner = new Scanner(;
		System.out.print("scan age:");
		int age = scanner.nextInt();
//		boolean canDrink=(age>=18)&&(age<=60);
		boolean canNotDrink=(age<18)||(age>60);
		if (canNotDrink) {
			System.out.println(" can´t drink");
		} else {
			System.out.println("can drink");
		System.out.print("print age: ");

<< Previous Next >>