Multithreading Java Interview Questions

 1. What is the start() and run() method of Thread class?

When the start() method is called, a new thread is created and this newly created thread executes the task that is kept in the run() method. One can call the start() method only once.  

When the run() method is called, no new thread is created as in the case of the start() method. This method is executed by the current thread. One can call the run() method multiple times. 

2. What is Thread in java?

3. What are the 2 ways of implementing Thread in java?

4. What is the difference between class lock and Object lock?

Class lock: each and every class has a unique lock usually referred to as a class level lock. These locks are achieved using the keyword ‘static synchronized’ and can be used to make static data thread-safe. It is generally used when one wants to prevent multiple threads from entering a synchronized block.

Object lock: each and every object has a unique lock usually referred to as an object-level lock. These locks are achieved using the keyword ‘synchronized’ and can be used to protect non-static data. It is generally used when one wants to synchronize a non-static method or block so that only the thread will be able to execute the code block on a given instance of the class.  

5. What is Daemon Thread?
daemon threads are basically referred to as a service provider that provides services and support to user threads. There are basically two methods available in thread class for daemon thread: setDaemon() and isDaemon(). 

These threads are referred to as low priority threads, therefore are especially required for supporting background tasks like garbage collection, releasing memory of unused objects, etc. 

6. What are wait() and Sleep() methods?

it is a non-static method that causes the current thread to wait and go to sleep until some other threads call the notify () or notifyAll() method for the object’s monitor (lock). It simply releases the lock and is mostly used for inter-thread communication. It is defined in the object class, and should only be called from a synchronized context.

7. What is difference between notify() and notifyall()?

8. What is Runnable and Callable interface?

9. What are benefits of using Multithreading?

10. What is Thread pool?

11. What is the purpose of Join Method?

12. Explain deadlock?

13. How do Threads Communicate with each other?

14. How to stop thread in java?

15. Explain the different priorities of Threads?

16. What is the primary drawback of Syncronized Methods?

17. What are the different states of a Thread?

18. Is 2 threads can have same name? if yes, How can you identify the same threads?

19. What is the priority of main thread?

20. What is the default priority of a thread?

21. What is Synchronization?

22. Is it possible to make constructors  synchronized? No, 

23. Can we use Synchronized Keyword with variables? no

24. Explain Volatile Variables in java? main memory

25. What is Inter-Thread Communication?

26. What is Context switching?

27. When should we use interrupt a Thread?

28. What is Race-Condition?


NLP - Acadamic Learning Topics

 Natural Learning Processing

Videos Playlist

Part-1

➡️NLP phases:  Link🔗 

Lexical analysis, Syntactic analysis, Semantic analysis, Discourse Integration, Pragmatic Analysis.

➡️Noisy channel model: Wikipedia🔗 : Framework used in spell checkers


➡️Concepts of Parts of Speech and Formal Grammar of Natural Grammar of English: Web Link

Part-2

➡️N-gram model: PPTYT video

➡️Language Models: YT video

➡️Neural Networks: PPT

Part-3

➡️POS tagging: YT Video (rule based, Transformation based, Probablistic based)

➡️Hidden Markov Model: YT video (N-gram: 2 Steps)


Part - 4 

➡️Parsing in NLP: PPT 

➡️Tree Bank: PPT

➡️CKY parsing: YT Video (Also probablistic CKY)


Part - 5 

➡️Vector Semantics: Web

➡️CBOW: GFG

➡️Skip-gram: Web

➡️Wordsense and WordNet: ChatGPT













Best Resources to learn Generative Ai

 

GENERATIVE AI RESOURCES

  1. Generative AI learning path by Google Cloud. A series of 10 courses on generative AI products and technologies, from the fundamentals of Large Language Models to how to create and deploy generative AI solutions on Google Cloud [Link].
  2. Generative AI short courses by DeepLearning.AI - Five short courses on generative AI including LangChain for LLM Application Development, How Diffusion Models Work and more. [Link].
  3. LLM Bootcamp: A series of free lectures by The full Stack on building and deploying LLM apps [Link].
  4. Building AI Products with OpenAI - a free course by CoRise in collaboration with OpenAI [Link].
  5. Free Course by Activeloop on LangChain & Vector Databases in Production [Link].
  6. Pinecone learning center - Lots of free guides as well as complete handbooks on LangChain, vector embeddings etc. by Pinecone [Link].
  7. Build AI Apps with ChatGPT, Dall-E and GPT-4  - a free course on Scrimba [Link].
  8. Gartner Experts Answer the Top Generative AI Questions for Your Enterprise - a report by Gartner [Link]
  9. GPT best practices: A guide by OpenAI that shares strategies and tactics for getting better results from GPTs [Link].
  10. OpenAI cookbook by OpenAI - Examples and guides for using the OpenAI API [Link].
  11. Prompt injection explained, with video, slides, and a transcript from a webinar organized by LangChain [Link].
  12. A detailed guide to Prompt Engineering by DAIR.AI [Link]
  13. What Are Transformer Models and How Do They Work. A tutorial by Cohere AI [Link]
  14. Learn Prompting: an open source course on prompt engineering[Link]

