Forums Register Login

When can we use fields(Integer.MIN_VALUE,Float.MIN_VALUE etc) of Wrapper Classes practically?

+Pie Number of slices to send: Send
Hi Friends,

Can anyone help me on this topic because i am not able to figure out when we can get these fields into use practically?
+Pie Number of slices to send: Send
We can use Integer.MAX_VALUE when we want to get the lowest number from an array of integers. Same logic can be applied for maximum number and for floats too.

+Pie Number of slices to send: Send
 

Alexandru Gifei wrote:We can use Integer.MAX_VALUE when we want to get the lowest number from an array of integers. Same logic can be applied for maximum number and for floats too.


So, you've worked at least one use out for yourself (and I'd be a bit careful with floats; they're not quite the same as Integers) - that's what we like to see here. Well done.

Now see if you can come up with a couple more - then it'll be pretty obvious why they're there.

And BTW, those fields are constants. Just try writing
Integer.MAX_VALUE = 3;
and you'll work out the difference.

Winston
+Pie Number of slices to send: Send
After searching these constants in the JDK, i found that they are used in other classes. For example in the java.lang.Long wrapper, in the getChars method. The Float.MIN_VALUE and .MAX_VALUE are used in the java.awt.font.TextLine class. So it seems the the developers that worked to create the JDK, reused the values.
+Pie Number of slices to send: Send
 

Alexandru Gifei wrote:The Float.MIN_VALUE and .MAX_VALUE are used in the java.awt.font.TextLine class. So it seems the the developers that worked to create the JDK, reused the values.


I never said they can't be used; I just said you need to be careful - ie, you need to understand what they mean - if you look at java.lang.Float, you'll see that it has TWO constants with "MIN" in the name, and both of them are greater than 0.

Winston
+Pie Number of slices to send: Send
 

Winston Gutkowski wrote:
I never said they can't be used; I just said you need to be careful - ie, you need to understand what they mean - if you look at java.lang.Float, you'll see that it has TWO constants with "MIN" in the name, and both of them are greater than 0.



Agreed. Float.MIN_VALUE and Float.MAX_VALUE are *not* the minimum and maximum possible values that a float variable can be assigned to. If they were, then the MIN_VALUE would have been NEGATIVE_INFINITY, and the MAX_VALUE would have been POSITIVE_INFINITY -- which are the smallest and largest possible values respectively.

Henry
+Pie Number of slices to send: Send
 

Henry Wong wrote:If they were, then the MIN_VALUE would have been NEGATIVE_INFINITY, and the MAX_VALUE would have been POSITIVE_INFINITY -- which are the smallest and largest possible values respectively.


Except for NaN of course.

Winston
+Pie Number of slices to send: Send
 

Winston Gutkowski wrote:

Alexandru Gifei wrote:The Float.MIN_VALUE and .MAX_VALUE are used in the java.awt.font.TextLine class. So it seems the the developers that worked to create the JDK, reused the values.


I never said they can't be used; I just said you need to be careful - ie, you need to understand what they mean - if you look at java.lang.Float, you'll see that it has TWO constants with "MIN" in the name, and both of them are greater than 0.

Winston


You are wrong . The class java.lang.Float has THREE constants with "MIN" in the name:
  • MIN_EXPONENT
  • MIN_NORMAL
  • MIN_VALUE
  • +Pie Number of slices to send: Send
     

    Pawel Pawlowicz wrote:You are wrong . The class java.lang.Float has THREE constants with "MIN" in the name:


    Curses! You got me.

    Winston
    Everybody's invited. Even this tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com


    reply
    reply
    This thread has been viewed 3220 times.
    Similar Threads
    NX: URLyBird 1.1.3 Find criteria
    dom Versus sax
    Q. equals and ==
    How to persist the array in Javascript
    servlet's constructor
    More...

    All times above are in ranch (not your local) time.
    The current ranch time is
    Mar 29, 2024 03:07:28.