The following short quiz consists of 4 questions and will tell you whether you are qualified to be a professional. The questions are NOT that difficult.

1. How do you put a giraffe into a refrigerator?

Correct Answer: Open the refrigerator, put in the giraffe, and close the door. This question tests whether you tend to do simple things in an overly complicated way.

2. How do you put an elephant into a refrigerator?

Did you say, Open the refrigerator, put in the elephant, and close the refrigerator?

Wrong Answer.

Correct Answer: Open the refrigerator, take out the giraffe, put in the elephant and close the door. This tests your ability to think through the repercussions of your previous actions.

3. The Lion King is hosting an animal conference. All the animals attend…. except one. Which animal does not attend?

Correct Answer: The Elephant. The elephant is in the refrigerator. You just put him in there. This tests your memory.

Okay, even if you did not answer the first three questions correctly, you still have one more chance to show your true abilities.

4. There is a river you must cross but it is used by crocodiles, and you do not have a boat. How do you manage it?

Correct Answer: You jump into the river and swim across. Have you not been listening? All the crocodiles are attending the Animal Meeting. This tests whether you learn quickly from your mistakes.

In java String Builder Should be Used in case you need to perform concatenate more string together.

i.e

 public String toString()
 {
    return  a + b + c ;
 }

For the above code using + will be converted to

a = new StringBuilder()
    .append(a).append(b).append(c)
    .toString();

For the above case you can use concat as below but since + will be converted as String Builder its better to use + rather than concat.

 public String toString()
 {
    return  a.concat(b).concat(c);
 }

The key is whether you are writing a single concatenation all in one place or accumulating it over time.

There's no point in explicitly using StringBuilder.

But if you are building a string e.g. inside a loop, use StringBuilder.

To clarify, assuming that hugeArray contains thousands of strings, code like this:

...
String result = "";
for (String s : hugeArray) {
    result = result + s;
}

It should be as below

 ...
StringBuilder sb = new StringBuilder();

for (String s : hugeArray) {
    sb.append(s);
}
String result = sb.toString();

Common elements in two arrays javascript

arrNum1 = new Array(1,2,3);
arrNum2 = new Array(2,3,4,5);
arrNum3 = new Array();

arrNum3 =  intersect_safe(arrNum1, arrNum2);

for(i=0;i<arrNum3.length;i++)
 alert(arrNum3[i]);

function intersect_safe(a, b)
{
  var ai=0, bi=0;
  var result = new Array();

   while(ai<a.length && bi < b.length )
  {
     if(a[ai] != b[bi])
     { 
       bi++; 
     }
     else
     {
       result.push(a[ai]);
       ai++;
       bi++;
     }
  }

  return result;
}
var arr = new Array();
arr[0] = 100;
arr[1] = 0;
arr[2] = 50;

Array.prototype.max = function() {
  return Math.max.apply(null, this)
}

Array.prototype.min = function() {
  return Math.min.apply(null, this)
}

var min = Math.min.apply(null, arr),
    max = Math.max.apply(null, arr);

To find the Maximum value in Array Use Below

 var max_of_array = Math.max.apply(Math, array);
CREATE TABLE ipaddress(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
                       date VARCHAR(255),
                       ip VARCHAR(255));

INSERT INTO ipaddress(date, ip)
               VALUES('1-1-2012', '195.165.1.2'),
                     ('1-1-2012', '195.165.1.3'),
                     ('12-2-2012', '195.165.1.8');

Total number of Visits should be grouped based on IP Address

SELECT COUNT(ip), MONTHNAME(STR_TO_DATE(date, '%c-%e-%Y')) as period
  FROM ipaddress
 GROUP BY period;
package com.javadb2.mugil.employee;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.javadb2.mugil.db.display;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;

public class update
{	 
	public static void main(String args[])
	{
	  bean objBean = new bean();
	  objBean.setEmpId(Integer.parseInt(getInput("Enter Employee Id :")));
	  objBean.setEmpName((String)getInput("Enter Employee Name:"));
	  objBean.setEmpSalary(Integer.parseInt(getInput("Salary")));
	  updateValues(objBean);
	}
	
