0% found this document useful (0 votes)
10 views12 pages

Tech Interview Qs

Uploaded by

shreanvitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views12 pages

Tech Interview Qs

Uploaded by

shreanvitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

TECHNICAL INTERVIEW QUESTIONS

JAVA

1. **What is Java?**
- Java is a high-level, object-oriented programming language designed to have as few
implementation dependencies as possible.

2. **What are the main features of Java?**


- Platform-independent, object-oriented, secure, robust, multithreaded, and high
performance.

3. **What is the JVM?**


- The Java Virtual Machine (JVM) is an engine that provides a runtime environment to
execute Java bytecode.

4. **What are JDK and JRE?**


- JDK (Java Development Kit) is a software development kit for Java, while JRE (Java
Runtime Environment) provides the libraries, Java Virtual Machine (JVM), and other
components to run applications written in Java.

5. **What are Java's access speci ers?**


- `public`, `protected`, `default` (package-private), and `private`.

6. **What is garbage collection in Java?**


- The process by which the JVM automatically removes unused objects from memory to
free up resources.

7. **What is the nalize() method?**


- A method called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.

8. **What are the types of memory areas allocated by JVM?**


- Heap, Stack, Method Area, Program Counter Register, and Native Method Stack.
fi
fi
9. **What is the di erence between an interface and an abstract class?**
- An interface can have only abstract methods and static nal variables, while an
abstract class can have both abstract and concrete methods.

10. **How do ArrayList, LinkedList, HashMap, HashSet, TreeMap, and TreeSet di er?**
- `ArrayList`: Resizable array implementation.
- `LinkedList`: Doubly linked list implementation.
- `HashMap`: Hash table-based implementation.
- `HashSet`: Hash table-based set.
- `TreeMap`: Red-Black tree-based map.
- `TreeSet`: Red-Black tree-based set.

11. **How does the HashMap work internally?**


- Uses an array of buckets where each bucket is a linked list; the key's hash code
determines the bucket.

12. **What are the di erences between fail-fast and fail-safe iterators?**
- Fail-fast: Immediately throws `ConcurrentModi cationException` if the collection is
modi ed.
- Fail-safe: Works on a copy of the collection, allowing modi cations without exception.

13. **What is multithreading in Java?**


- The ability of a CPU or a single core in a multi-core processor to execute multiple
threads concurrently.

14. **What are the di erent ways to create a thread in Java?**


- Extending `Thread` class or implementing `Runnable` interface.

15. **What is synchronization in Java?**


- A mechanism that ensures that only one thread can access a resource at a time.

16. **What is a deadlock in Java?**


- A condition where two or more threads are blocked forever, each waiting for the other
to release a resource.
fi
ff
ff
ff
fi
fi
fi
ff
17. **What are thread-safe collections in Java?**
- Collections like `ConcurrentHashMap`, `CopyOnWriteArrayList`, and
`CopyOnWriteArraySet` that are designed to be safely used by multiple threads.

18. **What are threads, and how are they di erent from processes?**
- Threads are the smallest unit of execution within a process, while processes are
instances of programs that can contain multiple threads.

19. **Explain synchronized, volatile, wait(), notify(), and notifyAll().**


- `synchronized`: Prevents concurrent access.
- `volatile`: Ensures visibility of changes to variables across threads.
- `wait()`: Causes the current thread to wait until another thread invokes `notify()` or
`notifyAll()`.
- `notify()`: Wakes up one waiting thread.
- `notifyAll()`: Wakes up all waiting threads.

20. **What are thread pools, and how do you create them using the ExecutorService?**
- A thread pool reuses a xed number of threads to execute tasks, created using
`Executors.newFixedThreadPool()`, `newCachedThreadPool()`, etc.

21. **What are checked and unchecked exceptions?**


- Checked: Checked at compile-time (e.g., `IOException`).
- Unchecked: Checked at runtime (e.g., `NullPointerException`).

22. **How does the try-catch- nally block work?**


- `try`: Contains code that might throw an exception.
- `catch`: Catches and handles exceptions.
- ` nally`: Executes code regardless of whether an exception was thrown.

