• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Ankush Kaundal
Ranch Hand
Posts: 36
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Alexandru Gifei
Ranch Hand
Posts: 42
Java Linux Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Alexandru Gifei
Ranch Hand
Posts: 42
Java Linux Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  •  
    Winston Gutkowski
    Bartender
    Posts: 10575
    66
    Eclipse IDE Hibernate Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Pawel Pawlowicz wrote:You are wrong . The class java.lang.Float has THREE constants with "MIN" in the name:

    Curses! You got me.

    Winston
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!