• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Integral types

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am not able to understand why Byte b1= new Byte(1); line generates an error..
Pls explain what am I missing..

Also , I wud like to know how to identify double & float value;
is it that only if explicitly specified 10.0f it is a float,else 10.0 is a double

May be what i m asking is too simple..pls excuse

public class Test12{
public static void main(String a[]){
byte b = 100;
Byte b1= new Byte(1);
Byte b2 = new Byte(b);
System.out.println(b1 == b2);
System.out.println(b1.equals(b2));
}
}
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By default, a floating point number is a double. If you want a float, you have to put a "f" next to your number.

example:
10.2, 12.36 are doubles,
25.689f is a float.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am not able to understand why Byte b1= new Byte(1); line generates an error



The Byte constructor takes a byte or a String. The literal 1 is an int. So you must cast it: Byte b1= new Byte((byte)1);

See Corey's next article (really)
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also specify a double explicitly, for example: 42.0d
 
A "dutch baby" is not a baby. But this tiny ad is baby sized:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic