]]>Bitwise operators and Shift operatorshttp://www.tkk7.com/yglwxl/archive/2008/05/20/201630.html涔?jié)瀹?/dc:creator>涔?jié)瀹?/author>Tue, 20 May 2008 05:22:00 GMThttp://www.tkk7.com/yglwxl/archive/2008/05/20/201630.htmlhttp://www.tkk7.com/yglwxl/comments/201630.htmlhttp://www.tkk7.com/yglwxl/archive/2008/05/20/201630.html#Feedback0http://www.tkk7.com/yglwxl/comments/commentRss/201630.htmlhttp://www.tkk7.com/yglwxl/services/trackbacks/201630.html
鎸変綅榪涜涓庤繍綆?錛?&
鎸変綅榪涜鎴栬繍綆?錛?|
鎸変綅榪涜浣嶅紓榪愮畻錛?^
鎸変綅榪涜鍙栧弽榪愮畻錛?~
鎸変綅榪涜寰幆宸︾Щ錛?lt;<錛岃繍綆楃宸︿晶瀵硅薄宸︾Щ鐢卞彸渚ф寚瀹氱殑浣嶆暟錛屼綆浣嶈ˉ0錛屾渶楂樹綅鎶涘純銆傚甫絎﹀彿鐨勫乏縐諱綅榪愮畻鐩稿綋浜庡宸︽搷浣滄暟榪涜涔?榪愮畻銆?
鎸変綅榪涜寰幆鍙崇Щ錛?gt;>錛岃繍綆楃宸︿晶瀵硅薄鍙崇Щ鐢卞彸渚ф寚瀹氱殑浣嶆暟錛岃嫢鍊間負姝o紝鍦ㄦ渶楂樹綅鎻掑叆0錛岃嫢鍊間負璐燂紝鍦ㄦ渶楂樹綅鎻掑叆1錛屽嵆縐誨叆鐨勬渶楂樹綅鍜屽師鏈楂樼鍙蜂綅鐩稿悓銆傚甫絎﹀彿鐨勫彸縐諱綅榪愮畻鐩稿綋浜庡宸﹁竟鐨勮繍綆楀璞¤繘琛岄櫎2榪愮畻銆?
鎸変綅榪涜鏃犵鍙峰彸縐伙細>>>錛屾棤璁鴻繍綆楃宸﹁竟鐨勮繍綆楀璞″彇鍊兼璐燂紝閮藉湪楂樹綅鎻掑叆0錛屽嵆縐誨叆浣嶅緇堣ˉ0.
瑕佹敞鎰忔槸娌℃湁鎸変綅榪涜鏃犵鍙峰乏縐葷殑銆備綅榪愮畻絎︾殑鎿嶄綔鏁板彧鑳芥槸鏁存暟錛宑har,byte,short,
int鍜宭ong,榪涜浣嶈繍綆楁椂錛屾繪槸鍏堝皢瀛楃鍨嬪箋佸瓧鑺傚瀷鍊煎拰鐭暣鍨嬪艱漿鎹負鏁村瀷鍐嶈繘琛屼綅榪愮畻銆備綅榪愮畻絎︽父鏍囩殑鎿嶄綔鏁扮敤浜庢寚瀹氱Щ鍔ㄧ殑浣嶆暟錛屾寜瑙勫畾鍏朵笉搴旇秴榪囧乏渚ф暟鐨勮繘鍒惰〃紺轟綅鏁般?
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鈥攁 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.tkk7.com/yglwxl/archive/2008/05/20/199515.html涔?jié)瀹?/dc:creator>涔?jié)瀹?/author>Tue, 20 May 2008 05:10:00 GMThttp://www.tkk7.com/yglwxl/archive/2008/05/20/199515.htmlhttp://www.tkk7.com/yglwxl/comments/199515.htmlhttp://www.tkk7.com/yglwxl/archive/2008/05/20/199515.html#Feedback0http://www.tkk7.com/yglwxl/comments/commentRss/199515.htmlhttp://www.tkk7.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