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 8704709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:10:35+00:00 2026-06-13T03:10:35+00:00

In some of our companys projects code I often read something like this: boolean

  • 0

In some of our companys projects code I often read something like this:

boolean foo = Boolean.FALSE;

Besides the fact that AFAIK I only have to initialize local variables in Java at all (no random values like in Pascal) and besides the fact that especially for booleans I often WANT to have an initialization, what do I miss here? Why not:

boolean foo = false;

I don’t get it. And code analyzation tools like PMD and Findbugs mark it, too. But why?

Edit:
Without really knowing much about the bytecode except that it is there I created an example class and decompiled it. The Boolean.FALSE went to:

0: getstatic #15 // Field java/lang/Boolean.FALSE:Ljava/lang/Boolean; 
3: invokevirtual #21 // Method java/lang/Boolean.booleanValue:()Z 
6: istore_1 

The ‘false’ variant went to:

0: iconst_1 
1: istore_1 

So without knowing too much about this, I’d guess that more statements means more time to execute so it’s not only wrong but also slower in the long run.

  • 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-13T03:10:36+00:00Added an answer on June 13, 2026 at 3:10 am
    boolean foo = Boolean.FALSE;
    

    This is strange and unnecessarily complicated code, written by someone who likely didn’t know Java very well. You shouldn’t write code like this, and PMD and FindBugs are right to mark this.

    Boolean.FALSE is a java.lang.Boolean object that gets auto-unboxed; the compiler essentially translates this to:

    boolean foo = Boolean.FALSE.booleanValue();
    

    I don’t have to initialize variables in Java at all…

    Member variables do not need to be initialized explicitly; if you don’t, they’ll be initialized with a default value (which is false in the case of boolean). Local variables do need to be explicitly initialized; if you try to use a local variable without initializing it, the compiler will give you an error.

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

Sidebar

Related Questions

My company (EU-based) is considering to release some parts of our code under a
I'm updating some of our old code to use C++11 features in place of
We have some HTTP handlers specified in our web.config. When we were running this
at our company we have some drupal projects that share some custom developed modules,
We've got a series of code projects in different parts of our source tree
Our company is offering some trainings and asks us what would we want to
Our company, Company A, may soon be partnering with Company B under some sort
We'll soon have some high school kids here in our company for some training
Some of our FogBugz users experience that the Screenshot tool does not start-up automatically
some of our customers have Quick book online and some of our customers have

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.