Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9062525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:45:31+00:00 2026-06-16T15:45:31+00:00

Possible Duplicate: Java – boolean primitive type – size I’ve designed this program to

  • 0

Possible Duplicate:
Java – boolean primitive type – size

I’ve designed this program to calculate the size of a boolean in Java.

public class BooleanSizeTest{
    /**
     * This method attempts to calculate the size of a boolean.
     */
    public static void main(String[] args){
        System.gc();//Request garbage collection so that any arbitrary objects are removed.
        long a1, a2, a3;//The variables to hold the free memory at different times.
        Runtime r = Runtime.getRuntime();//Get the runtime.
        System.gc();//Request garbage collection so that any arbitrary objects are removed.
        a1 = r.freeMemory();//The initial amount of free memory in bytes.
        boolean[] lotsOfBools = new boolean[10_000_000];//Declare a boolean array.
        a2 = r.freeMemory();
        System.gc();//Request garbage collection.
        a3 = r.freeMemory();// Amount of free memory after creating 10,000,000 booleans.
        System.out.println("a1 = "+a1+", a2 = "+a2+", a3 = "+a3);
        double bSize = (double)(a1-a2)/10_000_000;/*Calculate the size of a boolean 
        using the difference of a1 and a2*/  
        System.out.println("boolean = "+bSize);
    }
}

When I run the program, it says that the size is 1.0000016 bytes. Now, the Oracle Java documentation says that the size of a boolean is “not defined”. [See link].
Why is this so? Also, a boolean variable represents 1 bit of information (true and false), so what happens to the remaining seven bits?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:45:32+00:00Added an answer on June 16, 2026 at 3:45 pm

    Accessing 1 bit is an expensive operation; if you retrieve data from memory, you are most likely to do it by word, or by byte. In Java, the internal representation of a boolean is an implementation detail that you shouldn’t be concerned unless you are doing a VM implementation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Java: Global Exception Handler I thought of something like this: public static
Possible Duplicate: Java ArrayList of ? extends Interface There is this code: public static
Possible Duplicate: Java's Interface and Haskell's type class: differences and similarities? When I started
Possible Duplicate: Java how to: Generic Array creation import java.util.EmptyStackException; import java.util.Vector; public class
Possible Duplicate: Java: Always override equals? should I override equals function for any class
Possible Duplicate: Java += operator In Java, this is not valid (doesn't compile), as
Possible Duplicate: Java - C-Like Fork? I have a static void main with this:
Possible Duplicate: java class declaration <T> Sometimes I've seen that java classes are created
Possible Duplicate: Java static class initialization Why is the string variable updated in the
Possible Duplicate: Java abstract interface Why do Java developers use public abstract for interfaces?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.