Sunday, September 29, 2013

Resolve "Target runtime Apache Tomcat v6.0 is not defined." error

Go to window ->preferences ->Server->Runtime environments .
add server Apache Tomcat v6.0 Mention the directory where apache-tomact server is placed

Please find the links to similar errors below.
how-to-remove-default-workspace
resolve-unbound-classpath-container-jre
resolve-target-runtime-apache-tomcat

Resolve Unbound classpath container: 'JRE System Library [jdk1.5.0_06]'/similiar error in project

when an existing dynamic web project is imported into another workspace you may get this error.
Reason:
JRE System Library jdk1.5.0_06 is not available in the project workspace.
Resolution:
a)Add the Library jdk1.5.0_06 in the project
Go to window ->preferences ->Java ->Installed JREs.Add a Standard VM with
JRE name jdk1.5.0_06
b)Create a new dynamic web project in the workspace and add the files from existing project
into the new project created.

Please find the links to similar errors below.
how-to-remove-default-workspace
resolve-unbound-classpath-container-jre
resolve-target-runtime-apache-tomcat

How to remove the default workspace in the RAD/Eclipse?

If you have selected some workspace as deafult by checking the “use this as the default and do not ask again” option when Workspace is loaded,then the same workspace gets loaded everytime you open the RAD/Eclipse.

Use the following steps to remove the default work space :
 Step 1 : Select window-> Preferences-> Select StartUp and Shutdown option in preferences.
 Step 2 : Check the option Prompt for workspace on startup and click on Apply and Ok buttons
Now you will be asked to select the workspace every time you try to open the workspace

Please find the links to similar errors below.
resolve-unbound-classpath-container-jre
resolve-target-runtime-apache-tomcat

Tuesday, September 24, 2013

Bitwise Shift operators in java with code

Java provides bit wise shift operation only on integral types (int, long, possibly short and byte or char).

There are 3 types of bit wise shift operators.

1) >> (Signed right shift operator)

It will shift the bit pattern of the first argument to the right by the number of positions mentioned in the second argument.  It fills in positions on the left with zeros. It keeps the sign of the argument unchanged.

           
Example
Meaning In Binary format
Result
2 >>1
10  should be shifted to right by 1 position (keep the sign unchanged)
1
-2 >> 1
10  should be shifted to right by 1 position (keep the sign unchanged) 
-1


Byte representation (8 bytes)
2 >> 1
1
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1

-2 >> 1
-1
1
0
0
0
0
0
1
0
1
0
0
0
0
0
0
1
Red color to indicate sign


This operator gives the value which is equal to the integer division by 2^n where n is the number of positions.

2) << (Signed left shift operator)

It will shift the bit pattern of the first argument to the left by the number of positions mentioned in the second argument. It fills in positions on the right with zeros.
 It keeps the sign of the argument unchanged.

Example
Meaning In Binary format
Result
2 << 1
10  should be shifted to left by 1 position (keep the sign unchanged)
4
-2 << 1
10  should be shifted to left by 1 position (keep the sign unchanged) 
- 4


Byte representation (8 bytes)
2 << 1
4
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0

-2 << 1
-4
1
0
0
0
0
0
1
0
1
0
0
0
0
1
0
0
Red color to indicate sign


This operator gives the value which is equal to the integer multiplication by 2^n where n is the number of positions.

3)  >>> (Unsigned right shift operator)
It shifts bit pattern of the first argument to the right by the number of positions mentioned in the second argument without caring what the original sign was. It fills in positions on the left with zeros.

Byte representation (8 bytes)
2 >>> 1
1
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1

-2 >>> 1
65
1
0
0
0
0
0
1
0
0
1
0
0
0
0
0
1
Red color to indicate sign

This operator works differently based on the sign of the first argument. It does not keep the sign of the argument. (Which means it may change) .In case of Positive numbers it works just like a signed right shift operator. For negative numbers this operator produces a positive value.

Java code to test the shift operators is below. (Please note that the code below uses 32 bytes since integer is used)

public class BitOperatorsExample {
public static void main(String[] args) {
int i = 2;
int negi = -2;
int leftShiftPositive = i << 1;   // 20
int leftShiftNegative = negi << 1;  // -4
int rightShiftPositive = i >> 1;  // 2
int rightShiftNegative = negi >> 1; // -1
int UnsignedRightShiftPositive = i >>> 1; //1
int UnsignedRightShiftNegative =  negi >>> 1; //2147483647
System.out.println(Math.pow(2, 31));
System.out.println("leftShiftPositive :"+ leftShiftPositive);
System.out.println("leftShiftNegative :"+ leftShiftNegative);
System.out.println("rightShiftPositive :"+ rightShiftPositive);
System.out.println("rightShiftNegative :"+ rightShiftNegative);
System.out.println("UnsignedRightShiftPositive :"+ UnsignedRightShiftPositive);
System.out.println("UnsignedRightShiftNegative :"+ UnsignedRightShiftNegative);
}
}

Resolve "Target runtime Apache Tomcat v6.0 is not defined." error

Go to window ->preferences ->Server->Runtime environments . add server Apache Tomcat v6.0 Mention the directory where apache-toma...