What is the difference between forking a process and spawning a thread? 
When you fork a process, the new process will run the same code as parent process but in different memory space, but when you spawn a new thread in existing process, it just creates another independent path of execution but share same memory space.

What is a critical section? 

A critical section is the part of a code, which is very important and in multi-threading must be exclusively modified by any thread. Semaphore or mutex is used to protect critical section. In Java, you can use synchronized keyword or ReentrantLock to protect a critical section.

Difference-between-shallow-copy-vs-deep-copy

Difference Between Shallow Copy Vs Deep Copy In Java

Difference between valid and well-formed XML?
A well-formed XML is the one which has root element and all tags are closed properly, attributes are defined properly, their value is also quoted properly. On another hand, a valid XML is the one which can be validated against an XSD file or schema. So it’s possible for an XML to be well-formed but not valid because they contain tags which may not be allowed by their schema.

Difference between DOM and SAX parser? 
DOM parser is an in-memory parser so it loads whole XML file in memory and create a DOM tree to parse. SAX parser is an event based parser, so it parses XML document based on the event received e.g. opening tag, closing tag, the start of attribute or end of the attribute. Because of their working methodology, DOM parser is not suitable for large XML file as they will take a lot of space in memory and your process may run out of memory, SAX is the one which should be used to parse large files. For small files, DOM is usually much faster than SAX.

Difference between Thread & Process in Java ?

In the Java programming language, concurrent programming is mostly concerned with threads.

  • A computer system normally has many active processes and threads.
  • This is true even in systems that only have a single execution core, and thus only have one thread actually executing at any given moment.
  • Processing time for a single core is shared among processes and threads through an OS feature called time slicing.

Process:

  • Process is a program in execution.
  • A process has a self-contained execution environment.
  • A process generally has a complete, private set of basic run-time resources; in particular, each process has its own memory space.
  • To facilitate communication between processes, most operating systems support Inter Process Communication (IPC) resources, such as pipes and sockets.
  • IPC is used not just for communication between processes on the same system, but processes on different systems.
  • To facilitate communication between processes, most operating systems support Inter Process Communication (IPC) resources, such as pipes and sockets.
  • IPC is used not just for communication between processes on the same system, but processes on different systems.
  • If you run a Java program in UNIX and if that program creates 10 Threads, it still one process and you can find that by using ps -ef | grep processname.

Threads:

  • Threads are sometimes called lightweight processes.
  • Both processes and threads provide an execution environment, but creating a new thread requires fewer resources than creating a new process.
  • Each process has its own separate memory space but Threads from same process same memory space.
  • Threads exist within a processevery process has at least one.
  • Threads share the process’s resources, including memory and open files. This makes for efficient, but potentially problematic, communication( think about thread safety).
  • From the application programmer’s point of view, you start with just one thread, called the main thread.

What is an immutable class?

  • A class is said to be Immutable if its state cannot be changed once created,
  • for example, String in Java is immutable.
  • Once you create a String say “Java”, you cannot change its content. Any modification in this string e.g. converting into upper case,  concatenating with another String will result in the new object.
  • An immutable object is very useful for concurrent programming because they can be shared between multiple threads without worrying about synchronization. In fact, the whole model of functional programming is built on top of Immutable objects.
  • Must read: https://codinko.wordpress.com/2015/10/26/final-and-immutable-in-java/

What is SQL injection & how to prevent it?

  • SQL injection is a security vulnerability which allows an intruder to steal data from the system.
  • Any system which takes input from the user and creates SQL query without validating or sanitizing that input is vulnerable to SQL injection. In such system, an intruder can inject SQL code instead of data to retrieve more than expected data. There are many instances on which sensitive information are stolen by exploiting this vulnerability.

In Java, you can avoid SQL injection by using Prepared statement.

What is the difference between an inner join and a left join in SQL? 
In SQL, there are mainly two types of joins, inner join, and outer join.

Outer joins can be two types right outer join and left outer join.

The main difference between inner join and left join is that in
inner join :- only matching records from both tables are selected
left join:- , all records from left table are selected in addition to matching records from both tables.

Always watch out for queries which have “all” in it, they usually require left join
e.g. to write SQL query to find all departments and a number of employees on it. If you use inner join to solve this query, you will miss empty departments where no one works.

