Archive for July, 2007

1182 Java Utilities Package and Bit Manipulation Chapter (Space web hosting)

Friday, July 27th, 2007

1182 Java Utilities Package and Bit Manipulation Chapter 20 118 119 // button to perform bitwise complement 120 JButton complementButton = new JButton( “Complement” ); 121 122 complementButton.addActionListener( 123 124 new ActionListener() { 125 126 // perform bitwise complement and display results 127 public void actionPerformed( ActionEvent event ) 128 { 129 input2Field.setText( “” ); 130 bits2Field.setText( “” ); 131 132 int value = Integer.parseInt( input1Field.getText() ); 133 134 resultField.setText( Integer.toString( ~value ) ); 135 bits1Field.setText( getBits( value ) ); 136 bits3Field.setText( getBits( ~value ) ); 137 } 138 } 139 ); 140 141 buttonPanel.add( complementButton ); 142 143 Container container = getContentPane(); 144 container.add( inputPanel, BorderLayout.WEST ); 145 container.add( bitsPanel, BorderLayout.EAST ); 146 container.add( buttonPanel, BorderLayout.SOUTH ); 147 148 setSize( 600, 150 ); 149 setVisible( true ); 150 } 151 152 // display numbers and their bit form 153 private void setFields() 154 { 155 value1 = Integer.parseInt( input1Field.getText() ); 156 value2 = Integer.parseInt( input2Field.getText() ); 157 158 bits1Field.setText( getBits( value1 ) ); 159 bits2Field.setText( getBits( value2 ) ); 160 } 16 16 // display bit representation of specified int value 16 private String getBits( int value ) 16 { 16 // create int value with 1 in leftmost bit and 0s elsewhere 16 int displayMask = 1 << 31; 16 16 // buffer to build output 16 StringBuffer buffer = new StringBuffer( 35 ); Fig. 20.8Demonstrating the bitwise AND, bitwise inclusive OR, bitwise exclusive OR Fig. 20.8 and bitwise complement operators (part 4 of 6).
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Chapter 20 Java Utilities Package and Bit Manipulation (Free web servers)

Thursday, July 26th, 2007

Chapter 20 Java Utilities Package and Bit Manipulation 1181 66 // perform bitwise AND and display results 67 public void actionPerformed( ActionEvent event ) 68 { 69 setFields(); 70 resultField.setText( 71 Integer.toString( value1 & value2 ) ); 72 bits3Field.setText( getBits( value1 & value2 ) ); 73 } 74 } 75 ); 76 77 buttonPanel.add( andButton ); 78 79 // button to perform bitwise inclusive OR 80 JButton inclusiveOrButton = new JButton( “Inclusive OR” ); 81 82 inclusiveOrButton.addActionListener( 83 84 new ActionListener() { 85 86 // perform bitwise inclusive OR and display results 87 public void actionPerformed( ActionEvent event ) 88 { 89 setFields(); 90 resultField.setText( 91 Integer.toString( value1 | value2 ) ); 92 bits3Field.setText( getBits( value1 | value2 ) ); 93 } 94 } 95 ); 96 97 buttonPanel.add( inclusiveOrButton ); 98 99 // button to perform bitwise exclusive OR 100 JButton exclusiveOrButton = new JButton( “Exclusive OR” ); 101 102 exclusiveOrButton.addActionListener( 103 104 new ActionListener() { 105 106 // perform bitwise exclusive OR and display results 107 public void actionPerformed( ActionEvent event ) 108 { 109 setFields(); 110 resultField.setText( 111 Integer.toString( value1 ^ value2 ) ); 112 bits3Field.setText( getBits( value1 ^ value2 ) ); 113 } 114 } 115 ); 116 117 buttonPanel.add( exclusiveOrButton ); Fig. 20.8Demonstrating the bitwise AND, bitwise inclusive OR, bitwise exclusive OR Fig. 20.8 and bitwise complement operators (part 3 of 6).
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Msn web hosting - 1180 Java Utilities Package and Bit Manipulation Chapter

Thursday, July 26th, 2007

1180 Java Utilities Package and Bit Manipulation Chapter 20 15 private int value1, value2; 16 17 // set up GUI 18 public MiscBitOps() 19 { 20 super( “Bitwise operators” ); 21 22 JPanel inputPanel = new JPanel(); 23 inputPanel.setLayout( new GridLayout( 4, 2 ) ); 24 25 inputPanel.add( new JLabel( “Enter 2 ints” ) ); 26 inputPanel.add( new JLabel( “” ) ); 27 28 inputPanel.add( new JLabel( “Value 1″ ) ); 29 input1Field = new JTextField( 8 ); 30 inputPanel.add( input1Field ); 31 32 inputPanel.add( new JLabel( “Value 2″ ) ); 33 input2Field = new JTextField( 8 ); 34 inputPanel.add( input2Field ); 35 36 inputPanel.add( new JLabel( “Result” ) ); 37 resultField = new JTextField( 8 ); 38 resultField.setEditable( false ); 39 inputPanel.add( resultField ); 40 41 JPanel bitsPanel = new JPanel(); 42 bitsPanel.setLayout( new GridLayout( 4, 1 ) ); 43 bitsPanel.add( new JLabel( “Bit representations” ) ); 44 45 bits1Field = new JTextField( 33 ); 46 bits1Field.setEditable( false ); 47 bitsPanel.add( bits1Field ); 48 49 bits2Field = new JTextField( 33 ); 50 bits2Field.setEditable( false ); 51 bitsPanel.add( bits2Field ); 52 53 bits3Field = new JTextField( 33 ); 54 bits3Field.setEditable( false ); 55 bitsPanel.add( bits3Field ); 56 57 JPanel buttonPanel = new JPanel(); 58 59 // button to perform bitwise AND 60 JButton andButton = new JButton( “AND” ); 61 62 andButton.addActionListener( 63 64 new ActionListener() { 65 Fig. 20.8Fig. 20.8 Demonstrating the bitwise AND, bitwise inclusive OR, bitwise exclusive OR and bitwise complement operators (part 2 of 6).
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Ipower web hosting - Chapter 20 Java Utilities Package and Bit Manipulation

Wednesday, July 25th, 2007

Chapter 20 Java Utilities Package and Bit Manipulation 1179 able value is left shifted one bit by the expression value <<= 1 (this is equivalent to value =value <<1). These steps are repeated for each bit in variable value. At the end of method getBits, the StringBufferis converted to a Stringin line 79 and returned from the method. Figure 20.7 summarizes the results of combining two bits with the bitwise AND (&) operator. Common Programming Error 20.1 Using the logical AND operator (&&) for the bitwise AND operator (&) is a common programming error. Figure 20.8 demonstrates the bitwise AND operator, the bitwise inclusive OR operator, the bitwise exclusive OR operator and the bitwise complement operator. The program uses method getBits (lines 163 188) to get a String representation of the integer values. The program allows the user to enter values into JTextFields (for the binary operators, two values must be entered), and then to press the button representing the operation they would like to test. The program displays the result of each operation in both integer and bitwise representations. The first output window for Fig. 20.8 shows the results of combining the value 65535 and the value 1with the bitwise AND operator (&). All the bits except the low-order bit in the value 65535 are masked off (hidden) by ANDing with the value 1. Bit 1 Bit 2 Bit 1 &Bit 2 000 100 010 111 Fig. 20.7Results of combining two bits with the bitwise AND operator (&). 20. 1 // Fig. 20.8: MiscBitOps.java 2 // Using the bitwise AND, bitwise inclusive OR, bitwise 3 // exclusive OR, and bitwise complement operators. 4 5 // Java core packages 6 import java.awt.*; 7 import java.awt.event.*; 8 9 // Java extension packages 10 import javax.swing.*; 11 12 public class MiscBitOps extends JFrame { 13 private JTextField input1Field, input2Field, 14 bits1Field, bits2Field, bits3Field, resultField; Fig. 20.8Demonstrating the bitwise AND, bitwise inclusive OR, bitwise exclusive OR Fig. 20.8 and bitwise complement operators (part 1 of 6).
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

