• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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

 
Ranch Hand
Posts: 36
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 42
Postgres Database Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Postgres Database Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23907
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2235
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10780
    71
    Hibernate Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
     
    I brought this back from the farm where they grow the tiny ads:
    Thread Boost feature
    https://coderanch.com/t/674455/Thread-Boost-feature
    reply
      Bookmark Topic Watch Topic
    • New Topic