]]>Bitwise operators and Shift operatorshttp://www.aygfsteel.com/yglwxl/archive/2008/05/20/201630.html九宝九宝Tue, 20 May 2008 05:22:00 GMThttp://www.aygfsteel.com/yglwxl/archive/2008/05/20/201630.htmlhttp://www.aygfsteel.com/yglwxl/comments/201630.htmlhttp://www.aygfsteel.com/yglwxl/archive/2008/05/20/201630.html#Feedback0http://www.aygfsteel.com/yglwxl/comments/commentRss/201630.htmlhttp://www.aygfsteel.com/yglwxl/services/trackbacks/201630.html
按位q行与运?Q?&
按位q行或运?Q?|
按位q行位异q算Q?^
按位q行取反q算Q?~
按位q行循环左移Q?lt;<Q运符左侧对象左移由右侧指定的位数Q低位补0Q最高位抛弃。带W号的左UMq算相当于对左操作数q行?q算?
按位q行循环右移Q?gt;>Q运符左侧对象右移由右侧指定的位数Q若gؓ正,在最高位插入0Q若gؓ负,在最高位插入1Q即Ud的最高位和原最高符号位相同。带W号的右UMq算相当于对左边的运对象进行除2q算?
按位q行无符号右U:>>>Q无符左边的运对象取值正负,都在高位插入0Q即Ud位始l补0.
要注意是没有按位q行无符号左Uȝ。位q算W的操作数只能是整数Qchar,byte,short,
int和long,q行位运时QL先将字符型倹{字节型值和短整型D{换ؓ整型再进行位q算。位q算W游标的操作数用于指定移动的位数Q按规定其不应超q左侧数的进制表CZ数?
The bitwise operators allow you to manipulate individual bits in an integral primitive data type.Bitwise operators perform Boolean algebra on the corresponding bits in the two arguments to produce the result. The bitwise operators come from C’s low-level orientation, where you often manipulate hardware
directly and must set the bits in hardware registers. Java was originally designed to be embedded in TV set-top boxes, so this low-level orientation still made sense. However, you probably won’t use the bitwise operators much.
The bitwise AND operator (&) produces a one in the output bit if both input bits are one; otherwise, it produces a zero.
The bitwise OR operator (|) produces a one in the output bit if either input bit is a one and produces a zero only if both input bits are zero.
The bitwise EXCLUSIVE OR, or XOR (^), produces a one in the output bit if one or the other input bit is a one, but not both.
The bitwise NOT (~, also called the ones complement operator) is a unary operator; it takes only one argument. (All other bitwise operators are binary operators.) Bitwise NOT produces the opposite of the input bit—a one if the input bit is zero, a zero if the input bit is one.
Java determines the size of each primitive type. These sizes don’t change from one machine
architecture to another as they do in most languages. This size invariance is one reason Java
programs are more portable than programs in most other languages.
All numeric types are signed, so don’t look for unsigned types.
The size of the boolean type is not explicitly specified; it is only defined to be able to take the literal values true or false.
The “wrapper” classes for the primitive data types allow you to make a non-primitive object on the heap to represent that primitive type. For example:
char c = 'x';
Character ch = new Character(c);
Or you could also use:
Character ch = new Character('x');
Java SE5 autoboxing will automatically convert from a primitive to a wrapper type:
Character ch = 'x';
and back:
char c = ch;
The reasons for wrapping primitives will be shown in a later chapter.
High-precision numbers
Java includes two classes for performing high-precision arithmetic: BigInteger and
BigDecimal. Although these approximately fit into the same category as the “wrapper” classes, neither one has a primitive analogue.
Both classes have methods that provide analogues for the operations that you perform on
primitive types. That is, you can do anything with a BigInteger or BigDecimal that you can with an int or float, it’s just that you must use method calls instead of operators. Also, since there’s more involved, the operations will be slower. You’re exchanging speed for accuracy.
BigInteger supports arbitrary-precision integers. This means that you can accurately represent integral values of any size without losing any information during operations.
BigDecimal is for arbitrary-precision fixed-point numbers; you can use these for accurate
]]>Introduction to Objectshttp://www.aygfsteel.com/yglwxl/archive/2008/05/20/199515.html九宝九宝Tue, 20 May 2008 05:10:00 GMThttp://www.aygfsteel.com/yglwxl/archive/2008/05/20/199515.htmlhttp://www.aygfsteel.com/yglwxl/comments/199515.htmlhttp://www.aygfsteel.com/yglwxl/archive/2008/05/20/199515.html#Feedback0http://www.aygfsteel.com/yglwxl/comments/commentRss/199515.htmlhttp://www.aygfsteel.com/yglwxl/services/trackbacks/199515.html1.The hidden implementation
The goal of the class creator is to build a class that exposes only what is necessary to the client programmer and keeps everything else hidden. Why?
(1)Becuase if it is hidden, the client programmer can't access it, which means that the class creator can change the hidden portion at will withou worring about the impact on anyone else.
(2)The hidden portion usually reprsents the tender insides of an object that could easily be corrupted by a careless or uninformed client programmer, so hiding the implementation reduces program bugs.
2.Reusing the implementation
The simplest way to reuse a class is to just use an object of that class directly, but you can also place an object of that class inside a new class. We call this "creating a member object." Your new class can be made up of any mumber and type of other objectss, in any combination that you need to achieve the fuctionality desired in your new class. Because you are composing a new class from existing classes, this conception is called composition. Compositon is often referred to as a "has-a" relationship, as "A car has an engine."
Because inheritance is so important in OOP, it is often highly emphasized, and the new programmer can get the idea that inheritance should be used everywhere. This can result in awkward and overly complicated designs. Instead, you should first look to composition when creating new classes, since it is simpler and more flexible. If you take this approach,your designer will be cleaner. Once you have had some experience, it will be reasonably obvious when you need inheritance.
3.Inheritance
You have two ways to differentiate your new derived class from the original base class.
The first is quite straightforward: You simply add brand new methods to the derived class. This means that the base class simply didn't as much as you wanted it to, so you added more methods. This simple and primitive use for inheritance is, at times, the perfect solution to your problem. However, you should look closely for the posiblilty that your base class might also need these additional methods. This process of discovery and iteration of your design happens regularly in OOP.
The second and more important way to differentiate your new class is to change the behavior of an existing base-class method. This is referred to as overriding that method. To override a method, you simply create a new definition for the method in the derived class. You are saying, "I am using the same interface method here, but I want it to do something different for my new type."
4.Is-a vs. is-like-a relationships
5.Interchangeable objects with polymorphism
6The single rooted hierarchy
All objects have a single rooted hierarchy can be guaranteed to have certain functionality. You know you can perform certain basic operations on every object in your system. All objects can easy be created on the heap, and argument passing is greatly simplified.
A single rooted hierarchy makes it much easier to implement a garbage collector, which is one of the fundamental improvements of Java over C++. And since information about the type of an object is guaranteed to be in all objects, you'll never end up with an object whose type you cannot determine. This is especially important with system-level operations, such as exception handling, and to allow greater flexibility in programming.
7.Containers
8.Parameterized types(generics)
One of the big changes in Java SE5 is the addition of parameterized types, called generics in java. you will recongize the use of generics by angle brackets with types inside.
9.Object creation & lifetime
How can you possibly know when to destroy the objects?
(1).C++ takes the approach that control of efficiency is the most important issue, so it give the programmer a choice.
(2).Java, in heap