15 Interview Questions you might get in an interview as a Software Engineer
I am glad to be back after some time. In today’s article, I am a little bit deviating from what I have published so far. So in this article, I am going to discuss the most important 15 questions you might get in an interview.
Sofware Engineering interviews are somewhat tricky and also you need to have a broad knowledge of every aspect of a programming language before facing an interview. You need to have key concepts in programming languages like oop concepts, databases, data structures, deployments, and also some basics in javascript
So let’s look at 10 interview questions and answers.
Interview begins…
Most interviewers will ask to have a brief introduction to yourself while starting the interview. This is where you should show your colors to them. What you have done, what have you achieved so far, and what you are currently doing should be mentioned here clearly. The most important thing here is to show how much you love to have that job. You can take up to 5 minutes to explain all the things and also do not take more than 5 minutes as this will lead to getting bored by the interviewers.
First Question
In most interviews, there might have a logical question as to the first question. This will include writing a code from the given question or explaining a data structure to you. They will give enough time to think about this and also be prepared to answer the question. So be creative and also make sure to answer the question to the point.
As an example, I have pointed out two questions that are used in an interview.
1. Write a java program to count the characters in a sentence
This is a simple program that you can write easily and showcase your ability to code. Most probably, they might be asking what is your most confident programming language at the beginning of the interview. So there, you can tell them what’s your preferred language and start coding.
You can open up any code editor you preferred and start coding on your own with a given PC or write down it on paper. Either way, interviewers only care about what your logic and coding standards in there.
Below is the answer to writing a java program to count the characters in a sentence.
public class Main {
public static void main(String[] args) {
String sentence = "Interview Questions";
int count= 0;
for(int i=0; i< sentence.length(); i++){
if(sentence.charAt(i) == 'e'){
count++;
}
}
System.out.println("Totol 'e' in the sentence : " + count);
}
The results will be as follows.
So always try to make clean code and should be able to explain what you have done.
(There is a high probability that you will get a data structure question as to the first question. So here, you should have a better understanding of what are data structures and their implementation. Most probably the questions will be from stacks, queues, and linked lists.)
2. What are ER diagrams?. Do you have experience with database designing?
So here, you should have a basic idea of how the ER diagrams behave and make them.
ER diagrams also can be defined as Entity Relational diagrams and they are visual representations of different entities within a system and how they relate to each other.
ER diagram has mainly three components.
1. Entity
2. Attribute
3. Relationship
Maybe you asked to create an ER diagram for a project you have done recently. So here I have to take a scenario and will draw an ER diagram upon that.
Below is a simple scenario that may be given in an interview to draw. The example is taken from the https://courses.washington.edu/ past paper.
From the highlighted words, we can catch the relationship between these entities. If there is a many-to-many relationship between two entities, there should have an additional table combining these two tables. Another thing, if there is a many to one relationship between two entities, where the foreign key should be placed in the entity that has the many relationship.
3. Explain object-oriented concepts.
Interviewers will go through your theoretical knowledge of programming. A most common question in every interview is to explain the object-oriented concepts. You should have proper knowledge of oop concepts.
The answer to this question should mention four concepts in object-oriented programming. Then you need to explain to them a little and if they ask questions from them, you need to get prepared for this kind of question as well.
1. Inheritance
2. Encapsulation
3. Abstraction
4. Polymorphism
Inheritance
One object acquires all the properties of the parent object.
Encapsulation
Binding code and data together into a single unit. Keeping the fields within a class private, then providing access to them via public methods.
Abstraction
Using simple things to represent complexity. Another meaning is, hiding internal details and showing functionality.
Polymorphism
One task is performed in different ways. Use overloading and overriding to achieve polymorphism.
4. Do you know design patterns in java? Explain a design pattern that is most familiar to you using a real-world scenario.
This kind of question is very common. There are various design patterns in java that come under 3 different categories.
1. Creational Pattern
2. Structural Pattern
3. Behavioral Pattern
So from all these patterns, will discuss factory design pattern and how it is implemented in a real-world scenario.
The Factory Design Pattern is a commonly used design pattern where we need to create a Loosely Coupled System.
5. What is the key difference between java and python?
Java is a statically typed(Statically typed is a programming language characteristic in which variable types are explicitly declared and thus are determined at compile time) and compiled language, and python is a dynamically typed(A language is dynamically typed if the type is associated with run-time values, and not named variables/fields/etc) an interpreted language. This single difference makes java faster at runtime and easier to debug. But python is easier to use and easier to read.
Usages
Python is often used with new programmers or junior developers entering a data science role. The big machine learning libraries, Tensorflow and PyTorch are both written in python.
Java is used a lot for web development. It is more common among senior-level programmers. It allows for asynchronous programming and has a decent Natural Language Processing community.
Are both java and python fully object-oriented programming languages?
Python is not a pure object-oriented language as it does not support encapsulation property which is the feature of Object-Oriented Programming Languages.
Java is also not a pure object-oriented language as the primitive data types in Java are not considered objects. (primitive data types in java — int, byte, short, long, float, double, boolean, and char)
An example of a pure object-oriented language is Smalltalk where primitive data types are considered objects.
6. What is SQL injection?
SQL injection is a common attack vector that uses malicious SQL code for backend database manipulation to access information that was not intended to be displayed.
Results may be, A successful attack may result in the unauthorized viewing of user lists, the deletion of entire tables, and, in certain cases, the attacker gaining administrative rights to a database.
Ex-
An attacker wishing to execute SQL injection manipulates a standard SQL query to exploit non-validated input vulnerabilities in a database.
We use this backend API to get the people with the nic (national Id card) number of 979283732V.
The API used here is.
http://localhost/customer?nic=`979283732V` OR 1=1
So let’s see the difference there.
This will show only one value. But if we add the ‘OR 1=1’ to it, this query automatically will become true and the query will show all the values within that table.
Attackers are also able to take advantage of incorrectly filtered characters to alter SQL commands, including using a semicolon to separate two fields.
The API used here is.
http://localhost/customer?nic=`979283732V`; DROP TABLE
Select first_name, last_name
from carsalemanagement.customer
where nic = ‘979283732V’; drop table carsalemanagement.customer
This will delete the entire table in the database. So this is SQL injection and there are various methods to working.
How to avoid SQL injection?
Always use the input validation as this makes sure it is the accepted type, length, format, and so on. Only valid that passes the validation can be processed.
Avoiding administrative privilege- Don't connect your application to the database using an account with root access. This should be done only if absolutely needed since the attackers could gain access to the whole system. Even the non-administrative accounts server could place risk on an application, even more so if the database server is used by multiple applications and databases.
7. What are CORS and CSRF?
CORS is a mechanism to allow two different domains to talk to each other (by relaxing the same-origin policy), whereas the same-origin policy and CSRF token restrict domains to talk to each other.
Before the actual request is sent, a preflight request will be sent to check if the server allows domain A to send this request type. If it does, domain A will send the original request.
we have to protect the POST routes with CSRF tokens (GET routes don’t need CSRF because they can be read anyway by embedded tags as shown above. Just make sure you don’t have a state-changing get method).
If we get the URL, https://www.cors.org:9600, when changes the url like changing the HTTPS or port or even the www, then we are not in the same origin.
What if you apply not allowed cross-origin communication?
The solution for this is CORS. (Cross-Origin Resource Sharing). We can achieve this by allowing requests through the HTTP headers in the response. The browser gets the response from the server and compares the access control origin with the requested website origin and promises access to the origin if they match.
Access-Control-Allow-Origin: Allowed Origin (allow for specific)
Access-Control-Allow-Origin: * (anyone can talk to you)
You should have the feeling that these CORS are for the restrictions that exist for security reasons.
8. What is Normalization.
Normalization is the process of reducing data redundancy and eliminating undesirable characteristics like inertia, updating, and deleting anomalies. The purpose of normalization in SQL is to eliminate redundant data and ensure the data is stored logically.
The following image shows the types of normalizations.
So let’s discuss the 1st, 2nd, and 3rd Normalization as this will surely come as an interview question.
1st Normal Form Rule.
Each table cell should contain a single value.
Each record needs to be unique.
So if there is a row with multiple values in there, then this is against the 1st Normal Form rule. If this, then you need to add a separate row with each of them limiting only one value for each cell.
Ex:-
Think you have several phone numbers for a customer on a cell. This is against the 1st Normal Form and you should separate the phone numbers by adding another row or many rows including only one value for each cell.
2nd Normal Form Rule.
A composite key is a primary key composed of multiple columns used to identify a record uniquely. Think you have two people with the same name Pasan. But you can identify them easily with a column of address. Hence, we require both Full Name and Address to identify a record uniquely. That is a composite key.
To be within the 2nd normal form,
Be in 1NF
Single column primary key that does not functionally dependant on any subset of candidate key relation.
So as an example, see the below example.
We have divided our 1NF table into two tables viz. Table 1 and Table2. Table 1 contains member information. Table 2 contains information on movies rented. Records can be uniquely identified in Table 1 using membership id.
3rd Normal Form Rule.
Be in 2NF
Has no transitive funcional dependencies.
A transitive functional dependency is when changing a non-key column, might cause any of the other non-key columns to change.
If you have two columns names full name and salutation, then changing the name will change the salutation also.
We have again divided our tables and created a new table which stores Salutations. There are no transitive functional dependencies, and hence our table is in 3NF
9. What is indexing?
Indexing is used to optimize the performance of DB by minimizing the number of disk accesses required when the query is processed.
Indexes aid in the retrieval of data from databases. In essence, it accelerates select queries and where clauses. However, it decreased the performance of INSERT and UPDATE queries at the same time. As a result, we must exercise extreme caution while employing indexes.
Why indexing is not suitable for database tables which have a higher number of insert and update queries?
The index itself occupies space on disk and memory (when used). So, if space or memory are issues then too many indexes could be a problem. When data is inserted/updated/deleted, then the index needs to be maintained as well as the original data. This slows down updates and locks the tables (or parts of the tables), which can affect query processing.
10. What is the difference between SQL and NoSQL?
SQL databases are relational, NoSQL daabases are non-relational
SQL databases use structured query language and have a predefined schema. NoSQL databases have dynamic schemas for unstructured data.
SQL databases are vertically scalable, while NoSQL databases are horizontally scalable.
SQL databases are table-based, while NoSQL databases are document, key-value, graph, or wide-column stores.
SQL databases are better for multi-row transactions, while NoSQL is better for unstructured data like documents or JSON.
SQL must exhibit four ACID properties.
Atomicity — All transactions must succeed or fail.
Consistency — rules which validate and prevent corruption
Isolation — prevents concurrent transactions from affecting each other
Durability — makes transactions final. Even system failure cannot roll back the effects of a successful transaction
NoSQL must follow the CAP theorem.
Consistency — Every request receives the most recent result of an error.
Availability — Every request has a non-error result, regardless of how recent that result is.
Partition Tolerance — Any delays or losses between nodes will not interrupt the system’s operation.
11. What are closures?
In JavaScript, we need closures when a variable that is defined outside the scope in reference is accessed from some inner scope.
var num = 10;
function sum()
{
document.writeln(num+num);
}
sum();
A closure is a feature in JavaScript where an inner function has access to the outer (enclosing) function’s variables.
Function references data outside of its own scope like from the global environment or an outer function that leaves us with an open expression that references other free variables throughout the environment. A closure is not just a function, it’s a function combined without a state or lexical environment.
Usages: encapsulation
12. Difference between var, let, and const keywords in javascript.
Var — Global Scope or function scoped. The scope of the var keyword is the global or function scope. It means variables defined outside the function can be accessed globally, and variables defined inside a particular function can be accessed within the function.
let — Blocked scoped. The scope of a let variable is only block scoped. It can’t be accessible outside the particular block ({block}).
const — blocked scoped. When users declare a const variable, they need to initialize it, otherwise, it returns an error. The user cannot update the const variable once it is declared.
13. What is dependency injection?
The main idea of the dependency injection is to have to get used to the libraries or framework in our code.
Dependency is some class using another class. (Inject dependency)
A dependency is an external resource a program needs to work. These can be external libraries the code literally depends on or services the program functionally needs, like internet APIs and databases.
14. What are database anomalies?
Database anomaly is normally the flaw in databases that occurs because of poor planning and storing everything in a flat database. Generally, this is removed by the process of normalization which is performed by splitting/joining tables.
So let’s discuss three types of anomalies of insertion, update and delete anomaly.
Insertion Anomaly — An insertion anomaly occurs when we are not able to insert certain attributes in the database without the presence of other attributes.
Update Anomaly- This occurs in case of data redundancy and partial update.
Delete Anomaly — This happens by automatically deleting any other data when deleting data.
15. What are transactions in the database?
A transaction in a database system must maintain Atomicity, Consistency, Isolation, and Durability commonly named ACID properties in order to ensure accuracy completeness, and data integrity.
Atomicity — Transaction or all its operations are executed or none. There must be no state in a database where a transaction is left partially completed.
Consistency — The database must remain in a consistent state after any transaction. No transaction should have any adverse effect on the data residing in the database.
Durability — The database should be durable enough to hold all its latest updates even if the system fails or restarts.
Isolation — In a database system where more than one transaction is being executed simultaneously and in parallel. No transaction will affect the existence of any other transaction.
The following commands are used to control the transactions.
COMMIT — to save the changes
ROLLBACK — to roll back the changes
SAVEPOINT — create points within the groups of transactions in which to rollback
SET TRANSACTION — places a name on a transaction.
So here is the end of 15 questions that you might be getting in an interview. Some of them are a little bit difficult, but once you know the theory inside them, you can answer these questions easily. Hope you understand all and have a nice day!