• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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
 
Space pants. Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic