Stack Queue Algorithm Questions

Algorithm Questions - Series 2

Stack/Queue Algorithm Questions

Balanced--symbol checker
1. Read the symbol until EOF.
2a. If the symbol is an opening symbol, put it into the stack.
2b. If it is a closing symbol:
    i. If the stack is empty, report error.
    ii. Otherwise, pop the stack, if it's not the corresponding closing symbol, report an error.
3. At the end, if there is still element in the stack, report an error.
Postfix notation
In a postfix expression, an operator always follows its operands. Brackets and parentheses are unnecessary; we can simply traverse it and compute the result.
The algorithm for evaluating any postfix expression:
* While there are input tokens left
  o Read the next token from input.
  o If the token is a value
        + Push it onto the stack.
  o Otherwise, the token is an operator (operator here includes both operators, and functions).
        + It is known a priori that the operator takes n arguments.
        + If there are fewer than n values on the stack
              # (Error) The user has not input sufficient values in the expression.
        + Else, Pop the top n values from the stack.
        + Evaluate the operator, with the values as arguments.
        + Push the returned results, if any, back onto the stack.
* If there is only one value in the stack
  o That value is the result of the calculation.
* If there are more values in the stack
  o (Error) The user input has too many values.
Infix to postfix conversion
Read the token of infix expression
If it is operand, immediately output it.
If it is open parenthesis, put it to stack.
If close parenthesis, pop back symbols until an open parenthesis appears.
If operator, pop all symbols until a symbol of lower precedence or a right-associative symbol of equal precedence appears, then push the operator.
At the end, pop all remaining stack symbols.
Q. How to use array or list to implement a stack/queue.
Q. Use a single array to implement three stacks
1. Divide the array in three equal parts and allow the individual stack to grow in that limited space.
Q. Design a stack which, in addition to push and pop, also has a function min which returns the minimum element?
Use an additional stack which keeps track of the mins.
 public void push(int value){  
  if (value <= min()) { s2.push(value); }  
  super.push(value);  
 }  
 public Integer pop() {  
  int value = super.pop();  
  if (value == min()) { s2.pop(); }  
  return value;  
 }  
Q. Implement a data structure SetOfStacks, which should be composed of several stacks, and should create a new stack once the previous one exceeds capacity.
Implement a function popAt(int index) which performs a pop operation on a specifc sub-stack
class SetOfStacks
{ ArrayList stacks = new ArrayList();}
Push operates on the last stack, if the last stack is at capacity, we need to create a new stack.
Pop also operate on the last stack, If the last stack is empty (after popping), then we should remove it from the list of stacks.
Q. Implement a queue using two stacks
S1 will be ordered with the newest elements on the top, while s2 will have the oldest elements on the top.
We push the new elements onto s1, and peek and pop from s2. When s2 is empty, we’ll transfer all the elements from s1 onto s2, in reverse order
Q. sorts a stack in ascending order.
Method signature: Stack sort(Stack s).
 public static Stack<Integer> sort(Stack<Integer> s) {  
  Stack<Integer> r = new Stack<Integer>();  
  while(!s.isEmpty()) {  
   int tmp = s.pop();  
   while(!r.isEmpty() && r.peek() > tmp) {  
    s.push(r.pop());  
   }  
   r.push(tmp);  
  }  
  return r;  
 }  

Resources

String/List Algorithm Questions

Algorithm Questions - Series 1

String/List Algorithm Questions

String
Q. Reverse a C-Style String
Q. Replace all spaces in a string with '%20' [C, C++]
Construct the new string backwards - from back to front.
Q. Find the First Non-repeated Character
Q. Deletes characters from a string. Use the prototype string removeChars( string str, string remove );
Q. Convert String to Integer
Q. Convert Integer to String
Q. Reverse the order of the words in a string
S. Reverse the whole string then iterate it to reverse each word.
Q. You are given a string like "aaaabbbcc", do an in place conversion which write frequency of each character (which come continuously) with that character. If character repeats only once, don't write '1'.
Q. You have a string "RGBBGBGR". Eliminate the pairs (two same chars adjacent to each other) recursively:
 void removePair(char[] input)   
 {   
   int len = input.length;   
   int i, j = 0;      
   for (i=1; i <= len; i++)   
   {      
     while ((input[i] == input[j]) && (j >= 0)) //Cancel pairs   
     { i++; j--; }   
     input[++j] = input[i];   
   }   
 }  