1178 Java Utilities Package and Bit Manipulation Chapter (Professional web hosting)

Wednesday, July 25th, 2007

1178 Java Utilities Package and Bit Manipulation Chapter 20 60 // buffer to build output 61 StringBuffer buffer = new StringBuffer( 35 ); 62 63 // for each bit append 0 or 1 to buffer 64 for ( int bit = 1; bit <= 32; bit++ ) { 65 66 // use displayMask to isolate bit and determine whether 67 // bit has value of 0 or 1 68 buffer.append( 69 ( value & displayMask ) == 0 ? '0' : '1' ); 70 71 // shift value one position to left 72 value <<= 1; 73 74 // append space to buffer every 8 bits 75 if ( bit % 8 == 0 ) 76 buffer.append( ' ' ); 77 } 78 79 return buffer.toString(); 80 } 81 82 // execute application 83 public static void main( String args[] ) 84 { 85 PrintBits application = new PrintBits(); 86 87 application.setDefaultCloseOperation( 88 JFrame.EXIT_ON_CLOSE ); 89 } 90 91 } // end class PrintBits Fig. 20.6Printing the bits in an integer (part 3 of 3). Fig. 20.6 Lines 68 69 append a 1 or a 0 to a StringBuffer for the current leftmost bit of variable value. Assume that value contains 4000000000 (11101110 01101011 00101000 00000000). When value and displayMask are combined using &, all the bits except the high-order (leftmost) bit in variable valueare masked off (hidden), because any bit ANDed with 0 yields 0. If the leftmost bit is 1, value &display- Maskevaluates to a nonzero value and 1is appended; otherwise, 0is appended. Then vari
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Cheapest web hosting - Chapter 20 Java Utilities Package and Bit Manipulation

Tuesday, July 24th, 2007

Chapter 20 Java Utilities Package and Bit Manipulation 1177 7 8 // Java extension packages 9 import javax.swing.*; 10 11 public class PrintBits extends JFrame { 12 private JTextField outputField; 13 14 // set up GUI 15 public PrintBits() 16 { 17 super( “Printing bit representations for numbers” ); 18 19 Container container = getContentPane(); 20 container.setLayout( new FlowLayout() ); 21 22 container.add( new JLabel( “Enter an integer ” ) ); 23 24 // textfield to read value from user 25 JTextField inputField = new JTextField( 10 ); 26 27 inputField.addActionListener( 28 29 new ActionListener() { 30 31 // read integer and get bitwise representation 32 public void actionPerformed( ActionEvent event ) 33 { 34 int value = Integer.parseInt( 35 event.getActionCommand() ); 36 outputField.setText( getBits( value ) ); 37 } 38 } 39 ); 40 41 container.add( inputField ); 42 43 container.add( new JLabel( “The integer in bits is” ) ); 44 45 // textfield to display integer in bitwise form 46 outputField = new JTextField( 33 ); 47 outputField.setEditable( false ); 48 container.add( outputField ); 49 50 setSize( 720, 70 ); 51 setVisible( true ); 52 } 53 54 // display bit representation of specified int value 55 private String getBits( int value ) 56 { 57 // create int value with 1 in leftmost bit and 0s elsewhere 58 int displayMask = 1 << 31; 59 Fig. 20.6Printing the bits in an integer (part 2 of 3). Fig. 20.6
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

1176 Java Utilities Package and Bit Manipulation Chapter (Web hosting)

Tuesday, July 24th, 2007

