Skip to main content

Posts

Showing posts from July, 2015
Bitwise operator works on bits and performs bit-by-bit operation. Assume if a = 60; and b = 13; now in binary format they will be as follows: a = 0011 1100 b = 0000 1101 Operator Description Example & Binary AND Operator copies a bit to the result if it exists in both operands. (A & B) will give 12 which is 0000 1100 | Binary OR Operator copies a bit if it exists in either operand. (A | B) will give 61 which is 0011 1101 ^ Binary XOR Operator copies the bit if it is set in one operand but not both. (A ^ B) will give 49 which is 0011 0001 ~ Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. (~A ) will give -61 which is 1100 0011 in 2's complement form due to a signed binary number. << Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operan A << 2 will give 240 which is 1111 0000 >> Binary Right Shift Operator. The left operands value is moved rig...
What is the difference between String str = new String ( "abc" ); and String str = "abc" ; ie what is the difference between String Literal and String object. Ans: In this example both string literals refer the same object: String a = "abc" ; String b = "abc" ; System . out . println ( a == b ); // true Here, 2 different objects are created and they have different references: String c = new String ( "abc" ); String d = new String ( "abc" ); System . out . println ( c == d ); // false String Literal uses constant pool memory whereas String Object refers the Heap memory.  When we create string b it doesnot create another string but but use the reference of the a  String.
What happens when you compile/run the following code: class MyClass { public static void main(String[] args) { new MyClass(); } Ans: It executes and create a object for that class without reference. The output of the program is nothing.