Insights from My Experience in the Oracle PFE 2025 Program’s Technical Interview

Insights from My Experience in the Oracle PFE 2025 Program’s Technical Interview

Technical Questions:

1. How to allocate and reallocate memory in C?

  • malloc(size): Allocates uninitialized memory of the specified size.

  • calloc(num, size): Allocates and initializes memory for an array with num elements, each of size bytes.

  • realloc(ptr, size): Resizes previously allocated memory to a new size, preserving existing data if possible.

2. How to free memory in C?

Use the free(ptr) function to release allocated memory. Make sure that ptr points to a memory block allocated by malloc, calloc, or realloc.

3. How does C know how many bytes to free when calling free()?

When memory is allocated using malloc or calloc, the size of the block is stored in a header before the allocated memory. The free() function reads this metadata to figure out the size of the memory block to release.

4. How is C++ different from C?

C++ is an extension of C that includes support for object-oriented programming, stronger type checking, and features like classes, inheritance, polymorphism, and templates. C is procedural and focuses on functions and structured programming.

5. What is the difference between C++ and Java?

  • C++: A compiled language that supports manual memory management and is platform-dependent.

  • Java: Both interpreted and compiled, it features automatic memory management (garbage collection) and is platform-independent because of the JVM.

6. How does the JIT (Just-In-Time) compiler optimize Java code?

The JIT (Just-In-Time) compiler in Java improves performance by converting bytecode into native machine code while the program is running, instead of before it starts. This means code that runs often can be optimized for the specific hardware, making it faster over time. The JIT compiler applies optimizations such as inlining, loop unrolling, and constant folding to speed up execution.

7. What is the new keyword in Java?

The new keyword is used to allocate memory for objects dynamically on the heap.

8. What are the stack, heap, and string pool in Java?

  • Stack: This is the memory area used for method calls, local variables, and function frames.

  • Heap: This is the memory area for objects that are allocated dynamically.

  • String Pool: A section of the heap that stores immutable string literals to save memory.

9. What is the difference between a thread and a process?

A process is an independent program that runs in its own memory space. A thread is the smallest unit within a process and shares memory and resources with other threads in the same process. Threads are lighter than processes, allowing for faster communication and less overhead. However, processes provide better isolation and stability.

10. What are the components of a process?

A process consists of:

  • Code Segment: The executable instructions of the program.

  • Data Segment: Global and static variables.

  • Heap: Dynamically allocated memory.

  • Stack: Function call frames and local variables.

  • Registers: Used by the CPU for processing (e.g., program counter, stack pointer).

  • Threads: Units of execution within the process.

  • File Descriptors: References to files opened by the process.

11. What is a garbage collector in Java?

The garbage collector (GC) automatically frees up memory by removing objects that are no longer used. Memory is divided into:

  • Young Generation: Contains short-lived objects (Eden and Survivor spaces).

  • Old Generation: Contains long-lived objects.

12. What is the Java Memory Model (JMM)?

The Java Memory Model (JMM) is part of the Java specification that defines how threads in a Java program interact with memory. It explains how changes to variables made by one thread become visible to other threads, ensuring consistency in a multi-threaded environment.

Key aspects of the JMM include:

  • Shared Memory Visibility: The JMM ensures that when a thread modifies shared variables, these changes are visible to other threads if the correct synchronization (like synchronized blocks or the volatile keyword) is used.

  • Happens-Before Relationship: This defines the order of operations, ensuring that actions in one thread (like writing to a variable) "happen-before" related actions in another thread (like reading the variable).

  • Thread Safety: The JMM provides rules to prevent issues like race conditions, where threads might read or write shared data inconsistently.

  • Optimization Constraints: While the JMM allows the JVM to optimize code for performance, it ensures these optimizations do not compromise the correctness of a multi-threaded program.

13. Why is a thread called a lightweight process?

A thread is called a lightweight process because it shares the same memory space and resources with other threads in the same process, reducing overhead. Unlike a full process, a thread does not need its own memory allocation, making it more efficient. Threads can be created and switched between more quickly than processes, leading to better performance.

14. What is serialization?

Serialization is the process of converting an object into a byte stream so it can be saved to a file or sent over a network. The reverse process is called deserialization.

15. What is virtual memory?

Virtual memory expands a system's physical memory by using disk space, allowing programs to use more memory than is physically available.

Problem Solving:

Problem 1: Sum of Series

Given two integers n and x, return the sum of the series:

$$S(n, x) = 1 + x^1 + x^2 + \dots + x^n = \sum_{i=0}^{n} x^i$$

  • The time complexity of the optimal solution is O(n).

  • The space complexity is O(1).

Problem 2: Product of Array Except Self

https://leetcode.com/problems/product-of-array-except-self/description/

  • Time Complexity: O(n)O(n)O(n)