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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:59:20+00:00 2026-06-04T00:59:20+00:00

The question is: Why in this case i get compilation error in Java? byte

  • 0

The question is:

Why in this case i get compilation error in Java?

byte x = 0;
x = 128;

But this is legal:

x+= 999l;

I use eclipse, jdk 7.

Thank You

  • 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-04T00:59:21+00:00Added an answer on June 4, 2026 at 12:59 am

    In your first one:

    byte x = 0;
    x = 128;
    

    A byte is a signed integral type, 8-bits wide, and can express the range of -128 to +127.

    x = 128 means “assign x to 128“, and by default, 128 is of type int, so you’re trying to assign an int to byte which would cause Possible loss of precision errors, because int is wider than byte. To get this to work, you would have to explicitly cast the value of 128.

    byte x = 0;
    x = (byte)128; // x is now -128.
    

    For your second example, adding values to x is fine, but you just overflow the values.

    byte x = 0;
    x += 999L; // don't really need the long qualifier here
    // x is now -25.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a general question about MVC as a pattern, but in this case
I have a use case with NServiceBus explained in this question. Essentially there is
This is more a general question but my particular case involves a ruby/rails app
I posted this question here on purpose, although - for my case - it
I see a question about this here . However, in my case, It is
Yesterday while going through this question, I found a curious case of passing and
I want to implement a case insensitive hash map. This question by itself isn't
This question has been asked a lot of times in many forums. But I
This question has been asked before but with no real answer. I wan't to
This might be a pretty straightforward question, but I'm trying to understand some of

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.