Q. Remove the duplicate characters in a string without using any additional buffer [C,C++].
1. Same technique as before, use an int to express whether the char has appeared before.
S2.
 for (int i = 1; i < len; ++i) {  
 int j;  
 for (j = 0; j < tail; ++j)   
 {if (str[i] == str[j]) break;}  
 if (j == tail) {  
 str[tail] = str[i];  
 ++tail;  
 }  
 }  
Q. Find all the characters, which are present in the character array given. The order of character should remain intact.
Q. Decide if two strings are anagrams [变位词] or not.
S. Check if the two strings have identical counts for each unique char.
1. Use an int array letters [256] to count number of each char in the first string s.
2. Iterate each char in the second string t:
If char ch doesn't exist in s, return false, else decrease the number of letters[ch] by one.
3. At last, check whether all values in letters is 0, if not return false else return true.
Q. Check if s2 is a rotation of s1 using isSubstring?
Check if length(s1) == length(s2). If not, return false
Else, concatenate s1 with itself and see whether s2 is substring of the result
Q. Determine if a string has all unique characters without using any additional buffer.
Save space usage by using an int as bit vector to express whether the char has appeared before.
 public static boolean isUniqueChars(String str)  
 {  
   int checker = 0;  
   for (int i = 0; i < str.length(); ++i)  
   {  
     int val = str.charAt(i);  
     if ((checker & (1 << val)) > 0) return false;  
     checker |= (1 << val);  
   }  
   return true;  
 }  
Q. Prints all possible ordering of the characters in a string. Treat each character in the input string as a distinct character, even if it is repeated. – Dynamic programming
Q. Combinations of a String
Print all possible combinations of the characters in a string. Two combinations that differ only in ordering of their characters are the same combination.

Array
Q. Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees in place? [TODO]
Q. Find minimum and maximum in an unsorted array in minimum number of comparisons.
Pick 2 elements at a time 1) compare the larger element with max find till now, 2) compare the smaller elements with min find till now and 3) update accordingly. – Time complexity O(3n/2).
Q1. A sorted array has been rotated, how to find the minimum element?
For a particular point, if LEFT < RIGHT, then the range does not contain the reset, if LEFT > RIGHT, then it does.
Q2. How to find an element?
Q. There is an m x n grid. One can only move either down or right at any point in time. Calculate how many possible unique paths are there and print all paths.
Paths[i][j] = paths[i][j-1] + paths[i-1][j]
Q. Find triplets in an integer array A[] which satisfy following condition:a[i]^2 + a[j]^2 = a[k]^2
Q. There is an integer array consisting positive and negative integers. Find maximum positive difference S defined as: S = a[i] - a[j] where i>j and S > 0
 void MaxDiff(int in[], int sz, int &start, int &end) {  
  int min = 0;  
  int maxDiff = 0;  
  start = end = 0;  
  for (int i = 0; i < sz; i++) {  
   if (in[i] < in[min])  min = i;  
   int diff = in[i] - in[min];  
   if (diff > maxDiff) { start = min; end = i; maxDiff = diff; }  
  }  
 }  
Q. You have an array containing only '0's and '1's. Sort this array in minimum time.
 while(j>i){  
  if(array[i] == 0){  
   i++; continue;  
  }  
  while(array[--j] == 1);  
  if(j>i) SWAP(array[i],array[j]);  
 }  

 Lo := 1; Mid := 1; Hi := N;  
 while Mid <= Hi do  
   Invariant: a[1..Lo-1]=0 and a[Lo..Mid-1]=1 and a[Hi+1..N]=2; a[Mid..Hi] are unknown.  
   case a[Mid] in  
     0: swap a[Lo] and a[Mid]; Lo++; Mid++  
     1: Mid++  
     2: swap a[Mid] and a[Hi]; Hi--  
Sort array A[], then initialize 2 pointers, one points to the head, another to the end. add elements the head and end point to, if the sum is equal with the number, return, if greater than the number, decrease end pointer by 1, else increase start by 1.
Q. There is an integer array consisting positive numbers only. Find maximum possible sum of elements such that there are no 2 consecutive elements present in the sum.
 S(i) = MAX {S(i-1), S(i-2) + T(i) }  
 S(-1) = 0,S(0) = T(0);  
 sum2 = 0;  
 sum = sum1 = array[0];  
 for(i=1; i<len; i++)  
 {  
   sum = MAX(sum2 + array[i], sum1);  
   sum2 = sum1;  
   sum1 = sum;  
 }  
