Difference between revisions of "Interview Questions"

From Hawk Wiki
Jump to: navigation, search
(abstract class)
(Java)
 
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
==Some Translation==
 
==Some Translation==
n! Multiplicative
+
n! Factorial
 +
 
 
==Object-oriented programming==
 
==Object-oriented programming==
 
Check here [[Interview_Questions(OOP)]]
 
Check here [[Interview_Questions(OOP)]]
 
==C++ Interview==
 
==C++ Interview==
 
[[C++ interview]]
 
[[C++ interview]]
 +
==Javascript/Jquery==
 +
[[AJAX&Jquery]]<br>
 +
[http://{{SERVERNAME}}/downloads/designpattern/ Design Pattern]
  
 
==Algorithm Interview Problems==
 
==Algorithm Interview Problems==
 
[[Algorithm Problems]]<br>
 
[[Algorithm Problems]]<br>
 +
==Data Structure==
 
[[All about Binary search tree]]<br>
 
[[All about Binary search tree]]<br>
 
[[All about Linked List]]<br>
 
[[All about Linked List]]<br>
[[Heap & Heap Sort]]
+
[[Heap & Heap Sort]]<br>
 +
[[TRIE]]<br>
 +
[[Algorithm Sorting]]<br>
  
 
==Regular Expression ==
 
==Regular Expression ==
 
http://www.zytrax.com/tech/web/regex.htm
 
http://www.zytrax.com/tech/web/regex.htm
 
==C/C++==
 
===ArrayList Vs LinkedList===
 
ArrayList: fast random access<br>
 
slow at delete<br>
 
memory fill up issue<br>
 
LinkedList: slow random access<br>
 
quick delete<br>
 
no memory fill up issue<br>
 
complex data structure<br>
 
  
 
==PHP==
 
==PHP==
===abstract class===
+
[[PHP interview]]
Can not be Instantiable.(cannot become instant. Can only be inherited)<br>
+
==Java==
<pre>
+
[[Java interview]]
abstract class Fruit {
+
==Python==
private $color;
+
[[Python interview]]
 
+
abstract public function eat()
+
 
+
public function setColor($c) {
+
  $this->color = $c;
+
}
+
}
+
</pre>
+
 
+
<b>Difference between Abstract Class and Interface</b><br>
+
Abstract Classes<br>
+
 
+
An abstract class can provide some functionality and leave the rest for derived class<br>
+
The derived class may or may not override the concrete functions defined in base class<br>
+
The child class extended from an abstract class should logically be related<br><br>
+
Interface<br>
+
 
+
An interface cannot contain any functionality. It only contains definitions of the methods<br>
+
The derived class must provide code for all the methods defined in the interface<br>
+
Completely different and non-related classes can be logically be grouped together using an interface<br>
+
 
+
===Single or Double Quotes?===
+
<pre>
+
//Sometimes people use double quotes in PHP to avoid having to use the period to separate code. For example, you could write:
+
$color='red';
+
echo "I have a $color shirt on today<br/>";
+
//Faster however is not always better. A better way to write this code would be:
+
echo 'I have a ' .$color. ' shirt on today<br/>';
+
echo 'I have a $color shirt on today<br/>';
+
</pre>
+
Output:
+
<pre>
+
I have a red shirt on today
+
I have a red shirt on today
+
I have a $color shirt on today
+
</pre>
+
===Avoid Mysql Injection===
+
<pre>
+
$_POST['username'] = 'aidan';
+
$_POST['password'] = "' OR ''='";
+
$query = "SELECT * FROM users WHERE user='{$_POST['username']}' AND password='{$_POST['password']}'";
+
$passwd=mysql_real_escape_string($_POST['password']);
+
$passwd1=addslashes($_POST['password']);
+
echo $passwd."<br />";
+
echo $passwd1."<br />";
+
echo ($query);
+
</pre>
+
Output
+
<pre>
+
\' OR \'\'=\'
+
\' OR \'\'=\'
+
SELECT * FROM users WHERE user='aidan' AND password='' OR ''=''
+
</pre>
+
This would allow anyone to log in without a valid password.
+
===Static method===
+
Declaring class properties or methods as static makes them accessible without needing an instantiation of the class.
+
<pre>
+
<?php
+
class Foo
+
{
+
    public static $my_static = 'foo';
+
 
+
    public function staticValue() {
+
        return self::$my_static;
+
    }
+
}
+
 
+
class Bar extends Foo
+
{
+
    public function fooStatic() {
+
        return parent::$my_static;
+
    }
+
}
+
 
+
 
+
print Foo::$my_static . "\n";
+
 
+
$foo = new Foo();
+
print $foo->staticValue() . "\n";
+
print $foo->my_static . "\n";      // Undefined "Property" my_static
+
print $foo::$my_static . "\n";
+
$classname = 'Foo';
+
print $classname::$my_static . "\n"; // As of PHP 5.3.0
+
 
+
print Bar::$my_static . "\n";
+
$bar = new Bar();
+
print $bar->fooStatic() . "\n";
+
</pre>
+
 
+
==JavaScript==
+
Closure.
+
<pre>
+
<script>
+
function say667() {
+
  // Local variable that ends up within closure
+
  var num = 666;
+
 
+
  //var sayAlert = function() { alert(num); }
+
  return function() { num++; alert(num); };
+
}
+
 
+
var sayNumba = say667();
+
sayNumba();
+
sayNumba();
+
</script>
+
</pre>
+
The example will keep var num in the memory. alert 667 and 668 on each call;
+
==Swap 2 numbers in one line==
+
<pre>
+
//swap
+
$a=10;
+
$b=20;
+
$a=$a+$b-($b=$a);
+
echo $a." and ". $b."\n";
+
// output 20 and 10
+
$a^=$b^=$a^=$b; //This has a bug. You cannot do things like this $a^=$a^=$a^=$a
+
echo $a." and ". $b;
+
//output 10 and 20
+
</pre>
+
==Calculate degree between hour and minute hand==
+
<pre>
+
<?php
+
$time=array();
+
$time['h']=12;
+
$time['m']=15;
+
$time['s']=30;
+
function clockDegree($time){
+
$mPercent=((float)$time['m']+((float)$time['s']/60.0))/60.0;
+
$mDegree=$mPercent*360;
+
$hdegree=((int)$time['h']%12+(float)$mPercent)/12.0*360;
+
echo abs($mDegree-$hdegree);
+
}
+
clockDegree($time);
+
</pre>
+

Latest revision as of 00:27, 17 March 2015

Some Translation

n! Factorial

Object-oriented programming

Check here Interview_Questions(OOP)

C++ Interview

C++ interview

Javascript/Jquery

AJAX&Jquery
Design Pattern

Algorithm Interview Problems

Algorithm Problems

Data Structure

All about Binary search tree
All about Linked List
Heap & Heap Sort
TRIE
Algorithm Sorting

Regular Expression

http://www.zytrax.com/tech/web/regex.htm

PHP

PHP interview

Java

Java interview

Python

Python interview