RSA Algorithm

 RSA Algorithm

RSA (Rivest–Shamir–Adleman) is a widely used public-key cryptosystem, meaning it utilizes a pair of mathematically linked keys for encryption and decryption. Here's a deeper look into RSA:

Core Concept:

  • RSA leverages the mathematical difficulty of factoring large prime numbers.
  • It's computationally easy to multiply large prime numbers together, but extremely hard to reverse the process and find the original primes.

Key Generation:

  1. Prime Numbers: Two large, distinct prime numbers (p and q) are chosen as the foundation.
  2. Modulus (n): The product of p and q (n = p * q) becomes the public key's modulus.
  3. Euler's Totient (φ(n)): A mathematical function (Euler's totient) is applied to n, resulting in φ(n).
  4. Public Exponent (e): A public exponent (e) is chosen such that 1 < e < φ(n) and has no common factors with φ(n).
  5. Private Exponent (d): Using a mathematical equation (modular multiplicative inverse), a private exponent (d) is derived that satisfies the equation (e * d) ≡ 1 (mod φ(n)).

Key Distribution:

  • The public key (e, n) is freely distributed. Anyone can encrypt messages using this key.
  • The private key (d, n) is kept confidential. It's used for decryption.

Encryption Process:

  1. Plaintext Conversion: The message (plaintext) is converted into numerical blocks smaller than the modulus (n).
  2. Encryption: Each plaintext block (M) is raised to the power of the public exponent (e) and then modulo n. This creates the ciphertext block (C) using the formula: C = M^e (mod n).

Decryption Process:

  1. Ciphertext Received: The receiver gets the ciphertext block (C).
  2. Decryption: The private exponent (d) is used to decrypt the message. The original block (M) is recovered using the formula: M = C^d (mod n).

Security and Applications:

  • The security of RSA relies on the difficulty of factoring large n. As key sizes increase, so does the difficulty of breaking the encryption.
  • RSA is commonly used for:
    • Secure communication (HTTPS, digital signatures)
    • Secure key exchange for other encryption algorithms
    • Digital signing of documents to ensure authenticity

Limitations:

  • RSA is computationally slower than symmetric algorithms like AES.
  • It's not ideal for encrypting large amounts of data directly. It's often used to encrypt smaller chunks like keys for symmetric encryption.

Overall, RSA remains a cornerstone of public-key cryptography, providing secure communication and digital signatures for various applications.

Columnar Transposition

 Columnar Transposition

The columnar transposition cipher is a classic technique for encryption that relies on rearranging the letters of the message, not substituting them. Here's a breakdown of the algorithm:

Encryption Process:

  1. Key Selection: Choose a keyword. The length of the keyword determines the number of columns used in the encryption process.
  2. Message Preparation: Write the plaintext message out in rows, with the number of rows determined by the length of the longest word (including spaces or punctuation) if needed. You can add padding characters (e.g., "X") to fill in any incomplete rows.
  3. Column Labeling: Write the chosen keyword letters at the top of each column, following the alphabetical order of the letters in the keyword (repeating if necessary).
  4. Columnar Transposition: Read the message down each column and write the letters out in a new sequence, following the order defined by the keyword at the top.

Example:

  • Plaintext: "Meet me at the park tomorrow night"
  • Keyword: "LOVE" (alphabetical order: "ELOV")

Steps:

  1. Plaintext (9 characters, needs padding with "X"): "Meet me a_X_X_X_X night" (6 rows)
  2. Columns labeled with "ELOV" (repeated)
  3. Transposed message: "MXaete_ nXhight Xlroooa_"

Decryption Process:

  1. Keyword and Columns: Use the same keyword to define the column order.
  2. Message Segmentation: Write the ciphertext into a grid matching the number of columns (based on the keyword).
  3. Columnar Reading: Read each column from top to bottom, and concatenate the resulting rows to get the original message.

In the above example:

  1. Keyword: "LOVE" (repeated)
  2. Ciphertext grid:
    M X a e t e _ 
    n X h i g h t 
    X l r o o o a _
    
  3. Decrypted message: "Meet me at_the park tomorrow night" (remove padding)

Security and Applications:

  • The security of the columnar transposition cipher relies on the secrecy of the keyword. A longer and more complex keyword makes it harder to crack the code.
  • However, with techniques like frequency analysis and knowledge of the language, the cipher can be vulnerable, especially for short keywords.
  • Historically, columnar transpositions were used for simple military communication.
  • In modern cryptography, it's considered a weak encryption method due to its limitations.

Additional Notes:

  • There are variations of the columnar transposition cipher, such as double columnar transposition where the message is encrypted twice using different keywords for added complexity.
  • While not a secure standalone method, the concept of columnar transposition can be combined with other encryption techniques for more robust security.

Popular Post

MindMaps

Featured post

Question 1: Reverse Words in a String III

  def reverseWords(s: str) -> str: words = s.split() return ' '.join(word[::-1] for word in words)