Q. Print all valid parenthesis Sequences for a given number of pairs of parenthesis. -Dynamic programming
 void printbracket(char[] out, int level, int open, int close)   
 {   
   if (level == 2 *n)   
   { System.out.print(out); return; }   
   out[level] = '(';   
   if ((open + 1) <= n && open >= close)   
   { printbracket(out, level + 1, open + 1, close); }   
   out[level] = ')';   
   if ((close + 1) <= n && open >= close)   
   { printbracket(out, level + 1, open, close + 1); }   
 }  
Q. An array contains integers, every integer occurs 2 times, one integer appears only once. Find out that integer.
Q. An array contains integers, every integer occurs 3 times, one integer appears only once. Find out that integer. [TODO]
Basically, it makes use of the fact that x^x = 0. So all paired elements get XOR'd and vanish leaving the lonely element.
Since XOR operation is associative, commutative. It does not matter in what fashion elements appear in array, we still get the answer.
Linked List
Q. Remove duplicates from an unsorted linked list.
Maintain 2 pointers, "current" does a normal iteration, while "runner" iterates through all prior nodes to check for dups. whenever found one match, remove current node and break the loop - as there would be only one dup node before.
Q. Find the nth to last element of a singly linked list.
1. At first p1 points to the head, iterate to make p2 point to the nth node.
2. Check for p2->next == null, if yes return value of p1, otherwise increment p1 and p2.
Q. Only give a pointer to one node, delete it from a single linked list.
Copy the data from the next node into this node and then delete the next node.
This problem can not be solved if the node to be deleted is the last node in the linked list.
Q. Swap adjacent element in a link list
Q. You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1’s digit is at the head of the list. Write a function that adds the two numbers and returns the sum as a linked list.
 LinkedListNode addLists(LinkedListNode l1, LinkedListNode l2, int carry) {  
  if (l1 == null && l2 == null) { return null; }  
  LinkedListNode result = new LinkedListNode(carry, null, null);  
  int value = carry;  
  if (l1 != null) { value += l1.data; }  
  if (l2 != null) { value += l2.data; }  
  result.data = value % 10;  
  LinkedListNode more = addLists(l1 == null ? null : l1.next, l2 == null ? null : l2.next,          value > 10 ? 1 : 1);  
  result.setNext(more);  
  return result;  
 }  
Q. Decide whether a linked list has a loop if yes, return node at the beginning of the loop.
1. Find meeting point by moving two pointers, n1 with speed 1 and n2 with speed 2, they will end up meeting if the linked list has a loop.
2. Move n1 to Head. Keep n2 at Meeting Point. Each is k steps from the Loop Start. If they move at the same pace, they must meet at Loop Start.

Resources

Tree Algorithm Questions

Algorithm Series 4

Tree Algorithm Questions