23. **What is the di erence between throw and throws?**


- `throw`: Used to explicitly throw an exception.
- `throws`: Declares that a method might throw an exception.

24. **Explain the Java memory model.**


fi
ff
fi
fi
ff
- Speci es how the Java virtual machine works with computer memory (RAM) and
ensures visibility of memory operations across threads.

25. **What is garbage collection, and how does it work?**


- The process of automatically detecting and freeing up memory that is no longer in use
by the application.

26. **What are strong, weak, soft, and phantom references?**


- `Strong`: Default reference type.
- `Weak`: Doesn't prevent garbage collection.
- `Soft`: Collected only when memory is low.
- `Phantom`: Used to track object nalization.

27. **Explain lambda expressions and functional interfaces in Java 8.**


- Lambda expressions: Shorter syntax for anonymous classes.
- Functional interfaces: Interfaces with a single abstract method (e.g., `Runnable`).

28. **What are streams in Java 8, and how do you use them?**
- Streams: Enable functional-style operations on sequences of elements.
- Used for processing collections through a pipeline of operations like ` lter()`, `map()`,
and `collect()`.

29. **How do Optional and the new date/time API work in Java 8?**
- `Optional`: Container object used to avoid null checks.
- New date/time API: Provides a comprehensive date/time handling with `LocalDate`,
`LocalTime`, `ZonedDateTime`, etc.

30. **What are the Singleton, Factory, Builder, and Observer design patterns?**
- Singleton: Ensures a class has only one instance.
- Factory: Creates objects without specifying the exact class.
- Builder: Simpli es object creation with complex constructors.
- Observer: Allows an object to notify observers of state changes.

31. **When would you use Dependency Injection?**


fi
fi
fi
fi
- To decouple the creation of dependencies from the use of an object, promoting better
modularity and testability.

32. **Explain the JVM architecture.**


- Consists of class loader, runtime data areas, execution engine, and native interface.

33. **What are the di erent types of class loaders?**


- Bootstrap, Extension, System/Application, and custom class loaders.

34. **How does the Just-In-Time (JIT) compiler work?**


- Converts bytecode into native machine code at runtime for improved performance.

35. **What are the di erences between Java IO and NIO?**


- IO: Stream-oriented, blocking.
- NIO: Bu er-oriented, non-blocking, more e cient for high-volume data.

36. **Explain the use of bu ers and channels in NIO.**


- Bu ers: Containers for data.
- Channels: Connections to data sources or destinations.

37. **How do you implement serialization and deserialization in Java?**


- Using `Serializable` interface and `ObjectInputStream`/`ObjectOutputStream`.

38. **What are the di erent types of references in Java?**


- Strong, Weak, Soft, and Phantom references.

39. **How does the Java Stream API work, and what are its bene ts?**
- Provides a functional approach to processing sequences of elements, o ering
bene ts like parallel processing and concise code.

40. **What is the di erence between an interface and an abstract class?**


- Same as question 9, interfaces have only abstract methods and constants, whereas
abstract classes can have both abstract and concrete methods.
fi
ff
ff
ff
ff
ff
ff
ff
ffi
fi
ff
PYTHON
1. **How do you handle exceptions in Python?**
- Using `try`, `except`, `else`, and ` nally` blocks.

2. **How do you create a dictionary in Python?**


- Using curly braces `{}` or the `dict()` function.

3. **What is web scraping? How do you perform web scraping in Python?**


- Extracting data from websites. Using libraries like BeautifulSoup, Scrapy, or Selenium.

4. **What is a set in Python? How is it di erent from a list?**


- A collection of unique elements, unordered and unindexed. Lists are ordered and can
contain duplicate elements.

5. **Explain the use of NumPy in Python.**


- Provides support for large multi-dimensional arrays and matrices, along with a
collection of mathematical functions to operate on them.

6. **Explain the di erence between lists and tuples.**


- Lists are mutable, tuples are immutable.

7. **What is the time complexity of basic list operations like `append`, `pop`, etc.?**
- `append`: O(1), `pop`: O(1) for the last element, O(n) for the rst element.

