Posts

Showing posts with the label Interview Questions

SOLID Principles

SOLID  is an acronym for the first five object-oriented design (OOD) principles SOLID stands for: S - Single-responsibility Principle O - Open-closed Principle L - Liskov Substitution Principle I - Interface Segregation Principle D - Dependency Inversion Principle

Explain MySQL Index & its type ?

Indexes are used to find rows with specific column values quickly. Without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows.  Five Types of Indexes When you create an index or add one to an existing table, you’ll create it as one of several types of indexes. A unique index is one in which all column values must be unique. In a single column unique index there can be no duplication of values in the column being indexed. In a multi-column unique index the values can be duplicated in a single column, but the combination of column values in each row must be unique. You use a unique index to prevent duplicate values and you often define the index after a table has been created. A primary key is a unique index in which no value can be NULL. Every row must have a value for the column or combination of columns. You would usually define a primary key on the smallest number of columns possible because of this, and most of the time a

How does request life cycle work in Laravel?

The entry point for all requests to a Laravel application is the public/index.php file. All requests are directed to this file by your web server (Apache / Nginx) configuration. The index.php file doesn't contain much code it's just starting point for loading the rest of the framework. The index.php file loads the Composer generated autoloader definition and then retrieves an instance of the Laravel application from bootstrap/app.php script. The first action taken by Laravel itself is to create an instance of the application/service container. HTTP / Console Kernels Next, the incoming request is sent to either the HTTP kernel or the console kernel, depending on the type of request that is entering the application. These two kernels serve as the central location that all requests flow through. For now, let's just focus on the HTTP kernel, which is located in the app/Http/Kernel.php. The HTTP kernel extends the Illuminate\Foundation\Http\ Kernel class, which defines an array

What is the difference between self and static in PHP?

The main differences is that static allows late static bindings. One of the most useful scenarios that I found was for creating Base classes for Singleton Classes: class A { // Base Class     protected static $name = '';     protected static function getName() {         return static::$name;     } } class B extends A {     protected static $name = 'MyCustomNameB'; } class C extends A {     protected static $name = 'MyCustomNameC'; } echo B::getName(); // MyCustomNameB echo C::getName(); // MyCustomNameC Using return static::$name in the Base class will return what was statically attached when it was extended. If you were to use return self::$name then B::getName()  would return an empty string as that is what is declared in the Base class.

Why we need interface in PHP?

An interface allows unrelated classes to implement the same set of methods, regardless of their positions in the class inheritance hierarchy. An interface enables you to model multiple inheritance because a class can implement more than one interface whereas it can extend only one class. Interfaces are 100% abstract classes – they have methods but the methods have no ‘guts’. Interfaces cannot be instantiated – they are a construct in OOP that allows you to inject ‘qualities’ into classes .. like abstract classes. Where an abstract class can have both empty and working/concrete methods, interface methods must all be shells – that is to say, it must be left to the class (using the interface) to flesh out the methods. Interfaces allow you to define/create a common structure for your classes – to set a standard for objects. Interfaces solves the problem of single inheritance – they allow you to inject ‘qualities’ from multiple sources. Interfaces provide a flexible base/root s

What is autoload in PHP?

Autoloading is the process of automatically loading PHP classes without explicitly loading them with the require() , require_once() , include() , or include_once() functions. It's necessary to name your class files exactly the same as your classes. As of PHP 7.2.0 the __autoload() function has been deprecated. Now it is recommended to use the spl_autoload_register() for that purpose instead.

How can we prevent XSS attacks?

Preventing cross-site scripting is trivial in some cases but can be much harder depending on the complexity of the application and the ways it handles user-controllable data. In general, effectively preventing XSS vulnerabilities is likely to involve a combination of the following measures: Filter input on arrival - At the point where user input is received, filter as strictly as possible based on what is expected or valid input. Encode data on output - At the point where user-controllable data is output in HTTP responses, encode the output to prevent it from being interpreted as active content. Depending on the output context, this might require applying combinations of HTML, URL, JavaScript, and CSS encoding. Use appropriate response headers - To prevent XSS in HTTP responses that aren't intended to contain any HTML or JavaScript, you can use the Content-Type and X-Content-Type-Options headers to ensure that browsers interpret the responses in the way you intend. Co

How does XSS work?

Image
Cross-site scripting works by manipulating a vulnerable web site so that it returns malicious JavaScript to users. When the malicious code executes inside a victim's browser, the attacker can fully compromise their interaction with the application.

XSS - cross site scripting

What is the difference between XSS and CSRF? XSS involves causing a web site to return malicious JavaScript, while CSRF involves inducing a victim user to perform actions they do not intend to do. What is the difference between XSS and SQL injection?  XSS is a client-side vulnerability that targets other application users, while SQL injection is a server-side vulnerability that targets the application's database. How do I prevent XSS in PHP?  Filter your inputs with a whitelist of allowed characters and use type hints or typecasting. Escape your outputs with htmlentities and ENT_QUOTES for HTML contexts, or JavaScript Unicode escapes for JavaScript contexts. How do I prevent XSS in Java? Filter your inputs with a whitelist of allowed characters and use a library such as Google Guava to HTML-encode your output for HTML contexts, or use JavaScript Unicode escapes for JavaScript contexts

Difference between jQuery parent() and parents() method?

Image
The basic difference is the parent() function travels only one level in the DOM tree, where parents() function search through the whole DOM tree. To understand this, let's look at the below-given HTML code. When you make a call to parent() function like $("#spnText").parent() It will give you "P" as the output.parent() function selects the first parent in the DOM tree. Now,if we call parents() function like $("#spnText").parents() It will give all parents in DOM tree which are, p->dvChild->dvParent->form-> body->html. You can pass a filter in parents() function  as well to select specific parent like if you want to select both the divs then $("#spnText").parents('div');

What are magic methods in PHP?

PHP supports multiple magic methods, those methods can be identified by two underscore prefix(__).  These are special functions should be defined by the user but no need to call them explicitly. It will be called on an appropriate event occurrence. For example, class __construct() will be called while instantiating the class. PHP magic methods must be defined inside the class. Note : Declaring the constructor method private prevents external code from directly creating an object. This is handy for creating singleton classes that restrict the number of objects that can exist. PHP Magic Methods and Purposes Below are the magic methods invoked on creating Class Instance - __construct() -  The __construct() method is most commonly used magic method. Here you can do initialization you need when an object is created. You can define any number of arguments that will be passed when creating objects. __destruct()  - The __destruct() method is called when the object is destroyed

Traits in PHP

What are the Traits in Laravel? Traits are a simple group of methods that you want to include in another class. Why we use Traits? A Trait, like an abstract class, cannot be instantiated by itself. The trait is created to reduce the limitations of single inheritance in PHP by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies.

SQL Interview Questions

1) What are the usages of SQL? To execute queries against a database To retrieve data from a database To inserts records in a database To update records in a database To delete records from a database To create new databases To create new tables in a database To create views in a database 2) Does SQL support programming? No, SQL doesn't have loop or Conditional statement. It is used like commanding language to access databases. 3) What are the subsets of SQL? Data definition language (DDL) - Data definition language(DDL) allows you to CREATE, ALTER and DELETE database objects such as schema, tables, view, sequence etc. Data manipulation language (DML) - Data manipulation language makes user able to access and manipulate data. It is used to perform following operations. Insert data into database Retrieve data from the database Update data in the database Delete data from the database Data control language (DCL) - Data control