Binary Search Tree Implementation in Java
Binary Heap Implementation
How to insert and delete from a binary search trees?
How to balance an AVL/red-black tree?
Preorder Traversal, No Recursion
void preorderTraversal( Node root ){
    Stack stack = new Stack();
    stack.push( root );
    while( true ){
        Node curr = stack.pop();
        if( curr == null ) break;
        curr.printValue();
        Node n = curr.getRight();
        if( n != null ) stack.push( n );
        n = curr.getLeft();
        if( n != null ) stack.push( n );
    }
}
1.Cursor <= root
2.While true
{    a.If cursor is not null;
              i.push in stack
              ii.Cursor <= left child of cursor
     b.end
     c.If Cursor is NULL
              i.Cursor <= top of stack
              ii.Pop from stack and print
              iii.Cursor <= Right child of cursor
     d.end
}
Push the root node to the child stack.
While child stack is not empty
Pop a node from the child stack, and push it to the parent stack.
Push its left child followed by its right child to the child stack.
Now the parent stack would have all the nodes ready to be traversed in post-order.
En-queue right child prior to left child during BFS, and put them into a stack, print the stack after BFS is done.
Check if a tree is balanced?
public static boolean isBalanced(TreeNode root){
  return (maxDepth(root) - minDepth(root) <= 1);
}
Check if a tree is binary search tree?
Check whether all node are starting at valid range of values allowed by the currentnode's ancestors.
boolean isValid(Node root) {
    return isValidHelper(root, Integer.MIN_VALUE,
                         Integer.MAX_VALUE);
}
boolean isValidHelper(Node curr, int min, int max) {
    if (curr.left != null) {
        if (curr.left.value < min ||
               !isValidHelper(curr.left, min, curr.value))
            return false;
    }
    if (curr.right != null) {
        if (curr.right.value > max ||
               !isValidHelper(curr.right, curr.value, max))
            return false;
    }
    return true;
}
Is a tree complete? [TODO]
Count number of nodes in the tree if they are less then k returns.
If (no_of_nodes(node->left) == k-1) return node->data
If (no_of_nodes(node->left) >= k) findkthmin(node->left,k)
else findkthmin(node->right, (k - no_of_nodes(node->left) -1))
Count ancestors for each of the nodes, the node whose number of ancestor is 0 is the root.
Set that node to null, and reconstruct ancestor count column and repeat above steps.
Given a sorted (increasing order) array, create a binary tree with minimal height
public static TreeNode addToTree(int arr[], int start, int end){
  if (end < start) {
    return null;
  }
  int mid = (start + end) / 2;
  TreeNode n = new TreeNode(arr[mid]);
  n.left = addToTree(arr, start, mid - 1);
  n.right = addToTree(arr, mid + 1, end);
  return n;
}
Given a binary search tree, create a linked list of all the nodes at each depth.
Find the next node (eg, in-order successor) of a given node in a binary search tree where each node has a link to its parent
public static TreeNode inorderSucc(TreeNode e) {
  if (e != null) {
    TreeNode p;
    // Found right children -> return 1st inorder node on right
    if (e.parent == null || e.right != null) {
      p = leftMostChild(e.right);
    } else {
      // Go up until we’re on left instead of right (case 2b)
      while ((p = e.parent) != null) {
        if (p.left == e) {
          break;
        }
        e = p;
      }
    }
    return p;
  }
  return null;
}
Inorder Successor in binary tree without parent pointer
http://tech-queries.blogspot.com/2010/04/inorder-succesor-in-binary-tree-wo.html
The trick is that whenever you go left in searching of that node, make the value of the variable as the value of the parent (I mean from where you go left).

Quasi-Isomorphic trees
Two trees s and t are quasi-isomorphic if s can be transformed into t by swapping left and right children of some of the nodes of s.
The values in the nodes are not important in determining quasi-isomorphism, only the shape is important.
return (quasiisomorphic(treeone->left, treetwo->left)
      && quasiisomorphic(treeone->right, treetwo->right)
      || quasiisomorphic(treeone->right, treetwo->left)
      && quasiisomorphic(treeone->left, treetwo->right));

Isomorphic trees
Two binary trees s and t are isomorphic if they have the same shape; the values stored in the nodes do not affect whether two trees are isomorphic.
return (isomorphic(treeone->left, treetwo->left)
       && isomorphic(treeone->right, treetwo->right));

Print all paths in a binary tree which sum up to that value
On every node, we look "up” to see if we’ve found the sum – bottom-up.
void findSum(TreeNode head, int sum, ArrayList buffer,
      int level) {
  if (head == null) return;
  int tmp = sum;
  buffer.add(head.data);
  for (int i = level;i >- 1; i--){
    tmp -= buffer.get(i);
    if (tmp == 0) print(buffer, i, level);
  }
  ArrayList c1 = (ArrayList) buffer.clone();
  ArrayList c2 = (ArrayList) buffer.clone();
  findSum(head.left, sum, c1, level + 1);
  findSum(head.right, sum, c2, level + 1);
}
Decide if T2 is a subtree of T1 - O(nm)
boolean containsTree(TreeNode t1, TreeNode t2) {
  if (t2 == null) return true; // The empty tree is always a subtree
  else return subTree(t1, t2);
}
boolean subTree(TreeNode r1, TreeNode r2) {
  if (r1 == null)
    return false; // big tree empty & subtree still not found.
  if (r1.data == r2.data) {
    if (matchTree(r1,r2)) return true;
  }
  return (subTree(r1.left, r2) || subTree(r1.right, r2));
}
boolean matchTree(TreeNode r1, TreeNode r2) {
  if (r2 == null && r1 == null)
    return true; // nothing left in the subtree
  if (r1 == null || r2 == null)
    return false; //  big tree empty & subtree still not found
  if (r1.data != r2.data)
    return false;  // data doesn’t match
  return (matchTree(r1.left, r2.left) &&
      matchTree(r1.right, r2.right));
  }
}
Find the Lowest common ancestor of two nodes in a binary tree 
Solution 1:
If each node has a link to its parent, we could trace p and q’s paths up until they intersect
Solution 2:
Follow a chain in which p and q are on the same side. That is, if p and
q are both on the left of the node, branch left to look for the common ancestor. When p and q are no longer on the same side, you must have found the first common ancestor.
Sub-function: test whether a node is a child of another node - use recursion
Variant:
Find the first common ancestor of two nodes in a binary search tree
Node findLowestCommonAncestor( Node root, Node p1,
                               Node p2 ){
    while( root != null ){
        int value = root.getValue();
        int value1 = p1.getValue(), value2 = p2.getValue();
        if( value > value1 && value > value2 )
        {
            if(root.getLeft()==p1 || root.getLeft()==p2) return root;
            root = root.getLeft();
        } else if( value < value1 && value < value2 ){
            if(root.getRight()==p1 || root.getRight()==p2) return root;       
            root = root.getRight();
        } else {
            return root;
        }
   }
   return null;
}
Find a path between nodesina Binary Tree
The essence is to identify the lowestcommonancestor.
Huffman code
Always merge 2 least-frequent nodes and re-put it to the priority queue.
Minimum Spanning Tree algorithm
Prim's algorithm
The set A forms a single tree. The safe edge added to A is always a least-weight edge connecting the tree to a vertex not in the tree.
The tree starts from an arbitrary root vertex r.
At each step with an edge that contributes the minimum amount possible to the tree's weight.

Resources

Greedy Algorithm

Algorithm Series 3

Greedy Algorithm

What is Greedy Algorithm?
A greedy algorithm is any algorithm that follows the problem solving heuristic of making the locally optimal choice at each stage with the hope of finding the global optimum.

Greedy algorithms do not always yield optimal solutions, but for many problems they do. For those problems which greedy algorithm does yield optimal solutions, we need prove its correctness.
How?
1.  Cast the optimization problem as one in which we make a choice and are left with one subproblem to solve.
2.  Prove that there is always an optimal solution to the original problem that makes the greedy choice, so that the greedy choice is always safe.
3.  Demonstrate that, having made the greedy choice, what remains is a subproblem with the property that if we combine an optimal solution to the subproblem with the greedy choice we have made, we arrive at an optimal solution to the original problem.
4. Prove whether the solution of greedy algorithm is globally optimal solution.

We develop our substructure with an eye toward making a greedy choice that leaves just one subproblem to solve optimally.
When to use Greedy Algorithm?
Greedy-choice property
A globally optimal solution can be arrived at by making a locally optimal (greedy) choice.
Optimal substructure

Difference between Dynamic programming
Unlike dynamic programming, which solves the subproblems bottom up, a greedy strategy usually progresses in a top-down fashion, making one greedy choice after another, reducing each given problem instance to a smaller one.
Examples
To the traveling salesman problem, greedy algorithm means: "At each stage visit the unvisited city nearest to the current city".

The fractional knapsack problem is solvable by a greedy strategy, whereas the 0–1 problem is not.

Huffman code
Always merge 2 least-frequent nodes and re-put it to the priority queue.
HUFFMAN(C)
n |C|
Q C
for i 1 to n - 1
     do allocate a new node z
        left[z] x EXTRACT-MIN (Q)
        right[z] y EXTRACT-MIN (Q)
        f [z] f [x] + f [y]
        INSERT(Q, z)
return EXTRACT-MIN(Q)

Activity-selection problem
Dynamic-programming solution
C[i,j] = max(i<k<j){C[i,k] + C[k,j] + 1} 
Add fictitious activities a0 and an+1 and adopt the conventions that f0 = 0 and sn+1 = ∞.

Converting to a greedy solution
Consider any nonempty subproblem Sij, and let am be the activity in Sij with the earliest finish time (proof by contradiction):
1.  Activity am is used in some maximum-size subset of mutually compatible activities of Sij.
2.  The subproblem Sim is empty, so that choosing am leaves the subproblem Smj as the only one that may be nonempty.
GREEDY-ACTIVITY-SELECTOR(s, f) 
n ← length[s] 
A ← {a1} 
i ← 1 
for m ← 2 to n 
     do if sm ≥ fi 
           then A ← A U {am} 
                i ← m 
return A 
Greedy solution
Always pick the one with the earliest finish time that can be legally scheduled. It maximizes the amount of unscheduled time remaining.

Minimum Spanning Tree algorithm for a connected, undirected graph- O(E*lgV)
Let (u, v) be a light edge crossing (S, V - S). Then, edge (u, v) is safe for A. - Prove by cut-and-paste technique. At each step it adds to the forest an edge of least possible weight.
Prim's algorithm
The set A forms a single tree. The safe edge added to A is always a least-weight edge connecting the tree to a vertex not in the tree. 
The tree starts from an arbitrary root vertex r.
At each step with an edge that contributes the minimum amount possible to the tree's weight.
By using Fibonacci heaps, Prim's algorithm can be sped up to run in time O(E + VlgV).
A = {(v, π[v]) : v ∈ V - {r}}.
MST-PRIM(G, w, r)
for each u ∈ V [G]
     do key[u] ← ∞
        π[u] ← NIL
key[r] ← 0
Q ← V [G]
while Q ≠ Ø
    do u ← EXTRACT-MIN(Q)
       for each v ∈ Adj[u]
           do if v ∈ Q and w(u, v) < key[v]
                 then π[v] ← u
                      key[v] ← w(u, v)

Kruskal's algorithm
The set A is a forest. The safe edge added to A is always a least-weight edge in the graph that connects two distinct components.
MST-KRUSKAL(G, w)
A ← Ø
for each vertex v ∈ V[G]
     do MAKE-SET(v)
sort the edges of E into nondecreasing order by weight w
for each edge (u, v) ∈ E, taken in nondecreasing order by weight
    do if FIND-SET(u) ≠ FIND-SET(v)
           then A ← A ∪ {(u, v)}
                UNION(u, v)
return A
Single-Source Shortest Path
For shortest-path problem of unweighted graph, breadth-first-search can be used.

Positive-weighted shortest-path problem in a weighted, directed graph
Dijkstra's algorithm
Dijkstra's algorithm maintains a set S of vertices whose final shortest-path weights from the source s have already been determined. The algorithm repeatedly selects the vertex u V - S with the minimum shortest-path estimate, adds u to S, and relaxes all edges leaving u. In the following implementation, we use a min-priority queue Q of vertices, keyed by their d values.
DIJKSTRA(G, w, s)
INITIALIZE-SINGLE-SOURCE(G, s)
S ← Ø
Q ← V[G]
while Q ≠ Ø
    do u ← EXTRACT-MIN(Q)
       S ← S ∪{u}
       for each vertex v ∈ Adj[u]
           do RELAX(u, v, w)
Negative-weighted shortest-path problem in a directed acyclic graph
Bellman-Ford algorithm [TODO]

Topological Sorting
1. Find any vertex that has no incoming edges, process it and logically remove it - lower the incoming edges for each vertex adjacent to it. - apply this strategy to the rest of the graph.

Resources

Eclipse Tips and Tricks Series 1

Eclipse Tips and Tricks Series 1

Find: ^\s*\n
Replace with: (empty)

Eclipse search and replace
Multiple line search/replace
The dot (.) is configured to _not_ match line delimiters.
If you want to find two words on two lines try: word1[\s\S]*word2

Replace log "Message" with log "Message" debug
In the Find Field: log(.*)
Int the Replace with Field: log$1 debug
$i where i is the i'th capture group.

Right click on the project -> select properties
-> Go to 'Builders' section -> Select the 'New' button -> choose 'Ant Build'
-> Use the 'Browse Workspace' buttons to choose the build file and the base directory
-> Go to the 'Targets' section -> Configure the targets for tasks: After a 'Clean', Manual Build, Auto Build.

