Thoughtworks: TR Interview:-Interview Experience 1 - (90 Mins On Zoom, 2 Interviewers)
Thoughtworks: TR Interview:-Interview Experience 1 - (90 Mins On Zoom, 2 Interviewers)
TR Interview :-
Need - Serialization is usually used when the need arises to send your
data over network or stored in files. By data I mean objects and not text.
Now the problem is your Network infrastructure, and your Hard disk are
hardware components that understand bits and bytes but not JAVA
objects. Serialization is the translation of your Java object's values/states
to bytes to send it over network or save it.
How to do – (Don’t focus on code if you don’t want to, only go through
it if you have time)
Step1. Class must implement the interface java.io.Serializable in
order for its object to get serialized.
Step 2. Use write Object() method to save serialized object in file.
Figure 3. Deserialization
Note :- If you call the setDaemon() method after starting the thread, it will
throw IllegalThreadStateException.
9. Threads :- These are light-weight processes within a process.
Thread Priority -> Default priority of main thread is 5. Priority ranges
from 1 to 10.
t.getPriority() -> to get priority of thread t1.
t1.setPriority(3) -> to set priority of thread t1 to 3.
Threads can be created by using two mechanisms :
(i). Extending the Thread class
We create a class that extends the java.lang.Thread class. This class
overrides the run() method available in the Thread class. A thread begins
its life inside run() method.
Output ->
Output ->
Figure 9. Creating thread using lambda function. No need to extend or implement anything to the class.
10. Hashing in Java :- In hashing there is a hash function that maps keys to
some values. But these hashing function may lead to collision that is two
or more keys are mapped to same value.
HashMap ->
HashMap<K, V> is a part of Java’s collection. It stores the data in
(Key, Value) pairs.
It allows to store the null keys, but there should be only one null
key and there can be any number of null values.
It implements Map interface.
It is unsynchronized.
Implementation ->
Working of HashMap – (V. V. Important)
LinkedHashMap -> Keys are maintained by insertion order, i.e. they are
stored, in the order they are inserted. O(1) for lookup and insertion. It may
have one null key and multiple null values.
TreeMap -> Keys are stored in sorted order. It can’t have null keys but can
have multiple null values. So, if you want to sort the keys of a HashMap just
convert it to TreeMap.
filter: The filter method is used to select elements as per condition from
the stream.
forEach: The forEach method is used to iterate through every element of
the stream.