VueJs basic interview questions?

What are life cycle hooks in VueJs? beforeCreate - The first component in the creation hooks. This allows us to perform actions before our component has been added to DOM. We don't have access to DOM inside of this hook. Created -This hook is invoked when Vue has set up events and data observation. Here, events are active and access to reactive data is enabled though templates have not yet been mounted or rendered. beforeMount - The beforeMount hooks runs right before the initial render happens and after the template or render functions have been complied. Mounted - This is a most used hook and you will have full access to the reactive component, templates, and rendered DOM (via. this.$el). The most frequently used patterns are fetching data for your component. beforeUpdate - This hook runs after data changes on our component and the update cycle begins. But it runs right before the DOM is patched and re-renders. Updated - This hook runs after data changes on your compo

CodeIgniter Interview Questions

CodeIgniter is an open-source MVC based framework for PHP. It is a loosely coupled framework that we can use for the rapid development of websites and mobile APIs. 1) How to check the version of the CodeIgniter framework? In system/core/CodeIgniter.php, check CI_VERSION constant value define(‘CI_VERSION’, ‘3.0.6’); 2) How to set CSRF token in CodeIgniter? CSRF is used to set the protection in CodeIgniter. To set CSRF, you have to put the corresponding config value True. Syntax: $config['csrf_protection'] = TRUE; 3) How many types of messages you can log in to CodeIgniter? There are three message types in Codeigniter. They are : Error Messages. These are actual errors, such as PHP errors or user errors. Debug Messages. These are messages that assist in debugging. For example, if a class has been initialized, you could log this as debugging info. Informational Messages. These are the lowest priority messages, simply giving information regarding some process.

Basic PHP Interview Questions?

1) What is PHP?  PHP is a server-side scripting language that is basically used for developing dynamic web pages.  2) What is the difference between echo( ) and print ( )? echo and print are more or less the same. They are both used to output data to the screen.The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters while print can take one argument. echo is marginally faster than print.  3) What is print_r( )? This is also an output function used in PHP, It is used to display the whole array in PHP.  4) How to include files in PHP? We can include a file using "include( )" or "require( )" function with file path as its parameter. 5) What is the difference between GET and POST? We can send small data using GET method but POST method can transfer a large amount of data and POST is secure method than GET method.  7) How to declare an array in P

AJAX Interview Questions

1) What are the usages of SQL? To execute queries against a database To retrieve data from a database To inserts records in a database To update records in a database To delete records from a database To create new databases To create new tables in a database To create views in a database 2) Does SQL support programming? No, SQL doesn't have loop or Conditional statement. It is used like commanding language to access databases. 3) What are the subsets of SQL? Data definition language (DDL) - Data definition language(DDL) allows you to CREATE, ALTER and DELETE database objects such as schema, tables, view, sequence etc. Data manipulation language (DML) - Data manipulation language makes user able to access and manipulate data. It is used to perform following operations. Insert data into database Retrieve data from the database Update data in the database Delete data from the database Data control language (DCL) - Data control