Export specific java sources
During bug fix, we usually need export code of this change, we can do this by:
1) Add some specific mark on these files - such as the defect number listed in change history section in this file header.
2) Ctrl+f to search this keyword/mark in this project
3) In search view, select all java source files found (with Ctrl), don't select the package.
4) Export java source files as a jar: File -> Export

Excluding .svn directories when export jar
You can exclude svn-directories for all projects easily by adding the .svn/ to the Filtered resources field in the Java/Compiler/Building preferences.
E.g. Filtered Resources: *.launch, .svn/
or you can use Subclipse for Eclipse.

Configuration
Window > Preferences > Java > Code Style > Clean Up
Remove trailing space

Assign Key bindings to actions that are not assigned, such as "Generate getter and setter’", etc.
Navigate to Window -> Preferences -> General -> Keys

Import and export preferences:
Use the File -> Export / Import option to do this. Preferences like code formatting, code templates, default compiler settings etc will be readily available.

Remember more workspaces
By default eclipse remembers the last 5 workspaces used. You can increase / decrease this number by navigating to Window -> Preferences -> General -> Startup and Shutdown -> Workspaces.

What does $NON-NLS-1$ mean?
http://stackoverflow.com/questions/654037/what-does-non-nls-1-mean
They silence a warning that Eclipse emits when it encounters string literals (and has been configured to complain).

Other Eclipse Related Resources

Labels

Java (159) Lucene-Solr (110) All (60) Interview (59) J2SE (53) Algorithm (37) Eclipse (35) Soft Skills (35) Code Example (31) Linux (26) JavaScript (23) Spring (22) Windows (22) Web Development (20) Tools (19) Nutch2 (18) Bugs (17) Debug (15) Defects (14) Text Mining (14) J2EE (13) Network (13) PowerShell (11) Chrome (9) Continuous Integration (9) How to (9) Learning code (9) Performance (9) UIMA (9) html (9) Design (8) Dynamic Languages (8) Http Client (8) Maven (8) Security (8) Trouble Shooting (8) bat (8) blogger (8) Big Data (7) Google (7) Guava (7) JSON (7) Problem Solving (7) ANT (6) Coding Skills (6) Database (6) Scala (6) Shell (6) css (6) Algorithm Series (5) Cache (5) IDE (5) Lesson Learned (5) Miscs (5) Programmer Skills (5) System Design (5) Tips (5) adsense (5) xml (5) AIX (4) Code Quality (4) GAE (4) Git (4) Good Programming Practices (4) Jackson (4) Memory Usage (4) OpenNLP (4) Project Managment (4) Python (4) Spark (4) Testing (4) ads (4) regular-expression (4) Android (3) Apache Spark (3) Become a Better You (3) Concurrency (3) Eclipse RCP (3) English (3) Firefox (3) Happy Hacking (3) IBM (3) J2SE Knowledge Series (3) JAX-RS (3) Jetty (3) Restful Web Service (3) Script (3) regex (3) seo (3) .Net (2) Android Studio (2) Apache (2) Apache Procrun (2) Architecture (2) Batch (2) Build (2) Building Scalable Web Sites (2) C# (2) C/C++ (2) CSV (2) Career (2) Cassandra (2) Distributed (2) Fiddler (2) Google Drive (2) Gson (2) Html Parser (2) Http (2) Image Tools (2) JQuery (2) Jersey (2) LDAP (2) Life (2) Logging (2) Software Issues (2) Storage (2) Text Search (2) xml parser (2) AOP (1) Application Design (1) AspectJ (1) Bit Operation (1) Chrome DevTools (1) Cloud (1) Codility (1) Data Mining (1) Data Structure (1) ExceptionUtils (1) Exif (1) Feature Request (1) FindBugs (1) Greasemonkey (1) HTML5 (1) Httpd (1) I18N (1) IBM Java Thread Dump Analyzer (1) JDK Source Code (1) JDK8 (1) JMX (1) Lazy Developer (1) Mac (1) Machine Learning (1) Mobile (1) My Plan for 2010 (1) Netbeans (1) Notes (1) Operating System (1) Perl (1) Problems (1) Product Architecture (1) Programming Life (1) Quality (1) Redhat (1) Redis (1) Review (1) RxJava (1) Solutions logs (1) Team Management (1) Thread Dump Analyzer (1) Troubleshooting (1) Visualization (1) boilerpipe (1) htm (1) ongoing (1) procrun (1) rss (1)

Popular Posts