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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "byte" Watch "byte" New topic
Author

byte

Robbie kyodo
Ranch Hand

Joined: May 05, 2003
Posts: 97
why
byte = long + byte
is legal ?


SCJP 2 1.4
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
It is not legal. The example?


SCJP2. Please Indent your code using UBB Code
Robbie kyodo
Ranch Hand

Joined: May 05, 2003
Posts: 97
byte b = 1;
long l = 1000;
b = l + b;
System.out.println (b);
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
I THINK b is not byte any more. It is long.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Compiler complains: possible loss of precision.
Robbie kyodo
Ranch Hand

Joined: May 05, 2003
Posts: 97
1. class Teal {
2. public static void main (String[] args) {
3. byte b=1;
4. long l=1000;
5. b += l;
6. }
7. }

frm Dan's
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8764
    
    5
Robbie -
b = b + l
is different than
b += l
In the second case the compiler puts a (an implicit) cast in for you.


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Robbie kyodo
Ranch Hand

Joined: May 05, 2003
Posts: 97
Hi Bert
tot
a += b;
is a=a+b
can u break up the above case for me ?
Yi Meng
Ranch Hand

Joined: May 07, 2003
Posts: 270
byte b=1;
long l=1000;
b += l; //line 3
here on line 3, it is actually the same as:
b=(byte)(b+l);
(JLS 15.26.2 )
which is obviously different from
b=b+l;


Meng Yi
Robbie kyodo
Ranch Hand

Joined: May 05, 2003
Posts: 97
This is something new.....what the !!@@#@#
Robbie kyodo
Ranch Hand

Joined: May 05, 2003
Posts: 97
Hi Kathy
Is compound operator part of the objectives???
Robbie kyodo
Ranch Hand

Joined: May 05, 2003
Posts: 97
This is something new.....what the !!@@#@#
Robbie kyodo
Ranch Hand

Joined: May 05, 2003
Posts: 97
This is something new.....what the !!@@#@#
Robbie kyodo
Ranch Hand

Joined: May 05, 2003
Posts: 97
This is something new.....what the !!@@#@#
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
Yes the compound operators like += are part of the objectives and are likely to show up in code examples.
Bill


Java Resources at www.wbrogden.com
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8764
    
    5
Robbie -
We talk about it around pages 150-151, also you will find it in the JLS 15.26.2.
The JLS sez:
E1 op= E2 is equivalent to
E1 = (T)((E1) op (E2))
where T is the type of E1.
-Bert
Robbie kyodo
Ranch Hand

Joined: May 05, 2003
Posts: 97
THks guys phew ...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: byte
 
Similar Threads
Byte Wrapper class
boolean
Wrapper classes
reading -1 from file ?
WA #1.....word association