1176 Java Utilities Package and Bit Manipulation Chapter 20 Operator Name Description & bitwise AND The bits in the result are set to 1if the corresponding bits in the two operands are both 1. | bitwise inclusive OR The bits in the result are set to 1if at least one of the corresponding bits in the two operands is 1. ^ bitwise exclusive OR The bits in the result are set to 1if exactly one of the corresponding bits in the two operands is 1. << left shift Shifts the bits of the first operand left by the number of bits specified by the second operand; fill from the right with 0 bits. >> right shift with sign extension Shifts the bits of the first operand right by the number of bits specified by the second operand. If the first operand is negative, 1s are shifted in from the left; otherwise, 0s are shifted in from the left. >>> right shift with zero extension Shifts the bits of the first operand right by the number of bits specified by the second operand; 0s are shifted in from the left. ~ one s complement All 0bits are set to 1and all 1bits are set to 0. Fig. 20.5The bitwise operators . g. 20.5 When using the bitwise operators, it is useful to display values in their binary representation to illustrate the effects of these operators. The application of Fig. 20.6 allows the user to enter an integer into a JTextField and press Enter. Method actionPerformed(lines 32 36) reads the Stringfrom the JTextField, converts it to an integer and invokes method getBits (lines 55 80) to obtain a String representation of the integer in bits. The result is displayed in the output JTextField. The integer is displayed in its binary representation in groups of eight bits each. Method getBitsuses the bitwise AND operator to combine variable value with variable displayMask. Often, the bit- wise AND operator is used with an operand called a mask an integer value with specific bits set to 1. Masks are used to hide some bits in a value while selecting other bits. In get- Bits, mask variable displayMask is assigned the value 1<<31or 10000000 00000000 00000000 00000000 The left shift operator shifts the value 1from the low-order (rightmost) bit to the high-order (leftmost) bit in displayMaskand fills in 0bits from the right. 1 // Fig. 20.6: PrintBits.java 2 // Printing an unsigned integer in bits 3 4 // Java core packages 5 import java.awt.*; 6 import java.awt.event.*; Fig. 20.6Printing the bits in an integer (part 1 of 3). Fig. 20.6
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Chapter 20 Java Utilities Package and Bit (Geocities web hosting) Manipulation

Monday, July 23rd, 2007

Chapter 20 Java Utilities Package and Bit Manipulation 1175 0 through 5. Then simply shift this value by adding 1 to produce a number in the range from 1 through 6. The expression is as follows: Math.abs( r.nextInt() ) % 6 + 1 The calls r.nextFloat() r.nextDouble() generate uniformly distributed values in the range 0.0 <= x < 1.0. The call r.nextGaussian() generates a double value with a probability density of a Gaussian (i.e., normal ) distribution (mean of 0.0 and standard deviation of 1.0). 20.8 Bit Manipulation and the Bitwise Operators Java provides extensive bit-manipulation capabilities for programmers who need to get down to the so-called bits-and-bytes level. Operating systems, test equipment software, networking software and many other kinds of software require that the programmer communicate directly with the hardware. In this section and the next, we discuss Java s bit- manipulation capabilities. We introduce Java s bitwise operators, and we demonstrate their use in live-code examples. Computers represent all data internally as sequences of bits. Each bit can assume the value 0 or the value 1. On most systems, a sequence of 8 bits forms a byte the standard storage unit for a variable of type byte. Other data types are stored in larger numbers of bytes. The bitwise operators can manipulate the bits of integral operands (i.e., those having type byte, char, short, int and long). Note that the bitwise operator discussions in this section show the binary representations of the integer operands. For a detailed explanation of the binary (also called base 2) number system, see Appendix E, Number Systems. The bitwise operators are bitwise AND (&), bitwise inclusive OR (|), bitwise exclusive OR (^), left shift (<<), right shift with sign extension (>>), right shift with zero extension (>>>) and complement (~). The bitwise AND, bitwise inclusive OR and bitwise exclusive OR operators compare their two operands bit by bit. The bitwise AND operator sets each bit in the result to 1 if the corresponding bit in both operands is 1. The bitwise inclusive OR operator sets each bit in the result to 1 if the corresponding bit in either (or both) operand(s) is 1. The bitwise exclusive OR operator sets each bit in the result to 1 if the corresponding bit in exactly one operand is 1. The left shift operator shifts the bits of its left operand to the left by the number of bits specified in its right operand. The right shift operator with sign extension shifts the bits in its left operand to the right by the number of bits specified in its right operand if the left operand is negative, 1s are shifted in from the left; otherwise, 0s are shifted in from the left. The right shift operator with zero extension shifts the bits in its left operand to the right by the number of bits specified in its right operand 0s are shifted in from the left. The bitwise complement operator sets all 0 bits in its operand to 1 in the result and sets all 1 bits to 0 in the result. Detailed discussions of each bitwise operator appear in the following examples. The bitwise operators are summarized in Fig. 20.5.
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Free web design - 1174 Java Utilities Package and Bit Manipulation Chapter