8. **How do you optimize Python code for performance?**


- Using e cient algorithms and data structures, pro ling code with tools like `cPro le`,
and using libraries like NumPy for heavy computations.

9. **Explain the concept of REST APIs. How do you create one in Python?**
- REST APIs use HTTP requests for CRUD operations. Created using frameworks like
Flask or Django REST framework.

10. **What is the di erence between `__init__` and `__new__` methods in Python?**
- `__init__`: Initializes a new instance of a class. `__new__`: Creates a new instance of a
class.
ffi
ff
ff
fi
ff
fi
fi
fi
11. **How do you perform data visualization in Python? Name some libraries.**
- Using libraries like Matplotlib, Seaborn, Plotly, and Bokeh.

12. **What is the purpose of `if __name__ == '__main__'`?**


- To ensure that code block runs only if the script is executed directly, not when
imported as a module.

13. **What are lambda functions? How are they used?**


- Anonymous functions de ned with `lambda` keyword. Used for short, throwaway
functions.

14. **What is Django? Explain its architecture.**


- A high-level web framework for rapid development. Follows MVT (Model-View-
Template) architecture.

15. **Explain the concept of a linked list. How do you implement it in Python?**
- A data structure consisting of nodes, each containing data and a reference to the next
node. Implemented using classes.

16. **What are Python's built-in libraries for data analysis and scienti c computing?**
- NumPy, Pandas, SciPy, and Matplotlib.

17. **What are Python's built-in data structures?**


- Lists, tuples, sets, dictionaries.

18. **What are decorators in Python?**


- Functions that modify the behavior of other functions or methods.

19. **What are Python's built-in data types?**


- int, oat, str, list, tuple, set, dict, bool, NoneType.

20. **Explain the di erence between `is` and `==` operators.**


- `is`: Checks for object identity. `==`: Checks for value equality.
fl
ff
fi
fi
21. **How do you create a virtual environment in Python?**
- Using `venv` module: `python -m venv env_name`.

22. **Explain the use of `super()` function in inheritance.**


- Calls a method from the parent class.

23. **What is Pandas library used for? (Name 5 functions of pandas)**


- Data manipulation and analysis. Functions: `read_csv()`, `DataFrame()`, `merge()`,
`groupby()`, `pivot_table()`.

24. **What are modules and packages in Python?**


- Modules: Single Python les. Packages: Directories of Python modules.

25. **Explain the use of `self` in Python classes.**


- Refers to the instance of the class. Used to access class attributes and methods.

26. **What is a list comprehension? Give an example.**


- Concise way to create lists. Example: `[x for x in range(10) if x % 2 == 0]`.

27. **What are generators in Python? How do they work?**


- Functions that yield items one at a time using `yield` keyword. More memory e cient
for large sequences.

28. **What is TensorFlow? How is it used in Python?**


- Open-source machine learning library. Used for building and training neural networks.

29. **What is Python? What are its key features?**


- A high-level, interpreted language known for its readability and versatility. Key
features: simple syntax, dynamic typing, rich standard library.

30. **What is Flask? How is it di erent from Django?**


- A lightweight web framework. Flask is minimal and exible, whereas Django is full-
featured and follows the "batteries-included" philosophy.
fi
ff
fl
ffi
C++
1. **What is the use of the `inline` keyword in C++?**
- Suggests to the compiler to insert the function's body at the point of call to reduce
function call overhead.

2. **Explain the diamond problem in C++.**


- Occurs in multiple inheritance when two classes inherit from the same base class and
are then inherited by a fourth class, causing ambiguity.

3. **What is a friend function in C++?**


- A function declared with the `friend` keyword inside a class, allowing it to access the
class’s private and protected members.

4. **What is the di erence between `struct` and `class` in C++?**


- By default, `struct` members are public, while `class` members are private.

5. **What is the di erence between `delete` and `delete[]` in C++?**


- `delete` frees memory allocated for a single object, while `delete[]` frees memory
allocated for an array of objects.

6. **What are preprocessor directives in C++?**


