Skip to content

Instantly share code, notes, and snippets.

View Alchemik's full-sized avatar

Leszek Jasek Alchemik

View GitHub Profile
@Alchemik
Alchemik / Java Interview.MD
Last active May 27, 2024 18:40
Java Interview

Multithreading, Concurrency and Thread basics Questions

  1. Can we make array volatile in Java? This is one of the tricky Java multi-threading questions you will see in senior Java developer Interview. Yes, you can make an array volatile in Java but only the reference which is pointing to an array, not the whole array. What I mean, if one thread changes the reference variable to points to another array, that will provide a volatile guarantee, but if multiple threads are changing individual array elements they won't be having happens before guarantee provided by the volatile modifier.

  2. Can volatile make a non-atomic operation to atomic? This another good question I love to ask on volatile, mostly as a follow-up of the previous question. This question is also not easy to answer because volatile is not about atomicity, but there are cases where you can use a volatile variable to make the operation atomic.

One example I have seen is having a long field in your class. If you know that a long field is accessed

@Alchemik
Alchemik / Algorithms_2.java
Created September 15, 2016 05:15
Algorithms II
==================== Data Structures ====================
1 Linear
1.1 Arrays
1.2 Linked Lists
1.3 Stack
1.4 Queues
2 Hierarchical
2.1 Binary Tree (O(n) time complexity)
- BFS
- DFS
============================================================================================================
1. Sort:
- Merge Sort
- Quick Sort
- Bucket Sort
- Heap Sort
- Counting Sort
When to use: http://stackoverflow.com/questions/1933759/when-is-each-sorting-algorithm-used
2. Search:
@Alchemik
Alchemik / Git commands.md
Last active February 3, 2018 07:24
Git commands
Notes Git commands
Configure the author name and email address to be used with your commits.Note that Git strips some characters (for example trailing periods) from user.name. git config --global user.name "Sam Smith"
git config --global user.email sam@example.com
Create a new local repository git init
Create a working copy of a local repository: git clone /path/to/repository
For a remote server git clone username@host:/path/to/repository
Add one or more files to staging (index) git add <filename>
git add *

| Description | Command |