Join Regular Classroom : Visit ClassroomTech

Boolean in java

Java has a primitive datatype, called boolean, for logical values. It can have only one of two possible values,
true or false. After any conditional operations, it returns true or false.

Example:

/* JAVA program to understand Boolean */
/* www.codewindow.in */

import java.util.*;
public class codewindow
{
    public static boolean check(int a, int b)
    {
        if(a>b)
        {
            return false;
        }
        return true;
    }
    public static void main(String args[])
    {
        boolean b=true;
        b=check(10, 15);
        if(b)
        {
            System.out.print("10 is less than 15");
        }
        else
        {
            System.out.print("10 is greater than 15");
        }
    }
}

Output

10 is less than 15.

Literals in java

Integer Literals: Integers are probably the most commonly used type. Any whole number value is an integer literal. Examples are 1, 2, 3, and 42. Floating-Point Literals: Floating-point numbers represent decimal values with a fractional component. It consists of a whole number component followed by a decimal point followed by a fractional component. For example, 2.0, 3.14159, and 0.6667.


Boolean Literals: Java has a primitive type, called boolean, for logical values. It can have only one of two possible values, true or false. After any conditional operations, it returns true or false. Character Literals: Characters in Java are indices into the Unicode character set. They are 16-bit values that can be converted into integers and manipulated with the integer operators, such as the addition and subtraction operators. A literal character is represented inside a pair of single quotes.Example:’a’, ’e’ ,’I’ ,’o’ ,’u’.

String Literals: String literals in Java are specified by enclosing a sequence of characters between a pair of double-quotes. Example: “Hello world’’

Latest Post

Archives