	public static void updateValues(bean objBean)
	{	
		System.out.println(objBean.getEmpName());
		System.out.println(objBean.getEmpSalary());
		
		String strSQL = "UPDATE employeelist" +
				"   SET empname = ? ," +
				"       salary  = ?" +
				" WHERE empid = ?";
		
		try 
		{
			Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "pass");
			PreparedStatement stmt = (PreparedStatement) conn.prepareStatement(strSQL);
			
			stmt.setString(1, objBean.getEmpName());
			stmt.setDouble(2, objBean.getEmpSalary());
			stmt.setInt(3, objBean.getEmpId());
			
			int affected = stmt.executeUpdate();
						
			if(affected == 1)
			{
 			  System.out.println("Updated Successfully");
			}
			else
			{
			  System.err.println("Unable to Update Employee");
			}
		} 
		catch (SQLException e) 
		{
		  e.printStackTrace();
		}
	}

	public static String getInput(String prompt)
	{
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		
		System.out.print(prompt);
		System.out.flush();
		
		try 
		{
			return stdin.readLine();
		} 
		catch (Exception e) 
		{
			// TODO: handle exception
			return e.getMessage();
		}
	}
}	

Database Table

 CREATE TABLE employeeList(empid int not null primary key auto_increment,
                           empname varchar(255),
                           salary  double);

Bean Class

package com.javadb2.mugil.employee;

public class bean
{
  private int  empId;
  private String  empName;
  private double  empSalary;
	
  public int getEmpId() 
  {
    return empId;
  }
	
  public void setEmpId(int empId) 
  {
    this.empId = empId;
  }
	
  public String getEmpName() 
  {
    return empName;
  }
  
  public void setEmpName(String empName) 
  {
    this.empName = empName;
  }
  
  public double getEmpSalary() 
  {
    return empSalary;
  }

  public void setEmpSalary(double empSalary) 
  {
    this.empSalary = empSalary;
  }
}

Crud Operation with Bean Class

 package com.javadb2.mugil.employee;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.javadb2.mugil.db.display;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.Statement;

public class insert
{	
  public static void main(String[] args) 
  {
    bean objBean = new bean();
		
    objBean.setEmpName(display.getInput("Enter the Employee Name"));
    objBean.setEmpSalary(Integer.parseInt(display.getInput("Enter Salary")));
		
    boolean result = getInsertedKey(objBean);
		
    if(result)
    {
      System.out.println("The Last Inserted Primary Key is "+objBean.getEmpId());			 
    }
   }
	
   public static boolean getInsertedKey(bean objBean)
   {	
     ResultSet keys = null;
		
     String strSQL = "INSERT INTO employeeList(empname, salary)VALUES(?,?)";		
		
     try 
     {
	Connection conn 	= getConnection();
	PreparedStatement stmt 	= (PreparedStatement) conn.prepareStatement(strSQL, Statement.RETURN_GENERATED_KEYS);
			
	stmt.setString(1, objBean.getEmpName());
	stmt.setDouble(2, objBean.getEmpSalary());
			
	int affected = stmt.executeUpdate();
			
	if(affected == 1)
	{
  	   keys = stmt.getGeneratedKeys();
	   keys.next();
	   int newkey = keys.getInt(1);
	   objBean.setEmpId(newkey);
	}
	else
	{
	   System.err.println("Unable to Update Values");
	   return false;
	}
      }
      catch (SQLException e) 
      {
	 processException(e);
	 System.err.println("Error in Establishing Connection");
      }
		
      return true;
  }
	
  public static Connection getConnection() throws SQLException
  {
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "pass");
    return conn;
  }
	
  public static void processException(SQLException e)
  {
     System.err.println("Error Message "+e.getMessage());
     System.err.println("Error Code"+e.getErrorCode());
     System.err.println("SQL State"+e.getSQLState());
  }
}