Monday, July 23rd, 2007

1174 Java Utilities Package and Bit Manipulation Chapter 20 Testing and Debugging Tip 20.2 Use Properties method list to display the contents of a Properties object for debugging purposes. Line 181 calls Properties method load to restore the contents of the Properties object from the InputStream specified as the first argument (in this case, a FileInputStream). Line 208 calls Properties method propertyNames to obtain an Enumeration of the property names. The value of each property can be determined by using method getProperty. 20.7 Random Class We discussed random-number generation in Chapter 6, Methods, where we used Math class method random. Java provides extensive additional random number generation capabilities in class Random. We briefly walk through the API calls here. A new random-number generator can be created by using Random r = new Random(); This form uses the computer s current time to seed its random-number generator differently during each constructor call and thus generates different sequences of random numbers for each Random object. To create a pseudorandom-number generator with repeatability, use Random r = new Random( seedValue ); The seedValue argument (type long) is used in the random number calculation to seed the random number generator. If the same seedValue is used every time, the Random object produces the same sequence of random numbers. Testing and Debugging Tip 20.3 While a program is under development, use the form Random(seedValue) that produces a repeatable sequence of random numbers. If a bug occurs, fix the bug and test with the same seedValue; this allows you to reconstruct the exact same sequence of random numbers that caused the bug. Once the bugs have been removed, use the form Random(), which generates a new sequence of random numbers each time the program is run. The call r.setSeed( seedValue ); resets r s seed value at any time. The calls r.nextInt() r.nextLong() generate uniformly distributed random integers. You can use Math.abs to take the absolute value of the number produced by nextInt, thus giving a number in the range from zero through approximately 2 billion. Then use the % operator to scale the number. For example, to roll a six-sided die, if you scale with a 6, you will get a number in the range from
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

Chapter 20 Java Utilities (Web hosting bandwidth) Package and Bit Manipulation

Monday, July 23rd, 2007

Chapter 20 Java Utilities Package and Bit Manipulation 1173 219 } // end method ListProperties 220 221 // display String in statusLabel label 222 public void showstatus( String s ) 223 { 224 statusLabel.setText( s ); 225 } 226 227 // execute application 228 public static void main( String args[] ) 229 { 230 PropertiesTest application = new PropertiesTest(); 231 232 application.setDefaultCloseOperation( 233 JFrame.EXIT_ON_CLOSE ); 234 } 235 236 } // end class PropertiesTest Fig. 20.4 Demonstrating class Properties(part 6 of 6). Line 25 uses the no-argument constructor to create an empty Propertiestable with no default properties. Class Properties also provides an overloaded constructor that receives a reference to a Propertiesobject containing default property values. Lines 68 69 call Propertiesmethod setPropertyto store a value for the specified key. If the key does not exist in the table, setProperty returns null; otherwise, it returns the previous value for that key. Lines 116 117 call Properties method getProperty to locate the value associated with the specified key. If the key is not found in this Properties object, get- Propertyuses the one in the default Propertiesobject (if there is one). The process continues recursively until there are no more default Propertiesobjects (remember that every Properties object can be initialized with a default Properties object), at which point getPropertyreturns null. An overloaded version of this method receives two arguments, the second of which is the default value to return if getPropertycannot locate the key. Line 150 calls Properties method store to save the contents of the Propertiesobject to the OutputStreamobject specified as the first argument (in this case, a FileOutputStream). The String argument is a description of the Properties object. Class Properties also provides method list, which takes a PrintStream argument. This method is useful for displaying the set of properties.
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.