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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:31:12+00:00 2026-05-27T05:31:12+00:00

Say I have a Java program such: //case1 Long first = 1; Long second

  • 0

Say I have a Java program such:

//case1
Long first = 1;
Long second = 1;
Long third = first - second;

//case2
Long first = Long.MAX_VALUE;
Long second = 100000L;
Long third = first - second;

Those two cases should have the exact same execution time and overhead shouldn’t they? The actual operation is performed on every bit in the Long right, regardless of the value contained within it, right?

If my assumption is true,is there any language where this is NOT the case?

EDIT: The case that prompted this is a 16 bit PIC we are using at work ( C code), that calculates averages over a variable amount of time. After the answers below from M S and Thom, I now understand that it IS possible to introduce a bug this way, since the PIC is computing mission critical information, on a time-sensitive basis.

Thank you all very much.

  • 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-05-27T05:31:13+00:00Added an answer on May 27, 2026 at 5:31 am

    What you say is true in Java — the operations execute in a time that is independent of the values. In some languages (such as Lisp), if the value exceeds the maximum legal value for the data type, execution automatically switches to use a “big integer” package, which slows the execution down considerably.

    EDIT
    There is a slight difference between the first and second cases: the value 1 is special (as is 0). The byte code for

    Long first=1L;
    

    is:

    lconst_1
    invokestatic    #2; //Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
    astore_1
    

    whereas if the constant is (say) 2L, one gets this byte code:

    ldc2_w  #3; //long 2l
    invokestatic    #2; //Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
    astore_2
    

    Since lconst_1 runs faster than ldc2_w, there is a slight time difference between cases 1 and 2.

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

Sidebar

Related Questions

Let's say I have a java program that makes an HTTP request on a
Lets say we have a program which contains such classes: public interface AbstractItem {
I have a Big O notation question. Say I have a Java program that
first of all, i like to say that i have read the other two
Let's say I have some Java code: public class SomeClass { static { private
Let's say I have a java.util.Properties object. The Properties object has a method called
Say I have a GUI Java project of something that simulates an ATM machine,
Say I have the following simple java bean: class MyBean { private Date startDate;
Say I have a couple of java runtime environments running on my system which
Say I have a binary file (generated with Java) containing a 32 bit int

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.