aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Integral types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Integral types" Watch "Integral types" New topic
Author

Integral types

rimzim sinha
Greenhorn

Joined: Oct 26, 2004
Posts: 17
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));
}
}
Olivier Lambert
Greenhorn

Joined: Apr 30, 2004
Posts: 9
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.


Oli,<br />SCJP
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
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)


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
You can also specify a double explicitly, for example: 42.0d
 
Don't get me started about those stupid light bulbs.
 
subject: Integral types