×

Java Boolean booleanValue() method

The booleanValue() method of Java Boolean class returns a Boolean value for the specified Boolean argument.

Syntax

public Boolean booleanValue()

Parameters

NA

Return Value

This method returns the primitive value of specified Boolean object.

Example 1

public class JavaBooleanBooleanValueExample1 {
    static int i=1;
    public static void main(String[] args) {
        // create a boolean object
        Boolean b1 = new Boolean(true);
        //returns a Boolean value for the specified Boolean arguments
        Boolean b2= b1.booleanValue();
        System.out.println(i + ". Boolean value of "+b1 +" : "+b2);
        Boolean b3 = false;
        //assigning boolean value of b3 to b4
        boolean b4 = b3.booleanValue();
        System.out.println(i++ +". Boolean value for "+b3+" : "+b4);
    }
}

Output

1. Boolean value of true : true
2. Boolean value for false : false

Example2:

import java.util.Scanner;
public class JavaBooleanBooleanValueExample2 {
     public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
         System.out.println("Enter your name and age");
         System.out.print("Name1 : ");String str1 =scanner.next();
         System.out.print("Age1 :"); int age1=scanner.nextInt();
         System.out.println();
         System.out.print("Name2 : ");String str2 =scanner.next();
         System.out.print("Age2 :"); int age2=scanner.nextInt();
         Boolean b3=(age1>age2)?true:false;
           if(b3.booleanValue()){
                System.out.println(str1+" is elder than "+str2);
            }
           else{
               System.out.println(str2+" is elder than "+str1);
            }
        }
    } 

Output:

Enter your name and age
Name1 : Reema
Age1 :21
Name2 : Geetanjali
Age2 :22
Geetanjali is elder than Reema

Example 3

public class JavaBooleanBooleanValueExample3 {
    public static void main(String[] args) {
        //for null value it will give an exception
        Boolean b1 = null;
        Boolean b2=b1.booleanValue();
        System.out.println("Value is "+b2);
    }
}

Output

Exception in thread "main" java.lang.NullPointerException
      at com.TutorialAndExample.JavaBooleanBooleanValueExample3.main(JavaBooleanBooleanValue
Example3.java:7)

Related Topics

Banking Application in Java

JDBC (Java Database Connectivity), which provides an API to connect to, execute, and fetch data from any databases, can be used to handle transactions in Java. There are several factors...

7 minutes read.

Highest precedence in Java

In Java, the operator is the first thing that springs to mind when discussing precedence. The order in which the operators in an expression are evaluated is controlled by a...

3 minutes read.

Concurrent Modification Exception In Java

When an object is attempted to be updated concurrently when it is not allowed, the ConcurrentModificationException arises. This error typically occurs while using Java Collection classes. When another thread is iterating...

5 minutes read.

Multithreading Program in Java

Multithreading Program in Java: Before discussing multithreading, it is important to discuss threads. Threads are the most fundamental part of a process. A process can have one or more threads....

4 minutes read.

Process and Thread in Java

Process It is a program that is running on your computer. The process is a heavy-weight, which takes memory separately to other processes. The process may be a small background task like spell-checker; it...

11 minutes read.

Logger class in Java

Logging is a crucial component of Java that aids developers in tracking down mistakes. The logging technique is included with the computer language Java. The possibility of collect the log...

7 minutes read.

Shopping Bill in Java

Java Shopping Bill Here in this program, we are about to create a JAVA class called Products which will have some properties or attributes like prod_name (Product Name ), qty (quantity),...

4 minutes read.

How to Assign Static Value to Date in Java?

In this tutorial, we will learn certain ways to assign a static value to a date in java. We will see the limitation of each method that will lead to...

3 minutes read.

Console Errors in Java

An unlawful motion taken through the person that reasons this system to act abnormally is amistake until this system is compiled or run; maximum programming mistakes pass unnoticed.The software is...

3 minutes read.

Buffer reader to read string in Java

The Buffered Reader class of Java is used to read the stream of characters from the input stream. Program to read string using Buffer reader import java.io.*; class  Demo {   public static void main(String...

3 minutes read.

Java Math scalb() Method

The scalb() method of Java Math class returns a single perfectly rounded product of floating-point and member of the double value set as if performed by d*2scaleFacor rounded value. Syntax: public static...

2 minutes read.

Constructor Program in Java

Constructor Program in Java In Java, a constructor is a piece of code that is used to create an object. A constructor is called implicitly when an object is created in...

7 minutes read.

Java Program to Add Digits Until the Number Becomes a Single Digit Number

We will develop Java programme that increase a number's digit count in order to reduce it to one. The issue is also known as the digit root problem. Example Consider the case where...

3 minutes read.

Java Snippets

The term "snippet" refers to a section of code that addresses numerous issues with just a few lines of code. Decreases the number of lines of code and improves programmer...

3 minutes read.

Bubble Sort in Java

Bubble Sort in Java Bubble sort isalso known as sinking sort. It is one of the simplest sorting algorithms. In the bubble sort algorithm, the given array is traversed from left...

5 minutes read.

Zygodromes in Java

Zygodrome is a positive number created by the same digits running non-trivially. A number is called a zygodrome if identical digits constantly occur together (in pairs). The Greek word "zyg"...

4 minutes read.

Composition in Java

Composition Java uses the composition method to implement a has-a connection. Composition allows us to reuse code in the same way that Java inheritance does. The "is-a" relationship is implemented using the...

3 minutes read.

Methods in Java

The Methods in Java are the collection of statements that are executed when the method is called. By using the methods, the complexity of writing the code decreases. The method consists...

4 minutes read.

Upcasting in Java

To know what is Upcasting in Java we should first equip ourselves about what is casting or type casting in Java. Casting The process of providing or replacing a reference variable of...

3 minutes read.

Java Variable Declaration

In this article, you will be acknowledged about java variable declaration. You will be able to learn and interpret about declaring a variable in Java. Variable in Java Variables are necessary for...

6 minutes read.