|
|
|
1000 Java Tips ebook
|
|
 

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java
programming articles and tips. Please take your copy here.
Take your copy of free "Java Technology Screensaver"!. |
|
Easy Learn Java: Programming Articles, Examples and Tips - Page 26
Previous
1060 Stories (530 Pages, 2 Per Page)
Next
Why I can not compile it:
|
Question: Why I can not compile it:
byte aa = 2;
aa = - - aa;
I think the construction: - -aa is equivalent to -(-aa)...
Answer: The Java programming language
supports various arithmetic operators for all floating-point and integer
numbers. These operators are + (addition), - (subtraction), * (multiplication),
/ (division), and % (modulo).
In your example aa is a byte variable. You can use --aa instead..
***************************************
Our older tips: March 22, 2001 - October 21, 2002
read here.
All published and not published on site tips you can find
here
2 comments | | Score: 0
|
Posted by jalex on Sunday, March 16, 2003 (03:32:41) (2878 reads)
|
Q: Why do we need to use shift operator in Java? Can you give some examples?
|
Q: Why do we need to use shift
operator in Java? Can you give some examples?
Answer: Using shift operators in Java we can:
- 1. Make faster integer division/multiplication operations:
4839534 * 4
can be done like this:
4839534 << 2
or
543894 / 2
can be done like this:
543894 >> 1
Shift operations much more faster than multiplication for most of processors.
- 2. Reassembling byte streams to int values
- 3. For accelerating operations with graphics since Red, Green and Blue colors
coded by separate bytes.
- 4. Packing small numbers into one single long...
18 comments | | Score: 4
|
Posted by jalex on Friday, February 28, 2003 (00:00:00) (7901 reads)
|
|
|