Keyword

Result: 158 questions

What is the process to create a table in R language without using external files?

Answer:

MyTable= data.frame ()

 edit (MyTable)

The above code will open an Excel Spreadsheet for entering data into MyTable.

Learn Data Science in R Programming to land a top gig as an Enterprise Data Scientist!

View

How would you implement a stack and a queue in Go? Explain and provide code examples.

Answer:

You use slices to implement a stack or queue by yourself:

type Stack []int
func (s Stack) Empty() bool { return len(s) == 0 }
func (s *Stack) Push(v int) { (*s) = append((*s), v) }
func (s *Stack) Pop() int {
	v := (*s)[len(*s)-1]
	(*s) = (*s)[:len(*s)-1]
	return v
}

type Queue []int
func (q Queue) Empty() bool    { return len(q) == 0 }
func (q *Queue) Enqueue(v int) { (*q) = append((*q), v) }
func (q *Queue) Dequeue() int {
	v := (*q)[0]
	(*q) = (*q)[1:len(*q)]
	return v
}

func main() {
	s := Stack{}
	s.Push(1)
	s.Push(2)
	fmt.Println(s.Pop())
	fmt.Println(s.Pop())
	fmt.Println(s.Empty())
	// Output:
	// 2
	// 1
	// true

	q := Queue{}
	q.Enqueue(1)
	q.Enqueue(2)
	fmt.Println(q.Dequeue())
	fmt.Println(q.Dequeue())
	fmt.Println(q.Empty())
	// Output:
	// 1
	// 2
	// true
}

The queue implementation above is correct, but it is suboptimal. There are better but lengthier implementations, like this one.

Occasionally, you would prefer the Go standard library’s container/list to implement them for their conciseness, genericity, and extra list data structure related operations:

stack := list.New()
stack.PushBack(1)
stack.PushBack(2)
fmt.Println(stack.Remove(stack.Back()))
fmt.Println(stack.Remove(stack.Back()))
fmt.Println(stack.Len() == 0)
// Output:
// 2
// 1
// true

queue := list.New()
queue.PushBack(1)
queue.PushBack(2)
fmt.Println(queue.Remove(queue.Front()))
fmt.Println(queue.Remove(queue.Front()))
fmt.Println(queue.Len() == 0)
// Output:
// 1
// 2
// true

Although, their usage is generally discouraged for their slower performance, compared to slices iteration pattern. Let’s compare the two following examples:

// Iterate through a list and print its contents.
for e := queue.Front(); e != nil; e = e.Next() {
    fmt.Println(e.Value)
}
for _, e := range queue {
    fmt.Println(e)
}

“Always use a slice.”, Dave Cheney

Another possibility to implement a queue is to use buffered channels, but this is never a good idea, because:

  1. The buffer size is determined at the channel creation and cannot be increased.
  2. It is impossible to peek at the next queue element without retrieving it from the queue.
  3. There is a risk of deadlock: “Novices are sometimes tempted to use buffered channels within a single goroutine as a queue, lured by their pleasingly simple syntax, but this is a mistake. Channels are deeply connected to goroutine scheduling, and without another goroutine receiving from the channel, a sender—and perhaps the whole program—risks becoming blocked forever. If all you need is a simple queue, make one using a slice.”, Brian Kernighan.
View

What is Object Oriented Programming?

Answer:

This is usually a pretty open ended question. You should understand classes (objects are instantiated classes), abstract classes, interfaces, methods, properties,inheritance, multiple inheritance as well as why OOP is helpful as compared to procedural programming.

http://net.tutsplus.com/tutorials/php/object-oriented-php-for-beginners/

View

What is MVC?

Answer:

Most programmers know this, but interviewers will likely look for a deep understanding of MVC, and some explanation or examples on how/why/ when you used it. 

MVC - Model, View, Controller - is simply a way of organizing your code into 3 separate layers each with there own job. 

Model - Usually contains data access code and all of you business logic code. 
View - Contains markup/design code, generally html,xml, json. 
Controller - Usually contains very little code, just whatever is needed to call the Model code and render the View code.

http://www.symfony-project.org/book/1_0/02-exploring-symfony-s-code

View

What are some of the big changes PHP has gone through in the past few years?

Answer:

There are a number, but the big ones people are looking for are: 
a. PHP 5.0 realised the object model (AKA OOP).
b. 5.1 added PDO - for accessing databases.
c. 5.3 - added namespace support and late static bindings.

http://en.wikipedia.org/wiki/PHP#Release_history

View

What is the difference between $_GET and $_POST

This is a great question because an interviewer can tell how deeply you understand HTTP and the request/response. If you don't have good understanding of HTTP protocol, google around and get a grasp on it. 
Good answer 
Explain the HTTP protocol and how every request contains a method, generally(GET,POST,PUT,DELETE) and what each method signifies. 
Bad answer 
$_GET stores variables passed in url as query strings. $_POST stores variables past from using method = $_POST 

http://djce.org.uk/dumprequest

View

In a PHP class what are the three visibility keywords of a property or method?

Answer:

public, private and protected. The default is public. 
Public -> Any class may instantiate the class and call the method or property. 
Protected -> Only the class itself or inherited (children) classes may call a method or property.
Private -> Only the class itself may call a method or property.

http://php.net/manual/en/language.oop5.visibility.php

View

What is Polymorphism?

Answer:

Don't get scared by the big word. It's simply the idea that one object can can take on many forms. So in PHP OOP one class "cars" may have two classes that extend it, for example a "Honda" class and a "BMW" class.

http://stackoverflow.com/questions/210460/try-to-describe-polymorphism-as-easy-as-you-can

View

How do you load classes in PHP?

Answer:

They are trying to gauge your understanding of how class auto loading works. Review the "autoload" and "spl_autoload_register" function (note:you should use the later). The autoload function basically triggers a function when a class is instantiated, you can put whatever logic you like in it but generally you want to include the class file based on some sort of naming convention.

http://www.php.net/manual/en/function.spl-autoload-register.php

View

What is the value of "$day" in the below code?

Answer:

$wed= 1;    
$day = ($wed==1) ? 'today' : 'tommorrow';
// $day is now set to 'today'

Companies often ask about the ternary operator (?). which is simply a shorthand for if else statements.

http://davidwalsh.name/php-shorthand-if-else-ternary-operators

View

What is the Scope Resolution Operator?

Answer:

"::" double colons is the scope operator it is used to call methods of a class that has not been instantiated. You should also understand static methods and how they differ from regular methods.

http://www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php 
http://php.net/manual/en/language.oop5.static.php

View

What are some PHP Design patterns you have worked with?

Answer:

Design patterns are simply commonly used techniques within your code, they often are implemented in different ways so they can be a bit tricky to grasp without writing them yourself. If you are unfamiliar with them I would start by learning the Singleton Pattern and the Strategy Pattern.

http://www.ibm.com/developerworks/library/os-php-designptrns/

View

What is the difference between single-quoted and double-quoted strings in PHP?

Answer:

PHP strings can be specified not just in two ways, but in four ways.

  1. Single quoted strings will display things almost completely "as is." Variables and most escape sequences will not be interpreted. The exception is that to display a literal single quote, you can escape it with a back slash \', and to display a back slash, you can escape it with another backslash \\ (So yes, even single quoted strings are parsed).
  2. Double quote strings will display a host of escaped characters (including some regexes), and variables in the strings will be evaluated. An important point here is that you can use curly braces to isolate the name of the variable you want evaluated. For example let's say you have the variable $type and you what to echo "The $types are" That will look for the variable $types. To get around this use echo "The {$type}s are" You can put the left brace before or after the dollar sign. Take a look at string parsing to see how to use array variables and such.
  3. Heredoc string syntax works like double quoted strings. It starts with <<<. After this operator, an identifier is provided, then a newline. The string itself follows, and then the same identifier again to close the quotation. You don't need to escape quotes in this syntax.
  4. Nowdoc (since PHP 5.3.0) string syntax works essentially like single quoted strings. The difference is that not even single quotes or backslashes have to be escaped. A nowdoc is identified with the same <<< sequence used for heredocs, but the identifier which follows is enclosed in single quotes, e.g. <<<'EOT'No parsing is done in nowdoc.

Speed:
I would not put too much weight on single quotes being faster than double quotes. They probably are faster in certain situations. Here's an article explaining one manner in which single and double quotes are essentially equally fast since PHP 4.3 (Useless Optimizations toward the bottom, section C). Also, this benchmarks page has a single vs double quote comparison. Most of the comparisons are the same. There is one comparison where double quotes are slower than single quotes.

View

What does ob_start do?

Answer:

Makes it so PHP does not output anything. Companies ask this because many large frameworks wrap a bunch of code in ob_start() and ob_get_clean(). So understanding how that function works is pretty important.

http://myphpsource.blogspot.com/2010/01/obstart-save-php-output-to-string-php.html

View

What does "&" mean in '&$var' ?

Answer:

'&' indicates a reference

http://schlueters.de/blog/archives/125-Do-not-use-PHP-references.html

View

What is the meaning of a final class and a final method?

Answer:

Final keywords indicates that the class or method cannot be extended.

http://php.net/manual/en/language.oop5.final.php

View

Does PHP support multiple inheritance?

Answer:

No. You should understand what multiple inheritance is.

http://en.wikipedia.org/wiki/Multiple_inheritance

View

What are some magic methods in PHP, how might you use them?

Answer:

Magic methods are basically triggers that occur when particular events happen in your coding. __GET, __SET are magic methods that are called (behind the seen) when you get or set a class property.

http://php.net/manual/en/language.oop5.magic.php

View

Are objects in PHP 5 passed by value or reference?

Answer:

This is basically a trick questions. To understand how they are passed you need to understand how objects are instantiated. Study the below link:

http://ca2.php.net/manual/en/language.oop5.references.php

View

What is the difference between $var and $$var?

Answer:

$$var sets the value of $var as a variable.

            $day='monday';
            $$day='first day of week';
            echo $monday; //outputs 'first day of week'
            

http://us2.php.net/manual/en/language.variables.variable.php

View

© 2017 QuizBucket.org