What is loose-coupling?
Loose coupling is a desirable quality of software, which allows one part of the software to modify without affecting another part of the software. For example, in a loosely coupled software, a change in UI layout should not affect the back-end class structure

What is the difference between composition, aggregation, and association? 

  • Association means two objects are related to each other but can exist without each other
  • Composition is a form of association where one object is composed of multiple objects, but they only exists together
  • Aggregation is a collection of objects.

Can you describe three different kinds of testing that might be performed on an application before it goes live?

  • unit testing, integration testing and smoke testing.
  • Unit testing is used to test individual units to verify whether they are working as expected, integration testing is done to verify whether individually tested module can work together or not and smoke testing is a way to test whether most common functionality of software is working properly or not e.g. in a cab ordering website, you should be able to book or  cancel the cabs.

What is difference between & and && operator? 

  • bitwise operator (&) can be applied to both integer and boolean
  • logical operator (&&) can only be applied to boolean variables.
  • When you do a & b then AND operator is applied to each bit of both integer number, while in the case of a && b, the second argument may or may not be evaluated, that’s why it is also known as short circuit operator

How do you get the last digit of an integer? 
By using modulus operator, number % 10 returns the last digit of the number,
for example, 1234%10 will return 4

Similarly, division operator can be used to get rid of the last digit of  a number e.g. 1234/10 will give 123

This is an important technique to know and useful to solve problems like number palindrome or reversing numbers.

Object Oriented Design Principles?

https://codinko.wordpress.com/2015/12/10/java-object-oriented-design-principles/

What is the difference between a binary tree and a binary search tree?

Binary search tree is an ordered binary tree, where the value of all nodes in the left tree are less than or equal to node and values of all nodes in right subtree is greater than or equal to the node (e.g. root). It’s an important data structure and can be used to represent a sorted structure.

What is time complexity of an algorithm?

Time complexity specifies the ratio of time to the input.

  • It shows how much time an algorithm will take to complete for a given number of input.
  • It’s approximated valued but enough to give you an indication that how your algorithm will perform if the number of input is increased from 1 to 1 million.

Basic differences between a linked list and an array? 

  • The most significant difference between them is that array stores its element at the contiguous location while linked list stores its data anywhere in memory.
  • This gives linked list enormous flexibility to expand itself because memory is always scattered.
  • It’s always possible that you wouldn’t be able to create an array to store 1M integers but can do by using linked list because space is available but not as contiguous chunk.
  • All other differences are the result of this fact. For example, you can search an element in array with O(1) time if you know the index but searching will take O(n) time in linked list.

Advanced: https://codinko.wordpress.com/2019/09/22/linkedlist-get-vs-arraylist-get/

Various ways to resolve collision in the hash table? 
linear probing, double hashing, and chaining. In linear probing, if the bucket is already occupied then function check next bucket linearly until it finds an empty one, while in chaining, multiple elements are stored in same bucket location.

What is a regular expression? 
A regular expression is a way to perform pattern matching on text data.

  • It’s very powerful tool to find something e.g. some character in a long string e.g. finding if a string contains some word or not.
  • Java supports  regular expression using java.util.regex package.
  • You can use the regular expression to check if an email is valid or not, if a phone number is valid, or if a zip code is valid, or to check if a String contains a number or not.
  • Though java.lang.String class provides a couple of methods with an inbuilt support of regular expression e.g.split method, replaceAll() and  matches method, which can be used for this purpose, but they have a drawback.
    They create a new regular expression pattern object, every time you call.
    Since most of the time we can just reuse the pattern, we don’t need to spend time on creating and compiling pattern, which is expensive compared to testing a String against the pattern.
  • For reusable patterns, you can take help of java.util.regex package,
    it provides two class Pattern and Matcher to create pattern and check String against that pattern.

eg:

import java.util.regex.Matcher;
import java.util.regex.Pattern;
// Regular expression pattern to test input
String regex = “(.)*(\\d)(.)*”;      
Pattern pattern = Pattern.compile(regex); // don’t do this inside a loop as creating pattern                                                                                  is expensive.

Matcher matcher = pattern.matcher(input);
boolean isMatch = matcher.matches();

What is a stateless system?

A stateless system is a system which doesn’t maintain any internal state. Such system will produce the same output for same input at any point of time. It’s always easier to code and optimize a stateless system, so you should always strive for one if possible.