- Instructions that are processed by the preprocessor before compilation (e.g.,
`#include`, `#de ne`).

7. **What is the purpose of the `explicit` keyword in C++?**


- Prevents implicit conversions and copy-initialization for constructors.

8. **Explain the concept of "deep copy" and "shallow copy" in C++.**


- Shallow copy: Copies object references. Deep copy: Copies actual data, creating
distinct objects.

9. **What is the use of the `namespace` keyword in C++?**


- De nes a scope to avoid name collisions by grouping related classes, functions, and
variables.
fi
fi
ff
ff
10. **What is a static member in C++?**
- A class member that is shared among all instances of the class and belongs to the
class rather than any object instance.

11. **What is the di erence between `malloc()` and `new` in C++?**


- `malloc()`: Allocates memory without calling constructors. `new`: Allocates memory
and calls constructors.

12. **What is a constructor in C++?**


- A special member function that initializes objects of a class.

13. **Explain the di erences between C and C++.**


- C++ supports object-oriented programming, function overloading, and additional
features like classes, whereas C is procedural.

14. **What is a virtual function in C++?**


- A function declared with the `virtual` keyword to allow derived classes to override it.

15. **What is a template in C++?**


- A feature that allows writing generic and reusable code for functions and classes.

16. **What are access speci ers in C++?**


- Keywords that de ne the access control for class members: `public`, `protected`, and
`private`.

17. **What is a move constructor in C++?**


- A constructor that transfers resources from a temporary object (rvalue) to a new
object.

18. **What is a destructor in C++?**


- A special member function called when an object goes out of scope or is deleted,
used to release resources.
ff
ff
fi
fi
19. **What are the di erences between pointers and references in C++?**
- Pointers can be reassigned and are nullable. References are aliases that must be
initialized when declared and cannot be null.

20. **How is exception handling implemented in C++?**


- Using `try`, `catch`, and `throw` blocks.

21. **What is a class and an object in C++?**


- A class is a blueprint for objects. An object is an instance of a class.

22. **What is the purpose of the `typedef` keyword in C++?**


- Creates an alias for an existing type.

23. **Explain the use of smart pointers in C++.**


- Provides automatic memory management to avoid memory leaks and dangling
pointers, using classes like `std::unique_ptr`, `std::shared_ptr`, and `std::weak_ptr`.

24. **What are virtual destructors in C++?**


- Destructors declared with `virtual` keyword to ensure derived class destructors are
called when an object is deleted through a base class pointer.

25. **What is dynamic memory allocation in C++?**


- Allocating memory at runtime using `new` and `delete`.

26. **What are rvalue references in C++?**


- References that can bind to temporary objects (rvalues) to enable move semantics
and e cient resource management.

27. **What is the purpose of the `std` namespace?**


- Contains all the standard C++ library classes, objects, and functions.

28. **What is the use of the `mutable` keyword in C++?**


- Allows a member of an object to be modi ed even if the object is `const`.
ffi
ff
fi
29. **What is the di erence between stack and heap?**
- Stack: Memory allocation for static storage duration and function calls, with
automatic deallocation. Heap: Dynamic memory allocation, requiring manual deallocation.

30. **What is the signi cance of the `this` pointer in C++?**


- Refers to the current object instance within a class method.

31. **What are the uses of the `const` keyword in C++?**


- To de ne constants, prevent modi cation of variables, specify member functions that
do not modify the object, and ensure parameters are not altered.

32. **Explain memory leaks in C++ and how to avoid them.**


- Memory allocated dynamically but not freed leads to memory leaks. Avoid by properly
using `delete` or smart pointers.

33. **How does C++ handle memory management di erently than Java?**
- C++ requires explicit memory management using `new` and `delete`, while Java uses
automatic garbage collection.

34. **What is a copy constructor in C++?**


- A constructor that creates a new object as a copy of an existing object.

35. **What is the Standard Template Library (STL) in C++?**


- A collection of template classes and functions for data structures and algorithms,
such as vectors, lists, queues, and iterators.
fi
ff
fi
fi
ff

You might also like